Beispiel #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;
            }
        }
        public void pendriveSelection(dynamic select)                                            //fn to display Pendrive variant selected by the user
        {
            var          user_id = Console.ReadLine();
            var          flag    = 0;
            int          stock   = 0;
            String       user_choice;
            Program      pur      = new Program();
            PendriveRead pendrive = new PendriveRead();

            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;

                    pendrive.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:");
                pendriveSelection(select);
            }

            void calculation(dynamic calc)
            {
                do
                {
                    Console.WriteLine();
                    Console.Write("Enter the Quantity Required:");
                    pendrive.qty        = Convert.ToInt32(Console.ReadLine());
                    pendrive.localPrice = pendrive.qty * pendrive.price;
                    Console.WriteLine("Total Price: Rs. {0}", pendrive.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 - pendrive.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\Pendrive.json", output);
                        selection();
                    }
                } while (user_choice == "y");
            }

            void selection()
            {
                {
                    Program.quantity.Add(pendrive.qty);
                    Program.totalPrice.Add(pendrive.localPrice);
                    Program.purchasePrice     += pendrive.localPrice;
                    Program.pendriveShopPrice += pendrive.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();
                    }
                }
            }
        }