boton vender de la venta venta listo

This commit is contained in:
carlos
2024-02-14 18:47:18 -06:00
parent cbc7201b23
commit 93d7aef100
18 changed files with 198 additions and 104 deletions
+36 -9
View File
@@ -778,7 +778,7 @@ namespace compabetov2.database
try
{
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);";
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);";
string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_variante, cantidad) VALUES(@idVenta, @fk_variante, @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";
@@ -803,12 +803,13 @@ namespace compabetov2.database
{
SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta);
commandEmpleado.Parameters.AddWithValue("@idProducto", detalleVenta.producto.idProducto);
commandEmpleado.Parameters.AddWithValue("@fk_variante", detalleVenta.producto.idVariante);
commandEmpleado.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
commandEmpleado.ExecuteNonQuery();
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion);
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
MessageBox.Show(detalleVenta.producto.fkProducto.ToString());
commandProdcutoStock.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
int stockActual = -1;
@@ -820,10 +821,8 @@ namespace compabetov2.database
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto);
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
commandProdcutoUpdate.ExecuteNonQuery();
}
transaccion.Commit();
@@ -1198,7 +1197,7 @@ namespace compabetov2.database
conexion.Open();
string sql = "select * from detalle_venta dv, Producto p WHERE dv.fk_producto = p.idproducto and dv.fk_venta = @idVenta";
string sql = "select * from detalle_venta dv, variantes v WHERE dv.fk_variante = v.idVariante and dv.fk_venta = @idVenta";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@idVenta", venta.id);
reader = command.ExecuteReader();
@@ -1534,6 +1533,30 @@ namespace compabetov2.database
}
}
public static SQLiteDataReader conseguirVariantesDAO()
{
SQLiteDataReader reader = null;
var db_conexion = new Conexion();
try
{
SQLiteConnection conexion = db_conexion.get_connection();
conexion.Open();
string sql = "SELECT * FROM variantes";
SQLiteCommand command = new SQLiteCommand(sql, conexion);
reader = command.ExecuteReader();
return reader;
}
catch (SQLiteException ex)
{
MessageBox.Show(ex.Message);
return reader;
}
}
private static void crearDB()
{
var db_conexion = new Conexion();
@@ -1555,6 +1578,7 @@ namespace compabetov2.database
"DROP TABLE IF EXISTS cuenta",
"DROP TABLE IF EXISTS detalle_envios",
"DROP TABLE IF EXISTS envios",
"DROP TABLE IF EXISTS variantes",
"CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
"contra TEXT NOT NULL)",
@@ -1570,6 +1594,9 @@ namespace compabetov2.database
"precio DECIMAL(10, 2) NOT NULL, img TEXT NOT NULL, stock INTEGER NOT NULL, " +
"fk_idcategoria INTEGER NOT NULL, FOREIGN KEY (fk_idcategoria) REFERENCES Categoria (idcategoria))",
"CREATE TABLE variantes (idVariante INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, precio DECIMAL(10,2), cantidad INTEGER DEFAULT 1, " +
"img TEXT,fk_producto INTEGER, FOREIGN KEY (fk_producto) REFERENCES Producto(idproducto))",
"CREATE TABLE Cliente (idcliente INTEGER PRIMARY KEY AUTOINCREMENT, nombres TEXT NOT NULL, apellidos TEXT NOT NULL, " +
"calle TEXT NOT NULL, colonia TEXT NOT NULL, cp TEXT NOT NULL, no_ext TEXT NOT NULL, no_int TEXT NOT NULL, referencia TEXT NOT NULL, " +
"telefono TEXT NOT NULL, telefono_extra TEXT NOT NULL)",
@@ -1578,8 +1605,8 @@ namespace compabetov2.database
"CREATE TABLE venta (idVenta INTEGER PRIMARY KEY AUTOINCREMENT,fecha TEXT, total DECIMAL(10, 2),responzable TEXT DEFAULT '');",
"CREATE TABLE detalle_venta (fk_venta INTEGER, fk_producto INTEGER,cantidad INTEGER DEFAULT 0, PRIMARY KEY (fk_venta, fk_producto), " +
"FOREIGN KEY (fk_venta) REFERENCES venta(idVenta),FOREIGN KEY (fk_producto) REFERENCES producto(idproducto));",
"CREATE TABLE detalle_venta (fk_venta INTEGER, fk_variante INTEGER,cantidad INTEGER, PRIMARY KEY (fk_venta, fk_variante)," +
"FOREIGN KEY (fk_venta) REFERENCES venta(idVenta),FOREIGN KEY (fk_variante) REFERENCES variantes(idVariante))",
"CREATE TABLE cuenta (idCuenta INTEGER PRIMARY KEY AUTOINCREMENT, total DECIMAL(10,2), fecha TEXT, estado TEXT DEFAULT 'ACTIVO', descripcion TEXT, cliente TEXT DEFAULT '')",
+2 -2
View File
@@ -10,10 +10,10 @@ namespace compabetov2.database.modelos
{
public int idVenta;
public int cantidad;
public Producto producto;
public Variante producto;
public decimal total;
public DetalleVentaModel(int cantidad, Producto producto, int id = -1, decimal total = 0)
public DetalleVentaModel(int cantidad, Variante producto, int id = -1, decimal total = 0)
{
this.cantidad = cantidad;
this.producto = producto;
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace compabetov2.database.modelos
{
public class Variante
{
public int idVariante;
public string nombre;
public decimal precio;
public int cantidad;
public string img;
public int fkProducto;
public Variante(int idVariante, string nombre, decimal precio, int cantidad, string img, int fkProducto)
{
this.idVariante = idVariante;
this.nombre = nombre;
this.precio = precio;
this.cantidad = cantidad;
this.img = img;
this.fkProducto = fkProducto;
}
}
}
+28 -10
View File
@@ -405,15 +405,8 @@ namespace compabetov2.database
{
DetalleVentaModel detalleVenta = new DetalleVentaModel(
(int)readerDetalleVenta.GetInt64(2),
new Producto(
(int)readerDetalleVenta.GetInt64(1),
readerDetalleVenta["nombre"].ToString(),
readerDetalleVenta["descripcion"].ToString(),
readerDetalleVenta.GetDecimal(6),
readerDetalleVenta["img"].ToString(),
(int)readerDetalleVenta.GetInt64(8)
),
(int)readerDetalleVenta.GetInt64(0)
new Variante(-1,"",0,0,"",-1)
) ;
detallesVenta.Add( detalleVenta );
}
@@ -455,6 +448,7 @@ namespace compabetov2.database
while (reader.Read())
{
Producto producto = new Producto(
reader.GetInt32(idIndex),
reader.GetString(nombreIndex),
@@ -466,7 +460,7 @@ namespace compabetov2.database
productos.Add(producto);
}
return productos;
}
@@ -498,5 +492,29 @@ namespace compabetov2.database
return dic;
}
public static List<Variante> conseguirVariantes()
{
List<Variante> variantes = new List<Variante>();
SQLiteDataReader reader = DAO.conseguirVariantesDAO();
while (reader.Read())
{
decimal precio = reader.GetDecimal(2);
int cantidad = (int)reader.GetInt64(3);
int fkProducto = (int)reader.GetInt64(5);
Variante vaiante = new Variante(
(int)reader.GetInt64(0),
reader["nombre"].ToString(),
precio,
cantidad,
reader["img"].ToString(),
fkProducto
);
variantes.Add(vaiante);
}
return variantes;
}
}
}