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



Comments



Description

AP7-AA4-Ev1-Desarrollo de aplicaciones Windows con C# y Visual Studio .NET Jorge Armando Guerrero Torres Servicio Nacional de Aprendizaje SENA Centro de Teleinformática y Producción Industrial Bogotá D.C Análisis y Desarrollo de Sistemas de Información 2017 USUARIO: Admin CONTRASEÑA: Admin using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Windows.Forms; namespace WindowsFormsApplication1 { class usuarios:conexion { private string usuario; private string contrasena; public usuarios() { usuario = string.Empty; contrasena = string.Empty; this.sql = string.Empty; } public string Usuario { get {return this.usuario;} set {this.usuario = value;} } public string Contrasena { get {return this.contrasena;} set {this.contrasena = value;} } public bool Buscar() { bool resultado = false; this.sql = string.Format(@"SELECT venUsuario FROM vendedores WHERE venUsuario ='{0}' AND venContrasena ='{1}'",this.usuario, this.contrasena); this.comandosql = new SqlCommand(this.sql,this.cnn); this.cnn.Open(); SqlDataReader reg = null; reg = this.comandosql.ExecuteReader(); if (reg.Read()) { resultado = true; mensajes= "Bienvenido datos correctos"; } else { mensajes = "Datos incorrectos"; } this.cnn.Close(); return resultado; } } } 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 WindowsFormsApplication1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); int a; int b; int c; } private void Form2_Load(object sender, EventArgs e) { } private void prodcuctosToolStripMenuItem_Click( object sender, EventArgs e) { Form3 a = new Form3(); a.Show(); } private void facturarToolStripMenuItem_Click(object sender, EventArgs e) { Form4 b = new Form4(); b.Show(); } private void inventarioToolStripMenuItem_Click( { object sender, EventArgs e) Form5 c = new Form5(); c.Show(); } private void clientesToolStripMenuItem_Click(object sender, EventArgs e) { Clientes c = new Clientes(); 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; 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(proCodigo.Text, proDescripcion.Text, proValor.Text, proCantidad.Text) == true) { MessageBox.Show("datos insertados"); this.Refresh(); proCodigo.Clear(); proDescripcion.Clear(); proValor.Clear(); proCantidad.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_SelectedIndexChanged(object 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_SelectedIndexChanged(object 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_SelectedIndexChanged(object 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"); } } } 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_SelectedIndexChanged(object 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; fila.Cells[4].Value = fila.Cells[5].Value factura.Text; = CodPro.Text; 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("@facNumero", Convert.ToString(factura.Text)); agregar.Parameters.AddWithValue("@facFecha", Convert.ToString(Row.Cells["colum2"].Value)); agregar.Parameters.AddWithValue("@facCliente", Convert.ToString(Row.Cells["colum3"].Value)); agregar.Parameters.AddWithValue("@facValortotal", Convert.ToString(valortotal.Text)); agregar.Parameters.AddWithValue("@facVendedor", Convert.ToString(Row.Cells["colum5"].Value)); agregar.ExecuteNonQuery(); } } catch { } finally { } } } try { SqlCommand agregarPro = new SqlCommand("insert into facturadetalleT values (@facNumero, @facProducto, @facCantidad)", conex); foreach (DataGridViewRow Row in dgv.Rows) { agregarPro.Parameters.Clear(); agregarPro.Parameters.AddWithValue("@facNumero", Convert.ToString(Row.Cells["Column6"].Value)); agregarPro.Parameters.AddWithValue("@facProducto", Convert.ToInt32(Row.Cells["Column7"].Value)); agregarPro.Parameters.AddWithValue("@facCantidad", Convert.ToInt32(Row.Cells["Column8"].Value)); 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) { } } } 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 Form5 : Form { combobox combo = new combobox(); agregarproducto sql = new agregarproducto(); public Form5() { InitializeComponent(); combo cb = new combo(); cb.llenaritems(comboBox2); } private void Form5_Load(object sender, EventArgs e) { } private void comboBox2_SelectedIndexChanged_1(object sender, EventArgs e) { SqlConnection conex = new SqlConnection("Data Source=.;Initial Catalog=facturacion;Integrated Security=True"); conex.Open(); SqlCommand cmd = conex.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText ('" + comboBox2.Text = "select * from productosT where proDescripcion like + "%')"; cmd.ExecuteNonQuery(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgv.DataSource = dt; conex.Close(); } } } 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 WindowsFormsApplication1 { public partial class Clientes : Form { agregarcliente c = new agregarcliente(); public Clientes() { InitializeComponent(); } private void Clientes_Load(object sender, EventArgs e) { } agregarcliente sql = new agregarcliente(); 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"); } } } } CODIGO UTILIZADO PARA LAS FUNCIONES CONEXIÓN CON 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); } } } USUARIOS: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Windows.Forms; namespace WindowsFormsApplication1 { class usuarios:conexion { private string usuario; private string contrasena; public usuarios() { usuario = string.Empty; contrasena = string.Empty; this.sql = string.Empty; } public string Usuario { get {return this.usuario;} set {this.usuario = value;} } public string Contrasena { get {this.contrasena set {return this.contrasena;} = value;} } public bool Buscar() { bool resultado = false; this.sql = string.Format(@"SELECT venUsuario FROM vendedores WHERE venUsuario ='{0}' AND venContrasena ='{1}'",this.usuario, this.contrasena); this.comandosql = new SqlCommand(this.sql,this.cnn); this.cnn.Open(); SqlDataReader reg = null; reg = this.comandosql.ExecuteReader(); if (reg.Read()) { resultado = mensajes= true; "Bienvenido datos correctos"; } else { mensajes = "Datos incorrectos"; } this.cnn.Close(); return resultado; } } } 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(); ad.Fill(ds, "tabla"); conexion.Close(); 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 productosT 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 proCodigo, string proDescripcion, string proValor, string proCantidad) { conexion.Open(); SqlCommand cmd = new SqlCommand(string.Format("update productosT set proDescripcion = '{0}', proValor = '{1}', proCantidad = '{2}' where proCodigo = {3}", new string[] { proDescripcion, proValor, proCantidad, proCodigo}), 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 productosT where proDescripcion = '{1}'", proDescripcion), 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 productosT where proCodigo = {0}",proCodigo), conexion); int filasafectadas = cmd.ExecuteNonQuery(); conexion.Close(); if (filasafectadas > 0) return true; else return false; } } } 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 cliDocumento, string cliNombre, string cliDireccion, string cliTelefono,string cliCorreo) { conexion.Open(); SqlCommand cmd = new SqlCommand(string.Format("insert into clientes values ({0}, '{1}', '{2}', '{3}', '{4}')", new string[] { cliDocumento, cliNombre, cliDireccion, cliTelefono, cliCorreo }), conexion); int filasafectadas = cmd.ExecuteNonQuery(); conexion.Close(); if (filasafectadas > 0) return true; else return false; } } } AGREGAR FACTURA 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 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 facturas", conexion); SqlDataAdapter ad = new SqlDataAdapter(cmd); ds = new DataSet(); ad.Fill(ds, "tabla"); conexion.Close(); return ds.Tables["tabla"]; } public bool ConsecutivoFactura(string facNumero, string facFecha, string facCliente, string facValortotal, string facVendedor) { conexion.Open(); SqlCommand cmd = new SqlCommand(string.Format("insert into facturas values ({0}, '{1}', '{2}', '{3}','{4}')", new string[] { facNumero, facFecha, facCliente, facValortotal, facVendedor }), 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[] { facNumero, facProducto, FacCantidad}), conexion); int filasafectadas = cmd.ExecuteNonQuery(); conexion.Close(); if (filasafectadas > 0) return true; else return false; } } } DEMAS CODIGO UTILIZADO 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 productosT" , cnn); dr = cmd.ExecuteReader(); while (dr.Read()) { cb.Items.Add(dr["proDescripcion"].ToString()); } } catch (Exception ex) { } } public 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 productosT", 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(); SqlCommand proDescripcion='" cmd = new SqlCommand("select + proDescripcion + "'", con); * 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 clientes", 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) { con.Open(); SqlCommand cmd = new SqlCommand("select * from clientes 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 productosT", 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 productosT where proDescripcion='" + 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()); } } }
Copyright © 2024 DOKUMEN.SITE Inc.