Esempio n. 1
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SaveCar save = new SaveCar();

            Console.WriteLine(year);

            /*If the all button is not active then use the year that's been selected
             * from the drop down menu*/
            if (year != "All")
            {
                if (carList.SelectedCar != null)
                {
                    SaveText.Text = save.Save(carList.SelectedCar, year);
                }
            }

            /*Else the all button has been selected, in this case get the JSON year of the car
             * thats in the Car object, and use this instead*/
            else
            {
                if (carList.SelectedCar != null)
                {
                    SaveText.Text = save.Save(carList.SelectedCar, carList.SelectedCar.carJSONYear);
                }
            }
        }
Esempio n. 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (carBox.SelectedIndex != -1)
     {
         SaveCar save = new SaveCar();
         save.removeCar(carBox.SelectedIndex);
         carBox.Items.RemoveAt(carBox.SelectedIndex);
     }
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
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);
            }
        }