Mermas Design

This commit is contained in:
Michael Robles
2024-01-22 02:36:18 -07:00
parent 2db5006ebb
commit 38de489250
67 changed files with 364 additions and 186 deletions
+371
View File
@@ -0,0 +1,371 @@
namespace compabetov2
{
partial class vender
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.horafecha = new System.Windows.Forms.Timer(this.components);
this.lblfecha = new System.Windows.Forms.Label();
this.lblhora = new System.Windows.Forms.Label();
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox9 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.labeltotal = new System.Windows.Forms.Label();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.panel2 = new System.Windows.Forms.Panel();
this.pictureBox7 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.flowLayoutPanel3 = new System.Windows.Forms.FlowLayoutPanel();
this.txtbusqueda = new System.Windows.Forms.TextBox();
this.bntImprimir = new System.Windows.Forms.Button();
this.responsablecb = new System.Windows.Forms.ComboBox();
this.btnFiar = new System.Windows.Forms.Button();
this.flowLayoutPanel2.SuspendLayout();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox9)).BeginInit();
this.flowLayoutPanel1.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).BeginInit();
this.SuspendLayout();
//
// horafecha
//
this.horafecha.Enabled = true;
this.horafecha.Tick += new System.EventHandler(this.horafecha_Tick);
//
// lblfecha
//
this.lblfecha.AutoSize = true;
this.lblfecha.Font = new System.Drawing.Font("Microsoft Sans Serif", 30F);
this.lblfecha.ForeColor = System.Drawing.Color.Navy;
this.lblfecha.Location = new System.Drawing.Point(493, 105);
this.lblfecha.Name = "lblfecha";
this.lblfecha.Size = new System.Drawing.Size(159, 58);
this.lblfecha.TabIndex = 13;
this.lblfecha.Text = "label2";
this.lblfecha.TextAlign = System.Drawing.ContentAlignment.TopCenter;
this.lblfecha.Click += new System.EventHandler(this.lblfecha_Click);
//
// lblhora
//
this.lblhora.AutoSize = true;
this.lblhora.Font = new System.Drawing.Font("Microsoft Sans Serif", 60F);
this.lblhora.ForeColor = System.Drawing.Color.MediumBlue;
this.lblhora.Location = new System.Drawing.Point(681, -14);
this.lblhora.Name = "lblhora";
this.lblhora.Size = new System.Drawing.Size(318, 113);
this.lblhora.TabIndex = 12;
this.lblhora.Text = "label1";
this.lblhora.Click += new System.EventHandler(this.lblhora_Click);
//
// flowLayoutPanel2
//
this.flowLayoutPanel2.BackgroundImage = global::compabetov2.Properties.Resources.rec;
this.flowLayoutPanel2.Controls.Add(this.panel1);
this.flowLayoutPanel2.Controls.Add(this.label1);
this.flowLayoutPanel2.Controls.Add(this.labeltotal);
this.flowLayoutPanel2.Location = new System.Drawing.Point(1605, -1);
this.flowLayoutPanel2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.flowLayoutPanel2.Name = "flowLayoutPanel2";
this.flowLayoutPanel2.Size = new System.Drawing.Size(324, 1191);
this.flowLayoutPanel2.TabIndex = 11;
this.flowLayoutPanel2.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel2_Paint);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Transparent;
this.panel1.Controls.Add(this.pictureBox9);
this.panel1.Location = new System.Drawing.Point(3, 2);
this.panel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(312, 263);
this.panel1.TabIndex = 8;
//
// pictureBox9
//
this.pictureBox9.Image = global::compabetov2.Properties.Resources.HomeroMenu;
this.pictureBox9.Location = new System.Drawing.Point(64, 34);
this.pictureBox9.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBox9.Name = "pictureBox9";
this.pictureBox9.Size = new System.Drawing.Size(190, 197);
this.pictureBox9.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox9.TabIndex = 8;
this.pictureBox9.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F);
this.label1.ForeColor = System.Drawing.Color.AliceBlue;
this.label1.Location = new System.Drawing.Point(3, 267);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(102, 39);
this.label1.TabIndex = 17;
this.label1.Text = "Total:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// labeltotal
//
this.labeltotal.AutoSize = true;
this.labeltotal.BackColor = System.Drawing.Color.Transparent;
this.labeltotal.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F);
this.labeltotal.ForeColor = System.Drawing.Color.AliceBlue;
this.labeltotal.Location = new System.Drawing.Point(111, 267);
this.labeltotal.Name = "labeltotal";
this.labeltotal.Size = new System.Drawing.Size(0, 39);
this.labeltotal.TabIndex = 18;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.BackgroundImage = global::compabetov2.Properties.Resources.rec;
this.flowLayoutPanel1.Controls.Add(this.panel2);
this.flowLayoutPanel1.Controls.Add(this.button1);
this.flowLayoutPanel1.Controls.Add(this.button2);
this.flowLayoutPanel1.Controls.Add(this.button3);
this.flowLayoutPanel1.Controls.Add(this.button5);
this.flowLayoutPanel1.Location = new System.Drawing.Point(-1, 0);
this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(324, 1199);
this.flowLayoutPanel1.TabIndex = 8;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Transparent;
this.panel2.Controls.Add(this.pictureBox7);
this.panel2.Location = new System.Drawing.Point(3, 2);
this.panel2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(312, 263);
this.panel2.TabIndex = 8;
//
// pictureBox7
//
this.pictureBox7.Image = global::compabetov2.Properties.Resources.HomeroMenu;
this.pictureBox7.Location = new System.Drawing.Point(64, 34);
this.pictureBox7.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBox7.Name = "pictureBox7";
this.pictureBox7.Size = new System.Drawing.Size(190, 197);
this.pictureBox7.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox7.TabIndex = 8;
this.pictureBox7.TabStop = false;
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Transparent;
this.button1.FlatAppearance.BorderSize = 0;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F);
this.button1.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.button1.Image = global::compabetov2.Properties.Resources.Menui1;
this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button1.Location = new System.Drawing.Point(3, 269);
this.button1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.button1.Name = "button1";
this.button1.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0);
this.button1.Size = new System.Drawing.Size(312, 114);
this.button1.TabIndex = 8;
this.button1.Text = "Menú";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.Transparent;
this.button2.FlatAppearance.BorderSize = 0;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F);
this.button2.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.button2.Image = global::compabetov2.Properties.Resources.estadisticasi;
this.button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button2.Location = new System.Drawing.Point(3, 387);
this.button2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.button2.Name = "button2";
this.button2.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0);
this.button2.Size = new System.Drawing.Size(312, 114);
this.button2.TabIndex = 9;
this.button2.Text = "Estadisticas";
this.button2.UseVisualStyleBackColor = false;
//
// button3
//
this.button3.BackColor = System.Drawing.Color.Transparent;
this.button3.FlatAppearance.BorderSize = 0;
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F);
this.button3.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.button3.Image = global::compabetov2.Properties.Resources.productoi;
this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button3.Location = new System.Drawing.Point(3, 505);
this.button3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.button3.Name = "button3";
this.button3.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0);
this.button3.Size = new System.Drawing.Size(312, 114);
this.button3.TabIndex = 10;
this.button3.Text = "Productos";
this.button3.UseVisualStyleBackColor = false;
//
// button5
//
this.button5.BackColor = System.Drawing.Color.Transparent;
this.button5.FlatAppearance.BorderSize = 0;
this.button5.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button5.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F);
this.button5.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.button5.Image = global::compabetov2.Properties.Resources.sesionc;
this.button5.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button5.Location = new System.Drawing.Point(3, 623);
this.button5.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.button5.Name = "button5";
this.button5.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0);
this.button5.Size = new System.Drawing.Size(312, 114);
this.button5.TabIndex = 12;
this.button5.Text = "Salir";
this.button5.UseVisualStyleBackColor = false;
//
// flowLayoutPanel3
//
this.flowLayoutPanel3.Location = new System.Drawing.Point(325, 283);
this.flowLayoutPanel3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.flowLayoutPanel3.Name = "flowLayoutPanel3";
this.flowLayoutPanel3.Size = new System.Drawing.Size(1273, 946);
this.flowLayoutPanel3.TabIndex = 14;
this.flowLayoutPanel3.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel3_Paint);
//
// txtbusqueda
//
this.txtbusqueda.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F);
this.txtbusqueda.Location = new System.Drawing.Point(365, 229);
this.txtbusqueda.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtbusqueda.Name = "txtbusqueda";
this.txtbusqueda.Size = new System.Drawing.Size(666, 36);
this.txtbusqueda.TabIndex = 15;
this.txtbusqueda.TextChanged += new System.EventHandler(this.txtbusqueda_TextChanged);
//
// bntImprimir
//
this.bntImprimir.Location = new System.Drawing.Point(1347, 76);
this.bntImprimir.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.bntImprimir.Name = "bntImprimir";
this.bntImprimir.Size = new System.Drawing.Size(75, 23);
this.bntImprimir.TabIndex = 17;
this.bntImprimir.Text = "Vender";
this.bntImprimir.UseVisualStyleBackColor = true;
this.bntImprimir.Click += new System.EventHandler(this.bntImprimir_Click);
//
// responsablecb
//
this.responsablecb.FormattingEnabled = true;
this.responsablecb.Items.AddRange(new object[] {
"Fabian Herrera",
"Cristofer Perez ",
"Angel Alexander",
"Emilio Urenda"});
this.responsablecb.Location = new System.Drawing.Point(1441, 76);
this.responsablecb.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.responsablecb.Name = "responsablecb";
this.responsablecb.Size = new System.Drawing.Size(121, 24);
this.responsablecb.TabIndex = 18;
this.responsablecb.SelectedIndexChanged += new System.EventHandler(this.responsablecb_SelectedIndexChanged);
//
// btnFiar
//
this.btnFiar.Location = new System.Drawing.Point(1363, 122);
this.btnFiar.Margin = new System.Windows.Forms.Padding(4);
this.btnFiar.Name = "btnFiar";
this.btnFiar.Size = new System.Drawing.Size(100, 28);
this.btnFiar.TabIndex = 19;
this.btnFiar.Text = "Fiar";
this.btnFiar.UseVisualStyleBackColor = true;
this.btnFiar.Click += new System.EventHandler(this.btnFiar_Click);
//
// vender
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(1827, 750);
this.Controls.Add(this.btnFiar);
this.Controls.Add(this.responsablecb);
this.Controls.Add(this.bntImprimir);
this.Controls.Add(this.txtbusqueda);
this.Controls.Add(this.flowLayoutPanel3);
this.Controls.Add(this.lblfecha);
this.Controls.Add(this.lblhora);
this.Controls.Add(this.flowLayoutPanel2);
this.Controls.Add(this.flowLayoutPanel1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "vender";
this.Text = "vender";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.vender_Load);
this.flowLayoutPanel2.ResumeLayout(false);
this.flowLayoutPanel2.PerformLayout();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox9)).EndInit();
this.flowLayoutPanel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.PictureBox pictureBox7;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.ComponentModel.BackgroundWorker backgroundWorker1;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox9;
private System.Windows.Forms.Timer horafecha;
private System.Windows.Forms.Label lblfecha;
private System.Windows.Forms.Label lblhora;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel3;
private System.Windows.Forms.TextBox txtbusqueda;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label labeltotal;
private System.Windows.Forms.Button bntImprimir;
private System.Windows.Forms.ComboBox responsablecb;
private System.Windows.Forms.Button btnFiar;
}
}
+667
View File
@@ -0,0 +1,667 @@
using compabetov2.database;
using compabetov2.database.modelos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
namespace compabetov2
{
public partial class vender : Form
{
private bool masBtnPresionado = false;
private bool menosBtnPresionado = false;
private List<Producto> productos;
private List<TableLayoutPanel> cartas = new List<TableLayoutPanel>();
private decimal total = 0;
private LoginModel loginPrincipal;
public vender(LoginModel loginPrincipal)
{
InitializeComponent();
getData();
llenarLayout();
this.loginPrincipal = loginPrincipal;
}
private void llenarLayout()
{
foreach (Producto producto in productos)
{
TableLayoutPanel carta = new TableLayoutPanel();
carta.ColumnCount = 1;
carta.RowCount = 2;
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 80F));
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 20F));
carta.Width = 220;
carta.Height = 300;
PictureBox pic = new PictureBox();
pic.Dock = DockStyle.Fill;
pic.SizeMode = PictureBoxSizeMode.Zoom;
string rutaImg = Path.Combine(Application.StartupPath, "Resources", producto.img);
pic.Image = Image.FromFile(rutaImg);//hay error aquí
pic.BackgroundImageLayout = ImageLayout.Stretch;
pic.Tag = producto.idProducto;
Label id = new Label();
id.Text = producto.idProducto.ToString();
id.BackColor = Color.FromArgb(82, 82, 82);
id.ForeColor = Color.White;
id.Width = 20;
id.Font = new Font(id.Font, FontStyle.Bold);
id.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
pic.Controls.Add(id);
Label precio = new Label();
precio.Text = "$" + producto.precion.ToString() + " - " + producto.nombre;
precio.BackColor = Color.FromArgb(82, 82, 82);
precio.ForeColor = Color.White;
precio.Width = 40;
precio.Font = new Font(id.Font, FontStyle.Bold);
precio.Dock = DockStyle.Bottom;
pic.Controls.Add(precio);
TableLayoutPanel HUD = new TableLayoutPanel();
HUD.ColumnCount = 3;
HUD.RowCount = 1;
HUD.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
HUD.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
HUD.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33F));
Label contador = new Label();
contador.Text = "0";
contador.Dock = DockStyle.Fill;
contador.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
contador.Font = new Font(contador.Font.FontFamily, 25);
Button btnMenos = new Button();
btnMenos.Text = "-";
btnMenos.Width = 25;
btnMenos.Height = 25;
btnMenos.Font = new Font(btnMenos.Font.FontFamily, 30);
btnMenos.ForeColor = Color.White;
btnMenos.Dock = DockStyle.Fill;
btnMenos.FlatStyle = FlatStyle.Flat;
btnMenos.FlatAppearance.BorderSize = 0;
btnMenos.BackColor = Color.FromArgb(33, 90, 255);
btnMenos.Click += new EventHandler(delegate (object sender, EventArgs e)
{
int numeroContador = int.Parse(contador.Text.ToString());
// Validar que el contador no sea 0 antes de restar
if (numeroContador > 0)
{
contador.Text = (numeroContador - 1).ToString();
total -= producto.precion;
label1.Text = $"Total: ${total}";
// Obtener información del Label id y precio
int idProducto = int.Parse(id.Text);
decimal precioProducto = producto.precion;
// Restar al ticket existente si ya se agregó
RestarDelTicket(idProducto, producto.nombre, precioProducto, 1);
}
else
{
// Mostrar mensaje de advertencia
MessageBox.Show("No puedes vender menos de 0 cosas", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
});
Button btnMas = new Button();
btnMas.Text = "+";
btnMas.Width = 25;
btnMas.Height = 25;
btnMas.Dock = DockStyle.Fill;
btnMas.Font = new Font(btnMas.Font.FontFamily, 30);
btnMas.ForeColor = Color.White;
btnMas.BackColor = Color.FromArgb(33, 90, 255);
btnMas.FlatStyle = FlatStyle.Flat;
btnMas.FlatAppearance.BorderSize = 0;
btnMas.Click += new EventHandler(delegate (object sender, EventArgs e)
{
int numeroContador = int.Parse(contador.Text.ToString());
contador.Text = (numeroContador + 1).ToString();
total += producto.precion;
label1.Text = $"Total: ${total}";
// Obtener información del Label id y precio
int idProducto = int.Parse(id.Text);
decimal precioProducto = producto.precion;
// Generar ticket y agregarlo al flowLayoutPanel2
GenerarTicket(idProducto, producto.nombre, producto.precion, int.Parse(contador.Text), total, rutaImg);
});
HUD.Controls.Add(btnMenos);
HUD.Controls.Add(contador);
HUD.Controls.Add(btnMas);
carta.Controls.Add(pic, 0, 0);
carta.Controls.Add(HUD, 0, 1);
cartas.Add(carta);
flowLayoutPanel3.Controls.Add(carta);
}
}
private void RestarDelTicket(int idProducto, string nombreProducto, decimal precio, int cantidad)
{
foreach (var item in flowLayoutPanel2.Controls)
{
TableLayoutPanel panelProducto = item as TableLayoutPanel;
if (panelProducto != null && panelProducto.Controls.Count > 1)
{
TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel;
if (panelInfo != null && panelInfo.Controls.Count > 2)
{
Label lbnombre = panelInfo.Controls[0] as Label;
if (lbnombre != null)
{
string textoLb = lbnombre.Text;
string[] cadenas = textoLb.Split(':');
string cadena = cadenas[1].Remove(0, 1);
if (cadena.Equals(nombreProducto))
{
Label Lbcantidad = panelInfo.Controls[2] as Label;
Label Lbtotal = panelInfo.Controls[3] as Label;
if (Lbcantidad != null && Lbtotal != null)
{
string textcantidad = Lbcantidad.Text;
string[] cantidadCadenas = textcantidad.Split(' ');
int NuevaCantiad = int.Parse(cantidadCadenas[1]) - cantidad;
int NuevoTotal = (int)(NuevaCantiad * precio);
// Actualizar el ticket existente
Lbcantidad.Text = $"Cantidad: {NuevaCantiad}";
Lbtotal.Text = $"Total: ${NuevoTotal}";
// Si la cantidad llega a 0, eliminar el ticket del flowLayoutPanel2
if (NuevaCantiad == 0)
{
flowLayoutPanel2.Controls.Remove(panelProducto);
}
break;
}
}
}
}
}
}
}
private void GenerarTicket(int idProducto, string nombreProducto, decimal precio, int cantidad, decimal total, string rutaImg)
{
bool existeProducto = false;
int contador_saltar_2_vueltas = 1;
foreach (var item in flowLayoutPanel2.Controls)
{
if (contador_saltar_2_vueltas <= 3)
{
contador_saltar_2_vueltas++;
continue;
}
TableLayoutPanel panelProducto = item as TableLayoutPanel;
TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel;
Label lbnombre = panelInfo.Controls[0] as Label;
string textoLb = lbnombre.Text;
string[] cadenas = textoLb.Split(':');
string cadena = cadenas[1].Remove(0, 1);
if (cadena.Equals(nombreProducto))
{
existeProducto = true;
Label Lbcantidad = panelInfo.Controls[2] as Label;
Label Lbtotal = panelInfo.Controls[3] as Label;
string textcantidad = Lbcantidad.Text;
string[] cantidadCadenas = textcantidad.Split(' ');
int NuevaCantiad = int.Parse(cantidadCadenas[1]) + 1;
int NuevoTotal = (int)(NuevaCantiad * precio);
Lbcantidad.Text = $"Cantidad: {NuevaCantiad}";
Lbtotal.Text = $"Total: ${NuevoTotal}";
}
}
if (!existeProducto)
{
TableLayoutPanel ticketProducto = new TableLayoutPanel();
ticketProducto.RowCount = 1;
ticketProducto.ColumnCount = 2;
ticketProducto.Height = 100;
ticketProducto.Width = 250;
ticketProducto.BackColor = Color.FromArgb(33, 90, 255);
PictureBox pic = new PictureBox();
pic.Dock = DockStyle.Fill;
pic.SizeMode = PictureBoxSizeMode.Zoom;
pic.Image = Image.FromFile(rutaImg);//hay error aquí
pic.BackgroundImageLayout = ImageLayout.Stretch;
Label id = new Label();
id.Text = idProducto.ToString();
id.BackColor = Color.FromArgb(82, 82, 82);
id.ForeColor = Color.White;
id.Width = 20;
id.Font = new Font(id.Font, FontStyle.Bold);
id.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
pic.Controls.Add(id);
TableLayoutPanel infoTicket = new TableLayoutPanel();
infoTicket.ColumnCount = 1;
infoTicket.RowCount = 4;
infoTicket.Dock = DockStyle.Fill;
Label lbNombre = new Label();
lbNombre.Dock = DockStyle.Fill;
lbNombre.Text = $"producto: {nombreProducto}";
lbNombre.ForeColor = Color.White;
Label lbPrecio = new Label();
lbPrecio.Dock = DockStyle.Fill;
lbPrecio.Text = $"Precio: ${precio}";
lbPrecio.ForeColor = Color.White;
Label lbCantidad = new Label();
lbCantidad.Dock = DockStyle.Fill;
lbCantidad.Text = $"Cantidad: {cantidad}";
lbCantidad.ForeColor = Color.White;
Label lbTotal = new Label();
lbTotal.Dock = DockStyle.Fill;
lbTotal.Text = $"Total: ${cantidad * precio}";
lbTotal.ForeColor = Color.White;
infoTicket.Controls.Add(lbNombre, 0, 0);
infoTicket.Controls.Add(lbPrecio, 0, 1);
infoTicket.Controls.Add(lbCantidad, 0, 2);
infoTicket.Controls.Add(lbTotal, 0, 3);
ticketProducto.Controls.Add(pic, 0, 0);
ticketProducto.Controls.Add(infoTicket, 1, 0);
// Agregar el ticket al flowLayoutPanel2
flowLayoutPanel2.Controls.Add(ticketProducto);
}
}
private void getData()
{
this.productos = service.conseguirProductos();
}
private void vender_Load(object sender, EventArgs e)
{
bntImprimir.Enabled = false;
responsablecb.SelectedIndexChanged += responsablecb_SelectedIndexChanged;
}
private void lblhora_Click(object sender, EventArgs e)
{
}
private void lblfecha_Click(object sender, EventArgs e)
{
}
private void horafecha_Tick(object sender, EventArgs e)
{
lblhora.Text = DateTime.Now.ToString("h:mm:ss");
lblfecha.Text = DateTime.Now.ToLongDateString();
}
private void cervezasgb_Enter(object sender, EventArgs e)
{
}
private void flowLayoutPanel3_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Cerrar el formulario de ventas
this.Close();
// Verificar si ya hay una instancia del formulario principal
MenuPrincipal menuprincipalForm = Application.OpenForms.OfType<MenuPrincipal>().FirstOrDefault();
if (menuprincipalForm == null)
{
// Si no hay una instancia, crear una nueva
menuprincipalForm = new MenuPrincipal(loginPrincipal);
// Establecer el formulario principal como el formulario MDI padre
menuprincipalForm.MdiParent = this.MdiParent;
// Mostrar el formulario principal
menuprincipalForm.Show();
}
else
{
// Si ya hay una instancia, simplemente llevarlo al frente
menuprincipalForm.BringToFront();
}
}
private void flowLayoutPanel2_Paint(object sender, PaintEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
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)
{
// Si la opción es "SI", imprimir el ticket
ImprimirTicket();
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if (detalleVentas.Count > 0)
{
VentaModel ventaModel = new VentaModel(total);
if (service.crearVentaDAO(ventaModel, detalleVentas))
{
MessageBox.Show("Venta hecha");
}
}
else
{
MessageBox.Show("No hay ningun producto agregado");
}
}
else
{
// Si la opción es "NO", mostrar mensaje de venta cancelada
MessageBox.Show("Venta cancelada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ImprimirTicket()
{
using (PrintDocument documentoImpresion = new PrintDocument())
{
documentoImpresion.PrintPage += (sender, e) => ImprimirContenido(e);
using (PrintDialog printDialog = new PrintDialog())
{
printDialog.Document = documentoImpresion;
if (printDialog.ShowDialog() == DialogResult.OK)
{
documentoImpresion.Print();
}
}
}
}
private void ImprimirContenido(PrintPageEventArgs e)
{
string responsable = responsablecb.SelectedItem.ToString();
// Contenido que deseas imprimir
string contenido = " Mini Súper\n" +
" Compa BETO\n" +
" Saturnino Peña #44\n" +
" Lomas de la Laguna\n" +
" 311 169 2829\n" +
$" Fecha: {DateTime.Now.ToString("dd/MM/yyyy")}\n" +
$" Hora: {DateTime.Now.ToString("hh:mm:ss")}\n" +
$" Atendió:\n " +
$" {responsable}\n" +
"Producto | Precio | Cantidad\n" +
"------------------------------------\n";
contenido += crearContenidoImprimir();
contenido += $"------------------------------------\n" +
$" Total: ${total}\n" +
"------------------------------------\n" +
" Mini Súper\n" +
" Compa BETO\n" +
" ¡Gracias por su compra!";
// Configuración de la fuente y del área de impresión
Font fuente = new Font("Arial", 10); // Ajustar el tamaño de fuente según sea necesario
PointF posicion = new PointF(0, e.MarginBounds.Top);
// Imprimir el contenido
e.Graphics.DrawString(contenido, fuente, Brushes.Black, posicion);
}
private string crearContenidoImprimir()
{
int contador_saltar_2_vueltas = 1;
string resultado = "";
foreach (var item in flowLayoutPanel2.Controls)
{
if (contador_saltar_2_vueltas <= 3)
{
contador_saltar_2_vueltas++;
continue;
}
TableLayoutPanel panelProducto = item as TableLayoutPanel;
TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel;
Label lbnombre = panelInfo.Controls[0] as Label;
Label lbPrecio = panelInfo.Controls[1] as Label;
Label Lbcantidad = panelInfo.Controls[2] as Label;
Label Lbtotal = panelInfo.Controls[3] as Label;
//nombre producto
string textoLbnombre = lbnombre.Text;
string[] cadenas = textoLbnombre.Split(':');
string productoNombre = cadenas[1].Remove(0, 1);
//precio
string textoLbPrecio = lbPrecio.Text;
cadenas = textoLbPrecio.Split('$');
string precioProducto = cadenas[1];
//cantidad
string textoLbCantidad = Lbcantidad.Text;
cadenas = textoLbCantidad.Split(':');
string cantidadProducto = cadenas[1].Remove(0, 1);
//total
string textoLbTotal = Lbtotal.Text;
cadenas = textoLbTotal.Split('$');
string totalProducto = cadenas[1];
resultado += $"{productoNombre} | ${precioProducto} | {cantidadProducto}\n";
}
return resultado;
}
private void button7_Click(object sender, EventArgs e)
{
List<DetalleVentaModel> detalleVentas = listaProductosVenta();
if(detalleVentas.Count > 0)
{
VentaModel ventaModel = new VentaModel(total);
if(service.crearVentaDAO(ventaModel, detalleVentas))
{
MessageBox.Show("Venta hecha");
}
}
else
{
MessageBox.Show("No hay ningun producto agregado");
}
}
private List<DetalleVentaModel> listaProductosVenta()
{
List<DetalleVentaModel> detalleVentas = new List<DetalleVentaModel>();
int contador_saltar_2_vueltas = 1;
foreach (var item in flowLayoutPanel2.Controls)
{
if (contador_saltar_2_vueltas <= 3)
{
contador_saltar_2_vueltas++;
continue;
}
TableLayoutPanel panelProducto = item as TableLayoutPanel;
TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel;
PictureBox pic = panelProducto.Controls[0] as PictureBox;
Label idLabel = null;
foreach (Control control in pic.Controls)
{
if (control is Label)
{
idLabel = (Label)control;
break;
}
}
int idProducto = int.Parse(idLabel.Text);
Producto producto = new Producto(idProducto);
Label Lbcantidad = panelInfo.Controls[2] as Label;
string textcantidad = Lbcantidad.Text;
string[] cantidadCadenas = textcantidad.Split(' ');
int cantidad = int.Parse(cantidadCadenas[1]);
DetalleVentaModel detalleVenta = new DetalleVentaModel(cantidad, producto);
detalleVentas.Add(detalleVenta);
}
return detalleVentas;
}
private void button6_Click(object sender, EventArgs e)
{
}
private void btnFiar_Click(object sender, EventArgs e)
{
List<DetalleCuentaModel> detallesCuenta = listaProductosCuenta();
if (detallesCuenta.Count > 0)
{
Cuenta ventaModel = new Cuenta(total);
if (service.crearCuenta(ventaModel, detallesCuenta))
{
MessageBox.Show("Fiado");
}
}
else
{
MessageBox.Show("No hay ningun producto agregado");
}
}
private List<DetalleCuentaModel> listaProductosCuenta()
{
List<DetalleCuentaModel> detallesCuentas = new List<DetalleCuentaModel>();
int contador_saltar_2_vueltas = 1;
foreach (var item in flowLayoutPanel2.Controls)
{
if (contador_saltar_2_vueltas <= 3)
{
contador_saltar_2_vueltas++;
continue;
}
TableLayoutPanel panelProducto = item as TableLayoutPanel;
TableLayoutPanel panelInfo = panelProducto.Controls[1] as TableLayoutPanel;
PictureBox pic = panelProducto.Controls[0] as PictureBox;
Label idLabel = null;
foreach (Control control in pic.Controls)
{
if (control is Label)
{
idLabel = (Label)control;
break;
}
}
int idProducto = int.Parse(idLabel.Text);
Producto producto = new Producto(idProducto);
Label Lbcantidad = panelInfo.Controls[2] as Label;
string textcantidad = Lbcantidad.Text;
string[] cantidadCadenas = textcantidad.Split(' ');
int cantidad = int.Parse(cantidadCadenas[1]);
DetalleCuentaModel detalleCuenta = new DetalleCuentaModel(producto, cantidad);
detallesCuentas.Add(detalleCuenta);
}
return detallesCuentas;
}
private void responsablecb_SelectedIndexChanged(object sender, EventArgs e)
{
bntImprimir.Enabled = responsablecb.SelectedIndex != -1;
}
private void txtbusqueda_TextChanged(object sender, EventArgs e)
{
}
}
}
+126
View File
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="horafecha.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>143, 17</value>
</metadata>
</root>