Exemple #1
0
        private void ParametricSearch()
        {
            ui.Clear();
            ui.DisplayInputHeader("Search for vehicles");

            ui.Write("Please enter parameters to search for!\n");
            ui.Write("Leave any unimportant parameters empty!\n");
            string regNo      = ui.GetTextFromUser("Registration number: ").ToUpper();
            string color      = ui.GetTextFromUser("Color: ".PadLeft(21));
            int    nrOfWheels = ui.GetIntegerFromUser("Nr of wheels: ".PadLeft(21), Const.AcceptEmptyString);
            string fuelType   = ui.GetTextFromUser("Fuel type: ".PadLeft(21));

            var matchList = new Garage <Vehicle>(garage.Count);

            foreach (var v in garage)
            {
                bool match = true; // positive default
                if (regNo != "" && v.RegNo != regNo)
                {
                    match = false; // miss
                }
                if (color != "" && v.Color != color)
                {
                    match = false; // miss
                }
                if (nrOfWheels != -1 && v.NrOfWheels != nrOfWheels)
                {
                    match = false; // miss
                }
                if (fuelType != "" && v.FuelType != fuelType)
                {
                    match = false; // miss
                }
                if (match)
                {
                    matchList.ParkVehicle(v); // not really "parked" but added
                                              // to the list of matching vehicles
                }
            }
            ui.Write("\n");
            if (matchList.Count > 0)
            {
                ui.Write("Matching vehicles:\n");
                DisplayVehicleList(matchList);
            }
            else
            {
                ui.WriteWarning("No vehicles matched your search.");
            }
            ui.WaitAndClear();
        }