Você está na página 1de 30

AP7-AA4-Ev1-Desarrollo de Aplicaciones Windows con C# y Visual Studio .

NET

Juan Fernando Gutiérrez Agudelo

Servicio Nacional de Aprendizaje SENA


Análisis y Desarrollo de Sistemas de Información
2018
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TiendaNaturistaNaturVida
{
public partial class frmPrincipal : Form
{
public frmPrincipal()
{
InitializeComponent();
int a;
int b;
int c;
}

private void frmPrincipal_Load(object sender, EventArgs e)


{

private void menuPrincipalToolStripMenuItem1_Click(object sender, EventArgs


e)
{

private void clientesToolStripMenuItem_Click(object sender, EventArgs e)


{
Clientes a = new Clientes();
a.Show();
}

private void productosToolStripMenuItem_Click(object sender, EventArgs e)


{
Productos b = new Productos();
b.Show();
}

private void ventasToolStripMenuItem_Click(object sender, EventArgs e)


{
Ventas c = new Ventas();
c.Show();

}
}
}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;
namespace TiendaNaturistaNaturVida

public partial class Clientes : Formagregarcliete c = new agregarcliete();

public Clientes()

InitializeComponent();

private void Clientes_Load(object sender, EventArgs e)

agregarcliete sql = new agregarcliete();

private void button1_Click(object sender, EventArgs e)

if (sql.Insertar(textBox1.Text, textBox2.Text, textBox3.Text,

textBox4.Text, textBox5.Text) == true)

MessageBox.Show("datos insertados");

this.Refresh();

textBox1.Clear();

textBox2.Clear();

textBox3.Clear();

textBox4.Clear();

textBox5.Clear();

this.Hide();

else {

MessageBox.Show("datos no insertados"); }

}
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace TiendaNaturistaNaturVida

public partial class Clientes : Form

agregarcliete c = new agregarcliete();

public Clientes()

InitializeComponent();

private void Clientes_Load(object sender, EventArgs e)

agregarcliete sql = new agregarcliete();

private void button1_Click(object sender, EventArgs e)

if (sql.Insertar(textBox1.Text, textBox2.Text, textBox3.Text,

textBox4.Text, textBox5.Text) == true)

MessageBox.Show("datos insertados");

this.Refresh();

textBox1.Clear();

textBox2.Clear();

textBox3.Clear();
textBox4.Clear();

textBox5.Clear();

this.Hide();

else {

MessageBox.Show("datos no insertados"); }

Agregar Cliente

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;

using System.Windows.Forms;

namespace WindowsFormsApplication1

class agregarcliente

private SqlConnection conexion = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

private DataSet ds;

public bool Insertar(string idcliente, string nomcliente, string telcliente,

string telcliente ,string correocliente)

conexion.Open();

SqlCommand cmd = new SqlCommand(string.Format("insert into cliente

values ({0}, '{1}', '{2}', '{3}', '{4}')," new string[] { idcliente, nomcliente,
dircliente, telcliente, correocliente }), conexion);

int filasafectadas = cmd.ExecuteNonQuery();

conexion.Close();

if (filasafectadas > 0) return true;

else return false;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;
using System.Data.SqlClient;

using System.Data;

namespace WindowsFormsApplication1

public partial class Form3 : Form

combobox combo = new combobox();

agregarproducto c = new agregarproducto();

public Form3()

InitializeComponent();

combo.Seleccionar(cob:comboBox2);

combo cb = new combo();

cb.llenaritems(comboBox1);

private void tabPage2_Click(object sender, EventArgs e)

private void tabPage1_Click(object sender, EventArgs e)

private void textBox3_TextChanged(object sender, EventArgs e)

private void tabPage3_Click(object sender, EventArgs e)

private void tabPage4_Click(object sender, EventArgs e)

private void button1_Click(object sender, EventArgs e)

{
if (sql.Insertar(idproducto.Text, desproducto.Text, valorproducto.Text,

cantidadproducto.Text) == true)

MessageBox.Show("datos insertados");

this.Refresh();

idproducto.Clear();

desproducto.Clear();

valorproducto.Clear();

cantidadproducto.Clear();

this.Hide();

}else

MessageBox.Show("datos no insertados");

private void Form3_Load(object sender, EventArgs e)

combo cb = new combo();

cb.llenaritems(ComboProductoEliminar);

agregarproducto sql = new agregarproducto();

private void dataGridView1_CellContentClick(object sender,

DataGridViewCellEventArgs e)

private void textBox1_TextChanged(object sender, EventArgs e)

private void comboBox2_SelectedIndexChangedo(bject sender, EventArgs e)

if (comboBox2.SelectedIndex > 0)

