Пример #1
0
        static public bool AskYesNoQ()
        {
            bool validInput = false;
            bool answer     = false;
            char input;

            while (!validInput)
            {
                try
                {
                    input = Convert.ToChar(Console.ReadLine());
                    if (input == 'y')
                    {
                        answer     = true;
                        validInput = true;
                    }
                    else if (input == 'n')
                    {
                        answer     = false;
                        validInput = true;
                    }
                    else
                    {
                        UserIO.PrintRed("Input not valid, plz try again");
                    }
                }
                catch (Exception)
                {
                    UserIO.PrintRed("Input not valid, plz try again");
                }
            }
            return(answer);
        }
Пример #2
0
        public void OrderIngredient()
        {
            Console.Clear();
            UserIO.PrintRed("Order Ingredient");
            Console.WriteLine();

            ShowAllIngredients();

            Console.WriteLine();
            Console.WriteLine("Select id of ingredient you want to order");
            int id = UserIO.GetUserInt(0, GlobalIngredients.Count - 1);

            Console.WriteLine();
            Console.WriteLine("Enter the amount (max 500)");
            int amount = UserIO.GetUserInt(0, 500);

            if (GlobalIngredients[id].Order(amount))
            {
                UserIO.PrintGreen($"You succesfully orderd {amount} pieces of {GlobalIngredients[id].Name} ");
                UpdateIngredients();
            }
            else
            {
                UserIO.PrintRed("Order failed");
            }
        }
Пример #3
0
        private void ShowInvoice(Order order)
        {
            Console.Clear();
            UserIO.PrintRed($"Order nr:{order.Id}  -  placed on: {order.Date}");
            Console.WriteLine();

            string name      = "";
            string size      = "";
            string crust     = "";
            string quantity  = "";
            string itemPrice = "";

            Console.ForegroundColor = ConsoleColor.Yellow;
            UserIO.PrintPretty("Name", 15, "Size", 30, "Crust", 45, "Quantity", 60, "ItemPrice", true);
            Console.ResetColor();
            Console.WriteLine();

            for (int i = 0; i < order.ItemsArray.Length; i++)
            {
                int pizzaId = order.ItemsArray[i][0];
                name      = Convert.ToString(Pizza_Manager.GlobalPizzas[pizzaId].Name);
                size      = Convert.ToString((PizzaSize)order.ItemsArray[i][1]);
                crust     = Convert.ToString((PizzaCrust)order.ItemsArray[i][2]);
                quantity  = Convert.ToString(order.ItemsArray[i][3]);
                itemPrice = Convert.ToString(order.ItemPriceArray[i]);

                UserIO.PrintPretty(name, 15, size, 30, crust, 45, quantity, 60, itemPrice, true);
            }

            Console.WriteLine();
            UserIO.PrintYellow($"Total items: {order.ItemCount}");
            UserIO.PrintGreen($"Total price: {order.TotalPrice}");
            Console.WriteLine();
            UserIO.PrintDarkRed("Press enter to go back");
        }
Пример #4
0
        static public double GetUserDouble(int minValue, int maxValue)
        {
            bool   validInput     = false;
            double validatedInput = 0;

            while (!validInput)
            {
                try
                {
                    validatedInput = Convert.ToDouble(Console.ReadLine());
                    if (validatedInput >= minValue && validatedInput <= maxValue)
                    {
                        validInput = true;
                    }
                    else
                    {
                        UserIO.PrintRed("Input not valid, plz try again");
                    }
                }
                catch (Exception)
                {
                    UserIO.PrintRed("Input not valid, plz try again");
                }
            }
            return(validatedInput);
        }
Пример #5
0
        static public int Menu(string[] options, string title)
        {
            ConsoleKey keyPressed;
            int        selectionIndex = 0;

            do
            {
                Clear();
                Console.CursorVisible = false;
                UserIO.PrintRed(title);
                Console.WriteLine();

                for (int i = 0; i < options.Length; i++)
                {
                    if (selectionIndex == i)
                    {
                        ForegroundColor = ConsoleColor.White;
                        Write("-> ");
                    }
                    else
                    {
                        ForegroundColor = ConsoleColor.Blue;
                        if (i == options.Length - 1)
                        {
                            ForegroundColor = ConsoleColor.DarkRed;
                        }
                        Write("   ");
                    }

                    Console.WriteLine(options[i]);
                }
                ResetColor();

                ConsoleKeyInfo keyInfo = ReadKey(true);
                keyPressed = keyInfo.Key;

                if (keyPressed == ConsoleKey.UpArrow)
                {
                    selectionIndex--;
                    if (selectionIndex < 0)
                    {
                        selectionIndex = options.Length - 1;
                    }
                }
                else if (keyPressed == ConsoleKey.DownArrow)
                {
                    selectionIndex++;
                    if (selectionIndex > options.Length - 1)
                    {
                        selectionIndex = 0;
                    }
                }
            } while (keyPressed != ConsoleKey.Enter);

            Console.CursorVisible = true;
            return(selectionIndex);
        }
