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
Binary file not shown.
File diff suppressed because one or more lines are too long
+6 -6
View File
@@ -152,7 +152,7 @@ namespace compabetov2
decimal totalVendidoMes = 0; decimal totalVendidoMes = 0;
foreach (DetalleVentaModel producto in detallesMes) foreach (DetalleVentaModel producto in detallesMes)
{ {
totalVendidoMes += producto.cantidad * producto.producto.precion; totalVendidoMes += producto.cantidad * producto.producto.precio;
// Crear una nueva fila // Crear una nueva fila
DataGridViewRow nuevaFila = new DataGridViewRow(); DataGridViewRow nuevaFila = new DataGridViewRow();
@@ -164,9 +164,9 @@ namespace compabetov2
// Establecer los valores de las celdas (puedes ajustar según tu necesidad) // Establecer los valores de las celdas (puedes ajustar según tu necesidad)
productoN.Value = $"{producto.producto.nombre}"; productoN.Value = $"{producto.producto.nombre}";
precio.Value = $"{producto.producto.precion}"; precio.Value = $"{producto.producto.precio}";
cantidad.Value = $"{producto.cantidad}"; cantidad.Value = $"{producto.cantidad}";
total.Value = $"{producto.cantidad * producto.producto.precion}"; total.Value = $"{producto.cantidad * producto.producto.precio}";
// Agregar las celdas a la fila // Agregar las celdas a la fila
nuevaFila.Cells.Add(productoN); nuevaFila.Cells.Add(productoN);
@@ -188,7 +188,7 @@ namespace compabetov2
decimal totalVendidoDia = 0; decimal totalVendidoDia = 0;
foreach (DetalleVentaModel producto in detallesDia) foreach (DetalleVentaModel producto in detallesDia)
{ {
totalVendidoDia += producto.cantidad * producto.producto.precion; totalVendidoDia += producto.cantidad * producto.producto.precio;
// Crear una nueva fila // Crear una nueva fila
DataGridViewRow nuevaFila = new DataGridViewRow(); DataGridViewRow nuevaFila = new DataGridViewRow();
@@ -200,9 +200,9 @@ namespace compabetov2
// Establecer los valores de las celdas (puedes ajustar según tu necesidad) // Establecer los valores de las celdas (puedes ajustar según tu necesidad)
productoN.Value = $"{producto.producto.nombre}"; productoN.Value = $"{producto.producto.nombre}";
precio.Value = $"{producto.producto.precion}"; precio.Value = $"{producto.producto.precio}";
cantidad.Value = $"{producto.cantidad}"; cantidad.Value = $"{producto.cantidad}";
total.Value = $"{producto.cantidad * producto.producto.precion}"; total.Value = $"{producto.cantidad * producto.producto.precio}";
// Agregar las celdas a la fila // Agregar las celdas a la fila
nuevaFila.Cells.Add(productoN); nuevaFila.Cells.Add(productoN);
+62 -42
View File
@@ -25,10 +25,11 @@ namespace compabetov2
{ {
private int numeroPagina = 1; // Variable para rastrear el número de página actual private int numeroPagina = 1; // Variable para rastrear el número de página actual
private Point lastPoint; private Point lastPoint;
private List<Producto> productos; private List<Variante> productos;
public decimal total = 0; public decimal total = 0;
private LoginModel loginPrincipal; private LoginModel loginPrincipal;
private Dictionary<string, Image> imagenes = new Dictionary<string, Image>(); private Dictionary<string, Image> imagenes = new Dictionary<string, Image>();
private List<DetalleVentaModel> carrito = new List<DetalleVentaModel>();
public vender(LoginModel loginPrincipal) public vender(LoginModel loginPrincipal)
@@ -90,7 +91,7 @@ namespace compabetov2
public void llenarLayout() public void llenarLayout()
{ {
flowLayoutPanel3.Controls.Clear(); flowLayoutPanel3.Controls.Clear();
foreach (Producto producto in productos) foreach (Variante producto in productos)
{ {
TableLayoutPanel carta = new TableLayoutPanel(); TableLayoutPanel carta = new TableLayoutPanel();
@@ -106,7 +107,8 @@ namespace compabetov2
PictureBox pic = new PictureBox(); PictureBox pic = new PictureBox();
pic.Dock = DockStyle.Fill; pic.Dock = DockStyle.Fill;
pic.SizeMode = PictureBoxSizeMode.Zoom; pic.SizeMode = PictureBoxSizeMode.Zoom;
if (imagenes.ContainsKey(producto.img)) { if (imagenes.ContainsKey(producto.img))
{
pic.Image = imagenes[producto.img]; pic.Image = imagenes[producto.img];
} }
else else
@@ -118,9 +120,9 @@ namespace compabetov2
} }
//hay error aquí //hay error aquí
pic.BackgroundImageLayout = ImageLayout.Stretch; pic.BackgroundImageLayout = ImageLayout.Stretch;
pic.Tag = producto.idProducto; pic.Tag = producto.idVariante;
Label id = new Label(); Label id = new Label();
id.Text = producto.idProducto.ToString(); id.Text = producto.idVariante.ToString();
id.BackColor = Color.FromArgb(82, 82, 82); id.BackColor = Color.FromArgb(82, 82, 82);
id.ForeColor = Color.White; id.ForeColor = Color.White;
id.Width = 20; id.Width = 20;
@@ -129,7 +131,7 @@ namespace compabetov2
pic.Controls.Add(id); pic.Controls.Add(id);
Label precio = new Label(); Label precio = new Label();
precio.Text = "$" + producto.precion.ToString() + " - " + producto.nombre; precio.Text = "$" + producto.precio.ToString() + " - " + producto.nombre;
precio.BackColor = Color.FromArgb(82, 82, 82); precio.BackColor = Color.FromArgb(82, 82, 82);
precio.ForeColor = Color.White; precio.ForeColor = Color.White;
precio.Width = 40; precio.Width = 40;
@@ -166,19 +168,23 @@ namespace compabetov2
int numeroContador = int.Parse(contador.Text.ToString()); int numeroContador = int.Parse(contador.Text.ToString());
// Validar que el contador no sea 0 antes de restar // Validar que el contador no sea 0 antes de restar
int indexCarrito = estaEnCarrito(producto.nombre);
if (existeTocket(producto.nombre)) if (indexCarrito != -1)
{ {
contador.Text = (numeroContador - 1).ToString(); contador.Text = (numeroContador - 1).ToString();
total -= producto.precion; total -= producto.precio;
label1.Text = $"Total: ${total}"; label1.Text = $"Total: ${total}";
// Obtener información del Label id y precio // Obtener información del Label id y precio
int idProducto = int.Parse(id.Text); decimal precioProducto = producto.precio;
decimal precioProducto = producto.precion;
// Restar al ticket existente si ya se agregó // Restar al ticket existente si ya se agregó
RestarDelTicket(idProducto, producto.nombre, precioProducto, 1); carrito[indexCarrito].cantidad = int.Parse(contador.Text);
if (carrito[indexCarrito].cantidad == 0)
{
carrito.RemoveAt(indexCarrito);
}
RestarDelTicket(producto.idVariante, producto.nombre, precioProducto, 1);
} }
else else
{ {
@@ -201,19 +207,29 @@ namespace compabetov2
btnMas.FlatAppearance.BorderSize = 0; btnMas.FlatAppearance.BorderSize = 0;
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e) btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
{ {
if(int.Parse(contador.Text.ToString()) < 0 && !existeTocket(producto.nombre)) { if (int.Parse(contador.Text.ToString()) < 0 && !existeTocket(producto.nombre))
{
contador.Text = "0"; contador.Text = "0";
} }
int numeroContador = int.Parse(contador.Text.ToString()); int numeroContador = int.Parse(contador.Text.ToString());
contador.Text = (numeroContador + 1).ToString(); contador.Text = (numeroContador + 1).ToString();
total += producto.precion; total += producto.precio;
label1.Text = $"Total: ${total}"; label1.Text = $"Total: ${total}";
// Obtener información del Label id y precio // Obtener información del Label id y precio
int idProducto = int.Parse(id.Text); int idProducto = int.Parse(id.Text);
decimal precioProducto = producto.precion; decimal precioProducto = producto.precio;
// Generar ticket y agregarlo al flowLayoutPanel2 // Generar ticket y agregarlo al flowLayoutPanel2
GenerarTicket(idProducto, producto.nombre, producto.precion, int.Parse(contador.Text), total, int indexCarrito = estaEnCarrito(producto.nombre);
if (indexCarrito != -1)
{
carrito[indexCarrito].cantidad = int.Parse(contador.Text);
}
else
{
carrito.Add(new DetalleVentaModel(int.Parse(contador.Text), producto));
}
GenerarTicket(idProducto, producto.nombre, producto.precio, int.Parse(contador.Text), total,
Path.Combine(Application.StartupPath, "Resources", producto.img)); Path.Combine(Application.StartupPath, "Resources", producto.img));
}); });
@@ -228,6 +244,18 @@ namespace compabetov2
} }
private int estaEnCarrito(string nombre)
{
for (int i = 0; i < carrito.Count; i++)
{
if (carrito[i].producto.nombre.Equals(nombre))
{
return i;
}
}
return -1;
}
private void RestarDelTicket(int idProducto, string nombreProducto, decimal precio, int cantidad) private void RestarDelTicket(int idProducto, string nombreProducto, decimal precio, int cantidad)
{ {
foreach (var item in flowLayoutPanel2.Controls) foreach (var item in flowLayoutPanel2.Controls)
@@ -409,16 +437,9 @@ namespace compabetov2
} }
private void getData() private void getData()
{ {
this.productos = service.conseguirProductos(); this.productos = service.conseguirVariantes();
} }
private void vender_Load(object sender, EventArgs e) private void vender_Load(object sender, EventArgs e)
@@ -496,34 +517,25 @@ namespace compabetov2
private void bntImprimir_Click(object sender, EventArgs e) private void bntImprimir_Click(object sender, EventArgs e)
{
//List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if (carrito.Count > 0)
{ {
DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (resultado == DialogResult.Yes) if (resultado == DialogResult.Yes)
{
// Si la opción es "SI", imprimir el ticket
ImprimirTicket();
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if (detalleVentas.Count > 0)
{ {
VentaModel ventaModel = new VentaModel(total, -1, "", VentaModel ventaModel = new VentaModel(total, -1, "",
responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text
); );
if (service.crearVentaDAO(ventaModel, detalleVentas)) if (service.crearVentaDAO(ventaModel, carrito))
{ {
MessageBox.Show("Venta hecha"); MessageBox.Show("Venta hecha");
eliminarProductosTocket(); eliminarProductosTocket();
llenarLayout(); llenarLayout();
total = 0; total = 0;
ImprimirTicket();
}
}
else
{
MessageBox.Show("No hay ningun producto agregado");
} }
} }
else else
@@ -532,6 +544,12 @@ namespace compabetov2
MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
} }
else
{
MessageBox.Show("No hay ningun producto agregado");
}
}
private void ImprimirTicket() private void ImprimirTicket()
@@ -699,7 +717,7 @@ namespace compabetov2
} }
} }
int idProducto = int.Parse(idLabel.Text); int idProducto = int.Parse(idLabel.Text);
Producto producto = new Producto(idProducto); Variante producto = new Variante(idProducto, "", 0, 0, "", 0);
Label Lbcantidad = panelInfo.Controls[2] as Label; Label Lbcantidad = panelInfo.Controls[2] as Label;
string textcantidad = Lbcantidad.Text; string textcantidad = Lbcantidad.Text;
@@ -790,7 +808,8 @@ namespace compabetov2
btnFiar.Enabled = true; btnFiar.Enabled = true;
btnEnviar.Enabled = true; btnEnviar.Enabled = true;
} }
else { else
{
bntImprimir.Enabled = false; bntImprimir.Enabled = false;
btnFiar.Enabled = false; btnFiar.Enabled = false;
@@ -807,7 +826,7 @@ namespace compabetov2
{ {
if (!txtbusqueda.Text.Equals("")) if (!txtbusqueda.Text.Equals(""))
{ {
productos = service.conseguirProductosFiltrados(txtbusqueda.Text); //productos = service.conseguirProductosFiltrados(txtbusqueda.Text);
llenarLayout(); llenarLayout();
} }
else else
@@ -862,7 +881,8 @@ namespace compabetov2
List<DetalleEnvioModel> detallesEnvio = listaProductosEnvio(); List<DetalleEnvioModel> detallesEnvio = listaProductosEnvio();
string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text; string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text;
Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable, "", "", total); Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable, "", "", total);
if(detallesEnvio.Count > 0){ if (detallesEnvio.Count > 0)
{
datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio, this); datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio, this);
datosEnvio.Show(); datosEnvio.Show();
} }
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+1
View File
@@ -108,6 +108,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="database\modelos\DetalleEnvioModel.cs" /> <Compile Include="database\modelos\DetalleEnvioModel.cs" />
<Compile Include="database\modelos\Envio.cs" /> <Compile Include="database\modelos\Envio.cs" />
<Compile Include="database\modelos\Variante.cs" />
<Compile Include="Empleados\AgregarEmpleado1.cs"> <Compile Include="Empleados\AgregarEmpleado1.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
+36 -9
View File
@@ -778,7 +778,7 @@ namespace compabetov2.database
try try
{ {
string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);"; 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 sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1";
string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto"; string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto";
string sqlProductoUpdate = "UPDATE Producto SET stock = @stock 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); SQLiteCommand commandEmpleado = new SQLiteCommand(sqlDetalle, conexion);
commandEmpleado.Parameters.AddWithValue("@idVenta", idVenta); 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.Parameters.AddWithValue("@cantidada", detalleVenta.cantidad);
commandEmpleado.ExecuteNonQuery(); commandEmpleado.ExecuteNonQuery();
SQLiteCommand commandProdcutoStock = new SQLiteCommand(sqlProductoStock, conexion); 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(); SQLiteDataReader stockReader = commandProdcutoStock.ExecuteReader();
int stockActual = -1; int stockActual = -1;
@@ -820,10 +821,8 @@ namespace compabetov2.database
SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion); SQLiteCommand commandProdcutoUpdate = new SQLiteCommand(sqlProductoUpdate, conexion);
commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad); commandProdcutoUpdate.Parameters.AddWithValue("@stock", stockActual - detalleVenta.cantidad);
commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.idProducto); commandProdcutoUpdate.Parameters.AddWithValue("@idproducto", detalleVenta.producto.fkProducto);
commandProdcutoUpdate.ExecuteNonQuery(); commandProdcutoUpdate.ExecuteNonQuery();
} }
transaccion.Commit(); transaccion.Commit();
@@ -1198,7 +1197,7 @@ namespace compabetov2.database
conexion.Open(); 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); SQLiteCommand command = new SQLiteCommand(sql, conexion);
command.Parameters.AddWithValue("@idVenta", venta.id); command.Parameters.AddWithValue("@idVenta", venta.id);
reader = command.ExecuteReader(); 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() private static void crearDB()
{ {
var db_conexion = new Conexion(); var db_conexion = new Conexion();
@@ -1555,6 +1578,7 @@ namespace compabetov2.database
"DROP TABLE IF EXISTS cuenta", "DROP TABLE IF EXISTS cuenta",
"DROP TABLE IF EXISTS detalle_envios", "DROP TABLE IF EXISTS detalle_envios",
"DROP TABLE IF EXISTS 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, "+ "CREATE TABLE Login (idlogin INTEGER PRIMARY KEY AUTOINCREMENT, tipo TEXT NOT NULL, usuario TEXT NOT NULL, "+
"contra 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, " + "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))", "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, " + "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, " + "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)", "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 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), " + "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_producto) REFERENCES producto(idproducto));", "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 '')", "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 idVenta;
public int cantidad; public int cantidad;
public Producto producto; public Variante producto;
public decimal total; 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.cantidad = cantidad;
this.producto = producto; 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;
}
}
}
+27 -9
View File
@@ -405,15 +405,8 @@ namespace compabetov2.database
{ {
DetalleVentaModel detalleVenta = new DetalleVentaModel( DetalleVentaModel detalleVenta = new DetalleVentaModel(
(int)readerDetalleVenta.GetInt64(2), (int)readerDetalleVenta.GetInt64(2),
new Producto( new Variante(-1,"",0,0,"",-1)
(int)readerDetalleVenta.GetInt64(1),
readerDetalleVenta["nombre"].ToString(),
readerDetalleVenta["descripcion"].ToString(),
readerDetalleVenta.GetDecimal(6),
readerDetalleVenta["img"].ToString(),
(int)readerDetalleVenta.GetInt64(8)
),
(int)readerDetalleVenta.GetInt64(0)
) ; ) ;
detallesVenta.Add( detalleVenta ); detallesVenta.Add( detalleVenta );
} }
@@ -455,6 +448,7 @@ namespace compabetov2.database
while (reader.Read()) while (reader.Read())
{ {
Producto producto = new Producto( Producto producto = new Producto(
reader.GetInt32(idIndex), reader.GetInt32(idIndex),
reader.GetString(nombreIndex), reader.GetString(nombreIndex),
@@ -498,5 +492,29 @@ namespace compabetov2.database
return dic; 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;
}
} }
} }
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
3f62af869539c2801b7da3577ef2feb00e7c32f1cefc777b57202fa5ad70cc96 63a64a54bc73e8651fb89f1a0901353ab83d35804c69edd565e24f2be4325b47
Binary file not shown.
Binary file not shown.
Binary file not shown.