public List <Pojos.clsVariables> llenar() { List <Pojos.clsVariables> lstProd = new List <Pojos.clsVariables>(); string sql; MySqlCommand cm = new MySqlCommand(); MySqlDataReader dr; Conectar(); sql = "select p.codigo as CLAVE, p.nombre AS PRODUCTO, p.marca AS MARCA, c.nombre as CATEGORIA , p.precio AS PRECIO, p.cantidad AS CANTIDAD, p.color_sabor AS COLOR_SABOR from productos p join categorias c on p.categoria = c.id;"; cm.CommandText = sql; cm.CommandType = CommandType.Text; cm.Connection = cnConexion; dr = cm.ExecuteReader(); while (dr.Read()) { Pojos.clsVariables objValores = new Pojos.clsVariables(); objValores.CODIGO = dr.GetString("CLAVE"); objValores.NOMBRE = dr.GetString("PRODUCTO"); objValores.MARCA = dr.GetString("MARCA"); objValores.CATEGORIA = dr.GetString("CATEGORIA"); objValores.PRECIO = dr.GetDouble("PRECIO"); objValores.CANTIDAD = dr.GetInt32("CANTIDAD"); objValores.COLOR_SABOR = dr.GetString("COLOR_SABOR"); lstProd.Add(objValores); } Cerrar(); return(lstProd); }
private void button1_Click(object sender, EventArgs e) { Vista.Principal obj = new Vista.Principal(); Pojos.clsVariables objVariables = new Pojos.clsVariables(); Datos.clsConexion objConexion = new Datos.clsConexion(); objVariables.NOMBRE = txtNombre.Text; objVariables.CODIGO = txtCodigo.Text; objVariables.CATEGORIA = cmbCategoria.Text; objVariables.CANTIDAD = Int32.Parse(txtCantiadad.Text); objVariables.COLOR_SABOR = txtcolorSabor.Text; objVariables.PRECIO = Int32.Parse(txtPrecio.Text); objVariables.MARCA = txtMarca.Text; objConexion.BuscarPro(objVariables); if ("1" == objVariables.CODIGO) { objVariables.CODIGO = txtCodigo.Text; objConexion.editar(objVariables); MessageBox.Show("Medicamento Modificado", "Editar", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); obj.llenarT(); } else { MessageBox.Show("El codogo no se puede editar"); } }
private void btnEditar_Click(object sender, EventArgs e) { Vista.EditarProductos obj = new Vista.EditarProductos(); Pojos.clsVariables objVariables = new Pojos.clsVariables(); Datos.clsConexion objConexion = new Datos.clsConexion(); try { objVariables.CODIGO = dtgDatos.CurrentRow.Cells[0].Value.ToString(); objVariables.NOMBRE = dtgDatos.CurrentRow.Cells[1].Value.ToString(); objVariables.MARCA = dtgDatos.CurrentRow.Cells[2].Value.ToString(); objVariables.CATEGORIA = dtgDatos.CurrentRow.Cells[3].Value.ToString(); objVariables.PRECIO = Int32.Parse(dtgDatos.CurrentRow.Cells[4].Value.ToString()); objVariables.CANTIDAD = Int32.Parse(dtgDatos.CurrentRow.Cells[5].Value.ToString()); objVariables.COLOR_SABOR = dtgDatos.CurrentRow.Cells[6].Value.ToString(); obj.txtNombre.Text = objVariables.NOMBRE; obj.txtCodigo.Text = objVariables.CODIGO; obj.txtMarca.Text = objVariables.MARCA; //obj.txtCategoria.Text = objVariables.CATEGORIA; obj.txtPrecio.Text = objVariables.PRECIO + ""; obj.txtCantiadad.Text = objVariables.CANTIDAD + ""; obj.txtcolorSabor.Text = objVariables.COLOR_SABOR; obj.Show(); //this.Hide(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void EliminarPro(Pojos.clsVariables objValores) { string sql; MySqlCommand cm; Conectar(); cm = new MySqlCommand(); sql = "DELETE FROM productos WHERE codigo = '" + objValores.CODIGO + "'"; cm.CommandText = sql; cm.CommandType = CommandType.Text; cm.Connection = cnConexion; cm.ExecuteNonQuery(); Cerrar(); }
public void editar(Pojos.clsVariables objValores) { Conectar(); MySqlCommand cm = new MySqlCommand("EditarProducto", cnConexion); cm.Parameters.AddWithValue("@codi", objValores.CODIGO); cm.Parameters.AddWithValue("@nombre", objValores.NOMBRE); cm.Parameters.AddWithValue("@marca", objValores.MARCA); cm.Parameters.AddWithValue("@categoria", objValores.CATEGORIA); cm.Parameters.AddWithValue("@precio", objValores.PRECIO); cm.Parameters.AddWithValue("@cantidad", objValores.CANTIDAD); cm.Parameters.AddWithValue("@color_sabor", objValores.COLOR_SABOR); cm.CommandType = CommandType.StoredProcedure; cm.ExecuteNonQuery(); Cerrar(); }
private void button1_Click(object sender, EventArgs e) { Pojos.clsVariables objVariables = new Pojos.clsVariables(); Datos.clsConexion objConexion = new Datos.clsConexion(); objVariables.NOMBRE = txtNombre.Text; objVariables.CODIGO = txtCodigo.Text; objVariables.MARCA = txtMarca.Text; objVariables.CANTIDAD = Int32.Parse(txtCantidad.Text); objVariables.CATEGORIA = cmbCategoria.Text; objVariables.COLOR_SABOR = txtcolorSabor.Text; objVariables.PRECIO = Int32.Parse(txtPrecio.Text); objConexion.AgregarPro(objVariables); MessageBox.Show("Producto Registrado", "Agregar", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void BuscarPro(Pojos.clsVariables objValores) { string sql; MySqlCommand cm; MySqlDataReader dr; Conectar(); cm = new MySqlCommand(); sql = "SELECT * FROM productos WHERE " + objValores.CODIGO + "=codigo"; cm.CommandText = sql; cm.CommandType = CommandType.Text; cm.Connection = cnConexion; cm.ExecuteNonQuery(); dr = cm.ExecuteReader(); while (dr.Read()) { objValores.CODIGO = "1"; } Cerrar(); }
public void AgregarPro(Pojos.clsVariables objValores) { string sql; MySqlCommand cm; Conectar(); cm = new MySqlCommand(); cm.Parameters.AddWithValue("@codigo", objValores.CODIGO); cm.Parameters.AddWithValue("@nombre", objValores.NOMBRE); cm.Parameters.AddWithValue("@marca", objValores.MARCA); cm.Parameters.AddWithValue("@categoria", objValores.CATEGORIA); cm.Parameters.AddWithValue("@precio", objValores.PRECIO); cm.Parameters.AddWithValue("@cantidad", objValores.CANTIDAD); cm.Parameters.AddWithValue("@color_sabor", objValores.COLOR_SABOR); sql = "INSERT INTO productos (codigo,nombre,marca,categoria,precio,cantidad,color_sabor)VALUES (@codigo,@nombre,@marca,@categoria,@precio,@cantidad,@color_sabor)"; cm.CommandText = sql; cm.CommandType = CommandType.Text; cm.Connection = cnConexion; cm.ExecuteNonQuery(); Cerrar(); }
private void btnEliminar_Click(object sender, EventArgs e) { Pojos.clsVariables objVariables = new Pojos.clsVariables(); Datos.clsConexion objConexion = new Datos.clsConexion(); try { objVariables.CODIGO = dtgDatos.Rows[dtgDatos.SelectedRows[0].Index].Cells[0].Value.ToString(); if (MessageBox.Show("Seguro que desea eliminar al Producto con codigo " + objVariables.CODIGO, "Eliminar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { objConexion.EliminarPro(objVariables); MessageBox.Show("Se Eliminado"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Datos.clsConexion objconec = new Datos.clsConexion(); dtgDatos.DataSource = objconec.llenar(); }