private void ModificarBtn_Click(object sender, EventArgs e) { ConnectionSQLServer conexion = new ConnectionSQLServer(); conexion.OpenConnection(); if (CodigoTxB.Text == "" || NombreTxB.Text == "" || PrecioUnidadTxB.Text == "" || CantidadTxB.Text == "") { MessageBox.Show("No se puede modificar datos vacios"); } else { if (MessageBox.Show("Seguro que desea modificar?", "Modificar", MessageBoxButtons.YesNo) == DialogResult.Yes) { ProductosDT.CurrentRow.Cells[0].Value = CodigoTxB.Text; ProductosDT.CurrentRow.Cells[1].Value = NombreTxB.Text; ProductosDT.CurrentRow.Cells[2].Value = PrecioUnidadTxB.Text; ProductosDT.CurrentRow.Cells[3].Value = CantidadTxB.Text; int filas = conexion.ModificarDatos("UPDATE producto SET Codigo='" + CodigoTxB.Text + "',Nombre='" + NombreTxB.Text + "',PrecioUnidad='" + PrecioUnidadTxB.Text + "',Cantidad='" + CantidadTxB.Text + "' where Codigo='" + codigo + "'"); if (filas > 0) { MessageBox.Show("Se ha modificado correctamente"); ProductosDT.DataSource = conexion.TablaProductos("select * from Producto"); CodigoTxB.Text = ""; NombreTxB.Text = ""; PrecioUnidadTxB.Text = ""; CantidadTxB.Text = ""; } } } conexion.ActualizarItems(comboBox1); conexion.CloseConnection(); }
private void Agregar_Click(object sender, EventArgs e) { ConnectionSQLServer connection = new ConnectionSQLServer(); connection.OpenConnection(); if (CantidadProTxB.Text == "" || NombrePro.Text == "" || comboBox1.SelectedItem.ToString() == "") { MessageBox.Show("Favor de llenar todos los campos"); } else if (Convert.ToInt32(CantidadProTxB.Text) <= 0) { MessageBox.Show("No se permiten cantidades negativas y tampoco cantidades en cero"); CantidadProTxB.Text = ""; } else { int cod = Convert.ToInt32(comboBox1.SelectedItem.ToString()); int can = connection.VerCantidad("select Cantidad from Producto where Codigo='" + cod + "'"); if (Convert.ToInt32(CantidadProTxB.Text) > can) { MessageBox.Show("Lo sentimos la cantidad que ingreso revasa la cantidad en almacen"); comboBox1.SelectedItem = null; CantidadProTxB.Text = ""; } else { int cantidadF = can - Convert.ToInt32(CantidadProTxB.Text); connection.ModificarDatos("UPDATE Producto SET Cantidad='" + cantidadF + "' where Codigo='" + cod + "'"); int ventaT = precioPro * Convert.ToInt32(CantidadProTxB.Text); int filas = connection.IngresarDatosVenta("Insert Into VentaProducto (Nombre,PrecioUnidad,Cantidad,TotalVenta) Values(@Nombre,@PrecioUnidad,@Cantidad,@TotalVenta)", nombrePro, precioPro, Convert.ToInt32(CantidadProTxB.Text), ventaT); if (filas > 0) { TotalVenta += ventaT; NombrePro.Text = ""; CantidadProTxB.Text = ""; comboBox1.SelectedItem = null; } } } ProductosDT.DataSource = connection.TablaProductos("select * from Producto"); GridVentas.DataSource = connection.TablaVentaProducto("select * from VentaProducto"); connection.CloseConnection(); }