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 AgregarBtn_Click(object sender, EventArgs e) { ConnectionSQLServer conexion = new ConnectionSQLServer(); conexion.OpenConnection(); bool validar = false; if (CodigoTxB.Text == "" || NombreTxB.Text == "" || PrecioUnidadTxB.Text == "" || CantidadTxB.Text == "") { MessageBox.Show("Favor de llenar todos los parametros para poder guardar el producto"); } else { foreach (DataGridViewRow row in ProductosDT.Rows) { string codigo = Convert.ToString(row.Cells["CodigoColumn"].Value); string nombre = Convert.ToString(row.Cells["NombreColumn"].Value); if (CodigoTxB.Text == codigo || NombreTxB.Text == nombre) { validar = true; } } if (validar == true) { MessageBox.Show("El codigo o el nombre que desea ingresar ya existe, favor de colocar otro codigo o nombre"); CodigoTxB.Text = ""; NombreTxB.Text = ""; } else { int filas = conexion.IngresarDatos("Insert Into Producto(Codigo, Nombre, PrecioUnidad, Cantidad) Values(@Codigo,@Nombre,@PrecioUnidad,@Cantidad)", Int32.Parse(CodigoTxB.Text), NombreTxB.Text, Int32.Parse(PrecioUnidadTxB.Text), Int32.Parse(CantidadTxB.Text)); if (filas > 0) { MessageBox.Show("Lo datos se guardaron correctamente"); CodigoTxB.Text = ""; NombreTxB.Text = ""; PrecioUnidadTxB.Text = ""; CantidadTxB.Text = ""; } else { MessageBox.Show("Hubo un problema al guardar los datos"); } } } ProductosDT.DataSource = conexion.TablaProductos("select * from Producto"); 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(); }
private void MenuPrin_Load(object sender, EventArgs e) { // TODO: esta línea de código carga datos en la tabla 'productoVenta.VentaProducto' Puede moverla o quitarla según sea necesario. this.ventaProductoTableAdapter.Fill(this.productoVenta.VentaProducto); // TODO: esta línea de código carga datos en la tabla 'puntoVentaDataSet2.Producto' Puede moverla o quitarla según sea necesario. this.productoTableAdapter2.Fill(this.puntoVentaDataSet2.Producto); // TODO: esta línea de código carga datos en la tabla 'puntoVenta.Venta' Puede moverla o quitarla según sea necesario. this.ventaTableAdapter.Fill(this.puntoVenta.Venta); // TODO: esta línea de código carga datos en la tabla 'puntoVentaDataSet.Producto' Puede moverla o quitarla según sea necesario. this.productoTableAdapter.Fill(this.puntoVentaDataSet.Producto); ConnectionSQLServer conexion = new ConnectionSQLServer(); conexion.OpenConnection(); ProductosDT.DataSource = conexion.TablaProductos("select * from Producto"); GridVentas.DataSource = conexion.TablaVentaProducto("select * from VentaProducto"); DatetimeReporte.Value = DateTime.Now; conexion.LlenaComboBox(comboBox1); comboBox1.SelectedItem = null; conexion.CloseConnection(); }
private void EliminarBtn_Click(object sender, EventArgs e) { ConnectionSQLServer conexion = new ConnectionSQLServer(); conexion.OpenConnection(); if (CodigoTxB.Text == "") { MessageBox.Show("No se puede eliminar datos vacios"); } else { if (MessageBox.Show("Seguro que desea eliminar?", "Eliminar", MessageBoxButtons.YesNo) == DialogResult.Yes) { conexion.EliminarDatos("delete from producto where codigo = '" + CodigoTxB.Text + "'"); ProductosDT.DataSource = conexion.TablaProductos("select * from Producto"); CodigoTxB.Text = ""; NombreTxB.Text = ""; PrecioUnidadTxB.Text = ""; CantidadTxB.Text = ""; } } conexion.ActualizarItems(comboBox1); conexion.CloseConnection(); }