public void ControlGarage() { do { PrintingUtils.PrintingOpening(); string option = Console.ReadLine(); bool isValid = Enum.TryParse(option, out eOption result) && Enum.IsDefined(typeof(eOption), result); if (isValid) { try { controlGarageOptions(result); } catch { PrintingUtils.Delay(); } } else { Console.WriteLine("Please choose from the options above!"); System.Threading.Thread.Sleep(3000); } }while (m_LeaveStore == false); Console.WriteLine("Goodbye!"); }
private Vehicle createVehicle(CreatingVehicles.eTypeOfVehicles i_TypeOfVehicle) { CreatingVehicles vehiclesMaker = new CreatingVehicles(i_TypeOfVehicle); Vehicle vehicleToAdd = vehiclesMaker.CreateVehicle(); StringBuilder askForData = vehicleToAdd.AskForData; string[] splitAskForData = askForData.ToString().Split('\n'); List <int> enumable = getEnumableProperties(splitAskForData[splitAskForData.Length - 2]); string[] storeData = new string[splitAskForData.Length - 2]; for (int i = 0; i < storeData.Length; i++) { if (enumable.Contains(i)) { Type getType = getVehicleTypeOfEnum(i_TypeOfVehicle); PrintingUtils.PrintListOfEnum(splitAskForData[i], getType); storeData[i] = Console.ReadLine(); } else { Console.WriteLine(splitAskForData[i]); storeData[i] = Console.ReadLine(); } } vehicleToAdd.SetVehicleData = storeData; return(vehicleToAdd); }
private void getFuelToAdd(out FuelVehicle.eFuelType o_FuelType, out float o_FuelToAdd) { PrintingUtils.PrintListOfEnum("Please write below the fuel type:", typeof(FuelVehicle.eFuelType)); bool isValid = Enum.TryParse(Console.ReadLine(), out o_FuelType) && Enum.IsDefined(typeof(FuelVehicle.eFuelType), o_FuelType); if (isValid == false) { throw new FormatException("Fail parsing fuel type"); } Console.WriteLine("Please insert the amount of fuel you would like to add: "); bool isParse = float.TryParse(Console.ReadLine(), out o_FuelToAdd); if (isParse == false) { throw new FormatException("Fail parsing the amount of fuel to add"); } }
private void addVehicle() { Console.WriteLine("Creating Vehicle: "); Console.WriteLine("Please write your name: "); string ownerName = Console.ReadLine(); Console.WriteLine("Please write your phone number: "); string ownerPhone = Console.ReadLine(); bool isValid = false; do { bool isValidPhoneNumber = int.TryParse(ownerPhone, out int intPhoneNumber); if (isValidPhoneNumber == false) { Console.WriteLine("Fail to add the phone number you entered."); Console.WriteLine("Please write your phone number: "); ownerPhone = Console.ReadLine(); continue; } PrintingUtils.PrintListOfEnum("Please choose a vehicle", typeof(CreatingVehicles.eTypeOfVehicles)); string option = Console.ReadLine(); isValid = Enum.TryParse(option, true, out CreatingVehicles.eTypeOfVehicles result) && Enum.IsDefined(typeof(CreatingVehicles.eTypeOfVehicles), result); if (isValid) { Vehicle vehicle = createVehicle(result); AutoRepairShop.VehicleInShop toAdd = new AutoRepairShop.VehicleInShop( ownerName, ownerPhone, vehicle); r_AutoRepairShop.AddVehicleToStore(toAdd, out bool isAdded); PrintingUtils.VehicleAdded(toAdd.VehicleLicenseNumber, isAdded); break; } Console.WriteLine("please choose a valid option."); }while (isValid == false); }
private AutoRepairShop.VehicleInShop.eVehicleStatus?getStatus() { AutoRepairShop.VehicleInShop.eVehicleStatus?returnStatus; PrintingUtils.PrintListOfEnum( "Please write below the vehicle status:", typeof(AutoRepairShop.VehicleInShop.eVehicleStatus)); string status = Console.ReadLine(); bool isValid = Enum.TryParse(status, out AutoRepairShop.VehicleInShop.eVehicleStatus result) && Enum.IsDefined(typeof(AutoRepairShop.VehicleInShop.eVehicleStatus), result); if (isValid) { returnStatus = result; } else { string errorMessage = "You have to choose from the following options"; ValueOutOfRangeException ex = new ValueOutOfRangeException(1, 3, errorMessage); throw new FormatException("Fail parsing the vehicle status", ex); } return(returnStatus); }
private void controlGarageOptions(eOption i_Option) { try { AutoRepairShop.VehicleInShop.eVehicleStatus?status; string licenseNumber; Console.Clear(); switch (i_Option) { case eOption.AddVehicle: addVehicle(); break; case eOption.ShowVehiclesByLicense: PrintingUtils.PrintLicensesList(r_AutoRepairShop.ShowAllVehiclesInGarage()); break; case eOption.ShowVehiclesByStatus: status = getStatus(); PrintingUtils.PrintLicensesList(r_AutoRepairShop.ShowAllVehiclesInGarage(status), status); break; case eOption.ModifyStatus: licenseNumber = getLicenseNumber(); if (r_AutoRepairShop.IsVehicleExist(licenseNumber)) { status = getStatus(); r_AutoRepairShop.SetNewStatusToVehicle(licenseNumber, status, out bool isSucceeded); PrintingUtils.StatusModified(licenseNumber, status, isSucceeded); } else { throw new ArgumentException("Vehicle is not exist in the garage"); } break; case eOption.InflateWheels: licenseNumber = getLicenseNumber(); r_AutoRepairShop.SetWheelsPressureToMaximum(licenseNumber, out bool isInflated); PrintingUtils.InflateWheels(licenseNumber, isInflated); break; case eOption.RefuelVehicle: licenseNumber = getLicenseNumber(); if (r_AutoRepairShop.IsVehicleExist(licenseNumber)) { getFuelToAdd(out FuelVehicle.eFuelType fuelType, out float fuelToAdd); r_AutoRepairShop.FillInEnergyToVehicle( licenseNumber, fuelToAdd, out bool isRefueled, fuelType); PrintingUtils.EnergyAdded(licenseNumber, isRefueled, fuelType); } else { throw new ArgumentException("Vehicle is not exist in the garage"); } break; case eOption.LoadVehicle: licenseNumber = getLicenseNumber(); if (r_AutoRepairShop.IsVehicleExist(licenseNumber)) { float minutesToAdd = getMinutesToLoad(); r_AutoRepairShop.FillInEnergyToVehicle(licenseNumber, minutesToAdd, out bool isLoaded); PrintingUtils.EnergyAdded(licenseNumber, isLoaded); } else { throw new ArgumentException("Vehicle is not exist in the garage"); } break; case eOption.ShowVehicleDetails: licenseNumber = getLicenseNumber(); PrintingUtils.PrintVehicleDetails( r_AutoRepairShop.ShowDetailsOfVehicle(licenseNumber, out bool isExist), isExist); break; case eOption.Exit: m_LeaveStore = true; break; default: throw new ValueOutOfRangeException(1, 9); } if (i_Option != eOption.Exit) { PrintingUtils.Delay(); } } catch (Exception ex) { PrintingUtils.PrintExceptionErrors(ex); throw; } }