Пример #1
0
        public void ChoseCloth(Shop shop)
        {
            Console.WriteLine("Add the name, manufacturer, material and type!");
            Random rand    = new Random();
            string barCode = "";

            for (int count = 0; count < 6; count++)
            {
                barCode += rand.Next(0, 9);
            }

            long   barcode      = long.Parse(barCode); //not unique in any cases
            string name         = Console.ReadLine();
            string manufacturer = Console.ReadLine();
            string material     = Console.ReadLine();
            string type         = Console.ReadLine();

            Console.WriteLine("How much do you want to add?");
            int quantity;

            try
            {
                quantity = int.Parse(Console.ReadLine());
            }
            catch
            {
                throw new Exception("Cannot parse string to int!");
            }


            Console.WriteLine("How much it costs?");
            float price;

            try
            {
                price = float.Parse(Console.ReadLine());
            }
            catch
            {
                throw new Exception("Cannot parse string to float!");
            }

            ClothingProduct cloth = new ClothingProduct(barcode, name, manufacturer, material, type);

            shop.AddNewProduct(cloth, quantity, price);
        }
Пример #2
0
        public void ChoseFood(Shop shop)
        {
            Console.WriteLine("Add the name, manufacturer, calories!");
            Random rand    = new Random();
            string barCode = "";    //not unique

            for (int count = 0; count < 6; count++)
            {
                barCode += rand.Next(0, 9);
            }

            long     barcode      = long.Parse(barCode);
            string   name         = Console.ReadLine();
            string   manufacturer = Console.ReadLine();
            int      calories;
            DateTime bestBefore;

            try
            {
                calories = int.Parse(Console.ReadLine());
                Console.WriteLine("Now the date!");
                Console.Write("Year: ");
                int year = int.Parse(Console.ReadLine());
                Console.Write("\nMonth: ");
                int month = int.Parse(Console.ReadLine());
                Console.Write("\nDay: ");
                int day = int.Parse(Console.ReadLine());
                Console.WriteLine();

                bestBefore = new DateTime(year, month, day);
            }
            catch
            {
                throw new Exception("Convertion Problem!");
            }

            Console.WriteLine("How much do you want to add?");
            int quantity;

            try
            {
                quantity = int.Parse(Console.ReadLine());
            }
            catch
            {
                throw new Exception("Cannot parse string to int!");
            }


            Console.WriteLine("How much it costs?");
            float price;

            try
            {
                price = float.Parse(Console.ReadLine());
            }
            catch
            {
                throw new Exception("Cannot parse string to float!");
            }

            FoodProduct food = new FoodProduct(barcode, name, manufacturer, calories, bestBefore);

            shop.AddNewProduct(food, quantity, price);
        }
