public ObjArticulo(ObjArticulo articulo) { this.codigo = articulo.codigo; this.nombre = articulo.nombre; this.cantidad = articulo.cantidad; this.precio = articulo.precio; this.detalles = articulo.detalles; this.imagen = articulo.imagen; }
public QueryArticulo(string comando, ObjArticulo articulo) { try { string cnn = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString; using (SqlConnection conexion = new SqlConnection(cnn)) { conexion.Open(); switch (comando) { case "agregar": { SqlCommand cmd = new SqlCommand("INSERT INTO Articulo(nombre, cantidad, precio, detalles, imagen)" + "VALUES ('" + articulo.nombre + "', '" + articulo.cantidad + "', '" + articulo.precio + "', '" + articulo.detalles + "'," + "'" + articulo.imagen + "')", conexion); cmd.ExecuteNonQuery(); MessageBox.Show("Se ha agregado el articulo " + articulo.nombre); } break; case "modificar": { SqlCommand cmd = new SqlCommand("UPDATE Articulo SET nombre = '" + articulo.nombre + "', cantidad = '" + articulo.cantidad + "'," + " precio = '" + articulo.precio + "', detalles = '" + articulo.detalles + "', imagen = '" + articulo.imagen, conexion); cmd.ExecuteNonQuery(); MessageBox.Show("Se ha modificado el articulo " + articulo.nombre); } break; } conexion.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void BT_Agregar_Click(object sender, EventArgs e) { ObjArticulo articulo1 = new ObjArticulo(); total = 0; AC = true; E = false; if (TB_CodProd.Text != "Código de Artículo" || TB_NomPro.Text != "Nomdre de Artículo" || TB_CodProd.Text != "" || TB_NomPro.Text != "") { foreach (ObjArticulo articulo in list) { if (TB_NomPro.Text == articulo.nombre || Convert.ToInt32(TB_CodProd.Text) == articulo.codigo) { articulo1 = articulo; E = true; break; } } // Codigo Art, Nombre, Cantidad, Precio U, Total if (E) { if (TB_Cantidad.Text != "Cantidad" || TB_Cantidad.Text != "") { if (Convert.ToInt32(TB_Cantidad.Text) > 0) { try { totalVenta += articulo1.precio * Convert.ToInt32(TB_Cantidad.Text); total += articulo1.precio * Convert.ToInt32(TB_Cantidad.Text); } catch { MessageBox.Show("El campo de cantidad es incorrecto"); AC = false; } if (AC) { int rowEscribir = DGV_Venta.Rows.Count - 1; DGV_Venta.Rows.Add(1); DGV_Venta.Rows[rowEscribir].Cells[0].Value = articulo1.codigo; DGV_Venta.Rows[rowEscribir].Cells[1].Value = articulo1.nombre; DGV_Venta.Rows[rowEscribir].Cells[2].Value = TB_Cantidad.Text; DGV_Venta.Rows[rowEscribir].Cells[3].Value = articulo1.precio; DGV_Venta.Rows[rowEscribir].Cells[4].Value = total; list2.Add(articulo1); } } else { MessageBox.Show("Ingresa una cantidad mayor a 0"); } } } else { MessageBox.Show("No se encontró el artículo"); } } }