private static void catchExceptionAndContinue(GarageLogic.Garage i_Garage, Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(sr_PressAntKey); Console.ReadKey(); askUserForInstructions(i_Garage); }
private static GarageLogic.Car newCar(bool i_isElectric, GarageLogic.Garage i_Garage) { GarageLogic.Car car = GarageLogic.Creator.CreateNewCar(i_isElectric); setVehiclesMembers(i_Garage, car); return(car); }
private static GarageLogic.Truck newTruck(GarageLogic.Garage i_Garage) { GarageLogic.Truck truck = GarageLogic.Creator.CreateNewTruck(); setVehiclesMembers(i_Garage, truck); return(truck); }
private static GarageLogic.Motorcycle newMotorcycle(bool i_isElectric, GarageLogic.Garage i_Garage) { GarageLogic.Motorcycle motorcycle = GarageLogic.Creator.CreateNewMotorcycle(i_isElectric); setVehiclesMembers(i_Garage, motorcycle); return(motorcycle); }
// Ask for a license number from the user, is the number is not in the garage throw ArgumentNullException private string GetLicense(GarageLogic.Garage i_Garage) { Console.WriteLine("Please Enter License Number"); string license = Console.ReadLine(); bool isInGarage = false; while (!isInGarage) { try { isInGarage = i_Garage.IsInGarage(license); } catch (ArgumentNullException e) { Console.WriteLine("Vehicle is not in the Garage"); Console.WriteLine("Press -1 to get back to Main Menu, or any key to retry"); string userDecision = Console.ReadLine(); if (userDecision == "-1") { license = "-1"; break; } Console.Clear(); Console.WriteLine(Environment.NewLine + "Re-enter License Number: "); license = Console.ReadLine(); } } return(license); }
private static void addNewVehicleToGarage(GarageLogic.Garage i_Garage) { string[] specificPropertiesToGet = null; string[] specificPropertiesToSet = null; string licenseNumber = getUserInputOfVehicleLicenceNumberIfItIsNotExistiInGarage(i_Garage); if (!s_InterruptCurrTask) { UserInputOutput.WriteLine(GarageLogic.VehicleFactory.GetListOfAvailableVehiclesToBuild()); GarageLogic.Vehicle newVehicle = buildVehilce(UserInputOutput.ReadLine()); if (!s_InterruptCurrTask) { setStandardDetailsOfNewVehicle(newVehicle, licenseNumber); UserInputOutput.WriteLine(GarageLogic.PropulsionSystemFactory.GetListOfAvailableSystems()); newVehicle.SetPropulsionSystem(newVehicle.GetType().Name, UserInputOutput.ReadLine()); specificPropertiesToGet = newVehicle.GetSpecificPropertiesAsStrings(); specificPropertiesToSet = new string[specificPropertiesToGet.Length]; UserInputOutput.ClearScreen(); for (int i = 0; i < specificPropertiesToGet.Length; i++) { UserInputOutput.WriteLine(specificPropertiesToGet[i]); specificPropertiesToSet[i] = UserInputOutput.ReadLine(); } newVehicle.SetSpecificProperties(specificPropertiesToSet); string[] ownerDetailsToSet = getOwnerDetailsOfVehicleFromUser(); i_Garage.SetOwnerDetailsOfVehicle(licenseNumber, ownerDetailsToSet); i_Garage.AddVehicle(newVehicle); } } }
private static void printLicenceNumbersOfVehicles(GarageLogic.Garage i_Garage) { Console.WriteLine("Do you want to print with filter?"); Console.WriteLine("Press 0 for no filter, 1 for Repair In Progress, 2 for Repair Complete, 3 for Paid"); int chosenFilter; while (!int.TryParse(Console.ReadLine(), out chosenFilter) || !(chosenFilter >= 0 && chosenFilter <= 3)) { Console.WriteLine("Invalid filter. please choose valid filter."); } switch (chosenFilter) { case 0: Console.WriteLine(i_Garage.GetLicenceNumbers()); break; case 1: Console.WriteLine(i_Garage.GetLicenceNumbers(GarageLogic.Vehicle.eVehicleState.RepairInProgress)); break; case 2: Console.WriteLine(i_Garage.GetLicenceNumbers(GarageLogic.Vehicle.eVehicleState.RepairComplete)); break; case 3: Console.WriteLine(i_Garage.GetLicenceNumbers(GarageLogic.Vehicle.eVehicleState.Paid)); break; } }
internal static Dictionary <string, object> GetConfigurationByDictionary(Dictionary <string, Type> i_DefinerDict, GarageLogic.Garage i_Garage, Type i_TargetType) { Console.Clear(); Dictionary <string, object> valuesDict = new Dictionary <string, object>(); foreach (KeyValuePair <string, Type> property in i_DefinerDict) { while (true) { try { object value = GetPropertyFromUser(property.Key, property.Value, i_Garage, i_TargetType); if (value == null) { break; } valuesDict.Add(property.Key, value); Console.Clear(); break; } catch (Exception e) { Console.WriteLine($"Error - {e.InnerException.Message}, press any key to retry..."); Console.ReadKey(); } } } return(valuesDict); }
private static void inflateWheelsToMaxPressure(GarageLogic.Garage i_Garage) { string licenseNumber = getUserInputOfVehicleLicenceNumberIfItExistsInGarage(i_Garage); if (!s_InterruptCurrTask) { i_Garage.FillToMaxAirInWheelsOfVehicle(licenseNumber); } }
private static void showAllCurrentInformationOfVihecle(GarageLogic.Garage i_Garage) { string licenseNumber = getUserInputOfVehicleLicenceNumberIfItExistsInGarage(i_Garage); if (!s_InterruptCurrTask) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine(i_Garage.GetAllDetailsOfVehicle(licenseNumber)); } }
private static void manageGarage() { GarageLogic.Garage garage = new GarageLogic.Garage(); bool finishRun; do { askUserForInstructions(garage); finishRun = exitGerege(); }while (!finishRun); }
private static void chargeElectricVehicle(GarageLogic.Garage i_Garage) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine(@"Type an amount of minutes to charge"); float minutesToCharge = float.Parse(UserInputOutput.ReadLine()); string licenseNumber = getUserInputOfVehicleLicenceNumberIfItExistsInGarage(i_Garage); if (!s_InterruptCurrTask) { i_Garage.ChargeVehicleThatBasedOnElectricSystem(licenseNumber, minutesToCharge); } }
public void RunApp() { m_GarageManager = new GarageLogic.Garage(); bool exit = false; while (!exit) { printMenu(); string selection = Console.ReadLine(); switch (selection) { case "1": case1(); break; case "2": printLicensesByState(); break; case "3": case3(); break; case "4": case4(); break; case "5": case5(); break; case "6": case6(); break; case "7": case7(); break; case "8": Console.WriteLine("Good Bye!!"); exit = true; break; default: Console.WriteLine("Invalid option"); break; } System.Threading.Thread.Sleep(2000); } }
public GarageUI() { // Welcome message Console.WriteLine("welcome to the Garage Manager"); Thread.Sleep(1200); r_Garage = new GarageLogic.Garage(); Operation = new GarageOperations(); // Start Garage StartGarage(); Console.WriteLine("Thank you for chosing Garage Manager"); Console.WriteLine("Press any key to Exit"); }
public ConsoleUI() { m_Garage = new GarageLogic.Garage(); //DEBUG START //Vehicle v1 = m_Garage.vehicleBuilder.buildVehicle(VehicleBuilder.eVehicleType.FuelCar); //v1.LicenseNum = "123"; //m_Garage.AddVehicle(v1); //DEBUG END Run(); }
private static void fillAirInVehicle(GarageLogic.Garage i_Garage) { Console.WriteLine("Please enter the vehicle licence number"); string licenceNumber = Console.ReadLine(); try { i_Garage.FillAirInVehicle(licenceNumber); } catch (Exception ex) { catchExceptionAndContinue(i_Garage, ex); } }
private static void displayVehicleDetails(GarageLogic.Garage i_Garage) { Console.WriteLine("Please enter the vehicle licence number"); string licenceNumber = Console.ReadLine(); try { Console.WriteLine(i_Garage.DisplayVehicleDetails(licenceNumber)); } catch (Exception ex) { catchExceptionAndContinue(i_Garage, ex); } }
private static void askUserForInstructions(GarageLogic.Garage i_Garage) { Console.Clear(); Console.WriteLine("Hello Garage manager. What would you like to do?"); Console.WriteLine("Enter 1 to insert new vehicle to garage."); Console.WriteLine("Enter 2 to see licence number of vehicles in garage."); Console.WriteLine("Enter 3 to change state of vehicle."); Console.WriteLine("Enter 4 to fill air in vehicles wheels"); Console.WriteLine("Enter 5 to fill gas in fuel based vehicle."); Console.WriteLine("Enter 6 to charge electric based vehicle."); Console.WriteLine("Enter 7 to display full details of a vehicle."); int chosenAction; while (!int.TryParse(Console.ReadLine(), out chosenAction) || !(chosenAction >= 1 && chosenAction <= 7)) { Console.WriteLine("Invalid action. please choose valid action."); } switch (chosenAction) { case 1: insertNewVehicle(i_Garage); break; case 2: printLicenceNumbersOfVehicles(i_Garage); break; case 3: changeState(i_Garage); break; case 4: fillAirInVehicle(i_Garage); break; case 5: fillFuel(i_Garage); break; case 6: fillElectricity(i_Garage); break; case 7: displayVehicleDetails(i_Garage); break; } }
// fill air in an existing vehicle's wheels internal void FillAirInVehiclesWheels(GarageLogic.Garage i_Garage) { // gets license number and checks if exist in garage, if not may exit to main menu m_CurrentLicnese = GetLicense(i_Garage); if (m_CurrentLicnese.Equals("-1")) { return; } // fills air in the vehicle i_Garage.FillAirPressure(m_CurrentLicnese); // show success message and takes back to main menu SuccessFinishOperation(); }
public static void Run() { string userInput = null; GarageLogic.Garage garage = new GarageLogic.Garage(); while (!s_Exit) { showGarageMenu(); userInput = Console.ReadLine(); activeMethodAccordingToUserChoiseFromGarageMenu(ValidInputOptions.Parse(userInput), garage); exitIfUserDidNotChooseAnyOption(); } writeHaveAGoodDayMsg(); }
// Print all the details of a spesific vehicle internal void ShowFullVehicleDetails(GarageLogic.Garage i_Garage) { // gets license number and checks if exist in garage, if not may exit to main menu m_CurrentLicnese = GetLicense(i_Garage); if (m_CurrentLicnese.Equals("-1")) { return; } Console.WriteLine(i_Garage.ShowDetails(m_CurrentLicnese) + Environment.NewLine); i_Garage.ShowDetails(m_CurrentLicnese); // show success message and takes back to main menu SuccessFinishOperation(); }
private static string getUserInputOfVehicleLicenceNumberIfItExistsInGarage(GarageLogic.Garage i_Garage) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine(@"Type the 'licence number' of the vehicle"); string licenseNumberInput = UserInputOutput.ReadLine(); while (!i_Garage.isVehicleExists(licenseNumberInput) && !s_InterruptCurrTask) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine(@" The license number of vehicle you typed is not found. Please check your input before you type again or press 'X' to interrupt the task. "); s_InterruptCurrTask = isInterruptTheCurrTask(out licenseNumberInput); } return(licenseNumberInput); }
// Print a list of vehicles in the garage by filter of vehicle status internal void GetVehicleList(GarageLogic.Garage i_Garage) { int option = 0; Console.WriteLine("To Filter by status pick a number of option below: "); // iterate through car statuses available and print them foreach (GarageLogic.Garage.eCarStatus status in Enum.GetValues(typeof(GarageLogic.Garage.eCarStatus))) { Console.WriteLine(option + ". " + status.ToString()); option++; } Console.WriteLine("For default view press 3"); // sets and validate a car status to change to string optionUserPicked = Console.ReadLine(); while (!ValidtysUI.CheckMainPickValidity(optionUserPicked, 0, option)) { Console.WriteLine("Illegal input, Please pick a number between 0 to " + option); optionUserPicked = Console.ReadLine(); } // printing customers list with according filtering List <string> customersList = i_Garage.GetCustomersList(optionUserPicked); if (customersList.Count() == 0) { Console.WriteLine("No customers with required status are in the Garage, or no customers at all"); } else { foreach (string customer in customersList) { Console.WriteLine(customer); } } // show success message and takes back to main menu SuccessFinishOperation(); }
private static void setVehiclesMembers(GarageLogic.Garage i_Garage, GarageLogic.Vehicle i_Vehicle) { Console.WriteLine("Please insert licence number"); string licenceNumber = Console.ReadLine(); i_Vehicle.LicenceNumber = licenceNumber; if (i_Garage.InsertNewVehicleToGarage(i_Vehicle)) { Dictionary <string, string> generalVehicleDictionary = i_Vehicle.VehicleInput(); Dictionary <string, string> typeVehicleDictionary = i_Vehicle.NeededInputs(); fillDictionary(generalVehicleDictionary); fillDictionary(typeVehicleDictionary); try { i_Vehicle.ParseVehicleInput(generalVehicleDictionary); i_Vehicle.ParseNeededInput(typeVehicleDictionary); } catch (Exception ex) { i_Garage.DeleteVehicleFromGerage(licenceNumber); catchExceptionAndContinue(i_Garage, ex); } } else { Dictionary <string, string> excistingVehicleDictionary = i_Vehicle.InputForExistingVehicle(); fillDictionary(excistingVehicleDictionary); try { i_Vehicle.ParseExsitcingVehicleInput(excistingVehicleDictionary); } catch (Exception ex) { catchExceptionAndContinue(i_Garage, ex); } i_Vehicle.VehicleState = GarageLogic.Vehicle.eVehicleState.RepairInProgress; } }
private static void insertNewVehicle(GarageLogic.Garage i_Garage) { Console.WriteLine("To insert new elecrtic motorcycle, Enter 1, "); Console.WriteLine("To insert new fuel-based motorcycle, Enter 2, "); Console.WriteLine("To insert new elecrtic car, Enter 3"); Console.WriteLine("To insert new fuel-based car, Enter 4"); Console.WriteLine("To insert new truck, Enter 5"); int chosenVehiclel; int.TryParse(Console.ReadLine(), out chosenVehiclel); while (chosenVehiclel < 1 || chosenVehiclel > 5) { Console.WriteLine("Invalid input, please choose valid vehicle <1-5>"); int.TryParse(Console.ReadLine(), out chosenVehiclel); } switch (chosenVehiclel) { case 1: GarageLogic.Motorcycle electriMotorcyle = newMotorcycle(true, i_Garage); break; case 2: GarageLogic.Motorcycle fueledMotorcycle = newMotorcycle(false, i_Garage); break; case 3: GarageLogic.Car electricCar = newCar(true, i_Garage); break; case 4: GarageLogic.Car fueledCar = newCar(false, i_Garage); break; case 5: GarageLogic.Truck truck = newTruck(i_Garage); break; } }
private static void refeulFuelVehicle(GarageLogic.Garage i_Garage) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine(@"Type an amount of fuel you want to refill in liters"); float litersOfFuelToRefuel = float.Parse(UserInputOutput.ReadLine()); UserInputOutput.WriteLine(@" Choose a type of fuel: ===================== 1-> Octan98 2-> Octan96 3-> Octan95 4-> Soler"); GarageLogic.FuelType fuelType = GarageLogic.FuelType.Parse(UserInputOutput.ReadLine()); string licenseNumber = getUserInputOfVehicleLicenceNumberIfItExistsInGarage(i_Garage); if (!s_InterruptCurrTask) { i_Garage.FillFuelInVehicleThatBasedOnFuelSystem(licenseNumber, fuelType, litersOfFuelToRefuel); } }
private static void showLicenseNumsOfVehiclesAccordingTheKey(GarageLogic.Garage i_Garage) { string[] licenseNumsContainer = null; showVehiclesStatusOptions(); GarageLogic.GarageVehicleStatus key = GarageLogic.GarageVehicleStatus.Parse(UserInputOutput.ReadLine()); UserInputOutput.ClearScreen(); if (key.VehicleStatus == GarageLogic.eGarageVehicleStatus.AllStatuses) { licenseNumsContainer = i_Garage.GetLicenseNumsOfAllVehicles(); } else { licenseNumsContainer = i_Garage.GetLicenseNumsOfAllVehiclesWithSpecStatus(key); } foreach (string value in licenseNumsContainer) { UserInputOutput.WriteLine(value); } }
private static void changeVehicleStatusAccordingThekey(GarageLogic.Garage i_Garage) { showVehiclesStatusOptions(); GarageLogic.GarageVehicleStatus key = GarageLogic.GarageVehicleStatus.Parse(UserInputOutput.ReadLine()); while (key.VehicleStatus == GarageLogic.eGarageVehicleStatus.AllStatuses) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine( @" You can't change a vehicle's status to all statuses, choose only one statuse please!"); showVehiclesStatusOptions(); key = GarageLogic.GarageVehicleStatus.Parse(UserInputOutput.ReadLine()); } string licenseNumber = getUserInputOfVehicleLicenceNumberIfItExistsInGarage(i_Garage); if (!s_InterruptCurrTask) { i_Garage.ChangeVehicleStatus(licenseNumber, key); } }
private static void changeState(GarageLogic.Garage i_Garage) { Console.WriteLine("Please enter the vehicle licence number"); string licenceNumber = Console.ReadLine(); Console.WriteLine("Please enter 1 for Repair In Progress, 2 for Repair Complete, 3 for Paid."); int chosenState; while (!int.TryParse(Console.ReadLine(), out chosenState) || !(chosenState >= 1 && chosenState <= 3)) { Console.WriteLine("Invalid state. please choose valid state."); } GarageLogic.Vehicle.eVehicleState vehicleState = GarageLogic.Vehicle.eVehicleState.RepairInProgress; switch (chosenState) { case 1: vehicleState = GarageLogic.Vehicle.eVehicleState.RepairInProgress; break; case 2: vehicleState = GarageLogic.Vehicle.eVehicleState.RepairComplete; break; case 3: vehicleState = GarageLogic.Vehicle.eVehicleState.Paid; break; } try { i_Garage.ChangeVehicleState(licenceNumber, vehicleState); } catch (Exception ex) { catchExceptionAndContinue(i_Garage, ex); } }
// Change vehicle status internal void ChangeVehicleStatus(GarageLogic.Garage i_Garage) { // gets license number and checks if exist in garage, if not may exit to main menu m_CurrentLicnese = GetLicense(i_Garage); if (m_CurrentLicnese.Equals("-1")) { return; } Dictionary <string, GarageLogic.Garage.eCarStatus> statuses = new Dictionary <string, GarageLogic.Garage.eCarStatus>(); int number = 1; Console.WriteLine("Please pick one of the Statuses below: "); // iterate through car statuses available and print them foreach (GarageLogic.Garage.eCarStatus status in Enum.GetValues(typeof(GarageLogic.Garage.eCarStatus))) { Console.WriteLine(number + ". " + status.ToString()); statuses.Add(number.ToString(), status); number++; } number--; // sets and validate a car status to change to string statusPicked = Console.ReadLine(); while (!ValidtysUI.CheckMainPickValidity(statusPicked, 1, number)) { Console.WriteLine("Illegal input, Please pick a number between 1 to " + number); statusPicked = Console.ReadLine(); } // changes car status i_Garage.ChangeCarStatus(m_CurrentLicnese, statuses[statusPicked]); // show success message and takes back to main menu SuccessFinishOperation(); }