/*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 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); }
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()); } }