/*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 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 SelectCarButton_Click(object sender, EventArgs e) { Car theCar = cars.ElementAt(carBox.SelectedIndex); //getting the car printer. CarPrinter printer = new CarPrinter(); //printing the header for the car ie. manufacturer, model and description. string carInfo = printer.carHeader(theCar); //getting the rest of the cars details. string carDetails = printer.printcar(theCar, measurementSystem); CarInfo.Text = carInfo; CarDetails.Text = carDetails; SaveCar save = new SaveCar(); save.selectedCar(carBox.SelectedIndex); setImage(theCar.Manufacturer); }
/*Function that gets all the details for the car, including the * image for the car, and all the cars details.*/ public CarToBeDisplayed detailsToBeDisplayed(Car car) { //The information that we will return to the user, CarToBeDisplayed displayed = new CarToBeDisplayed(); //getting the car printer so we can get the cars that need printing. CarPrinter printer = new CarPrinter(); /*Setting the header and details to be the printers equivelent.*/ displayed.carDetails = printer.printcar(car, Properties.Settings.Default.ImperialOrMetric); displayed.carHeader = printer.carHeader(car); try { //Getting the carbadge class so we send the image url to the class. CarBadge badge = new CarBadge(); displayed.imageURL = badge.getBadge(car.Manufacturer); } catch (Exception error) { Console.WriteLine(error.ToString()); } return(displayed); }
public Overview() { InitializeComponent(); LoadCar load = new LoadCar(); cars = load.Load(); car = load.LoadSelectedCar(); /*Calculating the tax for each of the cars in car.*/ try { foreach (Car theCar in cars) { if (theCar.CO2gramsPerKilometer != null && theCar.CO2gramsPerKilometer != 0) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(theCar); } } if (car.CO2gramsPerKilometer != null && car.CO2gramsPerKilometer != 0) { TaxCalculator tax = new TaxCalculator(); float? taxCost = tax.CalculateTax(car); } } catch (Exception e) { Console.WriteLine(e.ToString()); } string thisDirectory = Directory.GetCurrentDirectory().ToString(); string fileLoc = thisDirectory + @"\Images\LeafIcon.png"; pictureBox1.Image = Image.FromFile(fileLoc); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; /*If the car is null that means that the user has not * yet selected a car to be there main car, in which case we will set the * first car in the array (if it exists) to be the selected car.*/ if (car == null) { /*Checking if the user has added any cars to the list before * if they have we will set the first of these cars to be the selected cars, else * we will display the user with an error message.*/ if (cars != null && cars.Count() > 0) { SaveCar save = new SaveCar(); save.selectedCar(0); //printer so we can print information about the car. CarPrinter printer = new CarPrinter(); string info = printer.carHeader(cars.ElementAt(0)); string details = printer.printcar(cars.ElementAt(0), measurementSystem); CarInfo.Text = info; CarDetails.Text = details; setImage(cars.ElementAt(0).Manufacturer); } /*Else we have no saved cars either so we will * display a messaage to the user saying we have no car.*/ else { setImage("error"); CarInfo.Text = "Error! Please go to Add Car and add your car/cars."; CarDetails.Text = "Error!"; } } //else a saved car does exist so use this instead. else { CarPrinter printer = new CarPrinter(); string info = printer.carHeader(car); string details = printer.printcar(car, measurementSystem); CarInfo.Text = info; CarDetails.Text = details; setImage(car.Manufacturer); } }