bugs con el stock
This commit is contained in:
@@ -4,6 +4,6 @@
|
|||||||
"\\Properties",
|
"\\Properties",
|
||||||
"\\Properties\\DataSources"
|
"\\Properties\\DataSources"
|
||||||
],
|
],
|
||||||
"SelectedNode": "\\mermas.cs",
|
"SelectedNode": "\\vender.cs",
|
||||||
"PreviewInSolutionExplorer": false
|
"PreviewInSolutionExplorer": false
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+36
-2
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
@@ -534,9 +535,22 @@ namespace compabetov2.database
|
|||||||
foreach (var item in stockNuevo)
|
foreach (var item in stockNuevo)
|
||||||
{
|
{
|
||||||
string sql = "UPDATE Producto SET stock = @stock WHERE idproducto = @idproducto;";
|
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);
|
SQLiteCommand command = new SQLiteCommand(sql, conexion);
|
||||||
command.Parameters.AddWithValue("@idproducto", item.idProducto);
|
command.Parameters.AddWithValue("@idproducto", item.idProducto);
|
||||||
command.Parameters.AddWithValue("@stock", item.stock);
|
command.Parameters.AddWithValue("@stock", stockActual + item.stock);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,6 +781,8 @@ namespace compabetov2.database
|
|||||||
string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);";
|
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 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 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);
|
SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion);
|
||||||
@@ -790,7 +806,25 @@ namespace compabetov2.database
|
|||||||
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
|
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
|
||||||
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
|
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
|
||||||
commandEmpleado.ExecuteNonQuery();
|
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();
|
transaccion.Commit();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+60
-51
@@ -103,8 +103,15 @@ namespace compabetov2
|
|||||||
btnMenos.Anchor = AnchorStyles.None;
|
btnMenos.Anchor = AnchorStyles.None;
|
||||||
btnMenos.Click += new EventHandler(delegate (object sender, EventArgs e)
|
btnMenos.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int numeroContador = int.Parse(txtStockAgregar.Text);
|
try
|
||||||
txtStockAgregar.Text = (numeroContador - 1).ToString();
|
{
|
||||||
|
int numeroContador = int.Parse(txtStockAgregar.Text);
|
||||||
|
txtStockAgregar.Text = (numeroContador - 1).ToString();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
txtStockAgregar.Text = "0";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Button btnMas = new Button();
|
Button btnMas = new Button();
|
||||||
@@ -119,8 +126,15 @@ namespace compabetov2
|
|||||||
btnMas.Anchor = AnchorStyles.None;
|
btnMas.Anchor = AnchorStyles.None;
|
||||||
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
|
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int numeroContador = int.Parse(txtStockAgregar.Text);
|
try
|
||||||
txtStockAgregar.Text = (numeroContador + 1).ToString();
|
{
|
||||||
|
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)
|
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)
|
private void button6_Click_1(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<Producto> stockNuevo = new List<Producto>();
|
List<Producto> stockNuevo = new List<Producto>();
|
||||||
foreach(Control control in stockPanel.Controls)
|
try {
|
||||||
{
|
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)
|
|
||||||
{
|
{
|
||||||
service.aumentarStock(stockNuevo);
|
TableLayoutPanel informacionProducto = control.Controls[0] as TableLayoutPanel;
|
||||||
llenarPanel();
|
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.
Reference in New Issue
Block a user