Пример #1
0
        private void getTruckProperties(ref Truck io_TruckToUpdate)
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the truck cargo volume.");
                    io_TruckToUpdate.CargoVolume = InputManager.GetInputAndConvertToInt();
                    OutputManager.ShowMessage(@"Is the truck containing dangerous products?
1. Yes
2. No");
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, 2);
                    io_TruckToUpdate.IsContainingDangerousProducts = userInput == 1;
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #2
0
        private void getCarProperties(ref Car io_CarToUpdate)
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the amount of doors in the car.");
                    io_CarToUpdate.AmountOfDoors = InputManager.GetInputAndConvertToInt();
                    OutputManager.ShowScreen <Car.eColor>("Please enter the number of the car color:");
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, Enum.GetValues(typeof(Car.eColor)).Length);
                    io_CarToUpdate.CarColor = (Car.eColor)userInput;
                    isInputValid            = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #3
0
        private void getMotorbikeProperties(ref Motorbike io_MotorbikeToUpdate)
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowScreen <Motorbike.eLicenseType>("Please enter the number of the desired licence type:");
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, Enum.GetValues(typeof(Motorbike.eLicenseType)).Length);
                    io_MotorbikeToUpdate.License = (Motorbike.eLicenseType)userInput;
                    OutputManager.ShowMessage("Please enter the motorbike engine volume.");
                    io_MotorbikeToUpdate.EngineVolume = InputManager.GetInputAndConvertToInt();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #4
0
        private int GetMainMenuValidInput()
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMainMenuScreen();
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, 7);
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
            }

            return(userInput);
        }
