Cada vez más cercas del fippp
This commit is contained in:
@@ -120,11 +120,18 @@ namespace compabetov2
|
||||
{
|
||||
contador.Text = (numeroContador - 1).ToString();
|
||||
total -= producto.precion;
|
||||
|
||||
// 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 cosas negativas", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
MessageBox.Show("No puedes vender menos de 0 cosas", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -190,6 +197,55 @@ namespace compabetov2
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user