Beispiel #1
0
        static void Main()
        {
            // Read the config file
            Initilizing.ReadConfigFile();

            // Read the pricelist file
            Initilizing.ReadPriceFile();

            // Read the parkinglist file
            ParkingHouse.ReadParkingFile();

            // Goes into the main menu
            Mainmenu.MainMenu();
        }
Beispiel #2
0
        /// <summary>
        /// This method determines how the menu will look and tosses it to the corresponding method.
        /// </summary>
        public static void ParkMenu()
        {
            Console.Clear();
            int freeSpaces = ParkingHouse.FreeSpaces();

            if (freeSpaces >= Initilizing.SpotValue)
            {
                AllChoises();
            }
            else if (freeSpaces == Initilizing.McValue)
            {
                OneSpace();
            }
            else if (freeSpaces == 0)
            {
                NoSpaces();
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method is for parking a vehicle.
        /// </summary>
        public static void ParkVehicle(string type)
        {
            Console.Clear();
            Console.WriteLine("Please enter the registration number:");
            string regNr        = Console.ReadLine().ToUpper();
            int    vehicleValue = 0;

            if (regNr is not "EXIT" && !regNr.Contains("|") && regNr.Length < 11 && regNr.Length > 4)
            {
                (Vehicle spotsTaken, ParkingSpot occupied) = ParkingHouse.FindVehicle(regNr);
                if (spotsTaken is null)
                {
                    if (type == "car")
                    {
                        Car newCar = new(regNr);
                        vehicleValue = newCar.value;
                        ParkingSpot spot = ParkingHouse.SpotFinder(vehicleValue);
                        spot.FreeSpace -= vehicleValue;
                        newCar.timeIn   = DateTime.Now;
                        spot.Vehicles.Add(newCar);
                        ParkingHouse.BackUp();
                        int slot = spot.SpotNumber;
                        Receipt(newCar, "car", slot);
                    }
                    else if (type == "mc")
                    {
                        MC newMc = new(regNr);
                        vehicleValue = newMc.value;
                        ParkingSpot spot = ParkingHouse.SpotFinder(vehicleValue);
                        spot.FreeSpace -= vehicleValue;
                        newMc.timeIn    = DateTime.Now;
                        spot.Vehicles.Add(newMc);
                        ParkingHouse.BackUp();
                        int slot = spot.SpotNumber;
                        Receipt(newMc, "mc", slot);
                    }
                }
                else
                {
                    Console.WriteLine("There is already a vehicle with that registration number parked. Please try again");
                    Console.ReadKey();
                    Parkmenu.ParkMenu();
                }
            }
Beispiel #4
0
        /// <summary>
        /// This method is for the main menu.
        /// </summary>
        public static void MainMenu()
        {
            Console.Clear();
            int fillPercent = ParkingHouse.FillDegree();

            Console.WriteLine($"The current fill degree is: { fillPercent } % ");
            MenuPrinter();
            Console.WriteLine("Welcome to Prague Parking. Please type the number of your menu choice" +
                              "\n1. Park vehicle " +
                              "  2. Check out vehicle" +
                              "  3. Search for and move vehicle" +
                              "  4. Settings and help" +
                              "  5. Close the application" +
                              "\n");
            Console.Write("Number: ");
            string menuChoice = Console.ReadLine();

            int.TryParse(menuChoice, out int choice);

            if (choice >= 1 && choice <= 5)
            {
                switch (choice)
                {
                case 1: Parkmenu.ParkMenu(); break;

                case 2: Checkout.CheckOut(); break;

                case 3: Movevehicle.MoveVehicle(); break;

                case 4: Settingsmenu.SettingsMenu(); break;

                case 5: CloseApplication(); break;

                default:
                    break;
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Invalid input, try again");
                MainMenu();
            }
        }
Beispiel #5
0
        /// <summary>
        /// This method is for the menu Check out vehicle.
        /// </summary>
        public static void CheckOut()
        {
            Console.Clear();
            Mainmenu.MenuPrinter();
            Console.Write("Please enter the registration number of the vehicle you would like to check out: ");
            string regNr = Console.ReadLine().ToUpper();

            (Vehicle foundVehicle, ParkingSpot spot) = ParkingHouse.FindVehicle(regNr);

            if (spot is not null)
            {
                int vehicleCost = 0;
                if (foundVehicle.value == Initilizing.CarValue)
                {
                    vehicleCost = Initilizing.CarCost;
                }
                else
                {
                    vehicleCost = Initilizing.McCost;
                }
                spot.RemoveVehicle(foundVehicle);
                ParkingHouse.BackUp();
                foundVehicle.timeOut = DateTime.Now;
                TimeSpan parkedTime = foundVehicle.timeOut - foundVehicle.timeIn;
                if (parkedTime.Hours < 1)
                {
                    if (parkedTime.Minutes <= Initilizing.FreeMinutes)
                    {
                        Console.WriteLine($"\nThe parking for { foundVehicle.RegNr } is less than { Initilizing.FreeMinutes } minutes and is therefore without cost. " +
                                          $"\nThis vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                    else
                    {
                        Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for more than { Initilizing.FreeMinutes } minutes but less than an hour. " +
                                          $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                }
                else
                {
                    if (parkedTime.Days < 30)
                    {
                        int parkedHours = parkedTime.Hours;
                        parkedHours += 1;
                        int startedDays  = parkedTime.Days;
                        int startedHours = parkedHours + (startedDays * 24);
                        vehicleCost = startedHours * vehicleCost;

                        if (parkedTime.Days >= 1)
                        {
                            Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for { parkedTime.Days } day(s) and { parkedHours } started hours. " +
                                              $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                            Console.ReadKey();
                            Mainmenu.MainMenu();
                        }
                        else
                        {
                            Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for { startedHours } started hours. " +
                                              $"\nThe cost for this parking is { vehicleCost } CZK. This vehicle has been checked out. \n\nPress any key to return to the main menu");
                            Console.ReadKey();
                            Mainmenu.MainMenu();
                        }
                    }
                    else
                    {
                        Console.WriteLine($"\nThe vehicle with the regnr { foundVehicle.RegNr } has been parked for more than a month. " +
                                          $"\nThe cost for this parking is on me :) This vehicle has been checked out. \n\nPress any key to return to the main menu");
                        Console.ReadKey();
                        Mainmenu.MainMenu();
                    }
                }
            }
            else if (regNr == "EXIT")
            {
                Mainmenu.MainMenu();
            }
            else
            {
                Console.WriteLine("There is no vehicle with that registration number, try again");
                Console.ReadKey();
                CheckOut();
            }
        }
Beispiel #6
0
        /// <summary>
        /// This method prints the layout of the parking house and fills the spots with vehicles.
        /// </summary>
        public static void MenuPrinter()
        {
            int spaces       = Initilizing.ParkValue;
            int first        = spaces / 4;
            int second       = first + first;
            int third        = second + first;
            int fourth       = third + (spaces - third);
            int moveCoursor1 = 0;
            int moveCoursor2 = 0;
            int moveCoursor3 = 0;
            int moveCoursor4 = 0;

            for (int i = 1; i <= first; i++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(i);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor1++;
                Console.SetCursorPosition(0, moveCoursor1);
                Console.Write(i + parkingString + "\n");
            }
            for (int j = first + 1; j <= second; j++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(j);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor2++;
                Console.SetCursorPosition(35, moveCoursor2);
                Console.Write(j + parkingString + "\n");
            }
            for (int k = second + 1; k <= third; k++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(k);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor3++;
                Console.SetCursorPosition(70, moveCoursor3);
                Console.Write(k + parkingString + "\n");
            }
            for (int l = third + 1; l <= fourth; l++)
            {
                string      parkingString = "";
                ParkingSpot currentSpot   = ParkingHouse.MainMenuFiller(l);
                foreach (Vehicle vehicle in currentSpot.Vehicles)
                {
                    parkingString += " " + vehicle.type + "-" + vehicle.RegNr;
                }
                moveCoursor4++;
                Console.SetCursorPosition(105, moveCoursor4);
                Console.Write(l + parkingString + "\n");
            }
        }
Beispiel #7
0
        /// <summary>
        /// This metod is for the menu choice "Search for and move vehicle"
        /// </summary>
        public static void MoveVehicle()
        {
            Console.Clear();
            Mainmenu.MenuPrinter();
            Console.Write("Please enter the registration number of the vehicle you would like to search for: ");
            string regNr = Console.ReadLine().ToUpper();

            if (regNr is not "EXIT")
            {
                (Vehicle foundVehicle, ParkingSpot oldSpot) = ParkingHouse.FindVehicle(regNr);
                if (foundVehicle is not null || oldSpot is not null)
                {
                    Console.Write($"\nThis vehicle is parked in spot { oldSpot.SpotNumber }, would you like to move it?: ");
                    string answer = Console.ReadLine().ToUpper();

                    if (answer == "Y" || answer == "YES")
                    {
                        Console.Write("Ok! Where would you like to park it instead?: ");
                        string spotAnswer = Console.ReadLine();
                        bool   correct    = int.TryParse(spotAnswer, out int spotSuggest);

                        if (correct)
                        {
                            ParkingSpot newSpot = ParkingHouse.FreeSpotFinder(foundVehicle.value, spotSuggest);
                            if (newSpot is not null)
                            {
                                oldSpot.RemoveVehicle(foundVehicle);
                                newSpot.Vehicles.Add(foundVehicle);
                                newSpot.FreeSpace -= foundVehicle.value;
                                Console.WriteLine($"\nThe { foundVehicle.type } with the registration number { foundVehicle.RegNr } " +
                                                  $"\nthat was parked in { oldSpot.SpotNumber } has been moved to { newSpot.SpotNumber }.");
                                ParkingHouse.BackUp();
                            }
                            else
                            {
                                Console.WriteLine("This spot is not available." +
                                                  "\nNo changes have been made, please start over");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Incorrect input, please start from the beginning");
                            Console.ReadKey();
                            MoveVehicle();
                        }
                    }
                    else if (answer == "EXIT")
                    {
                        Mainmenu.MainMenu();
                    }
                    else
                    {
                        Mainmenu.MainMenu();
                    }
                }
                else
                {
                    Console.WriteLine("\nThere is no vehicle parked witht that number, press any key to try again");
                    Console.ReadKey();
                    MoveVehicle();
                }
            }