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
+36 -2
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,7 +806,25 @@ 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();
return true;