예제 #1
0
        public void Run()
        {
            "Enter the capacity for the Garage".PrintLine();
            var capacity    = Console.ReadLine();
            int capacityNum = 0;

            capacityNum = capacity.ParesToInt(capacityNum);
            var op = new Oprations(capacityNum);
            WriteAndReadFile wRFile = new WriteAndReadFile(capacityNum);

            while (true)
            {
                ("Please navigate through the menu by inputting the number \n(1, 2, 3 ,4, 0) of your choice"
                 + "\n1. Add a new Vehicale"
                 + "\n2. Remove a Vehicale"
                 + "\n3. Print a list of the vehivls in the garage"
                 + "\n4. Print a number of the vehivls in the garage"
                 + "\n5. Search on vehicle via the registration number"
                 + "\n6. Search on vehicles via the Color, wheels number or type"
                 + "\n7. Save all Data to file"
                 + "\n8. Read all the saved Data"
                 + "\n0. Exit the application").PrintLine();

                char input = ' ';
                try
                {
                    input = Console.ReadLine()[0];
                }
                catch (IndexOutOfRangeException)
                {
                    Console.Clear();
                    ("Please enter some input!").PrintLine();
                }
                switch (input)
                {
                case '1':
                    Console.Clear();
                    op.AddVehicleOption();

                    break;

                case '2':
                    Console.Clear();
                    op.ListForRemoveVehicale();

                    op.RemoveItem();
                    break;

                case '3':
                    Console.Clear();
                    "\n*************List of Vehicles************\n".PrintLine();
                    op.PrintVehicleList();
                    $"number of vehicles is: {op.garageHandler.garage.Counter()}\n\n".PrintLine();
                    break;

                case '4':
                    Console.Clear();
                    op.PrintNumOfVehicle();
                    $"number of vehicles is: {op.garageHandler.garage.Counter()}\n\n".PrintLine();
                    break;

                case '5':
                    op.SearchOnVehicle();
                    break;

                case '6':
                    op.SerchViaProperties();
                    break;

                case '7':
                    wRFile.WriteFile();
                    break;

                case '8':
                    op.ReadFromFile();
                    break;

                case '0':
                    Environment.Exit(0);
                    break;

                default:
                    ("Please enter some valid input (0, 1, 2, 3, 4)").PrintLine();
                    break;
                }
            }
        }
예제 #2
0
        public void ReadFromFile()
        {
            WriteAndReadFile wdf = new WriteAndReadFile(Capacity);
            var lines            = wdf.ReadFile();
            var vehList          = garageHandler.garage.ToList();

            if (vehList.Capacity < lines.Capacity)
            {
                "You will not be able to restore all the data because the new capacity less than the data size!\n\n".PrintLine();
            }

            foreach (var line in lines)
            {
                string[] entries = line.Split(',');
                {
                    if (entries[0].ToLower() == "car")
                    {
                        Car car = new Car(entries[1], entries[2], int.Parse(entries[3]), int.Parse(entries[4]));

                        if (!RegistrationIsUnique(car))
                        {
                            garageHandler.Add(car);
                        }
                    }

                    if (entries[0].ToLower() == "boat")
                    {
                        Boat boat = new Boat(entries[1], entries[2], int.Parse(entries[3]), double.Parse(entries[4]));
                        garageHandler.Add(boat);
                    }

                    if (entries[0].ToLower() == "airplane")
                    {
                        Airplane air = new Airplane(entries[1], entries[2], int.Parse(entries[3]), int.Parse(entries[4]));

                        if (!RegistrationIsUnique(air))
                        {
                            garageHandler.Add(air);
                        }
                    }

                    if (entries[0].ToLower() == "bus")
                    {
                        Bus bus = new Bus(entries[1], entries[2], int.Parse(entries[3]), int.Parse(entries[4]));

                        if (!RegistrationIsUnique(bus))
                        {
                            garageHandler.Add(bus);
                        }
                    }

                    if (entries[0].ToLower() == "motorcycle")
                    {
                        Motorcycle motor = new Motorcycle(entries[1], entries[2], int.Parse(entries[3]), entries[4]);

                        if (!RegistrationIsUnique(motor))
                        {
                            garageHandler.Add(motor);
                        }
                    }
                }
            }
            { "Restoring the Date done successfully\n\n".PrintLine(); }
        }