Ejemplo n.º 1
0
        // filling in the menu with food items
        public void FillMenu()
        {
            try
            {
                var pizzaMarg = new Pizza("Pizza", "Margherita",
                                          "Mozzarella, tomato sauce, oregano, evoo & fresh basil", 16);
                var pizzaHaw = new Pizza("Pizza", "Hawaiian", "Premium leg ham, pineapple, mozzarella & tomato sauce",
                                         18);
                var pizzaMeat = new Pizza("Pizza", "Meat Lovers",
                                          "Chorizo sausage, premium leg ham, rolled pancetta, mild sopressa salami, mushrooms, mozzarella, tomato sauce & oregano",
                                          22);
                var tiramisu = new FoodItems("Dessert", "Tiramisu",
                                             "Fresh mascarpone cheese, Savoiardi biscuits, eggs, marsala, cacao powder & espresso coffee", 10);
                var chocolate = new FoodItems("Dessert", "Philadelphia cheesecake",
                                              "Homemade with fresh Philadelphia cream cheese", 11);
                var water = new FoodItems("Beverage", "Water", "Cool ridge water 600ML", 2);
                var juice = new FoodItems("Beverage", "Juice",
                                          "Apple, Orange, Pineapple, Tomato, Apple and Blackcurrant, Cranberry", 4);


                _menuItems.Add(pizzaMarg);
                _menuItems.Add(pizzaHaw);
                _menuItems.Add(pizzaMeat);
                _menuItems.Add(tiramisu);
                _menuItems.Add(chocolate);
                _menuItems.Add(water);
                _menuItems.Add(juice);

                FoodItemsGrid.ItemsSource = null;
                FoodItemsGrid.ItemsSource = _menuItems;

                DeliveryBlock.Text = _deliveryPrice.ToString("C2", System.Globalization.CultureInfo.GetCultureInfo("en-US"));
            }
            catch (Exception ex)
            {
                // Some other error occurred.
                // Report the error to the user.
                MessageBox.Show(ex.Message, "Error");
            }
        }
Ejemplo n.º 2
0
        // adding food items when "Add" button is clicked, only if every box has been filled in
        public void AddItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (TypeItems.SelectedItem?.ToString() != null &&
                    NextItemsCombo.SelectedItem?.ToString() != null &&
                    QuantityBox.Text != "" &&
                    NameBox.Text != "")
                {
                    switch (_size)
                    {
                    case "Small":
                        _price *= 0.75;
                        break;

                    case "Large":
                        _price *= 1.25;
                        break;
                    }

                    _price         *= _quantity;
                    _totalPrice    += _price;
                    TotalBlock.Text = _totalPrice.ToString("C2", System.Globalization.CultureInfo.GetCultureInfo("en-US"));

                    DeliveryBlock.Text = _deliveryPrice.ToString("C2", System.Globalization.CultureInfo.GetCultureInfo("en-US"));

                    var foodItem = new FoodItems(
                        TypeItems.SelectionBoxItem.ToString(),
                        NextItemsCombo.SelectedItem.ToString(),
                        _price,
                        _quantity
                        );
                    _foodItems.Add(foodItem);


                    DataGridOrderFood.ItemsSource = null;
                    DataGridOrderFood.ItemsSource = _foodItems;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show(
                    "Invalid Input Values");
            }
            catch (Exception ex)
            {
                // Some other error occurred.
                // Report the error to the user.
                MessageBox.Show(ex.Message, "Error");
            }

            // clearing all the boxes

            QuantityBox.Clear();
            AddItem.IsEnabled             = false;
            _price                        = 0;
            _quantity                     = 0;
            _size                         = "";
            NextItemsCombo.ItemsSource    = null;
            PizzaCrustCombo.SelectedIndex = -1;
            NextItemsCombo.Visibility     = Visibility.Hidden;
            PizzaCrustCombo.Visibility    = Visibility.Hidden;
            PizzaSizeCombo.Visibility     = Visibility.Hidden;
            PizzaCrustBlock.Text          = "";
            PizzaSizeBlock.Text           = "";
            PizzaSizeCombo.SelectedIndex  = -1;
            TypeItems.SelectedIndex       = -1;
            FoodBlock.Text                = "";
            NameBox.Text                  = _name;
            NameBox.IsEnabled             = false;
        }