示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Wholesaler wholesaler = new Wholesaler();
            Customer   customer   = new Customer();

//Some data as an example
            wholesaler.AddArticle("maciej", 2, DateTime.Now, 15M);
            wholesaler.AddArticle("bakłażan", 5, DateTime.Now, 12M);
            Shop shop = new Shop("MaciejShop");

            shop.AddArticle("rzodkiewka", 12, DateTime.Now, 4.2M);
            shop.AddArticle("burak", 15, DateTime.Now, 2.2M);
            shop.AddArticle("ziemniak", 300, DateTime.Now, 1.5M);
            //
            string odp = "";

            do
            {
                System.Console.WriteLine("Welcome to our ShopSystem.\nAt first you have to declare if you are a shop owner (o) or just a client (c) by typing o or c. ");
                odp = Console.ReadLine();
                switch (odp)
                {
                case "o":
                    do
                    {
                        System.Console.WriteLine("You are in shop management system.\nDo you want to buy articles(b) or see what you have in storage?(s)");
                        odp = Console.ReadLine();
                        switch (odp)
                        {
                        case "b": shop.ReceiveArticles(wholesaler);
                            break;

                        case "s": shop.DrawArticles();
                            break;

                        case "x": odp = "end1";
                            break;
                        }
                    }while(odp != "end1");
                    break;

                case "c":
                    do
                    {
                        System.Console.WriteLine("You are a client in a shop.\nDo you want to buy articles(a) or to see your basket(b)?");
                        odp = Console.ReadLine();
                        switch (odp)
                        {
                        case "a": shop.SellProducts(customer);
                            break;

                        case "b": customer.DrawArticles();
                            break;

                        case "x": odp = "end1";
                            break;
                        }
                    }while(odp != "end1");
                    break;

                case "x": odp = "end";
                    break;
                }
            }while(odp != "end");
        }
示例#2
0
        public void ReceiveArticles(Wholesaler wholesaler)
        {
            string answer;

            do
            {
                System.Console.WriteLine("Chose an item(id) to receive product or type x to exit.");
                foreach (var item in wholesaler.Articles)
                {
                    System.Console.WriteLine($"Id: {item.Id} Name: {item.Name} Quantity: {item.Quantity}");
                }

                answer = Console.ReadLine();

                switch (answer)
                {
                case "x": System.Console.WriteLine("Thanks for using.");
                    break;

                default:
                {
                    try
                    {
                        Convert.ToInt32(answer);
                    }
                    catch
                    {
                        System.Console.WriteLine("Wrong item Id!");
                        break;
                    }

                    if (wholesaler.Articles.Count - 1 < Convert.ToInt32(answer))
                    {
                        System.Console.WriteLine("Wrong item Id!");
                        break;
                    }

                    DrawDetails(wholesaler.Articles[Convert.ToInt32(answer)]);
                    System.Console.WriteLine("How much do you want to buy?");
                    var buyerQuantity = Console.ReadLine();

                    try
                    {
                        Convert.ToInt32(buyerQuantity);
                    }
                    catch
                    {
                        System.Console.WriteLine("Wrong number!");
                        break;
                    }

                    if (wholesaler.Articles[Convert.ToInt32(answer)].Quantity < Convert.ToInt32(buyerQuantity))
                    {
                        System.Console.WriteLine("There's not enough stuff!");
                        break;
                    }
                    wholesaler.Articles[Convert.ToInt32(answer)].Quantity -= Convert.ToInt32(buyerQuantity);
                    int id = 0;
                    if (Articles is null)
                    {
                        id = 0;
                    }
                    else
                    {
                        id = Articles.Count;
                    }
                    Article article = new Article(id, wholesaler.Articles[Convert.ToInt32(answer)].Name, Convert.ToInt32(buyerQuantity), wholesaler.Articles[Convert.ToInt32(answer)].ExpirationDate, wholesaler.Articles[Convert.ToInt32(answer)].TotalPrice);
                    if (Articles is null)
                    {
                        Articles = new List <Article>();
                    }
                    Articles.Add(article);
                }
                break;
                }
            } while (answer != "x");
        }