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
+95 -75
View File
@@ -25,10 +25,11 @@ namespace compabetov2
{
private int numeroPagina = 1; // Variable para rastrear el número de página actual
private Point lastPoint;
private List<Producto> productos;
private List<Variante> productos;
public decimal total = 0;
private LoginModel loginPrincipal;
private Dictionary<string, Image> imagenes = new Dictionary<string, Image>();
private List<DetalleVentaModel> carrito = new List<DetalleVentaModel>();
public vender(LoginModel loginPrincipal)
@@ -38,7 +39,7 @@ namespace compabetov2
llenarLayout();
llenarComBox();
this.loginPrincipal = loginPrincipal;
}
}
private void InitializeFlowLayout()
@@ -81,7 +82,7 @@ namespace compabetov2
private void llenarComBox()
{
List<Empleado> empleados = service.conseguirEmpleados();
foreach(Empleado empleado in empleados)
foreach (Empleado empleado in empleados)
{
responsablecb.Items.Add(empleado.nombre);
}
@@ -89,8 +90,8 @@ namespace compabetov2
public void llenarLayout()
{
flowLayoutPanel3.Controls.Clear();
foreach (Producto producto in productos)
flowLayoutPanel3.Controls.Clear();
foreach (Variante producto in productos)
{
TableLayoutPanel carta = new TableLayoutPanel();
@@ -106,7 +107,8 @@ namespace compabetov2
PictureBox pic = new PictureBox();
pic.Dock = DockStyle.Fill;
pic.SizeMode = PictureBoxSizeMode.Zoom;
if (imagenes.ContainsKey(producto.img)) {
if (imagenes.ContainsKey(producto.img))
{
pic.Image = imagenes[producto.img];
}
else
@@ -118,9 +120,9 @@ namespace compabetov2
}
//hay error aquí
pic.BackgroundImageLayout = ImageLayout.Stretch;
pic.Tag = producto.idProducto;
pic.Tag = producto.idVariante;
Label id = new Label();
id.Text = producto.idProducto.ToString();
id.Text = producto.idVariante.ToString();
id.BackColor = Color.FromArgb(82, 82, 82);
id.ForeColor = Color.White;
id.Width = 20;
@@ -129,7 +131,7 @@ namespace compabetov2
pic.Controls.Add(id);
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.ForeColor = Color.White;
precio.Width = 40;
@@ -166,19 +168,23 @@ namespace compabetov2
int numeroContador = int.Parse(contador.Text.ToString());
// Validar que el contador no sea 0 antes de restar
if (existeTocket(producto.nombre))
int indexCarrito = estaEnCarrito(producto.nombre);
if (indexCarrito != -1)
{
contador.Text = (numeroContador - 1).ToString();
total -= producto.precion;
total -= producto.precio;
label1.Text = $"Total: ${total}";
// Obtener información del Label id y precio
int idProducto = int.Parse(id.Text);
decimal precioProducto = producto.precion;
decimal precioProducto = producto.precio;
// 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
{
@@ -201,19 +207,29 @@ namespace compabetov2
btnMas.FlatAppearance.BorderSize = 0;
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
{
if(int.Parse(contador.Text.ToString()) < 0 && !existeTocket(producto.nombre)) {
contador.Text = "0";
if (int.Parse(contador.Text.ToString()) < 0 && !existeTocket(producto.nombre))
{
contador.Text = "0";
}
int numeroContador = int.Parse(contador.Text.ToString());
contador.Text = (numeroContador + 1).ToString();
total += producto.precion;
total += producto.precio;
label1.Text = $"Total: ${total}";
// Obtener información del Label id y precio
int idProducto = int.Parse(id.Text);
decimal precioProducto = producto.precion;
decimal precioProducto = producto.precio;
// 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));
});
@@ -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)
{
foreach (var item in flowLayoutPanel2.Controls)
@@ -255,7 +283,7 @@ namespace compabetov2
{
string textcantidad = Lbcantidad.Text;
string[] cantidadCadenas = textcantidad.Split(' ');
if(int.Parse(cantidadCadenas[1]) > 0)
if (int.Parse(cantidadCadenas[1]) > 0)
{
int NuevaCantiad = int.Parse(cantidadCadenas[1]) - cantidad;
@@ -409,16 +437,9 @@ namespace compabetov2
}
private void getData()
{
this.productos = service.conseguirProductos();
this.productos = service.conseguirVariantes();
}
private void vender_Load(object sender, EventArgs e)
@@ -456,7 +477,7 @@ namespace compabetov2
}
private void button1_Click(object sender, EventArgs e)
{
@@ -497,40 +518,37 @@ namespace compabetov2
private void bntImprimir_Click(object sender, EventArgs e)
{
DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (resultado == DialogResult.Yes)
//List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if (carrito.Count > 0)
{
// Si la opción es "SI", imprimir el ticket
ImprimirTicket();
DialogResult resultado = MessageBox.Show("¿Quieres hacer esa venta?", "Confirmación de Venta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if (detalleVentas.Count > 0)
if (resultado == DialogResult.Yes)
{
VentaModel ventaModel = new VentaModel(total,-1,"",
VentaModel ventaModel = new VentaModel(total, -1, "",
responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text
);
if (service.crearVentaDAO(ventaModel, detalleVentas))
if (service.crearVentaDAO(ventaModel, carrito))
{
MessageBox.Show("Venta hecha");
eliminarProductosTocket();
llenarLayout();
total= 0;
total = 0;
ImprimirTicket();
}
}
else
{
MessageBox.Show("No hay ningun producto agregado");
// Si la opción es "NO", mostrar mensaje de venta cancelada
MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
// Si la opción es "NO", mostrar mensaje de venta cancelada
MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("No hay ningun producto agregado");
}
}
@@ -554,10 +572,10 @@ namespace compabetov2
}
}
private void ImprimirContenido(PrintPageEventArgs e)
{
@@ -572,7 +590,7 @@ namespace compabetov2
$" Fecha: {DateTime.Now.ToString("dd/MM/yyyy")}\n" +
$" Hora: {DateTime.Now.ToString("hh:mm:ss")}\n" +
$" Atendió:\n " +
$" {responsable}\n" +
$" {responsable}\n" +
"Producto | Precio | Cantidad\n" +
"------------------------------------\n";
@@ -594,21 +612,21 @@ namespace compabetov2
e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion);
// Incrementa el número de página
// Tu lógica de impresión actual aquí
// Tu lógica de impresión actual aquí
// Incrementa el número de página
numeroPagina++;
// Incrementa el número de página
numeroPagina++;
// Imprime solo dos páginas
if (numeroPagina <= 2)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
numeroPagina = 1; // Reinicia el número de página para futuras impresiones
}
// Imprime solo dos páginas
if (numeroPagina <= 2)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
numeroPagina = 1; // Reinicia el número de página para futuras impresiones
}
}
@@ -660,11 +678,11 @@ namespace compabetov2
private void button7_Click(object sender, EventArgs e)
{
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if(detalleVentas.Count > 0)
if (detalleVentas.Count > 0)
{
VentaModel ventaModel = new VentaModel(total);
if(service.crearVentaDAO(ventaModel, detalleVentas))
if (service.crearVentaDAO(ventaModel, detalleVentas))
{
MessageBox.Show("Venta hecha");
}
@@ -699,7 +717,7 @@ namespace compabetov2
}
}
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;
string textcantidad = Lbcantidad.Text;
@@ -729,9 +747,9 @@ namespace compabetov2
{
Cuenta ventaModel = new Cuenta(total);
datosCuenta datoCuenta = new datosCuenta(ventaModel, detallesCuenta,this);
datosCuenta datoCuenta = new datosCuenta(ventaModel, detallesCuenta, this);
datoCuenta.Show();
}
else
{
@@ -790,7 +808,8 @@ namespace compabetov2
btnFiar.Enabled = true;
btnEnviar.Enabled = true;
}
else {
else
{
bntImprimir.Enabled = false;
btnFiar.Enabled = false;
@@ -798,7 +817,7 @@ namespace compabetov2
}
}
@@ -807,7 +826,7 @@ namespace compabetov2
{
if (!txtbusqueda.Text.Equals(""))
{
productos = service.conseguirProductosFiltrados(txtbusqueda.Text);
//productos = service.conseguirProductosFiltrados(txtbusqueda.Text);
llenarLayout();
}
else
@@ -861,27 +880,28 @@ namespace compabetov2
{
List<DetalleEnvioModel> detallesEnvio = listaProductosEnvio();
string responsable = responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text;
Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable,"","",total);
if(detallesEnvio.Count > 0){
datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio,this);
Envio envio = new Envio(-1, DateTime.Now.ToString(), "", "", responsable, "", "", total);
if (detallesEnvio.Count > 0)
{
datosEnvio datosEnvio = new datosEnvio(envio, detallesEnvio, this);
datosEnvio.Show();
}
else
{
MessageBox.Show("No hay ningun producto agregado");
}
}
public void eliminarProductosTocket()
{
for (int i = flowLayoutPanel2.Controls.Count -1; i > 2; i--)
for (int i = flowLayoutPanel2.Controls.Count - 1; i > 2; i--)
{
Control c = flowLayoutPanel2.Controls[i];
c.Dispose();
flowLayoutPanel1.Controls.Remove(c);
}
label1.Text = "Total: 0";
txtbusqueda.Text = "";
}