// Click en el botón "Intro" para añadir un producto a la lista del pedido private void btnIntro_Click(object sender, RoutedEventArgs e) { if (listVProducts.SelectedIndex != -1) { NewOrderItem order = new NewOrderItem(); order.Id = listVOrders.Items.Count + 1; order.Product = listVProducts.SelectedItem.ToString(); if (txtbOperation.Text != "") { order.Amount = Convert.ToInt16(txtbOperation.Text); txtbOperation.Text = ""; } else { order.Amount = 1; } if (listVOrders.Items.Contains(order)) { ((NewOrderItem)listVOrders.Items[listVOrders.Items.IndexOf(order)]).Amount = ((NewOrderItem)listVOrders.Items[listVOrders.Items.IndexOf(order)]).Amount + order.Amount; listVOrders.Items.Refresh(); } else { listVOrders.Items.Add(order); } } if (listVOrders.Items.Count > 0) { btnAccept.IsEnabled = true; } }
// Dos productos son iguales si tienen el mismo nombre public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj.GetType() != typeof(NewOrderItem)) { return(false); } NewOrderItem o = (NewOrderItem)obj; return(product.Equals(o.Product)); }