Пример #1
0
        public void purchase()                            //Function to display shops for selection
        {
            localhost.WebService1 obj      = new localhost.WebService1();
            LaptopRead            lap      = new LaptopRead();
            MouseRead             mouse    = new MouseRead();
            PendriveRead          pendrive = new PendriveRead();

            int choice;

            Console.Clear();
            Console.WriteLine("***************************** Welcome ******************************");
            Console.WriteLine();
            Console.WriteLine("------------Select the Shop 1/2/3 to display the Items--------------");
            Console.WriteLine();
            Console.WriteLine("-------> Shop-1: Laptop  Shop-2: Mouse  Shop-3: Pendrives <-------");

            Console.WriteLine();
            Console.Write("Choice: ");
            choice = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            switch (choice)
            {
            case 1:
                dynamic x = obj.Getlaptop();
                lap.lapDisplay(x);
                Console.ReadKey();
                break;

            case 2:
                dynamic z = obj.Getmouse();
                mouse.mouseDisplay(z);
                Console.ReadKey();
                break;

            case 3:
                dynamic y = obj.Getpendrive();
                pendrive.pendriveDisplay(y);
                Console.ReadKey();
                break;

            default:
                Console.WriteLine("Invalid choice - Please enter 1/2/3");
                Console.ReadLine();
                Console.Clear();
                break;
            }
        }
Пример #2
0
        public void mouseSelection(dynamic select)                                            //fn to display mouse variant selected by the user
        {
            var       user_id = Console.ReadLine();
            Program   pur     = new Program();
            MouseRead mouse   = new MouseRead();
            int       stock   = 0;
            var       flag    = 0;
            String    user_choice;

            foreach (var i in select)
            {
                if (user_id == i.Id.ToString())
                {
                    Console.WriteLine();
                    Console.WriteLine("---------------------------Your Selection-----------------------------");
                    Console.WriteLine();
                    String id           = i.Id;
                    String brandname    = i.Brand;
                    String price_detail = i.Price;
                    String model_detail = i.Model;
                    String Stock        = i.Stock;

                    mouse.price = Convert.ToInt32(price_detail);
                    stock       = Convert.ToInt32(Stock);
                    Program.brandCart.Add(brandname);
                    Program.priceCart.Add(price_detail);
                    Program.modelCart.Add(model_detail);

                    Console.WriteLine("Id: {0}", id);
                    Console.WriteLine("Brand: {0}", brandname);
                    Console.WriteLine("Model: {0}", model_detail);
                    Console.WriteLine("Price: Rs. {0}", price_detail);
                    Console.WriteLine("----------------------------------------------------------------------");

                    flag = 1;
                }
            }
            if (flag == 1)
            {
                calculation(select);
            }
            else
            {
                Console.WriteLine("Please Enter Correct Item Id:");
                mouseSelection(select);
            }

            void calculation(dynamic calc)
            {
                do
                {
                    Console.WriteLine();
                    Console.Write("Enter the Quantity Required:");
                    mouse.qty        = Convert.ToInt32(Console.ReadLine());
                    mouse.localPrice = mouse.qty * mouse.price;
                    Console.WriteLine("Total Price: Rs. {0}", mouse.localPrice);

                    Console.WriteLine();
                    Console.WriteLine("Do you want to Change quantity? (y/n)");
                    user_choice = Console.ReadLine();
                    Console.WriteLine();

                    while ((user_choice != "y") && (user_choice != "n"))
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid Option. Please Choose 'y' or 'n'");
                        user_choice = Console.ReadLine();
                    }

                    if (user_choice == "n")
                    {
                        stock = stock - mouse.qty;

                        foreach (var i in calc)
                        {
                            if (user_id == i.Id.ToString())
                            {
                                i.Stock = stock;
                            }
                        }
                        string output = JsonConvert.SerializeObject(calc, Formatting.Indented);
                        File.WriteAllText(@"C:\Users\dhinesh.ks\Desktop\WebService\Mouse.json", output);
                        selection();
                    }
                } while (user_choice == "y");
            }

            void selection()
            {
                {
                    Program.quantity.Add(mouse.qty);
                    Program.totalPrice.Add(mouse.localPrice);
                    Program.purchasePrice  += mouse.localPrice;
                    Program.mouseShopPrice += mouse.localPrice;
                    Console.WriteLine("Do you want to purchase another item...(Y/N)");
                    string choice = Console.ReadLine();
                    if (choice == "y" || choice == "Y")
                    {
                        pur.purchase();
                    }
                    else if (choice == "N" || choice == "n")
                    {
                        pur.display();
                    }
                    else
                    {
                        Console.WriteLine("Please Enter Y or N...");
                        selection();
                    }
                }
            }
        }