agrega ticket

This commit is contained in:
carlos
2024-01-08 21:41:49 -06:00
14 changed files with 203 additions and 79 deletions
+113 -25
View File
@@ -13,6 +13,7 @@ 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
{
@@ -26,7 +27,9 @@ namespace compabetov2
private bool menosBtnPresionado = false;
private List<Producto> productos;
private List<TableLayoutPanel> cartas = new List<TableLayoutPanel>();
// private List<Producto>
private decimal total = 0;
private Label ticketLabel;
@@ -49,16 +52,23 @@ namespace compabetov2
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 80F));
carta.RowStyles.Add(new RowStyle(SizeType.Percent, 20F));
carta.Width = 200;
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);
pic.BackgroundImageLayout = ImageLayout.Stretch;
pic.Tag = producto.idProducto;
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();
@@ -89,7 +99,7 @@ namespace compabetov2
contador.Text = "0";
contador.Dock = DockStyle.Fill;
contador.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
contador.Font = new Font(contador.Font.FontFamily, 30);
contador.Font = new Font(contador.Font.FontFamily, 25);
Button btnMenos = new Button();
btnMenos.Text = "-";
@@ -138,15 +148,15 @@ namespace compabetov2
total += producto.precion;
// Obtener información del Label id y precio
int idProducto = int.Parse(id.Text);
decimal precioProducto = producto.precion;
decimal precioProducto = producto.precion;
if (decimal.TryParse(precio.Text, NumberStyles.Currency, CultureInfo.CurrentCulture, out precioProducto))
{
// Generar ticket y agregarlo al flowLayoutPanel2
GenerarTicket(idProducto, producto.nombre, precioProducto, int.Parse(contador.Text), total);
//GenerarTicket(idProducto, producto.nombre, precioProducto, int.Parse(contador.Text), total);
}
else
{
@@ -155,9 +165,9 @@ namespace compabetov2
}
// Generar ticket y agregarlo al flowLayoutPanel2
GenerarTicket(idProducto, producto.nombre, precioProducto, int.Parse(contador.Text), total);
GenerarTicket(idProducto, producto.nombre, producto.precion, int.Parse(contador.Text), total, rutaImg);
// ... (código existente)
});
HUD.Controls.Add(btnMenos);
@@ -168,25 +178,97 @@ namespace compabetov2
carta.Controls.Add(HUD, 0, 1);
cartas.Add(carta);
flowLayoutPanel3.Controls.Add(carta);
}
}
private void GenerarTicket(int idProducto, string nombreProducto, decimal precio, int cantidad, decimal total)
private void GenerarTicket(int idProducto, string nombreProducto, decimal precio, int cantidad, decimal total, string rutaImg)
{
// Crear un nuevo control (puede ser un Label, Panel, etc.) para representar el ticket
Label ticketLabel = new Label();
ticketLabel.Text = $"ID: {idProducto} | Producto: {nombreProducto} | Precio: ${precio} | Cantidad: {cantidad} | Total: ${total}";
ticketLabel.BackColor = Color.LightGray; // Puedes ajustar el color de fondo según tu diseño
ticketLabel.AutoSize = true;
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;
// Agregar el ticket al flowLayoutPanel2
flowLayoutPanel2.Controls.Add(ticketLabel);
}
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(' ');
if (cadenas[1].Equals(nombreProducto))
{
existeProducto=true;
Label Lbcantidad = panelInfo.Controls[0] as Label;
Label Lbtotal = panelInfo.Controls[0] as Label;
string textcantidad = Lbcantidad.Text;
int NuevaCantiad = int.Parse(textcantidad.Split(' ')[1]);
string textoTotal = Lbtotal.Text;
int NuevoTotal = int.Parse(textoTotal.Split('$')[1]) * cantidad;
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;
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}";
Label lbPrecio = new Label();
lbPrecio.Dock = DockStyle.Fill;
lbPrecio.Text = $"Precio: ${precio}";
Label lbCantidad = new Label();
lbCantidad.Dock = DockStyle.Fill;
lbCantidad.Text = $"Cantidad: {cantidad}";
Label lbTotal = new Label();
lbTotal.Dock = DockStyle.Fill;
lbTotal.Text = $"Total: ${cantidad * precio}";
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);
}
}
@@ -196,6 +278,7 @@ namespace compabetov2
private void getData()
{
this.productos = service.conseguirProductos();
@@ -243,6 +326,11 @@ namespace compabetov2
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}