/// <summary> /// Funcion que limpia el carrito, actualiza el datagrid y devuelve el acumulador a 0 /// </summary> private void LimpiarCarrito() { int nroProducto; if (lstCarrito.Items.Count == 0) { MessageBox.Show("No hay productos en el carrito."); } else { foreach (ListViewItem item in lstCarrito.Items) { nroProducto = int.Parse(item.SubItems[0].Text); int cantidad = int.Parse(item.SubItems[2].Text); Producto productoAgregadoAlCarrito = Comercio.ObtenerProductoPorId(nroProducto); Comercio.QuitarProductoACarrito(productoAgregadoAlCarrito); acumuladorSubtotal = (acumuladorSubtotal - productoAgregadoAlCarrito.Precio); Comercio.AgregarProductoAInventario(nroProducto, cantidad); } Comercio.Carrito.Clear(); ActualizarInventario(); ActualizarCarrito(); acumuladorSubtotal = 0.00; lblNroSubtotal.Text = acumuladorSubtotal.ToString("#.##"); } }
private void btnQuitar_Click(object sender, EventArgs e) { if (lstCarrito.Items.Count == 0) { MessageBox.Show("No hay productos en el carrito."); } else { ListView.SelectedListViewItemCollection productosARestar = lstCarrito.SelectedItems; int nroProducto; foreach (ListViewItem item in productosARestar) { nroProducto = int.Parse(item.SubItems[0].Text); Producto productoAgregadoAlCarrito = Comercio.ObtenerProductoPorId(nroProducto); Comercio.QuitarProductoACarrito(productoAgregadoAlCarrito); acumuladorSubtotal = (acumuladorSubtotal - productoAgregadoAlCarrito.Precio); Comercio.AgregarProductoAInventario(nroProducto, 1); ActualizarInventario(); } lblNroSubtotal.Text = acumuladorSubtotal.ToString("#.##"); ActualizarCarrito(); } }