예제 #1
0
        //-----------------------------------------------------------------//
        private void completeVehicleInformation(ref Vehicle io_Vehicle, VehicleAllocator.eVehicleType i_VehicleType)
        {
            List <string> questions     = VehicleAllocator.GetQuestionsAboutVehicle(i_VehicleType, io_Vehicle);
            List <string> answers       = this.getAnswersAboutVehicle(questions);
            bool          isWrongAnswer = true;

            while (isWrongAnswer)
            {
                try
                {
                    VehicleAllocator.SetAnswersAboutVehicle(i_VehicleType, io_Vehicle, answers);
                    isWrongAnswer = false;
                }
                catch (Exception exception)
                {
                    if (exception is FormatException || exception is ValueOutOfRangeException || exception is ArgumentException)
                    {
                        while (exception != null)
                        {
                            Console.Write(exception.Message);
                            answers[int.Parse(exception.Source)] = Console.ReadLine();
                            exception = exception.InnerException;
                        }
                    }
                    else
                    {
                        throw exception;
                    }
                }
            }
        }
예제 #2
0
        //-----------------------------------------------------------------//
        private void getVehicleInformation(Garage i_Garage)
        {
            Console.WriteLine("Adding vehicle to the garage:" + Environment.NewLine);
            Garage.InformationOfVehicle informationOfVehicle = null;
            string licenseNumber = this.getLicenseNumberFromUser();

            if (i_Garage.VehiclesInTheGarage.TryGetValue(licenseNumber, out informationOfVehicle))
            {
                Console.WriteLine("This license number already exists in the garage, changing state to In Repair");
                informationOfVehicle.State = Garage.InformationOfVehicle.eVehicleStateInGarage.InRepair;
            }
            else
            {
                this.printVehicleMenu();
                VehicleAllocator.eVehicleType vehicleType = (VehicleAllocator.eVehicleType) this.getValidInputValueInRange(1, 5);
                Vehicle newVehicle = VehicleAllocator.AllocateVehicle(vehicleType, licenseNumber);
                informationOfVehicle = this.fillInformationForVehicle(newVehicle, vehicleType);
                i_Garage.VehiclesInTheGarage.Add(licenseNumber, informationOfVehicle);
                Console.WriteLine("Vehicle added to the garage successfully!");
            }

            this.printBackToMenuPause();
        }