示例#1
0
文件: Program.cs 项目: volhadl/Task-1
        /*
         * public static void Main(string[] args)
         * {
         *  CreateNumber firsthnum = new CreateNumber(Convert.ToInt32(Console.ReadLine()));
         *
         * }*/


        public static void Main(string[] args)
        {
            var userMenu = new Menu();
            var ioSystem = new IoManager();

            //userMenu.OperatorMenu();
            ioSystem.Print("Hello!");
            ioSystem.input();
        }
示例#2
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");
                }
            }
        }
示例#3
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. ");
                }
            }
        }
示例#4
0
        public static void SerializeBin(IEnumerable <Car> cars)
        {
            var ioManager = new IoManager();

            FileStream fs = new FileStream("DataFile.dat", FileMode.Create);

            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                formatter.Serialize(fs, cars);
            }
            catch (SerializationException e)
            {
                Console.WriteLine("Failed to serialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
        }
示例#5
0
        public static void DeserializeBin()
        {
            var binIoManager = new IoManager();

            IEnumerable <Car> cars = null;
            FileStream        fs   = new FileStream("DataFile.dat", FileMode.Open);

            try
            {
                BinaryFormatter formatter = new BinaryFormatter();

                cars = (List <Car>)formatter.Deserialize(fs);
            }
            catch (SerializationException e)
            {
                Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
            binIoManager.ShowTable(cars);
        }
示例#6
0
文件: CarWorker.cs 项目: volhadl/ol
        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);
            }
        }
示例#7
0
文件: Program.cs 项目: volhadl/Task-1
        public void OperatorMenu()
        {
            var ioManger = new IoManager();

            ioManger.Print("Enter num");
        }