Ejemplo n.º 1
0
        internal static string FindItem(List <Product> list)
        {
            string        itemBrand;
            List <int>    types  = new List <int>();
            List <string> brands = new List <string>();
            int           i      = 0;

            foreach (var item in list)
            {
                if (!types.Contains(item.Type))
                {
                    types.Add(item.Type);
                }
            }
            Console.WriteLine(Startup.languageInterface[45]);
            foreach (var type in types)
            {
                Console.WriteLine("{0} - {1}", type, Product.GetListItem(type));
            }
            Console.Write(Startup.languageInterface[46]);
            int input = InputChecker.CheckIfInt();

            foreach (var item in list)
            {
                if (item.Type == input)
                {
                    if (item.InStock != 0)
                    {
                        brands.Add(item.Brand);
                    }
                }
            }
            if (brands.Count > 0)
            {
                foreach (var brand in brands)
                {
                    Console.WriteLine("{0}:{1}", i, brand);
                    i++;
                }
                Console.Write(Startup.languageInterface[47]);
                input = InputChecker.CheckIfInt(brands.Count - 1);
                while (input >= brands.Count || input < 0)
                {
                    Console.WriteLine(Startup.languageInterface[48]);
                    int.TryParse(Console.ReadLine(), out input);
                }
                itemBrand = brands[input];
            }
            else
            {
                itemBrand = "Out of stock!";
            }
            return(itemBrand);
        }
Ejemplo n.º 2
0
        //Проверка за съществуването да даден хранителен тип от foodType списъка в Product.cs
        public static int CheckTypeInput(int currentValue)
        {
            for (int i = 0; i < Product.foodType.Count; i++)
            {
                Console.WriteLine("{0}-{1}", i, Product.GetListItem(i));
            }
            Console.WriteLine(Startup.languageInterface[20]);
            Console.WriteLine(Startup.languageInterface[0]);
            ConsoleKey answer = InputChecker.CheckIfEnter();

            if (answer == ConsoleKey.Enter)
            {
                Product.AddItemType();
                Console.Clear();
                foreach (var item in Product.foodType)
                {
                    Console.WriteLine(item);
                }
            }
            Console.Write(Startup.languageInterface[15]);
            bool correct = int.TryParse(Console.ReadLine(), out int type);

            if (string.IsNullOrEmpty(type.ToString()) && !correct)
            {
                Console.WriteLine(Startup.languageInterface[34]);
                return(currentValue);
            }
            else
            {
                while (correct == false || type > Product.foodType.Count || type < 0)
                {
                    if (correct == false)
                    {
                        Console.WriteLine(Startup.languageInterface[35]);
                        correct = int.TryParse(Console.ReadLine(), out type);
                    }
                    else if (type > Product.foodType.Count || type < 0)
                    {
                        Console.WriteLine(Startup.languageInterface[36]);
                        correct = int.TryParse(Console.ReadLine(), out type);
                    }
                }
                return(type);
            }
        }
Ejemplo n.º 3
0
        public List <Product> Sell(List <Product> list)
        {
            List <string> shoppingCart = ShoppingCart(list);

            foreach (var brandName in shoppingCart)
            {
                if (brandName != "Out of stock!")
                {
                    Console.Write(Startup.languageInterface[38], brandName);
                    //int.TryParse(Console.ReadLine(), out int ammount);
                    int ammount = InputChecker.CheckIfInt();
                    foreach (var item in list)
                    {
                        if (item.Brand == brandName)
                        {
                            while (item.InStock < ammount)
                            {
                                Console.WriteLine(Startup.languageInterface[39], brandName, item.InStock);
                                Console.Write(Startup.languageInterface[40]);
                                //int.TryParse(Console.ReadLine(), out ammount);
                                ammount = InputChecker.CheckIfInt(item.InStock);
                            }
                            item.InStock    -= ammount;
                            shoppingCardCost = shoppingCardCost + (item.Price * ammount) + ((item.Price * item.Overcharge) * ammount);
                            Startup.shopCash = Startup.shopCash + (item.Price * ammount) + ((item.Price * item.Overcharge) * ammount);
                            Console.WriteLine(Startup.languageInterface[41], Product.GetListItem(item.Type), brandName, item.InStock);
                            using (StreamWriter sw = new StreamWriter("files/log.txt", true))
                            {
                                sw.WriteLine(Startup.languageInterface[42], DateTime.Now, Product.GetListItem(item.Type), brandName, ammount, (item.Price * ammount) + ((item.Price * item.Overcharge) * ammount));
                            }
                            Console.WriteLine(Startup.languageInterface[62], shoppingCardCost);
                        }
                    }
                    Console.WriteLine(Startup.languageInterface[43]);
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[44]);
                }
            }
            return(list);
        }
Ejemplo n.º 4
0
        public List <Product> Restock(List <Product> list)
        {
            Console.WriteLine(Startup.languageInterface[51]);
            Console.WriteLine(Startup.languageInterface[52]);
            Console.WriteLine(Startup.languageInterface[78]);
            //int.TryParse(Console.ReadLine(), out int input);
            int input = InputChecker.CheckIfInt(3);

            switch (input)
            {
            case 1:
                foreach (var product in list)
                {
                    Console.Clear();
                    Console.WriteLine(Startup.languageInterface[53]);
                    Console.WriteLine(Startup.languageInterface[54], Product.GetListItem(product.Type), product.Brand, product.InStock, product.MaxStock);
                    Console.WriteLine(Startup.languageInterface[55]);
                    ConsoleKey answer = Console.ReadKey(true).Key;
                    if (answer == ConsoleKey.Enter)
                    {
                        Console.WriteLine(Startup.languageInterface[56]);
                        int order = InputChecker.CheckIfInt();
                        while (order + product.InStock > product.MaxStock || order < 0 || order * product.Price > Startup.shopCash)
                        {
                            if (order + product.InStock > product.MaxStock)
                            {
                                Console.WriteLine(Startup.languageInterface[57], product.MaxStock);
                            }
                            else if (order < 0)
                            {
                                Console.WriteLine(Startup.languageInterface[58]);
                            }
                            else if (order * product.Price > Startup.shopCash)
                            {
                                Console.WriteLine(Startup.languageInterface[59]);
                            }
                            Console.Write(Startup.languageInterface[60]);
                            order = InputChecker.CheckIfInt();
                        }
                        Startup.shopCash = Startup.shopCash - order * product.Price;
                        product.InStock  = order + product.InStock;
                    }
                }
                break;

            case 2:
                foreach (var product in list)
                {
                    int ammount = product.MaxStock - product.InStock;
                    if (Startup.shopCash > ammount * product.Price)
                    {
                        Startup.shopCash = Startup.shopCash - ammount * product.Price;
                        product.InStock  = product.MaxStock;
                    }
                    else
                    {
                        Console.WriteLine(Startup.languageInterface[59]);
                    }
                }
                break;

            default:

                break;
            }
            Console.Clear();
            Console.WriteLine(Startup.languageInterface[61]);
            return(list);
        }