Пример #6
0
 public void CreateNewIngredient()
 {
     if (GetValidUserInput())
     {
         Ingredient ingredient = new Ingredient(Id, Name, Quantity);
         Id++;
         StoreIngredient(ingredient);
         SetGlobalIngredients();
         UserIO.PrintGreen("Ingredient succesfully added, press enter to continue...");
     }
     else
     {
         Console.WriteLine();
         UserIO.PrintRed("adding item failed, press enter to continue...");
     }
 }
Пример #7
0
        public void MakeOrder()
        {
            PizzaManager pizzamanager = new PizzaManager();

            Pizza_Manager = pizzamanager;

            IngredientManager ingredientManager = new IngredientManager();

            Ingredient_Manager = ingredientManager;

            Order newOrder = new Order();
            bool  ordering = true;

            ItemIndex = 0;

            while (ordering)
            {
                Console.Clear();
                ShowCart(newOrder);
                GetUserInput(newOrder);
                SetOrder(newOrder);
                Console.Clear();
                ShowCart(newOrder);
                ItemIndex++;
                Console.WriteLine("Want some more? y/n");
                ordering = UserIO.AskYesNoQ();
            }
            //check if order can be made
            bool succes = CheckItemsAvailable(newOrder);

            if (!succes)
            {
                UserIO.PrintRed("---The order could not be made!---");
                Ingredient_Manager.SetGlobalIngredients();
                return;
            }
            Ingredient_Manager.UpdateIngredients();
            UserIO.PrintGreen("Order was made");
            //print factuur
            Console.ReadLine();
            ShowInvoice(newOrder);
            //store order
            StoreOrder(newOrder);
        }
Пример #8
0
        private void SetOrder(Order newOrder)
        {
            double itemPrice = 0;

            int pizzaId  = newOrder.Items[ItemIndex][0];
            int size     = newOrder.Items[ItemIndex][1];
            int crust    = newOrder.Items[ItemIndex][2];
            int quantity = newOrder.Items[ItemIndex][3];

            if (size == Convert.ToInt32(PizzaSize.small))
            {
                itemPrice = Pizza_Manager.GlobalPizzas[pizzaId].PriceSmall;
            }
            else if (size == Convert.ToInt32(PizzaSize.medium))
            {
                itemPrice = Pizza_Manager.GlobalPizzas[pizzaId].PriceMedium;
            }
            else if (size == Convert.ToInt32(PizzaSize.large))
            {
                itemPrice = Pizza_Manager.GlobalPizzas[pizzaId].PriceLarge;
            }
            else
            {
                UserIO.PrintRed("Error");
            }

            if (crust == Convert.ToInt32(PizzaCrust.CheeseCrust))
            {
                itemPrice += 2;
            }

            itemPrice *= quantity;
            newOrder.ItemPrice.Add(itemPrice);
            newOrder.ItemPriceArray = newOrder.ItemPrice.ToArray();

            newOrder.TotalPrice += itemPrice;
            newOrder.ItemCount  += quantity;
            //newOrder.Date = Convert.ToString(DateTime.Now);
            newOrder.Date = DateTime.Now;

            int id = File_Manager.CountLinesFile(App_Constands.FilePathOrder);

            newOrder.Id = id;
        }
Пример #9
0
 public bool Use(int amount)
 {
     if (Quantity - amount >= MinThreshold)
     {
         Quantity -= amount;
         return(true);
     }
     if (Quantity - amount >= 0)
     {
         UserIO.PrintRed($"Warning! Less then {MinThreshold} {Name} left!");
         Quantity -= amount;
         return(true);
     }
     else
     {
         UserIO.PrintRed($"Not enough {Name}, order some more!");
         return(false);
     }
 }
Пример #10
0
        static public string GetUserString()
        {
            bool   validInput = false;
            string input      = "";

            while (!validInput)
            {
                try
                {
                    input      = Console.ReadLine();
                    validInput = true;
                }
                catch (Exception)
                {
                    UserIO.PrintRed("Input not valid, plz try again");
                }
            }

            return(input);
        }
Пример #11
0
        public void ShowOnePizza(int id)
        {
            IngredientManager ingredientManager = new IngredientManager();

            UserIO.PrintRed($"{GlobalPizzas[id].Name}");
            Console.WriteLine();
            Console.WriteLine("Ingredients:");
            Console.WriteLine();
            for (int i = 0; i < GlobalPizzas[id].Ingredients.Length; i++)
            {
                int ingredientId = GlobalPizzas[id].Ingredients[i];
                Console.WriteLine($"  -{ingredientManager.GetOneIngredient(ingredientId)}");
            }

            Console.WriteLine();
            if (Convert.ToBoolean(GlobalPizzas[id].Veggy))
            {
                UserIO.PrintGreen("This is a vegetarian pizza");
            }
            UserIO.PrintYellow($"\nPriceSmall = {GlobalPizzas[id].PriceSmall} - PriceMedium = {GlobalPizzas[id].PriceMedium} - PriceLarge = {GlobalPizzas[id].PriceLarge}");
        }
