Esempio n. 1
0
        /*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());
            }
        }
Esempio n. 2
0
        private void Compare_Load(object sender, EventArgs e)
        {
            //reader.getJsonLocation("2016");
            cars         = reader.getCars();
            selectedCars = load.Load();

            userCar = load.LoadSelectedCar();

            string thisDirectory = Directory.GetCurrentDirectory().ToString();
            string fileLoc       = thisDirectory + @"\Images\LeafIcon.png";

            pictureBox1.Image    = Image.FromFile(fileLoc);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

            /*If the user has a car we will send the loadDefaultComparison the userCar,
             * else we will send over the first car in the array, and if this is not possible, then
             * the application is not working as intended so we will send an error message
             * to the user.*/
            if (userCar == null)
            {
                if (cars != null)
                {
                    loadDefaultComparison(cars.ElementAt(0));
                }
                else
                {
                    loadDefaultComparison(null);
                }
            }
            else
            {
                loadDefaultComparison(userCar);
            }

            latestYear = car1List.LatestFileYear;

            populateYears();
            populateManufacturers();
            populateSelectedCars();
        }
Esempio n. 3
0
        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);
            }
        }