{
string[] valores = combo.captar_info(comboBox2.Text);

textBox7.Text = valores[0];

textBox6.Text = valores[1];

textBox5.Text = valores[2];

private void button3_Click(object sender, EventArgs e)

private void comboBox1_SelectedIndexChangedo(bject sender, EventArgs e)

SqlConnection conexen = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

conexen.Open();

SqlCommand cmd = conexen.CreateCommand();

cmd.CommandType = CommandType.Text;

cmd.CommandText = "select * from productosT where proDescripcion like

('" + comboBox1.Text + "%')";

cmd.ExecuteNonQuery();

DataTable dt = new DataTable();

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(dt);

dgv.DataSource = dt;

conexen.Close();

private void comboBox3_SelectedIndexChangedo(bject sender, EventArgs e)

if (ComboProductoEliminar.SelectedIndex > 0)

string[] valores = combo.captar_info(ComboProductoEliminar.Text);

codProductoSeleccionado.Text = valores[0];

}
}

private void button6_Click(object sender, EventArgs e)

if (sql.actualizar(textBox7.Text, comboBox2.Text, textBox6.Text,

textBox5.Text))

MessageBox.Show("Datos Actualizado");

this.Hide();

else MessageBox.Show("Datos No Actualizados");

private void button5_Click(object sender, EventArgs e)

if (sql.eliminar(codProductoSeleccionado.Text))

MessageBox.Show("Datos Eliminados");

this.Hide();

else MessageBox.Show("Datos No Eliminados");

Agregar Producto

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;

using System.Windows.Forms;
namespace WindowsFormsApplication1

class agregarproducto

private SqlConnection conexion = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

private DataSet ds;

public DataTable mostrardatos()

conexion.Open();

SqlCommand cmd = new SqlCommand("select * from productosT", conexion);

SqlDataAdapter ad = new SqlDataAdapter(cmd);

ds = new DataSet();

acdo.nFeixlilo(nd.sC,lo"stea(b)l;a");

return ds.Tables["tabla"];

public bool Insertar(string proCodigo, string proDescripcion, string

proValor, string proCantidad)

conexion.Open();

SqlCommand cmd = new SqlCommand(string.Format("insert into producto

values ({0}, '{1}', '{2}', '{3}')", new string[] { proCodigo, proDescripcion,

proValor, proCantidad }), conexion);

int filasafectadas = cmd.ExecuteNonQuery();

conexion.Close();

if (filasafectadas > 0) return true;

else return false;

public bool actualizar(string idproducto, string desproducto, string

valorproducto, string cantidadproducto)

