示例#1
0
        private void AP_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int i      = ProductInput.SelectedIndex;
                int amount = int.Parse(AmountInput.Text);

                DietProduct product = new DietProduct(products[i], amount);
                diary.AddProductToList(product, mealType);

                this.Close();
            }
            catch (FormatException)
            {
                MessageBox.Show("Cannot add product to meal! Invalid data!");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong! :(");
            }
        }
示例#2
0
 // Interface method.
 public void AddProductToList(DietProduct product, string mealType)
 {
     if (mealType.Equals("Breakfast"))
     {
         breakfastProductsList.Items.Add(product);
     }
     else if (mealType.Equals("Lunch"))
     {
         lunchProductsList.Items.Add(product);
     }
     else if (mealType.Equals("Dinner"))
     {
         dinnerProductsList.Items.Add(product);
     }
 }