Пример #5
0
        private void showVehicleDetails()
        {
            bool          isInputValid   = false;
            StringBuilder vehicleIdInput = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the desired vehicle id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    OutputManager.ShowMessage(m_CurrentGarage.GetStoredVehicleDetailsString(vehicleIdInput.ToString()));
                    pressToContinue();
                    isInputValid = true;
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #6
0
        private void inflateAirInAllWheels()
        {
            bool          isInputValid   = false;
            StringBuilder vehicleIdInput = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the desired vehicle id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    m_CurrentGarage.InflateVehicleWheelsToMaximumCapacity(vehicleIdInput.ToString());
                    OutputManager.ShowMessage("Successully inflated all the wheels.");
                    pressToContinue();
                    isInputValid = true;
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #7
0
        private void showFilteredId()
        {
            int           userChoice, enumLength;
            StringBuilder stringOfIdToPrint;
            bool          isInputValid = false;

            enumLength = Enum.GetNames(typeof(StoredVehicle.eVehicleState)).Length;
            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowFilterByVehicleStateScreen();
                    userChoice = InputManager.GetInputAndConvertToInt();
                    isInRange(userChoice, 1, enumLength + 1);
                    stringOfIdToPrint = getFilteredVehicleId(userChoice);
                    OutputManager.ShowMessage(stringOfIdToPrint.ToString());
                    pressToContinue();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #8
0
        private void rechargeVehicle()
        {
            bool          isInputValid = false;
            int           fuelTypeInput = 0, enumLength = 0;
            StringBuilder vehicleIdInput  = null;
            float         fuelAmountInput = 0;

            enumLength = Enum.GetNames(typeof(VehicleFactory.eEngineType)).Length;
            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter desired vehicle id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    OutputManager.ShowScreen <VehicleFactory.eEngineType>("Enter the type of engine your vehicle has:");
                    fuelTypeInput = InputManager.GetInputAndConvertToInt();
                    isInRange(fuelTypeInput, 1, enumLength);
                    OutputManager.ShowMessage("Please enter the amount you wish to charge your vehicle:");
                    fuelAmountInput = InputManager.GetInputAndConvertToFloat();
                    if ((VehicleFactory.eEngineType)fuelTypeInput == VehicleFactory.eEngineType.Fuel)
                    {
                        rechargeFuel(vehicleIdInput.ToString(), fuelAmountInput);
                    }
                    else
                    {
                        rechargeElectric(vehicleIdInput.ToString(), fuelAmountInput);
                    }

                    OutputManager.ShowMessage("Successfully recharged.");
                    pressToContinue();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
        public static void InitiateGarage()
        {
            ViewManager newGarage = new ViewManager();

            try
            {
                newGarage.Start();
            }
            catch(Exception ex)
            {
                OutputManager.ShowErrorMessage(string.Format(@"Unexpected Error occured, Existing now.
            Error message: {0}", ex.Message));
                newGarage.pressToContinue();
            }
        }
Пример #10
0
        private void changeVehicleState()
        {
            int           stateChoiceInput = 0;
            bool          isInputValid     = false;
            StringBuilder vehicleIdInput   = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter desired vehicle's id, enter Q to go back.");
                    vehicleIdInput = InputManager.GetUserInput();
                    if (checkIfPressedQuit(vehicleIdInput))
                    {
                        break;
                    }
                    OutputManager.ShowScreen <StoredVehicle.eVehicleState>("Please enter the number of the desired vehicle's new state:");
                    stateChoiceInput = InputManager.GetInputAndConvertToInt();
                    isInRange(stateChoiceInput, 1, Enum.GetNames(typeof(StoredVehicle.eVehicleState)).Length);
                    m_CurrentGarage.ChangeVehicleState(vehicleIdInput.ToString(), (StoredVehicle.eVehicleState)stateChoiceInput);
                    OutputManager.ShowMessage("Successfuly changed the vehicle state.");
                    pressToContinue();
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #11
0
        private Vehicle createNewVehicle()
        {
            bool    isInputValid     = false;
            int     userVehicleInput = 0;
            int     userEngineInput  = 0;
            Vehicle vehicleToCreate  = null;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowScreen <VehicleFactory.eVehicleType>("Please enter the number of the desired vehicle:");
                    userVehicleInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userVehicleInput, 1, Enum.GetValues(typeof(VehicleFactory.eVehicleType)).Length);
                    OutputManager.ShowScreen <VehicleFactory.eEngineType>("Please enter the number of the desired engine type:");
                    userEngineInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userEngineInput, 1, Enum.GetValues(typeof(VehicleFactory.eEngineType)).Length);
                    vehicleToCreate = VehicleFactory.CreateVehicle((VehicleFactory.eVehicleType)userVehicleInput,
                                                                   (VehicleFactory.eEngineType)userEngineInput);
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(ex.Message);
                    pressToContinue();
                }
            }

            return(vehicleToCreate);
        }
Пример #12
0
        private void getVehicleProperties(ref Vehicle io_NewVehicleToUpdate)
        {
            bool isInputValid = false;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the vehicle license number");
                    io_NewVehicleToUpdate.ID = InputManager.GetUserInput().ToString();
                    OutputManager.ShowMessage("Please enter the vehicle model name");
                    io_NewVehicleToUpdate.ModelName = InputManager.GetUserInput().ToString();
                    OutputManager.ShowMessage("Please enter current engine energy.");
                    io_NewVehicleToUpdate.Engine.CurrentEnergy = InputManager.GetInputAndConvertToFloat();
                    io_NewVehicleToUpdate.calculateCurrentEnergyPercent();
                    OutputManager.ShowMessage("Please enter the wheels manufacturer.");
                    io_NewVehicleToUpdate.SetWheelsManufacturerName(InputManager.GetUserInput().ToString());
                    OutputManager.ShowMessage("Please enter the current wheels' air pressure.");
                    io_NewVehicleToUpdate.SetWheelsAirPressure(InputManager.GetInputAndConvertToFloat());
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message));
                    pressToContinue();
                }
            }
        }
Пример #13
0
        private VehicleOwner createNewVehicleOwner()
        {
            VehicleOwner newVehicleOwner = new VehicleOwner();
            bool         isInputValid    = false;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMessage("Please enter the owner name:");
                    newVehicleOwner.Name = InputManager.GetUserInput().ToString();
                    OutputManager.ShowMessage("Please enter the owners phone number:");
                    newVehicleOwner.PhoneNumber = InputManager.GetUserInput().ToString();
                    isInputValid = true;
                }
                catch (ArgumentException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("{0}", ex.Message));
                    pressToContinue();
                }
            }

            return(newVehicleOwner);
        }