Пример #3
0
        bool ChooseShop(Shop shop)
        {
            string choice = AnyInput("Please choose an option...");

            switch (choice)
            {
            case "1":     // is the shop open?
                Console.Clear();
                if (shop.IsOpen())
                {
                    Console.WriteLine("The shop is opened.");
                }
                else
                {
                    Console.WriteLine("The shop is closed.");
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "2":     // open shop
                Console.Clear();
                shop.Open();
                Console.WriteLine("The shop has just opened.");
                Thread.Sleep(1000);
                return(true);

            case "3":     // close shop
                Console.Clear();
                shop.Close();
                Console.WriteLine("The shop has just closed.");
                Thread.Sleep(1000);
                return(true);

            case "4":     // list the products
                Console.Clear();
                Dictionary <long, int>     quanityOfProduct   = new Dictionary <long, int>();
                Dictionary <long, Product> ProductsDictionary = new Dictionary <long, Product>();
                try
                {
                    foreach (Product product in shop.GetProducts())
                    {
                        long barcode = product.GetBarcode();
                        if (quanityOfProduct.ContainsKey(barcode))
                        {
                            quanityOfProduct[barcode] += +1;
                        }
                        else
                        {
                            quanityOfProduct.Add(barcode, 1);
                            ProductsDictionary.Add(barcode, product);
                        }
                    }
                    foreach (KeyValuePair <long, int> item in quanityOfProduct)
                    {
                        Product product = ProductsDictionary[item.Key];
                        Console.Write(product.ToString());
                        Console.WriteLine(", Quantity: " + item.Value);
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed.");
                    Thread.Sleep(1000);
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "5":     // find a product by name
                Console.Clear();
                try
                {
                    string  productName = AnyInput("The name of the product: ");
                    Product product     = shop.FindByName(productName);
                    Console.WriteLine(product.ToString());
                    AnyInput("Press any key to continue...");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed.");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no such product with this name.");
                    Thread.Sleep(1000);
                }
                return(true);

            case "6":     // get the owner of the shop
                Console.Clear();
                Console.WriteLine(shop.GetOwner());
                AnyInput("Press any key to continue...");
                return(true);

            case "7":     // add new product
                try
                {
                    Console.Clear();
                    Console.WriteLine("(1) Add a new foodproduct");
                    Console.WriteLine("(2) Add a new clothing product");
                    while (true)
                    {
                        if (!shop.IsOpen())
                        {
                            throw new ShopIsClosedException();
                        }
                        int    input        = IntInput("Choose an option...");
                        long   barcode      = LongInput("The barcode of the product: ");
                        string name         = AnyInput("The name of the product: ");
                        string manufacturer = AnyInput("The manufacturer of the product: ");
                        if (input == 1)
                        {
                            int         calories    = IntInput("The calorie of the product: ");
                            DateTime    bestBefore  = DateTimeInput("The expiration date of the product: ");
                            FoodProduct foodProduct = new FoodProduct(barcode, name, manufacturer, calories, bestBefore);
                            int         quantity    = IntInput("The quantity of the product: ");
                            int         price       = IntInput("The price of the product: ");
                            shop.AddNewProduct(foodProduct, quantity, price);
                            Console.WriteLine("The new product has added to the shop.");
                            Thread.Sleep(1000);
                            break;
                        }
                        else if (input == 2)
                        {
                            string          material        = AnyInput("The material of the product: ");
                            string          type            = AnyInput("The type of the product: ");
                            ClothingProduct clothingProduct = new ClothingProduct(barcode, name, manufacturer, material, type);
                            int             quantity        = IntInput("The quantity of the product: ");
                            int             price           = IntInput("The price of the product: ");
                            shop.AddNewProduct(clothingProduct, quantity, price);
                            Console.WriteLine("The new product has added to the shop.");
                            Thread.Sleep(1000);
                            break;
                        }
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (ProductAlreadyExistsException)
                {
                    Console.WriteLine("The product is already exist");
                    Thread.Sleep(1000);
                }
                return(true);

            case "8":     // add existing product
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long barcode  = LongInput("The barcode of the product: ");
                    int  quantity = IntInput("The quantity: ");
                    shop.AddProduct(barcode, quantity);
                    Console.WriteLine("The product is added to the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                return(true);

            case "9":     //Buy a product
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long    barcode       = LongInput("The barcode of the product: ");
                    Product boughtProduct = shop.BuyProduct(barcode);
                    cart.Add(boughtProduct);
                    prices.Add(shop.GetPrice(boughtProduct.GetBarcode()));
                    Console.WriteLine("The product is bought from the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has run out of this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "10":     // Buy products
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long           barcode        = LongInput("The barcode of the product: ");
                    int            quantity       = IntInput("The quantity: ");
                    List <Product> boughtProducts = shop.BuyProducts(barcode, quantity);
                    foreach (Product product in boughtProducts)
                    {
                        cart.Add(product);
                        prices.Add(shop.GetPrice(product.GetBarcode()));
                    }
                    Console.WriteLine("The products are bought from the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has not enough from this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "11":     // Get the price
                Console.Clear();
                try
                {
                    long barcode = LongInput("The barcode of the product: ");
                    Console.WriteLine("The price is: " + shop.GetPrice(barcode).ToString());
                    AnyInput("Press any key to continue...");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has not enough from this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "0":
                return(false);

            default:
                return(true);
            }
        }