Esempio n. 1
0
 public void AddItem(BarItem item)
 {
     items.Add(item);
     itemsColors.Add(item.Color);
     itemsNames.Add(item.Name);
     UpdateTotalQuantity(item.Quantity);
 }
Esempio n. 2
0
        public bool Contains(BarItem item)
        {
            if (itemsColors.Contains(item.Color) || itemsNames.Contains(item.Name))
                return true;

            return false;
        }
Esempio n. 3
0
 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!");
            }
        }