Пример #12
0
        public void DisplayOrderList()
        {
            SetGlobalOrders();
            Console.Clear();
            UserIO.PrintRed("Order List");
            Console.WriteLine();
            string[] listOrders = new string[GlobalOrders.Count + 1];

            bool checkingOrders = true;

            while (checkingOrders)
            {
                for (int i = 0; i < GlobalOrders.Count; i++)
                {
                    if (GlobalOrders[i].Id < 10)
                    {
                        listOrders[i] = $"Order: 0{GlobalOrders[i].Id}   Placed on: {GlobalOrders[i].Date}";
                    }
                    else
                    {
                        listOrders[i] = $"Order: {GlobalOrders[i].Id}   Placed on: {GlobalOrders[i].Date}";
                    }
                }

                //add last option to menu
                listOrders[GlobalOrders.Count] = "Back to menu";
                int id = UserIO.Menu(listOrders, "Orders");

                //check if selected option is "back to menu" if not, show the selected order
                if (id == GlobalOrders.Count)
                {
                    checkingOrders = false;
                }
                else
                {
                    ShowInvoice(GlobalOrders[id]);
                    Console.ReadLine();
                }
            }
        }
Пример #13
0
        private bool GetValidUserInput()
        {
            UserIO.PrintRed("Create new ingredient");
            Console.WriteLine();

            Console.WriteLine("Enter name");
            string name = UserIO.GetUserString();

            if (CheckIfInList(name))
            {
                Console.WriteLine();
                Console.WriteLine("Ingredient already exists!");
                return(false);
            }

            Console.WriteLine($"Enter quantity, Max stock is set to 500");
            int quantity = UserIO.GetUserInt(0, 500);

            Name     = name;
            Quantity = quantity;
            return(true);
        }
Пример #14
0
        private bool GetValidUserInput()
        {
            UserIO.PrintRed("Create new pizza");
            Console.WriteLine();
            Console.WriteLine("Enter name");
            string name = UserIO.GetUserString();

            if (CheckIfInList(name))
            {
                Console.WriteLine("Pizza already exists");
                return(false);
            }

            Console.WriteLine("Enter price for a small pizza");
            double priceSmall = UserIO.GetUserDouble(0, 1000);

            Console.WriteLine("Enter price for a medium pizza");
            double priceMedium = UserIO.GetUserDouble(0, 1000);

            Console.WriteLine("Enter price for a large pizza");
            double priceLarge = UserIO.GetUserDouble(0, 1000);

            Console.WriteLine("choose ingredients");
            int[] ingredients = GetIngredients();

            Console.WriteLine("Is this a vegetarian pizza? y/n");
            bool isVeg = UserIO.AskYesNoQ();

            Name        = name;
            PriceSmall  = priceSmall;
            PriceMedium = priceMedium;
            PriceLarge  = priceLarge;
            Ingredients = ingredients;
            IsVeg       = isVeg;
            return(true);
        }
Пример #15
0
        private void ShowBalanceForDay(int day)
        {
            //Loop true all orders and add the prices. fill 2 lists: one with all used ingredients (id),
            //the other with times they where used (quantity * size) 1=small 2=med 3=large
            double     earningsDay     = 0;
            int        itemsDay        = 0;
            List <int> ingredientId    = new List <int>();
            List <int> ingredientCount = new List <int>();

            foreach (var order in SortedByDay[day])
            {
                earningsDay += order.TotalPrice;
                itemsDay    += order.ItemCount;

                for (int i = 0; i < order.ItemsArray.Length; i++)
                {
                    int pizzaId       = order.ItemsArray[i][0];
                    int pizzaSize     = order.ItemsArray[i][1];
                    int pizzaQuantity = order.ItemsArray[i][3];
                    //Console.WriteLine(pizzaId);

                    int[] pizzaIngr = Pizza_Manager.GlobalPizzas[pizzaId].Ingredients;

                    //loop over pizza ingredients
                    for (int j = 0; j < pizzaIngr.Length; j++)
                    {
                        //if id is not in list, ad to list, else add count to existing
                        if (!ingredientId.Contains(pizzaIngr[j]))
                        {
                            ingredientId.Add(pizzaIngr[j]);
                            ingredientCount.Add(pizzaSize * pizzaQuantity);
                        }
                        else
                        {
                            int index = ingredientId.IndexOf(pizzaIngr[j]);
                            ingredientCount[index] += pizzaSize * pizzaQuantity;
                        }
                    }
                }
            }
            IngredientManager ingredientManager = new IngredientManager();

            Ingredient_Manager = ingredientManager;

            //Display obtained info

            Console.Clear();
            UserIO.PrintRed($"Balance for Day {SortedByDay[day][0].Date.ToString("d")}");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Yellow;
            UserIO.PrintPretty("Ingredient used", 20, "Times used");
            Console.WriteLine();
            Console.ResetColor();

            for (int i = 0; i < ingredientId.Count; i++)
            {
                UserIO.PrintPretty($"{ Ingredient_Manager.GetOneIngredient(ingredientId[i]) }", 20, $"{ ingredientCount[i] }");
            }
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"Total Items sold: {itemsDay}");
            UserIO.PrintGreen($"Total income: {earningsDay} EUR");
            Console.WriteLine();

            UserIO.PrintDarkRed("Press enter to go back");

            Console.ReadLine();
        }