/*function to be called when the settings form that we opened is being closed. * This function takes in an init form which we will use to calculate the new total costs.*/ public void SettingsClosed(Init init) { ListedToPrint newCars = new ListedToPrint(); newCars = init.RecalculateMPG(carList, carList.SelectedCar); carList = newCars.CarList; }
/*Function that takes in: * a. the textbox that contains the text. * b. the listed object so we can search through the manufacturers models * c. the listbox we wish to populate * and then returns an updated Listed object that contains the new CurrentCars * list.*/ public Listed UpdatedModelsThroughSearch(TextBox text, Listed carList, ListBox ModelBox) { CarListReader listReader = new CarListReader(); //using the CarListReader to search the Json file for the search result. IEnumerable <Car> searchedModels = listReader.searchModels(carList.CarsFromManufacturer, text.Text); //searching the description for what has been typed. IEnumerable <Car> searchedDescription = listReader.searchDescriptions(carList.CarsFromManufacturer, text.Text); //creating a list that contains both searchModels and searchedDescription carList.CurrentCars = searchedModels.Concat(searchedDescription); /*Setting the Current cars without restrictions to be the same as * the only difference between this and CurrentCars is this does not contain * the restrictions applied by the user.*/ carList.CurrentCarsWithoutRestrictions = carList.CurrentCars; //for each car that contains what we searched we will print the Car and the Description. PopulateListBoxWithCarsDetails(ModelBox, carList.CurrentCars); //if the user empties the search box then we want to refill the listbox with the array of models. if (text.Text.Equals("")) { carList.CurrentCars = carList.CarsFromManufacturer; PopulateListBoxWithCarsDetails(ModelBox, carList.CurrentCars); } return(carList); }
/*Function that takes in: * a. the fueltype of the vehicle we want to display e.g. if the user wants to display * only petrol cars then the fuelType would be petrol. * b. the list box we want to update, most likely ModelBox. * c. the IEnumerable<Car> we wish to update. * The function will then remove all but the selected from the array and return the new * array.*/ public Listed ShowOnlySelectedFuelType(string fuelType, ListBox list, Listed carList) { try { /*Only remove fuelTypes if the list we was given is not empty or null.*/ if (carList.CurrentCarsWithoutRestrictions.Count() != 0 && carList.CurrentCarsWithoutRestrictions != null) { Order order = new Order(); /*Setting the carLists CurrentCars to be the carlist without restrictions incase we have * a restriction already applied which will cause the carList to become empty * as a car cannot have 2 fuel types.*/ carList.CurrentCars = carList.CurrentCarsWithoutRestrictions; /*removing all but the cars with the selected fuelType.*/ carList.CurrentCars = order.RemoveAllButSpecified(carList.CurrentCars, fuelType); /*redrawing the ListBox with only cars of this fuelType.*/ PopulateListBoxWithCarsDetails(list, carList.CurrentCars); /*Returning the cars to be sorted when we remove all but the necessary fueltypes.*/ } } catch (Exception error) { Console.WriteLine(error.ToString()); } return(carList); }
/*function that takes in the listed object and alters 2 arrays: * 1. the cars from the specific manufacturer e.g. Ford as these are the currently * selected cars that we wish to update * 2. All the cars so when the user swithces manufacturers these also show the corrected * fuel costs. * the program also requires the selected car, this is so we can update the current selected car. * then calculates the new MPGs using the Recalculate function and returns a ListedToPrint, which is * a listed object with a printable string*/ public ListedToPrint RecalculateMPG(Listed cars, Car selectedCar) { CarPrinter printer = new CarPrinter(); /*Creating a new ListedToPrint object.*/ ListedToPrint list = new ListedToPrint(); /*The current cars we want to recalculate*/ cars.CurrentCars = RecalculateCarList(cars.CurrentCars); cars.Cars = RecalculateCarList(cars.CurrentCars); list.CarList = cars; list.ToPrint = ""; try { /*Only do the following if the user has selected a car.*/ if (selectedCar != null) { /*Recalculating the cost of a single car.*/ selectedCar = RecalculateCar(selectedCar); /*Getting all the cars details into a string*/ list.ToPrint = printer.carHeader(selectedCar) + printer.printcar(selectedCar, Properties.Settings.Default.ImperialOrMetric); } } catch (Exception error) { Console.WriteLine(error.ToString()); } return(list); }
private void ModBox_TextChanged(object sender, EventArgs e) { //clearing the ModelBox so we can replace it with the searched models. clearListBox(ModelBox); carList = listBoxes.UpdatedModelsThroughSearch(ModBox, carList, ModelBox); }
/*When the Car2ManufacturerList Index is changed a couple of things will happen * a. The logo at the bottom will change to correlate with the selected manufacturer * b. We will populate the models with the manufacturers models.*/ private void Car2ManufacturorList_SelectedIndexChanged(object sender, EventArgs e) { //only change the image when we have something selected(if selected has not been wiped.) if (Car2ManufacturorList.SelectedIndex != -1) { string manufacturer = Car2ManufacturorList.SelectedItem.ToString(); changeImage(Car2LogoPicture, manufacturer); car2List = listBoxes.ManufactuerSelected(Car2ModelList, manufacturer, car2List, Car2LogoPicture); } }
private void AddCarButton_Click(object sender, EventArgs e) { Listed list = new Listed(); list = list.DefaultForm1ToLoad(); this.Hide(); Form1 addCar = new Form1(list); addCar.Closed += (s, args) => this.Close(); addCar.Show(); }
/*When the user types something into the manufactuer textbox, then clear the existing * list of manufacturers and repopulate with the searched manufacturers.*/ private void textBox1_TextChanged(object sender, EventArgs e) { //clearning the CarBox so we can repopulate it. clearListBox(CarBox); //clearing the modbox search box as we are no longer on the same manufactorer. ModBox.Text = ""; //clearing the ModelBox as we are not longer on the same manufactorer. clearListBox(ModelBox); /*Searching for manufacturers based on what was typed into the MakeBox TexbBox.*/ carList = listBoxes.UpdateManufacturersThroughSearch(MakeBox, carList, CarBox); }
/*Function for when an item is selected in the CarBox.*/ private void CarBox_SelectedIndexChanged(object sender, EventArgs e) { //clearing the model searchbox as we're selecting a different model. ModBox.Text = ""; clearListBox(ModelBox); /*Clearing the unecessary lists in the carList.*/ carList = carList.ClearLists(carList); /*The manufactorer that has been selected by the CarBox*/ string manufactorer = CarBox.SelectedItem.ToString(); listBoxes.ManufactuerSelected(ModelBox, manufactorer, carList, LogoBox); }
private void CompareButton_Click(object sender, EventArgs e) { /*Creating a listed object to send to the compare form.*/ Listed list = new Listed(); list = list.DefaultForm1ToLoad(); Listed list2 = new Listed(); list2 = list.DefaultForm1ToLoad(); this.Hide(); Compare compareCar = new Compare(list, list2); compareCar.Closed += (s, args) => this.Close(); compareCar.Show(); }
/*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); }
public Listed DefaultForm1ToLoad() { CarListReader reader = new CarListReader(); Listed list = new Listed(); /*Setting the cars in JSON reader to be that of the most recent year.*/ JsonReader json = new JsonReader(); /*Getting the list of cars from json.*/ list.Cars = json.getCars(); list.Manufacturers = reader.GetManufacturers(list.Cars); list.searchedManufacturers = list.Manufacturers; list.LatestFileYear = json.getMostRecent(); return(list); }
public void SettingsClosed(Init init) { ListedToPrint newCars1 = new ListedToPrint(); newCars1 = init.RecalculateMPG(car1List, car1List.SelectedCar); car1List = newCars1.CarList; ListedToPrint newCars2 = new ListedToPrint(); newCars2 = init.RecalculateMPG(car2List, car2List.SelectedCar); car2List = newCars2.CarList; try { setComparison(car1List.SelectedCar, car2List.SelectedCar); } catch (Exception error) { Console.WriteLine(error.ToString()); } }
/*Function that takes in: * a. the textbox which contains the text. * b. the listed object so we can search through its manufacturers * c. the ListBox we wish to populate. * and then returns an updated Listed object that contains the new SearchedManufactuers * list.*/ public Listed UpdateManufacturersThroughSearch(TextBox text, Listed carList, ListBox CarBox) { CarListReader listReader = new CarListReader(); carList.searchedManufacturers = listReader.searchString(carList.Manufacturers, text.Text); /*Repopulating the listbox with what was searched rather than all the * manufacturers.*/ PopulateListBoxWithManufacturers(CarBox, carList.searchedManufacturers); /*if the user has reset the search box ie. MakeBox.Text = "" then we will * repopulate the listbox with all the makes.*/ if (text.Text.Equals("")) { carList.searchedManufacturers = carList.Manufacturers; PopulateListBoxWithManufacturers(CarBox, carList.searchedManufacturers); } return(carList); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Listed list = new Listed(); list.DefaultForm1ToLoad(); //loading a car from the database. LoadCar load = new LoadCar(); IEnumerable <Car> loadedCars = load.Load(); //if the car is null then there was no saved car. if (loadedCars.Count() == 0) { Application.Run(new Form1(list)); } else { Application.Run(new Overview()); } }
/*Function that takes in: * a. the classes Listed Object. * b. the element from the ListBox that the user has selected.*/ public Listed ModelSelected(int element, Listed carList) { Car car = null; /*If the user has selected a legitimate element that's not null.*/ if (element > -1) { /*selecting the car at the selected element.*/ car = carList.CurrentCars.ElementAt(element); /*If the car we just got is not null then we will calculate the cost.*/ if (car != null) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(car); } } /*setting the carLists selected car to either be the car at the element selected * or if the element selected is invalid then null.*/ carList.SelectedCar = car; /*Returns the car list after we've seleted the chosen car.*/ return(carList); }
/*Function that takes in: * a. The ListBox of the year that we want to display. * b. The Listed object we wish to update with the new cars. * c. The ListBox we wish to update with the new manufacturers. * and switches the Listed object to display the specific years cars.*/ private void SwitchingYear(ListBox year, Listed list, ListBox toUpdate) { //if the user has selected a year. if (year.SelectedIndex != -1) { CarListReader listReader = new CarListReader(); //the year that the user has selected. string selectedYear = year.SelectedItem.ToString(); JsonReader json = new JsonReader(selectedYear); list.Cars = json.getCars(); list.Manufacturers = listReader.GetManufacturers(list.Cars); list.searchedManufacturers = list.Manufacturers; listBoxes.PopulateListBoxWithManufacturers(toUpdate, list.Manufacturers); //setting the year to be the year that was selected. //year = selectedYear; //drawListBox(json); } }
/*Function that clears all the uncecessary lists when they are not needed.*/ public Listed ClearLists(Listed list) { return(list); }
/*constructor that takes in 2 Listed objects and sets thhe car1List, and the car2List * with these inputs.*/ public Compare(Listed list1, Listed list2) { car1List = list1; car2List = list2; InitializeComponent(); }
private void Car2ElectricButton_Click(object sender, EventArgs e) { car2List = listBoxes.ShowOnlySelectedFuelType("Electric", Car2ModelList, car2List); }
private void Car2HyrbidButton_Click(object sender, EventArgs e) { car2List = listBoxes.ShowOnlySelectedFuelType("Hybrid", Car2ModelList, car2List); }
private void Car1DieselButton_Click(object sender, EventArgs e) { car1List = listBoxes.ShowOnlySelectedFuelType("Diesel", Car1ModelList, car1List); }
private void ModelBox_SelectedIndexChanged(object sender, EventArgs e) { carList = listBoxes.ModelSelected(ModelBox.SelectedIndex, carList); }
private void HybridButton_Click(object sender, EventArgs e) { carList = listBoxes.ShowOnlySelectedFuelType("Hybrid", ModelBox, carList); }
public Form1(Listed theCarList) { carList = theCarList; InitializeComponent(); }
private void ElectricButton_Click(object sender, EventArgs e) { carList = listBoxes.ShowOnlySelectedFuelType("Electricity", ModelBox, carList); }