示例#1
0
        /// <summary>
        /// creating new vehicle.
        /// </summary>
        public static void CreateNewVehicle()
        {
            string typeOfVehicleInput = string.Empty;

            try
            {
                Console.WriteLine("Please choose the type of the vehicle :" + Environment.NewLine + "1.Car " + Environment.NewLine +
                                  "2.Motorcycle" + Environment.NewLine + "3.Truck");
                typeOfVehicleInput = Console.ReadLine();
                if (int.Parse(typeOfVehicleInput) >= 1 && int.Parse(typeOfVehicleInput) <= 3)
                {
                    bool checkPlateNumber = true;
                    while (checkPlateNumber)
                    {
                        //check if license number exists in garage
                        Console.WriteLine("Please enter license plate number");
                        string licensePlateNumberInput = Console.ReadLine();

                        checkPlateNumber = GarageLogic.Garage.CheckIfVehicleExistsInGarage(licensePlateNumberInput);
                        //checkPlateNumber = UserInputValidation.LicensePlateValidation(licensePlateNumber);
                        if (checkPlateNumber)
                        {
                            Console.WriteLine("This Vehicle already exists in the garage. starting treatment...");
                            //GarageLogic.GarageInfo.VehiclesState.Add(licensePlateNumberInput,new );
                        }
                        else
                        {
                            Vehicle.eVehicleType vehicleTypePick = Vehicle.GetVehicleTypeByDigit(int.Parse(typeOfVehicleInput));
                            string vehicleModelName = string.Format("Pleae enter your {0}'s Model: ", vehicleTypePick);
                            Console.WriteLine(vehicleModelName);
                            string modelNameInput = Console.ReadLine();

                            string vehiclePowerSupply = string.Format("Please enter your {0}'s Power Supply. 1.Fuel 2.Battery :  ", vehicleTypePick);
                            Console.WriteLine(vehiclePowerSupply);
                            string vehiclePowerSupplyInput       = Console.ReadLine();
                            PowerSource.ePowerSupply powerSupply = PowerSource.getPowerSupplyType(vehiclePowerSupplyInput);

                            string powerSupplyRemaining = string.Empty;
                            if (powerSupply == PowerSource.ePowerSupply.Fuel)
                            {
                                powerSupplyRemaining = string.Format("Please enter remaining fuel in your {0} by liters: ", vehicleTypePick);
                            }
                            else if (powerSupply == PowerSource.ePowerSupply.Battery)
                            {
                                powerSupplyRemaining = string.Format("Please enter remaining Battery time in your {0} by hours: ", vehicleTypePick);
                            }

                            Console.WriteLine(powerSupplyRemaining);
                            string powerSupplyRemainingInput = Console.ReadLine();

                            string manufacturerName = string.Format("Please enter your {0}'s tires Manufactuer Name: ", vehicleTypePick);
                            Console.WriteLine(manufacturerName);
                            string manufacturerNameInput = Console.ReadLine();

                            Vehicle createdVehicle = GarageLogic.VehiclesCreator.CreateVehicle(vehicleTypePick, modelNameInput,
                                                                                               licensePlateNumberInput, float.Parse(powerSupplyRemainingInput), powerSupply,
                                                                                               manufacturerNameInput);
                            AddVehicleDetails(createdVehicle);
                            AddVehicleToTreatment(createdVehicle);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string exceptionType = string.Format("input is not valid - {0}", ex.Message);
                Console.WriteLine(exceptionType);
            }
        }