conexion.Open();
SqlCommand cmd = new SqlCommand(string.Format("update producto set

desproducto = '{0}', valorproducto = '{1}', cantidadproducto = '{2}' where


idproducto =

{3}", new string[] { desproducto, valorproducto, cantidadproducto, idproducto}),


conexion);

int filasafectadas = cmd.ExecuteNonQuery();

conexion.Close();

if (filasafectadas > 0) return true;

else return false;

public DataTable Buscar(string proDescripcion)

conexion.Open();

SqlCommand cmd = new SqlCommand(string.Format("select * from producto

where desproducto = '{1}'", desproducto), conexion);

SqlDataAdapter ad = new SqlDataAdapter(cmd);

ds = new DataSet();

ad.Fill(ds, "tabla");

conexion.Close();

return ds.Tables["tabla"];

public bool eliminar(string proCodigo)

conexion.Open();

SqlCommand cmd = new SqlCommand(string.Format("delete from producto

where idproducto = {0}",idproducto), conexion);

int filasafectadas = cmd.ExecuteNonQuery();

conexion.Close();

if (filasafectadas > 0) return true;

else return false;

}
using System;

using System.Collections.Generic;
using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace WindowsFormsApplication1

public partial class Form4 : Form

facturacombo combo = new facturacombo();

agregarproducto c = new agregarproducto();

double val;

double cant;

decimal resultado;

public Form4()

InitializeComponent();

combo.Seleccionar(cob: listaCli);

combo.SeleccionarProducto(cob: listaPro);

combo cb = new combo();

cb.Users(username);

public SqlConnection conex = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

private void label2_Click(object sender, EventArgs e)

private void comboBox1_SelectedIndexChangedo(bject sender, EventArgs e)

if (listaPro.SelectedIndex > 0)
{

string[] valores = combo.captar_productos(listaPro.Text);

CodPro.Text = valores[0];

Valor.Text = valores[1];

private void Agregarpro_Click(object sender, EventArgs e)

val = Convert.ToDouble(Valor.Text);

cant = Convert.ToDouble(cantidad.Text);

resultado = Convert.ToDecimal(val * cant);

suma.Text = resultado.ToString();

DataGridViewRow fila = new DataGridViewRow();

fila.CreateCells(dgv);

fila.Cells[0].Value = fecha.Text;

fila.Cells[1].Value = documento.Text;

fila.Cells[2].Value = suma.Text;

fila.Cells[3].Value = username.Text;

ffiillaa..CCeellllss[[45]]..VVaalluuee == fCaocdtPurroa..TTeexxtt;;

fila.Cells[6].Value = cantidad.Text;

dgv.Rows.Add(fila);

fecha.Text = "";

cantidad.Text = "";

listaPro.Text = "";

CodPro.Text = "";

listaPro.ResetText();

decimal total = 0;

foreach (DataGridViewRow Row in dgv.Rows)

total += Convert.ToDecimal(Row.Cells["colum4"].Value);

valortotal.Text = Convert.ToString(total);
}

private void Form4_Load(object sender, EventArgs e)

dgv.AllowUserToAddRows = false;

private void textBox3_TextChanged(object sender, EventArgs e)

private void listaCli_SelectedIndexChanged(object sender, EventArgs e)

if (listaCli.SelectedIndex > 0)

string[] valores = combo.captar_info(listaCli.Text);

documento.Text = valores[0];

direccion.Text = valores[1];

telefono.Text = valores[2];

correo.Text = valores[3];

private void button2_Click(object sender, EventArgs e)

string consultar=("select * from facturas where facNumero = '"+

factura.Text + "'");

if(string.IsNullOrWhiteSpace(factura.Text))

MessageBox.Show("error");

else

if (consultar == factura.Text)

{ MessageBox.Show("Esta factura ya existe");

}
else

try

foreach(DataGridViewRow Row in dgv.Rows)

SqlCommand agregar = new SqlCommand("insert into facturas

values (@facNumero, @facFecha, @facCliente, @facValortotal, @facVendedor,)"conex);

conex.Open();

agregar.Parameters.Clear();

agregar.Parameters.AddWithValue("@idfactura",

Convert.ToString(factura.Text));

agregar.Parameters.AddWithValue("@fechafactura",

Convert.ToString(Row.Cells["colum2"].Value));

agregar.Parameters.AddWithValue("@idclientefactura",

Convert.ToString(Row.Cells["colum3"].Value));

agregar.Parameters.AddWithValue("@valorfactura",

Convert.ToString(valortotal.Text));

agregar.ExecuteNonQuery();

catch

finally

try

SqlCommand agregarPro = new SqlCommand("insert into factura


values (@idfactura, @idprodcutofactura, @cantidadfactura)," conex);

foreach (DataGridViewRow Row in dgv.Rows)

agregarPro.Parameters.Clear();

agregarPro.Parameters.AddWithValue("@idfactura",

Convert.ToString(Row.Cells["Column6"].Value));

agregarPro.Parameters.AddWithValue("@idproductoffactura",

Convert.ToInt32(Row.Cells["Column7"].Value));

Convert.ToInt32(Row.aCgerlelgsa["rCPorlou.mPna8r"a]m.eVtaelruse.)A)d;dWithValue("@fa
cCantidad",

agregarPro.ExecuteNonQuery();

MessageBox.Show("Datos agregados");

catch (Exception ex)

MessageBox.Show("Error al guardar"+ex);

finally

conex.Close();

private void Quitarproduc_Click_1(object sender, EventArgs e)

dgv.Rows.Remove(dgv.CurrentRow);

private void valortotal_TextChanged(object sender, EventArgs e)

private void button1_Click(object sender, EventArgs e)

}
}

Factura

using SSyysstteemm;.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Sql;

using System.Data;

using System.Data.SqlClient;

using System.Windows.Forms;

namespace WindowsFormsApplication1

class agregarfactura

private SqlConnection conexion = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

private DataSet ds;

public DataTable mostrardatos() {

conexion.Open();

SqlCommand cmd = new SqlCommand("select * from factura", conexion);

SqlDataAdapter ad = new SqlDataAdapter(cmd);

ds = new DataSet();

ad.Fill(ds, "tabla");

conexion.Close();

return ds.Tables["tabla"];

public bool ConsecutivoFactura(string idfactura, string fechafactura, string

idclientefactura, string valorfactura)

conexion.Open();

SqlCommand cmd = new SqlCommand(string.Format("insert into factura


values ({0}, '{1}', '{2}', '{3}')," new string[] { idfactura, fechafactura,

idclientefactura, valorfactura}), conexion);

int filasafectadas = cmd.ExecuteNonQuery();

conexion.Close();

if (filasafectadas > 0) return true;

else return false;

public bool FacturaDetalle(string facNumero, string facProducto, string

FacCantidad)

conexion.Open();

SqlCommand cmd = new SqlCommand(string.Format("insert into productosT

values ({0}, '{1}', '{2}')", new string[] { idfactura, idproductofactura,


cantidadfactura}),

conexion);

int filasafectadas = cmd.ExecuteNonQuery();

conexion.Close();

if (filasafectadas > 0) return true;

else return false;

Conexión de la Base de datos

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.SqlClient;

namespace WindowsFormsApplication1

class conexion

{
public string cadenaconexion;

protected string sql;

protected int resultado;

protected SqlConnection cnn;

protected SqlCommand comandosql;

protected string mensajes;

public conexion()

this.cadenaconexion = (@"Data Source=.;Initial Catalog =facturacion;

integrated security=true");

this.cnn = new SqlConnection(this.cadenaconexion);

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data;

using System.Data.SqlClient;

using System.Windows.Forms;

namespace WindowsFormsApplication1

class combo

SqlCommand cmd;

SqlConnection cnn;

SqlDataReader dr;

public combo()
{

try

cnn = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

cnn.Open();

catch (Exception ex)

public void llenaritems(ComboBox cb)

try

SqlDataReader dr;

cmd = new SqlCommand("select proDescripcion from producto," cnn);

dr = cmd.ExecuteReader();

while (dr.Read())

cb.Items.Add(dr["desproducto"].ToString());

catch (Exception ex)

p{ublic void Users(ComboBox cb)

try

SqlDataReader dr;

cmd = new SqlCommand("select venUsuario from vendedores," cnn);


dr = cmd.ExecuteReader();

while (dr.Read())

cb.Items.Add(dr["venUsuario"].ToString());

catch (Exception ex)

} }

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace WindowsFormsApplication1

class combobox

SqlConnection con = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

public void Seleccionar(ComboBox cob)

cob.Items.Clear();

con.Open();

SqlCommand cmd = new SqlCommand("select * from producto", con);

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())

{
cob.Items.Add(dr[1].ToString());

con.Close();

cob.Items.Insert(0, "---seleccione un Item- ");

cob.SelectedIndex = 0;

public string[] captar_info(string proDescripcion)

con.Open();

proDescripciSoqnl=C'o"m+manpdrocDmedsc=rinpecwioSnql+C"o'm"m,ancd(o"ns)e;lect * from
productosT where

SqlDataReader dr = cmd.ExecuteReader();

string[] resultado = null;

while (dr.Read())

string[] valores =

dr[0].ToString(),

dr[2].ToString(),

dr[3].ToString(),

};

resultado = valores;

con.Close();

return resultado;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data;
using System.Data.SqlClient;

using System.Windows.Forms;

namespace WindowsFormsApplication1

class facturacombo

SqlConnection con = new SqlConnection("Data Source=.;Initial

Catalog=facturacion;Integrated Security=True)";

public void Seleccionar(ComboBox cob)

cob.Items.Clear();

con.Open();

SqlCommand cmd = new SqlCommand("select * from cliente", con);

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())

cob.Items.Add(dr[1].ToString());

con.Close();

cob.Items.Insert(0, "---Seleccione a el Cliente- ");

cob.SelectedIndex = 0;

public string[] captar_info(string proDescripcion)

cSoqlnC.oOmpemnan()d;cmd = new SqlCommand("select * from cliente where

cliNombre='" + proDescripcion + "'", con);

SqlDataReader dr = cmd.ExecuteReader();

string[] resultado = null;

while (dr.Read())

string[] valores =

{
dr[0].ToString(),

dr[2].ToString(),

dr[3].ToString(),

dr[4].ToString(),

};

resultado = valores;

}con.Close();

return resultado;

public void SeleccionarProducto(ComboBox cob)

cob.Items.Clear();

con.Open();

SqlCommand cmd = new SqlCommand("select * from producto", con);

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())

cob.Items.Add(dr[1].ToString());

con.Close();

cob.Items.Insert(0, "---Seleccione un producto- ");

cob.SelectedIndex = 0;

public string[] captar_productos(string Descripcion)

con.Open();

SqlCommand cmd = new SqlCommand("select * from producto where

desproducto='" + Descripcion + "'", con);

SqlDataReader dr = cmd.ExecuteReader();

string[] resultado = null;

while (dr.Read())

{
string[] valores =

dr[0].ToString(),

dr[2].ToString(),

dr[3].ToString(),

};

resultado = valores;

con.Close();

return resultado;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Windows.Forms;

namespace WindowsFormsApplication1

static class Program

{ /// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

Você também pode gostar