/*Function that will be called when the Overview form opens this page * it will take in the list of the users cars, and then recalculate the mpg for the selected cars * and returns a CarsToPrint object which is a car list plus a string to print.*/ public CarsToPrint RecalculateMPGSelected(IEnumerable <Car> selectedCars, Car selectedCar) { /*class that convers a cars details to a string.*/ CarPrinter printer = new CarPrinter(); /*Creating new CarsToPrint object.*/ CarsToPrint cars = new CarsToPrint(); selectedCars = RecalculateCarList(selectedCars); cars.cars = selectedCars; cars.Header = ""; cars.Body = ""; try { /*If the user has a car selected.*/ if (selectedCar != null) { selectedCar = RecalculateCar(selectedCar); /*Getting all the cars details into a string*/ cars.Header = printer.carHeader(selectedCar); cars.Body = printer.printcar(selectedCar, Properties.Settings.Default.ImperialOrMetric); } } catch (Exception error) { Console.WriteLine(error.ToString()); } return(cars); }
/*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) { CarsToPrint newCars = new CarsToPrint(); LoadCar load = new LoadCar(); car = load.LoadSelectedCar(); newCars = init.RecalculateMPGSelected(cars, load.LoadSelectedCar()); try { CarInfo.Text = newCars.Header; CarDetails.Text = newCars.Body; } catch (Exception error) { Console.WriteLine(error.ToString()); } }