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