bugs con el stock

This commit is contained in:
carlos
2024-01-21 19:54:50 -06:00
parent f084bb8e20
commit 53dd047ba9
11 changed files with 97 additions and 54 deletions
+1 -1
View File
@@ -4,6 +4,6 @@
"\\Properties",
"\\Properties\\DataSources"
],
"SelectedNode": "\\mermas.cs",
"SelectedNode": "\\vender.cs",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+35 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics.Contracts;
@@ -534,9 +535,22 @@ namespace compabetov2.database
foreach (var item in stockNuevo)
{
string sql = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto;";
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
commandProdcutoStock.Parameters.AddWithValue("@idproducto", item.idProducto);
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
int stockActual = -1;
while (stockReader.Read())
{
stockActual = int.Parse(stockReader["stock"].ToString());
}
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@idproducto", item.idProducto);
command.Parameters.AddWithValue("@stock", item.stock);
command.Parameters.AddWithValue("@stock", stockActual + item.stock);
command.ExecuteNonQuery();
}
@@ -767,6 +781,8 @@ namespace compabetov2.database
string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);";
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);";
string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto";
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
@@ -790,6 +806,24 @@ namespace compabetov2.database
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
commandEmpleado.ExecuteNonQuery();
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
int stockActual = -1;
while (stockReader.Read())
{
stockActual = int.Parse(stockReader["stock"].ToString());
}
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
commandProdcutoUpdate.ExecuteNonQuery();
}
transaccion.Commit();
+60 -51
View File
@@ -103,8 +103,15 @@ namespace compabetov2
btnMenos.Anchor = AnchorStyles.None;
btnMenos.Click += new EventHandler(delegate (object sender, EventArgs e)
{
int numeroContador = int.Parse(txtStockAgregar.Text);
txtStockAgregar.Text = (numeroContador - 1).ToString();
try
{
int numeroContador = int.Parse(txtStockAgregar.Text);
txtStockAgregar.Text = (numeroContador - 1).ToString();
}
catch (Exception ex)
{
txtStockAgregar.Text = "0";
}
});
Button btnMas = new Button();
@@ -119,8 +126,15 @@ namespace compabetov2
btnMas.Anchor = AnchorStyles.None;
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
{
int numeroContador = int.Parse(txtStockAgregar.Text);
txtStockAgregar.Text = (numeroContador + 1).ToString();
try
{
int numeroContador = int.Parse(txtStockAgregar.Text);
txtStockAgregar.Text = (numeroContador + 1).ToString();
}catch (Exception ex)
{
txtStockAgregar.Text = "0";
}
});
@@ -149,19 +163,7 @@ namespace compabetov2
private void button6_Click(object sender, EventArgs e)
{
/*Categoria categoria = new Categoria(comboBox1.SelectedIndex + 1);
Producto producto = new Producto(
0,
txtnombreproducto.Text,
txtdescripcionproducto.Text,
decimal.Parse(txtprecioproducto.Text),
"",
int.Parse(txtstockproducto.Text),
categoria);
if (service.insertarProducto(producto)) {
}*/
}
@@ -169,44 +171,51 @@ namespace compabetov2
private void button6_Click_1(object sender, EventArgs e)
{
List<Producto> stockNuevo = new List<Producto>();
foreach(Control control in stockPanel.Controls)
{
TableLayoutPanel informacionProducto = control.Controls[0] as TableLayoutPanel;
TableLayoutPanel agregarPanel = control.Controls[1] as TableLayoutPanel;
//id
Label lbIdProducto = informacionProducto.Controls[0].Controls[0] as Label;
int idProducto = int.Parse(lbIdProducto.Text);
//stock a agregar
TextBox txtStock = agregarPanel.Controls[0] as TextBox;
int stock = int.Parse(txtStock.Text);
if(stock > 0) {
Producto productoStockNuuevo = new Producto(idProducto, "", "", 0, "", stock, null);
stockNuevo.Add(productoStockNuuevo);
}
}
string mensajeConfirmacion = "Se aumentara el stock a los\nsiguientes productos\n";
for(int i = 0; i < stockNuevo.Count; i++)
{
mensajeConfirmacion += productos[i].nombre + ": " + stockNuevo[i].stock + "\n";
}
if(stockNuevo.Count > 0)
{
DialogResult result = MessageBox.Show(mensajeConfirmacion, "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
try {
foreach (Control control in stockPanel.Controls)
{
service.aumentarStock(stockNuevo);
llenarPanel();
TableLayoutPanel informacionProducto = control.Controls[0] as TableLayoutPanel;
TableLayoutPanel agregarPanel = control.Controls[1] as TableLayoutPanel;
//id
Label lbIdProducto = informacionProducto.Controls[0].Controls[0] as Label;
int idProducto = int.Parse(lbIdProducto.Text);
//stock a agregar
TextBox txtStock = agregarPanel.Controls[0] as TextBox;
int stock = int.Parse(txtStock.Text);
if (stock != 0)
{
Producto productoStockNuuevo = new Producto(idProducto, "", "", 0, "", stock, null);
stockNuevo.Add(productoStockNuuevo);
}
}
string mensajeConfirmacion = "Se aumentara el stock a los\nsiguientes productos\n";
for (int i = 0; i < stockNuevo.Count; i++)
{
mensajeConfirmacion += productos[i].nombre + ": " + stockNuevo[i].stock + "\n";
}
if (stockNuevo.Count > 0)
{
DialogResult result = MessageBox.Show(mensajeConfirmacion, "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
service.aumentarStock(stockNuevo);
llenarPanel();
}
}
}
catch(Exception ex) {
MessageBox.Show("Solo debe introducir numeros","Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.