Пример #1
0
        static void Main(string[] args)
        {
            ComponentFactory componentFactory = new ComponentFactory();
            ProductFactory   productFactory   = new ProductFactory();
            SoftwareTypes    softwareTypes    = new SoftwareTypes();

            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("Welcome to Our E-shop");
                Console.WriteLine("What would you like to buy ?\n " +
                                  "press 'a' for  PC tower\n" +
                                  "press 'b' for a PC screen\n" +
                                  "press 'c' for a Personal Computer\n" +
                                  "press 'd' for a Workstation\n" +
                                  "press 'e' to exit\n");


                string answer = Console.ReadLine();

                if (answer.Equals("a"))
                {
                    PCTower pcTower = ConfigurePCTower(componentFactory, productFactory);
                    if (!pcTower.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(pcTower);
                }
                else if (answer.Equals("b"))
                {
                    PCScreen pcScreen = ConfigurePCScreen(productFactory);
                    if (!pcScreen.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(pcScreen);
                }
                else if (answer.Equals("c"))
                {
                    PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory);
                    if (!personalComputer.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    PrintReceiptInfo(personalComputer);
                }
                else if (answer.Equals("d"))
                {
                    PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory);
                    if (!personalComputer.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }

                    Console.WriteLine("Please select one of the available softwares\n");
                    foreach (var type in softwareTypes.Types)
                    {
                        Console.WriteLine(type.Value + "\n");
                    }
                    answer = Console.ReadLine();
                    Software software = componentFactory.CreateComponent("Software") as Software;
                    if (!software.SetValue(answer))
                    {
                        WrongInput();
                        continue;
                    }

                    Workstation workstation = productFactory.CreateProduct("Workstation") as Workstation;
                    if (!workstation.SetPersonalComputer(personalComputer) || !workstation.SetSoftware(software))
                    {
                        continue;
                    }

                    if (!workstation.IsValidProduct())
                    {
                        CannotFinishTheOrder();
                        continue;
                    }
                    PrintReceiptInfo(workstation);
                }
                else if (answer.Equals("e"))
                {
                    exit = true;
                }
                else
                {
                    WrongInput();
                }
            }
        }