static void Main(string[] args) { // Read the config file // läs in configfilen som steg 2 och jämför den med databasen!!! Ifall inte platserna stämmer så måste den ge ett felmeddelande Initilizing.ReadConfigFile(); // Read the pricelist file Initilizing.ReadPriceFile(); // Read the parkinglist file // TODO - byt ut denna mot att läsa in databasen! Börja med detta! ParkingHouse.ReadParkingFile(); // Detta är ett försök till att börja hämta data från databasen List <Vehicle> Vehicles = new List <Vehicle>(); DataAccess db = new(); Vehicles = db.GetVehicles(); foreach (Vehicle vehicle in Vehicles) { Console.WriteLine(vehicle.type); } // Goes into the main menu //Mainmenu.MainMenu(); }
/// <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 == 0) { NoSpaces(); } }
/// <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(); } }
/// <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); int counter = 0; foreach (Vehicle vehicle in currentSpot.Vehicles) { counter += 1; if (counter < 3) { parkingString += " " + vehicle.type + "-" + vehicle.RegNr; } else { parkingString = " More than 3 vehicles"; } } 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"); } }
/// <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 or the bikedescription 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) { TimeSpan parkedTime; if (foundVehicle.type is not "Bus") { spot.RemoveVehicle(foundVehicle); //ParkingHouse.BackUp(); foundVehicle.TimeOut = DateTime.Now; parkedTime = foundVehicle.TimeOut - foundVehicle.timeIn; } else { int removeSpot = spot.SpotNumber; ParkingSpot.RemoveBus(foundVehicle, removeSpot); //ParkingHouse.BackUp(); foundVehicle.TimeOut = DateTime.Now; 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 { foundVehicle.cost } 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); int vehicleCost = startedHours * foundVehicle.cost; 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(); } }
/// <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) { if (foundVehicle.type is not "Bus") { 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"); Console.ReadKey(); MoveVehicle(); } } else { Console.WriteLine("Incorrect input, please start from the beginning"); Console.ReadKey(); MoveVehicle(); } } else { Mainmenu.MainMenu(); } } else { Console.Write($"\nThis bus is parked in spot { oldSpot.SpotNumber } - { oldSpot.SpotNumber + 3 }, would you like to move it?: "); string answer = Console.ReadLine().ToUpper(); if (answer == "Y" || answer == "YES") { Console.Write("Ok! It can only be parked somewhere in the first 50 spots." + "\nplease inser the number of the first spot of the four you would like to park it in: "); string spotAnswer = Console.ReadLine(); bool correct = int.TryParse(spotAnswer, out int spotSuggest); if (correct) { int busSpace = foundVehicle.value / 4; ParkingSpot newSpot = ParkingHouse.FreeBusSpotFinder(spotSuggest); if (newSpot is not null && spotSuggest < 47) { int removeSpot = oldSpot.SpotNumber; ParkingSpot.RemoveBus(foundVehicle, removeSpot); ParkingHouse.ParkingSpots[spotSuggest - 1].FreeSpace -= busSpace; ParkingHouse.ParkingSpots[spotSuggest].FreeSpace -= busSpace; ParkingHouse.ParkingSpots[spotSuggest + 1].FreeSpace -= busSpace; ParkingHouse.ParkingSpots[spotSuggest + 2].FreeSpace -= busSpace; ParkingHouse.ParkingSpots[spotSuggest - 1].Vehicles.Add(foundVehicle); ParkingHouse.ParkingSpots[spotSuggest].Vehicles.Add(foundVehicle); ParkingHouse.ParkingSpots[spotSuggest + 1].Vehicles.Add(foundVehicle); ParkingHouse.ParkingSpots[spotSuggest + 2].Vehicles.Add(foundVehicle); Console.WriteLine($"\nThe bus with the registration number { foundVehicle.RegNr } " + $"\nthat was parked in { oldSpot.SpotNumber } - { oldSpot.SpotNumber + 3 } has been moved to { newSpot.SpotNumber } - { newSpot.SpotNumber + 3 }."); //ParkingHouse.BackUp(); } else if (spotSuggest > 47) { Console.WriteLine("Sorry, all spots above 50 have a too low ceiling to fit a bus"); } else { Console.WriteLine("This spot and the three following ones are not available." + "\nNo changes have been made, please start over"); } } else { Console.WriteLine("Incorrect input, please start from the beginning"); Console.ReadKey(); MoveVehicle(); } } else { Mainmenu.MainMenu(); } }