Files
compabetoOG/RegistroVentas.cs
T

163 lines
6.1 KiB
C#

using compabetov2.database;
using compabetov2.database.modelos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace compabetov2
{
public partial class RegistroVentas : Form
{
List<Dictionary<string, dynamic>> ventasYDetalles;
Estadiscticas ventanaPadre;
int cantidadVentas;
int cotaInferior = 0;
int cotaSuperior;
public RegistroVentas(List<Dictionary<string, dynamic>> ventasYDetalles, Estadiscticas ventanaPadre)
{
InitializeComponent();
this.ventanaPadre = ventanaPadre;
this.ventasYDetalles = ventasYDetalles;
cantidadVentas = ventasYDetalles.Count;
lbContador.Text = $"0 - {cantidadVentas}";
cotaSuperior = cantidadVentas > 20 ? 20 : cantidadVentas;
llenarPanel();
}
private void llenarPanel()
{
panelVentas.Controls.Clear();
for(int i = cotaInferior; i < cotaSuperior; i++)
{
Dictionary<string, dynamic> ventaYDetalles = ventasYDetalles[i];
VentaModel venta = ventaYDetalles["venta"];
TableLayoutPanel carta = new TableLayoutPanel();
carta.ColumnCount = 1;
carta.RowCount = 2;
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 70F));
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 30F));
carta.Width = 385;
carta.Height = 150;
carta.BackColor = Color.FromArgb(200, 200, 200);
FlowLayoutPanel infoPanel = new FlowLayoutPanel();
infoPanel.FlowDirection = FlowDirection.TopDown;
infoPanel.Dock = DockStyle.Fill;
Label lbFecha = new Label();
lbFecha.Text = $"Fecha: {venta.fecha}";
lbFecha.Font = new Font(lbFecha.Font.FontFamily, 16);
lbFecha.Width = 700;
Label lbResponzable = new Label();
lbResponzable.Text = $"Responsable: {venta.responzable}";
lbResponzable.Font = new Font(lbResponzable.Font.FontFamily, 16);
lbResponzable.Width = 700;
Label lbTotal = new Label();
lbTotal.Text = $"Total: {venta.total}";
lbTotal.Font = new Font(lbTotal.Font.FontFamily, 16);
lbTotal.Width = 700;
TableLayoutPanel botonesPanel = new TableLayoutPanel();
botonesPanel.RowCount = 1;
botonesPanel.ColumnCount = 2;
botonesPanel.Dock = DockStyle.Fill;
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
botonesPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
botonesPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
Button btnDetalles = new Button();
btnDetalles.Text = "Detalles";
btnDetalles.Dock = DockStyle.Fill;
btnDetalles.FlatStyle = FlatStyle.Flat;
btnDetalles.FlatAppearance.BorderSize = 0;
btnDetalles.BackColor = Color.FromArgb(33, 90, 255);
btnDetalles.Font = new Font(btnDetalles.Font.FontFamily, 16);
btnDetalles.ForeColor = Color.White;
btnDetalles.Click += new EventHandler(delegate (object sender, EventArgs e)
{
List<DetalleVentaModel> detalles = ventaYDetalles["detalles"];
string mensaje = "";
foreach (DetalleVentaModel detalle in detalles)
{
mensaje += $"{detalle.producto.nombre} - {detalle.cantidad}\n";
}
mensaje += $"Total: {venta.total}";
MessageBox.Show(mensaje);
});
Button btnImprimir = new Button();
btnImprimir.Text = "Ticket";
btnImprimir.Dock = DockStyle.Fill;
btnImprimir.FlatStyle = FlatStyle.Flat;
btnImprimir.FlatAppearance.BorderSize = 0;
btnImprimir.BackColor = Color.Yellow;
btnImprimir.Font = new Font(btnImprimir.Font.FontFamily, 16);
btnImprimir.ForeColor = Color.Black;
btnImprimir.Click += new EventHandler(delegate (object sender, EventArgs e)
{
});
infoPanel.Controls.Add(lbFecha);
infoPanel.Controls.Add(lbTotal);
infoPanel.Controls.Add(lbResponzable);
botonesPanel.Controls.Add(btnDetalles, 0, 0);
botonesPanel.Controls.Add(btnImprimir, 1, 0);
carta.Controls.Add(infoPanel, 0, 0);
carta.Controls.Add(botonesPanel, 0, 1);
panelVentas.Controls.Add(carta);
}
foreach (Dictionary<string,dynamic> ventaYDetalles in ventasYDetalles)
{
VentaModel venta = ventaYDetalles["venta"];
}
}
private void btnMenos_Click(object sender, EventArgs e)
{
cotaInferior -= 20;
cotaInferior = cotaInferior > 0 ? cotaInferior : 0;
cotaSuperior -= 20;
cotaSuperior = cotaInferior == 0 ? 20 : cotaSuperior;
llenarPanel();
lbContador.Text = $"{cotaInferior} - {cantidadVentas}";
}
private void btnMas_Click(object sender, EventArgs e)
{
cotaSuperior += 20;
cotaSuperior = cotaSuperior > cantidadVentas ? cantidadVentas : cotaSuperior;
cotaInferior += 20;
cotaInferior = cotaSuperior == cantidadVentas ? cotaSuperior - 20 : cotaInferior;
llenarPanel();
lbContador.Text = $"{cotaInferior} - {cantidadVentas}";
}
private void RegistroVentas_Load(object sender, EventArgs e)
{
}
}
}