Пример #1
0
        //Order User Interface
        //Allows user to order both preset and custom pizzas
        //Allows multiple orders before comfirmation
        //Allows resetting of order for convenience
        public static void orderUI()
        {
            bool flag = false;

            while (true)
            {
                Console.Clear();
                string pizza;
                int    pizzaAmount;
                Entity db = AccessDb.acc();

                var pizzas = Repository.GetPizza(db);
                Console.WriteLine("Large    Medium    Small    Pizzas"); // prints all pizzas and menus prices on console for user
                Console.WriteLine("----------------------------------");
                foreach (var pie in pizzas)
                {
                    double small  = Math.Round((Double)pie.Small, 2);
                    double medium = Math.Round((Double)pie.Med, 2);
                    double large  = Math.Round((Double)pie.Large, 2);
                    if (pie.PizzaType == "Custom")
                    {
                        Console.WriteLine($"${large}    ${medium}     ${small}    {pie.PizzaType}");
                    }
                    else
                    {
                        Console.WriteLine($"${large}   ${medium}     ${small}    {pie.PizzaType}");
                    }
                }



                Console.WriteLine();
                Console.WriteLine("1. Hawaiian                       o. Options");
                Console.WriteLine("2. Meat Lovers                    c. Clear Order");
                Console.WriteLine("3. Supreme");
                Console.WriteLine("4. Custom");
                Console.WriteLine();
                Console.WriteLine();
                if (flag == true)
                {
                    double preTotal = 0;
                    Console.WriteLine("Current Order:");
                    foreach (var piz in PizzaLt.PizzaList) //prints current order of user
                    {
                        Console.WriteLine($" {piz.Amount} {piz.PizzaType} {piz.Size} {piz.Crust} crust pizza(s) {piz.Topping}");
                        preTotal = piz.Total + preTotal;
                    }
                    Console.WriteLine($"Current Total ${preTotal}"); // prints current total
                }
                Console.WriteLine();
                Console.Write("Please select a type of Pizza, Clear Order, or Return to User Option: ");
                pizza = Console.ReadLine();
                Console.WriteLine();
                string toppings = "";
                if (pizza == "4")
                {
                    toppings = customUI(); // returs the toppings chosen from user
                }

                if (pizza == "1" || pizza == "2" || pizza == "3" || pizza == "4")
                {
                    Console.Write("How many pizzas would you like? ");
                    string pizzaAm;

                    pizzaAm = Console.ReadLine();

                    int value;
                    if (int.TryParse(pizzaAm, out value)) // checks if user type was an integer
                    {
                        pizzaAmount = Convert.ToInt32(pizzaAm);
                        if (pizzaAmount > 99) // if user asks for 100 pizzas or more, the program will not allow it
                        {
                            Console.WriteLine("Cannot purchase more than 99 pizzas");
                            Console.WriteLine("Please Press any key to continue your order");
                            Console.ReadKey();
                            orderUI();
                        }
                        string crust;
                        string size;
                        Console.WriteLine();
                        Console.WriteLine("Select Crust and Size");
                        Console.Write("t for thin, h for handtossed, p for pan: ");
                        crust = (Console.ReadLine());

                        if (crust == "t" || crust == "h" || crust == "p")
                        {
                            Console.Write("s for small, m for medium, and l for large: ");
                            size = Console.ReadLine();
                            if (size == "s" || size == "m" || size == "l")
                            {
                                int pizzaId = Convert.ToInt32(pizza); // converting user input to pizza Id

                                TypeChange tc = new TypeChange();     // converting user input to string equivalents
                                pizza = tc.returnPizza(pizza);
                                crust = tc.returnCrust(crust);
                                size  = tc.returnSize(size);
                                double total;
                                Console.WriteLine();
                                if (pizzaId == 4)
                                {
                                    Calculate cal = new Calculate();
                                    total = cal.calculateCostCustom(pizzaAmount, size, toppings, pizzaId); //send to a pizza cost method custom
                                }
                                else
                                {
                                    Calculate cal = new Calculate();
                                    total = cal.calculateCostPreset(pizzaAmount, size, pizzaId); //send to a pizza cost method preset
                                }

                                double currentTotal = total;
                                if (total > 250) // total cost cannot be more than 250
                                {
                                    Console.WriteLine("Cannot spend more than 250!");
                                    Console.WriteLine("Press any key to restart your order");
                                    Console.ReadKey();
                                    PizzaLt.PizzaList.Clear();
                                    orderUI();
                                }

                                if (flag == true)
                                {
                                    foreach (var piz in PizzaLt.PizzaList) // runs through the list of objects to display order on console
                                    {
                                        Console.WriteLine($"{piz.Amount} {piz.PizzaType} {piz.Size} {piz.Crust} crust pizza(s) {piz.Topping}");
                                        total = total + piz.Total;
                                        if (total > 250)
                                        {
                                            Console.WriteLine("Cannot spend more than 250!");
                                            Console.WriteLine("Press any key to restart your order");
                                            Console.ReadKey();
                                            PizzaLt.PizzaList.Clear();
                                            orderUI();
                                        }
                                    }
                                }
                                total = Math.Round(total, 2);
                                Console.WriteLine($"{pizzaAmount} {pizza} {size} {crust} crust pizza(s) {toppings}"); // displays current order
                                Console.WriteLine($"Your total is ${total}");
                                string confirm;
                                Console.WriteLine();
                                Console.WriteLine("y. Confirm and purchase order");
                                Console.WriteLine("a. Add to your current order");
                                Console.WriteLine();
                                Console.Write("Or enter anything else to clear and restart order: ");
                                confirm = Console.ReadLine();
                                if (confirm == "y") // confirming order begins the process to store user order
                                {
                                    PizzaLt.PizzaList.Add(new Pizzas(PCustomer.Id, currentTotal, pizzaAmount, pizza, size, crust, toppings));
                                    decimal tot;
                                    foreach (var piz in PizzaLt.PizzaList) // goes through the list of objects and stores them to the records table
                                    {
                                        tot = Convert.ToDecimal(piz.Total);
                                        tot = Math.Round(tot, 2);
                                        DateTime dateTime = DateTime.Now;
                                        Records  records  = new Records()
                                        {
                                            UserId    = piz.UserID,
                                            Total     = tot,
                                            DateT     = dateTime,
                                            AmountP   = piz.Amount,
                                            PizzaType = piz.PizzaType,
                                            Size      = piz.Size,
                                            Crust     = piz.Crust,
                                            LocatId   = Location.Id
                                        };

                                        Repository.AddRecords(db, records);
                                    }
                                    Console.WriteLine("Thank You for your purchase");
                                    Thread.Sleep(2000);
                                    optionsUI();
                                }
                                else if (confirm == "a")                                                                                      // adding will allow user to add another pizza to their order
                                {
                                    flag = true;                                                                                              // will show total order for user by running through the List of orders

                                    PizzaLt.PizzaList.Add(new Pizzas(PCustomer.Id, currentTotal, pizzaAmount, pizza, size, crust, toppings)); // stores the current order to a generic list

                                    Console.WriteLine("Please Press any key to continue your order");
                                    Console.ReadKey();
                                }
                                else
                                {
                                    PizzaLt.PizzaList.Clear();
                                    Console.WriteLine("Please Press any key to restart your order");
                                    Console.ReadKey();
                                }
                            }
                            else
                            {
                                Console.WriteLine("Invalid Choice");
                                Console.WriteLine("Please Press any key to continue your order");
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid Choice");
                            Console.WriteLine("Please Press any key to continue your order");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Choice");
                        Console.WriteLine("Please Press any key to continue your order");
                        Console.ReadKey();
                    }
                }
                else if (pizza == "o") // will clear the list of objects and return to user interface
                {
                    PizzaLt.PizzaList.Clear();
                    optionsUI();
                }
                else if (pizza == "c") // will clear the list of objects to reset order
                {
                    PizzaLt.PizzaList.Clear();
                }
                else
                {
                    Console.WriteLine("Invalid Choice");
                    Console.WriteLine("Please Press any key to continue your order");
                    Console.ReadKey();
                }
            }
        }