コード例 #1
0
        private static List <Order> MakePizzas(List <Order> currentList, StoreLocation s, User u)
        {
            bool makingPizza = true;

            while (makingPizza)

            {
                Console.WriteLine("\nWelcome '{0}'!\nPlease choose your toppings.\n1: Pepperoni\n" +
                                  "2: Ham\n" +
                                  "3: Sausage\n" +
                                  "4: Hotsauce\n", u.UserName);

                string   toppingChoices = Console.ReadLine();
                string[] userChoices    = toppingChoices.Split();
                Pizza    p = new Pizza();

                if (userChoices.Length <= 4)
                {
                    for (int i = 0; i < userChoices.Length; i++)
                    {
                        switch (userChoices[i])
                        {
                        case "1":
                            p.hasPepperoni = 1;
                            break;

                        case "2":
                            p.hasHam = 1;
                            break;

                        case "3":
                            p.hasSausage = 1;
                            break;

                        case "4":
                            p.hasHotsauce = 1;
                            break;

                        default:
                            Console.WriteLine("\nError. Invalid topping choices");
                            break;
                        }
                    }

                    p.price           = p.CalculatePizzaCost(userChoices.Length);
                    p.ingredientCount = userChoices.Length;
                    Order o = new Order(u, s, p, DateTime.Now);

                    if (p.ValidPizzaOrder(p, currentList))
                    {
                        s.UseInventory(s, p);
                        Console.WriteLine("\nPizza is now baking. Order appended to current list.");

                        Console.WriteLine("\nWhat would you like to do?\n1. Check current orders.\n2. Order another pizza.\n3. Stop ordering.");
                        string choice = Console.ReadLine();

                        switch (choice)
                        {
                        case "1":
                            currentListOfUserOrders.Add(o);
                            foreach (var list in currentListOfUserOrders)
                            {
                                Order.UserOrderString(p, u);
                            }
                            break;

                        case "2":
                            UIPrompt();
                            currentListOfUserOrders.Add(o);
                            break;

                        case "3":
                            currentListOfUserOrders.Add(o);
                            makingPizza = false;
                            Console.WriteLine("\nSaving information to database..." +
                                              "\nThank you for using Pizza app.");
                            Console.ReadLine();
                            Environment.Exit(0);
                            break;

                        default:
                            Console.WriteLine("\nUnknown choice.");
                            break;
                        }
                        makingPizza = false;
                    }
                }

                else
                {
                    Console.WriteLine("Error. Too many topping choices.\n");
                }
            }

            return(currentList);
        }