Пример #1
0
        private IBindingList GetOrderedDishesToDisplay()
        {
            IBindingList dataToDisplay = new BindingList <SummarizeOrderEntry>();

            foreach (var dishOrder in _appState.DishesInOrder)
            {
                decimal extrasPrice   = 0;
                var     orderedExtras = new StringBuilder();
                if (dishOrder.Extras != null && dishOrder.Extras.Any())
                {
                    foreach (var dishOrderExtra in dishOrder.Extras)
                    {
                        var extras = _orderHelpers.GetExtrasById(dishOrderExtra);
                        extrasPrice += extras.ExtrasPrice;
                        orderedExtras.AppendLine(extras.ExtrasName);
                    }
                }

                var     orderedDish = _orderHelpers.GetDishById(dishOrder.DishIdentifier);
                decimal price       = (orderedDish.DishPrice + extrasPrice) * dishOrder.Quantity;
                dataToDisplay.Add(new SummarizeOrderEntry
                {
                    DishName   = orderedDish.DishName,
                    Quantity   = dishOrder.Quantity,
                    Extras     = orderedExtras.ToString(),
                    TotalPrice = price
                });
            }

            return(dataToDisplay);
        }
Пример #2
0
        private void buttonAddDishToOrder_Click(object sender, EventArgs e)
        {
            Dish           selectedDish    = _orderHelpers.GetDishById(dataGridViewMenu.SelectedRows[0].Cells["DishIdentifier"].Value.ToString());
            IList <Extras> availableExtras = _orderHelpers.GetAvailableExtrasForCategory(selectedDish.DishCategory);

            DishOrder dishOrder = new DishOrder
            {
                DishIdentifier = selectedDish.DishIdentifier,
                Quantity       = Convert.ToInt32(numericUpDownDishQuantity.Value)
            };


            if (availableExtras.Any())
            {
                using (ChooseExtrasDialog chooseExtrasDialogForm = new ChooseExtrasDialog(availableExtras))
                {
                    chooseExtrasDialogForm.ShowDialog();
                    dishOrder.Extras = new List <string>();
                    IList <Extras> selectedExtras = chooseExtrasDialogForm.SelectedExtras;
                    if (selectedExtras != null)
                    {
                        foreach (var selectedExtra in selectedExtras)
                        {
                            dishOrder.Extras.Add(selectedExtra.ExtrasIdentifier);
                        }
                    }

                    if (chooseExtrasDialogForm.DialogResult == DialogResult.OK)
                    {
                        _appState.DishesInOrder.Add(dishOrder);
                        numericUpDownDishQuantity.Value = 1;
                    }
                }
            }
            else
            {
                _appState.DishesInOrder.Add(dishOrder);
                numericUpDownDishQuantity.Value = 1;
            }
        }