public void AddItem(BarItem item) { items.Add(item); itemsColors.Add(item.Color); itemsNames.Add(item.Name); UpdateTotalQuantity(item.Quantity); }
public bool Contains(BarItem item) { if (itemsColors.Contains(item.Color) || itemsNames.Contains(item.Name)) return true; return false; }
public double GetItemShare(BarItem item) { return Math.Round((item.Quantity / totalQuantity), 4); }
private void itemAddBtn_Click(object sender, RoutedEventArgs e) { if (BarInfoValidator.OneOrMoreFieldsEmpty(dataNameTextBox.Text, quantityTextBox.Text)) { MessageBox.Show("You must fill all data!"); return; } double quantityValue; if (!BarInfoValidator.IsValidDouble(quantityTextBox.Text)) { MessageBox.Show("You must enter valid floating-point number!"); return; } else quantityValue = double.Parse(quantityTextBox.Text); BarItem newItem = new BarItem { Name = dataNameTextBox.Text, Quantity = quantityValue, Color = (SolidColorBrush)barItemColorFill.Fill }; if (bar.Contains(newItem)) MessageBox.Show("Item with the specified name or color already exists!"); else { bar.AddItem(newItem); MessageBox.Show("Item added to the bar!"); } }