/*Function that takes in: * a. the ListBox for the model. * b. the manufactuerer selected from the ManufacturerBox. * c. the current Listed object. * d. the pictureBox we want to update with the selected manufacturers logo. * then returns all the cars from this selected manufacturer.*/ public Listed ManufactuerSelected(ListBox ModelBox, string manufacturer, Listed carList, PictureBox LogoBox) { CarListReader listReader = new CarListReader(); /*If the item is not all then do the following*/ if (!manufacturer.Equals("All")) { /*Getting the models*/ //contstructor that takes in a manufactorer and searches the array for cars that match the manufactorer. carList.CarsFromManufacturer = listReader.searchCars(carList.Cars, manufacturer); /*As we've only just drew the list of models we should assume that * the CurrentCars is the CarsFromManufacturer*/ carList.CurrentCars = carList.CarsFromManufacturer; carList.CurrentCarsWithoutRestrictions = carList.CurrentCars; /*Loading the manufacturers logo in the form.*/ CarBadge badge = new CarBadge(); string url = badge.getBadge(manufacturer); try { LogoBox.Image = Image.FromFile(url); LogoBox.SizeMode = PictureBoxSizeMode.StretchImage; } catch (Exception error) { Console.WriteLine(error.ToString()); } PopulateListBoxWithCarsDetails(ModelBox, carList.CarsFromManufacturer); } else { /*As we've selected all, just set the manufacturers to each available car in the * Listed object.*/ carList.CarsFromManufacturer = carList.Cars; carList.CurrentCars = carList.CarsFromManufacturer; carList.CurrentCarsWithoutRestrictions = carList.CurrentCars; PopulateListBoxWithCarsDetails(ModelBox, carList.CarsFromManufacturer); } /*Returning the carList after updating the carLists CarsFromManufacturer*/ return(carList); }
/*Using the searchCars function of the CarListReader class to find all the models for the * given manufacturer then populating the corresponding Model list with these models.*/ private List <Car> populateModels(string manufacturer, ListBox box) { //clearing the box. box.Items.Clear(); //getting every car with the manufacturer given. IEnumerable <Car> carModels = new List <Car>(); carModels = search.searchCars(cars, manufacturer); List <Car> searchedCars = carModels.ToList(); foreach (Car theCar in searchedCars) { string toAdd = theCar.Model + " " + theCar.Description; box.Items.Add(toAdd); } return(searchedCars); }