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 void addVehicle() { m_VehicleInformation.Clear(); m_QuestionsDictionary.Clear(); addClientDetails(); string licenseNumber = (string)m_VehicleInformation["LicenseNumber"]; if (m_Garage.VehicleFound(licenseNumber)) { m_Garage.ChangeVehicleStatus(licenseNumber, GarageLogic.eVehicleStatus.InRepair); Console.WriteLine("The vehicle is already in the garage, vehicle status changed to in-repair."); } else { int chosenOption = getChoiceFromEnum <GarageLogic.eVehicleType>(m_CarMenu); GarageLogic.eVehicleType vehicleType = (GarageLogic.eVehicleType)chosenOption; GarageLogic.Vehicle newVehicle = m_Garage.AddClient(vehicleType, m_VehicleInformation); newVehicle.CreateUserQuestions(m_QuestionsDictionary); foreach (GarageLogic.ExtendedDictionary questions in m_QuestionsDictionary) { setVehicleInformation(questions); } newVehicle.SetVehicleDetails(m_VehicleInformation); Console.WriteLine("Vehicle added to the garage and is in repair."); } }
private void insertNewVehicleToTheGarage() { bool isValidInput = false; while (!isValidInput) { Console.WriteLine("Please Enter your full Name:"); string customerFullName = UIValidation.ReadAndValidateNameFormat(Console.ReadLine()); Console.WriteLine("Please Enter your phone Number:"); string customerPhoneNumber = UIValidation.ReadValidateNumberSequence(Console.ReadLine(), 10); Console.WriteLine("What is the type of your vehicle?"); Console.WriteLine(@"1.Fuel motorcycle 2.Electric motorcycle 3.Fuel car 4.Electric car 5.Truck"); int optionNumber = 0; isValidInput = true; try { int numOfVehiclesTypesGarageHandles = Enum.GetNames(typeof(GarageLogic.VehicleGenerator.eVehicleType)).Length; optionNumber = int.Parse(UIValidation.ValidateChoiceNumberInRange(1, numOfVehiclesTypesGarageHandles, Console.ReadLine())); GarageLogic.VehicleGenerator.eVehicleType vehicleType = (GarageLogic.VehicleGenerator.eVehicleType)optionNumber; GarageLogic.VehicleGenerator vehicleGenerator = new GarageLogic.VehicleGenerator(); Dictionary <string, string> vehicleDictionary = vehicleGenerator.CreateSuitableVehicleDictionary(vehicleType); updateDictionary(vehicleDictionary); GarageLogic.Vehicle costumerVehicle = vehicleGenerator.CreateNewVehicle(vehicleType, vehicleDictionary); bool isAlreadyInGarage = r_Garage.AddANewVehicle(costumerVehicle, customerFullName, customerPhoneNumber); if (!isAlreadyInGarage) { Console.WriteLine(@"Your vehicle has been added to the garage!"); } else { Console.WriteLine(@"Your vehicle already exists in our system."); } } catch (FormatException exception) { Console.WriteLine(exception.Message); isValidInput = false; } catch (ValueOutOfRangeException exception) { Console.WriteLine(exception.Message); isValidInput = false; } catch (ArgumentException exception) { Console.WriteLine(exception.Message); isValidInput = false; } Console.ReadLine(); Console.Clear(); } }
private static void setStandardDetailsOfNewVehicle(GarageLogic.Vehicle i_Vehicle, string i_LicenseNum) { UserInputOutput.ClearScreen(); i_Vehicle.LicenseNum = i_LicenseNum; UserInputOutput.WriteLine(@"Enter the model name of your vehicle, please"); i_Vehicle.ModelName = UserInputOutput.ReadLine(); for (int i = 0; i < i_Vehicle.WheelsNum; i++) { UserInputOutput.WriteLine(string.Format(@"Enter the manufacturer name of {0} wheel, please", i + 1)); i_Vehicle.SetManufacturerNameOfSpecificWheel(i, UserInputOutput.ReadLine()); } }
private static GarageLogic.Vehicle buildVehilce(string i_TypeOfVehicle) { GarageLogic.Vehicle newVehicle = GarageLogic.VehicleFactory.BuildNewVehicle(i_TypeOfVehicle); while (newVehicle == null && !s_InterruptCurrTask) { UserInputOutput.ClearScreen(); UserInputOutput.WriteLine( @"This type of the vehicle, you inserted doesn't created on our vehicle factory. Insert another type of vehicl or press 'X' to interrupt the task."); s_InterruptCurrTask = isInterruptTheCurrTask(out i_TypeOfVehicle); newVehicle = GarageLogic.VehicleFactory.BuildNewVehicle(i_TypeOfVehicle); } return(newVehicle); }
private void setValueOfMemberField(PropertyInfo i_memberField, GarageLogic.Vehicle i_Vehicle) { string nameOfMemberField = i_memberField.Name; Type fieldType = i_memberField.PropertyType; //Type type = i_memberField.DeclaringType.FullName; string fieldOutName = string.Format("Enter the value for field - {0}:{1}", nameOfMemberField, Environment.NewLine); if (fieldType.IsEnum) { System.Array enumValues = System.Enum.GetValues(fieldType); m_UI.ShowOptionFromArray(fieldOutName, enumValues); int intValue = m_UI.GetIntNumber(); PropertyInfo propertyInfo = i_Vehicle.GetType().GetProperty(i_memberField.Name); //propertyInfo.SetValue(i_Vehicle, Convert.ChangeType(intValue, fieldType), null); propertyInfo.SetValue(i_Vehicle, Enum.ToObject(fieldType, intValue), null); } else if (fieldType == typeof(Boolean)) { fieldOutName = string.Concat(fieldOutName, string.Format("(1 - True, 0 - False){0}", Environment.NewLine)); m_UI.PrintMessage(fieldOutName); bool boolValue = m_UI.GetBool(); setMemberValue <bool>(i_memberField, i_Vehicle, boolValue); } else if (fieldType == typeof(float)) { m_UI.PrintMessage(fieldOutName); float floatValue = m_UI.GetFloatInput(); setMemberValue <float>(i_memberField, i_Vehicle, floatValue); } else if (fieldType == typeof(int)) { m_UI.PrintMessage(fieldOutName); int intValue = m_UI.GetIntNumber(); setMemberValue <int>(i_memberField, i_Vehicle, intValue); } else { m_UI.PrintMessage(fieldOutName); string value = m_UI.GetInput(); setMemberValue <string>(i_memberField, i_Vehicle, value); } }
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 void updateVehicleWithAnyExtraFields(GarageLogic.Vehicle i_Vehicle) { //FieldInfo[] vehicleMembers = i_Vehicle.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); //foreach (FieldInfo memberField in vehicleMembers) //{ // setValueOfMemberField(memberField, i_Vehicle); // printOptionsForMemberField(memberField); //} PropertyInfo[] props = (i_Vehicle).GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);//BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (PropertyInfo memberField in props) { if (!memberField.CanWrite) { continue; } bool v_InvalidInputType = true; while (v_InvalidInputType) { //printOptionsForMemberField(memberField); try { //string fieldOutName = string.Format("Enter the value for field - {0}:{1}", memberField.Name, Environment.NewLine); //Type type = memberField.GetType(); //var x = GetEnumTypeFromUser<memberField.DeclaringType>(fieldOutName); //vehicleType = GetEnumType<GarageLogic.eVehicleType>(Messages.SelectVehicleType); setValueOfMemberField(memberField, i_Vehicle); v_InvalidInputType = false; } catch (Exception ex) { m_UI.PrintMessage(ex.Message); } } } }
private void setMemberValue <T>(PropertyInfo i_memberField, GarageLogic.Vehicle i_Vehicle, T i_Value) { i_memberField.SetValue(i_Vehicle, i_Value); }