コード例 #1
0
        ////Handle Add Fuel by license Number
        private void handleAddFuel(Garage i_Garage)
        {
            string    licenseNumber = string.Empty;
            eFuelType fuelType;
            float     amountToFill;
            string    regexPatternForInputValidation = "^[1-4]{1}$";
            string    optionalErrorToShow            = "Invalid choise. please try again, and then press enter:";

            Console.WriteLine("Please enter a license number, and then press enter:");
            licenseNumber = Console.ReadLine();
            Console.WriteLine(
                @"Please select a fuel type:
Select one of the options by selecting the option's number (1-4), then press enter:
1. Octan98
2. Octan96
3. Octan95
4. Soler");
            string choice          = Console.ReadLine();
            bool   isCaseSensitive = false;

            checkInputValidation(ref choice, regexPatternForInputValidation, optionalErrorToShow, isCaseSensitive);
            fuelType = (eFuelType)Enum.Parse(typeof(eFuelType), choice);
            Console.WriteLine("Please enter the amount of liters of fuel to add, and then press enter:");
            amountToFill = float.Parse(Console.ReadLine());
            i_Garage.AddFuel(licenseNumber, fuelType, amountToFill);
        }
コード例 #2
0
ファイル: GarageUI.cs プロジェクト: Hadar-Yona/Self-Projects
        private static void addFuel(Vehicle i_Vehicle, Customer i_Customer)
        {
            Console.Clear();
            printGarageWelcome();
            System.Console.WriteLine(Environment.NewLine + "Please type the type of gas");
            string gasType = System.Console.ReadLine();

            System.Console.WriteLine(Environment.NewLine + "Please type the amount of gas you would like to add (in litters)");
            string inputAmount = System.Console.ReadLine();

            bool  flag   = false;
            float amount = 0;

            while (!flag)
            {
                try
                {
                    amount = float.Parse(inputAmount);
                    try
                    {
                        m_OurGarage.AddFuel(i_Vehicle, gasType, amount);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Clear();
                        System.Console.WriteLine(Environment.NewLine + "Successfully added" + Environment.NewLine);
                        Console.ForegroundColor = ConsoleColor.White;
                        flag = true;
                    }
                    catch (ArgumentException)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine(Environment.NewLine + "Type doesn't correspond to the vehicle's type, please type the value corresponding to "
                                                 + Vehicle.GetStringForVehicleType(i_Vehicle.VehicleType).ToLower() + " from: " + Environment.NewLine + printList(Enum.GetValues(typeof(eGasType))) + Environment.NewLine);
                        Console.ForegroundColor = ConsoleColor.White;
                        gasType = System.Console.ReadLine();
                    }
                    catch (ValueOutOfRangeException e)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine(e.Message);
                        Console.ForegroundColor = ConsoleColor.White;
                        inputAmount             = System.Console.ReadLine();
                    }
                    catch (InvalidOperationException)
                    {
                        maximalValuesHandeling(i_Vehicle, i_Customer);
                    }
                }
                catch (FormatException)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Illegal value, please type a number");
                    Console.ForegroundColor = ConsoleColor.White;
                    inputAmount             = Console.ReadLine();
                }
            }

            finishProcess(i_Vehicle, i_Customer);
        }
コード例 #3
0
        private void getNewFuelRateFromUser()
        {
            float fuelToAdd = 0;

            Screen.Clear();
            Console.WriteLine("Enter vehicle's license number:");
            string licenseNumberToAddFuel = Console.ReadLine();

            Fuel.eFuelType fuelType = getFuelTypeFromUser();
            Console.WriteLine("Please enter amount of fuel to add:");
            bool inputValid = float.TryParse(Console.ReadLine(), out fuelToAdd);

            if (inputValid == false)
            {
                throw new FormatException();
            }

            try
            {
                r_Garage.AddFuel(licenseNumberToAddFuel, fuelType, fuelToAdd);
                Screen.Clear();
                Console.WriteLine("{2} {0} Added successfully to Vehicle #{1} ", fuelType.ToString(), licenseNumberToAddFuel, fuelToAdd);
            }
            catch (MissingVehicleException ex)
            {
                Screen.Clear();
                Console.WriteLine("{0}", Environment.NewLine);
                Console.WriteLine("{0}", ex.Message);
                Console.WriteLine("{0}", Environment.NewLine);
            }
            catch (EngineTypeException ex)
            {
                Screen.Clear();
                Console.WriteLine("{0}", Environment.NewLine);
                Console.WriteLine("{0}", ex.Message);
                Console.WriteLine("{0}", Environment.NewLine);
            }
            catch (FuelTypeException ex)
            {
                Screen.Clear();
                Console.WriteLine("{0}", Environment.NewLine);
                Console.WriteLine("{0}", ex.Message);
                Console.WriteLine("{0}", Environment.NewLine);
            }
        }