Beispiel #1
0
        public static void MainMenu()
        {
            var ioManager = new IoManager();

            while (true)
            {
                ioManager.WriteStepMessage("Menu:");
                ioManager.WriteStepMessage("For work with Data base write: DBO");
                ioManager.WriteStepMessage("For work with Taxi Park write: PARK");

                string menuResponse = ioManager.ReadMenuStep();

                if (menuResponse == "EXITE")
                {
                    Environment.Exit(0);
                }
                else if (menuResponse == "DBO")
                {
                    ioManager.WriteStepMessage("Connection check:");
                    DBOWorker.DBOConnect();
                    DBOMenu();
                }
                else if (menuResponse == "PARK")
                {
                    try
                    {
                        var worker = new CarWorker();
                        worker.ParkMenu();
                    }
                    catch (Exception ex)
                    {
                        ioManager.Write("Somthing went wrong..." + ex.Message);
                        ioManager.Read();
                    }
                    ioManager.Read();
                }
                else
                {
                    ioManager.WriteStepMessage("There is no such command. Try again or write Exite for close programm");
                }
            }
        }
Beispiel #2
0
        public static void DBOMenu()
        {
            var dboIoManager = new IoManager();

            dboIoManager.WriteStepMessage("Data Base Menu:");
            dboIoManager.DBOSubMenu();
            while (true)
            {
                string dboMenuResponse = dboIoManager.ReadMenuStep();
                if (dboMenuResponse == "EXITE")
                {
                    dboIoManager.Write("Connection Closed");
                    break;
                }
                else if (dboMenuResponse == "ADD")
                {
                    DBOWorker.CarInsert();
                }
                else if (dboMenuResponse == "DELETE")
                {
                    DBOWorker.CarDelete();
                }
                else if (dboMenuResponse == "CARS")
                {
                    DBOWorker.SqlInsertMenu();
                }
                else if (dboMenuResponse == "SELECT")
                {
                    DBOWorker.GetCar();
                }
                else if (dboMenuResponse == "UPDATE")
                {
                    DBOWorker.CarPriceUpdate();
                }
                else
                {
                    dboIoManager.Write("There is no such command... Try again or write EXITE for return to Main menu. ");
                }
            }
        }
Beispiel #3
0
        public void ParkMenu()
        {
            var parkIoManager = new IoManager();

            try
            {
                var carPark = GetDefaultCarPark();

                parkIoManager.WriteStepMessage("Park Menu");
                parkIoManager.ParkMenu();
                while (true)
                {
                    string menuStepResp = parkIoManager.ReadMenuStep();
                    parkIoManager.Write(menuStepResp);

                    if (menuStepResp == "CREATE")
                    {
                        parkIoManager.WriteStepMessage("Taxi park is created:");
                        parkIoManager.ShowTable(carPark.Cars);
                    }
                    else if (menuStepResp == "PRICE")
                    {
                        parkIoManager.WriteStepMessage("Car park price:");
                        parkIoManager.WritePrice(carPark.GetPrice());
                    }
                    else if (menuStepResp == "SORT")
                    {
                        parkIoManager.WriteStepMessage("Cars sorted by Fuel Consumption:");
                        parkIoManager.ShowTable(carPark.Cars.OrderBy(car => car.FuelConsumption));
                    }
                    else if (menuStepResp == "SEARCH")
                    {
                        ShowSerchResultByYear(carPark.Cars);
                    }
                    else if (menuStepResp == "SAVEBIN")
                    {
                        ReadWriteDataManager.SerializeBin(carPark.Cars);
                    }
                    else if (menuStepResp == "OPENBIN")
                    {
                        if (!File.Exists(@"D:\\lol.xml"))
                        {
                            throw new OpenFileException("File doesn't exist...");
                        }
                        ReadWriteDataManager.DeserializeBin();
                    }
                    else if (menuStepResp == "XML")
                    {
                        parkIoManager.WriteStepMessage("XML fail is created:");
                        ReadWriteDataManager.SerializeXml(carPark);
                    }
                    else if (menuStepResp == "OPENXML")
                    {
                        if (!File.Exists(@"D:\\lol.xml"))
                        {
                            throw new OpenFileException("File doesn't exist...");
                        }

                        var result = ReadWriteDataManager.DeserializeXml();
                        parkIoManager.ShowTable(result.Cars);
                    }
                    else if (menuStepResp == "EXIT")
                    {
                        break;
                    }
                    else
                    {
                        parkIoManager.Write("There is no such command... Try again or write EXITE for return to Main menu. ");
                    }
                }
            }
            catch (Exception ex)
            {
                parkIoManager.Write("Somthing went wrong...\n" + ex);
            }
        }