Esempio n. 1
0
        private static void FilteredList()
        {
            bool        correctInput = false;
            bool        correctType  = false;
            string      userSelectedTypes;
            List <Type> userTypeList = new List <Type>();

            do
            {
                ui.Print("Choose type(s) of vehicle, comma separated. Use * as wildcard: ");
                userSelectedTypes = ui.GetInput();

                // Remove all spaces
                userSelectedTypes = Regex.Replace(userSelectedTypes, @"\s+", "");

                string[] userSelTypes = userSelectedTypes.Split(",");

                foreach (string typ in userSelTypes)
                {
                    switch (typ.ToLower())
                    {
                    case "airplane":
                        userTypeList.Add(Type.GetType("Garage.Airplane, Garage"));
                        break;

                    case "boat":
                        userTypeList.Add(Type.GetType("Garage.Boat, Garage"));
                        break;

                    case "bus":
                        userTypeList.Add(Type.GetType("Garage.Bus, Garage"));
                        break;

                    case "car":
                        userTypeList.Add(Type.GetType("Garage.Car, Garage"));
                        break;

                    case "motorcycle":
                        userTypeList.Add(Type.GetType("Garage.Motorcycle, Garage"));
                        break;

                    default:
                        break;
                    }
                }

                IEnumerable <Type> vehicleTypes = garageHandler.getVehicleTypes();

                foreach (Type vehicleType in vehicleTypes)
                {
                    for (int i = 0; i < userTypeList.Count(); i++)
                    {
                        if (vehicleType.Name.Equals(userTypeList.ElementAt(i).Name, StringComparison.OrdinalIgnoreCase))
                        {
                            correctType = true;
                        }
                    }
                }

                if (correctType == false)
                {
                    PrintIncorrectInputWarning("No vehicle of that type in garage. ");
                }

                if (userSelectedTypes.Length > 0)
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput || !correctType);

            correctInput = false;
            string userSelectedColours;

            do
            {
                ui.Print("Choose colour(s) comma separated. Use * as wildcard: ");
                userSelectedColours = ui.GetInput();

                if (userSelectedColours.Length > 0)
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput);

            correctInput = false;
            int minWheels;

            do
            {
                ui.Print("Choose minimum number of wheels: ");

                string tempString = ui.GetInput();
                int.TryParse(tempString, out minWheels);

                if (tempString.Length > 0 && minWheels >= 0)
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput);

            correctInput = false;
            int maxWheels;

            do
            {
                ui.Print("Choose maximum number of wheels: ");
                string tempString = ui.GetInput();
                int.TryParse(tempString, out maxWheels);

                if (tempString.Length > 0 && maxWheels >= 0)
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput);

            correctInput = false;
            string regNum;

            do
            {
                ui.Print("Choose registration number. Use * as wildcard: ");
                regNum = ui.GetInput();

                if (garageHandler.ValidateRegNum(regNum) || regNum == "*")
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput);

            correctInput = false;
            double minWeight;

            do
            {
                ui.Print("Choose minimum weight: ");
                string tempString = ui.GetInput();
                double.TryParse(tempString, out minWeight);

                if (tempString.Length > 0 && minWeight >= 0)
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput);

            correctInput = false;
            double maxWeight;

            do
            {
                ui.Print("Choose maximum weight: ");
                string tempString = ui.GetInput();
                double.TryParse(tempString, out maxWeight);

                if (tempString.Length > 0 && maxWeight >= 0 && maxWeight < int.MaxValue)
                {
                    correctInput = true;
                }
                else
                {
                    PrintIncorrectInputWarning("");
                }
            } while (!correctInput);

            ui.Print($"\n{garageHandler.HandleFilteredSearch(userTypeList/*userSelectedTypes*/, userSelectedColours, minWheels, maxWheels, regNum, minWeight, maxWeight)}\nPress enter to continue!");
            ui.GetInput();
        }