Ejemplo n.º 1
0
        /*Function that gets the car that has been selected (Car that user
         * has pressed select on) and returns the Car object for this.*/
        public Car LoadSelectedCar()
        {
            Car car;

            //if a saved car already exists.
            if ((Properties.Settings.Default.Manufacturer != null && Properties.Settings.Default.Manufacturer != "") &&
                (Properties.Settings.Default.Model != null && Properties.Settings.Default.Model != "") &&
                (Properties.Settings.Default.Description != null && Properties.Settings.Default.Description != "") &&
                (Properties.Settings.Default.Year != null && Properties.Settings.Default.Year != ""))
            {
                //getting the list of cars from the Json file.
                JsonReader json = new JsonReader(Properties.Settings.Default.Year);
                List <Car> cars = new List <Car>();
                cars = json.getCars();


                //creating a list of cars which will be displayed to the users.
                List <Car>    usersCars = new List <Car>();
                CarListReader reader    = new CarListReader();

                //getting the car.
                car = reader.findCar(Properties.Settings.Default.Model,
                                     Properties.Settings.Default.Manufacturer,
                                     Properties.Settings.Default.Description, cars);
            }
            //else there is no car so null car and return.
            else
            {
                car = null;
            }


            return(car);
        }
Ejemplo n.º 2
0
        /*Function that takes in:
         * a. the textbox that contains the text.
         * b. the listed object so we can search through the manufacturers models
         * c. the listbox we wish to populate
         * and then returns an updated Listed object that contains the new CurrentCars
         * list.*/
        public Listed UpdatedModelsThroughSearch(TextBox text, Listed carList, ListBox ModelBox)
        {
            CarListReader listReader = new CarListReader();

            //using the CarListReader to search the Json file for the search result.
            IEnumerable <Car> searchedModels =
                listReader.searchModels(carList.CarsFromManufacturer, text.Text);
            //searching the description for what has been typed.
            IEnumerable <Car> searchedDescription =
                listReader.searchDescriptions(carList.CarsFromManufacturer, text.Text);

            //creating a list that contains both searchModels and searchedDescription
            carList.CurrentCars = searchedModels.Concat(searchedDescription);

            /*Setting the Current cars without restrictions to be the same as
             * the only difference between this and CurrentCars is this does not contain
             * the restrictions applied by the user.*/
            carList.CurrentCarsWithoutRestrictions = carList.CurrentCars;

            //for each car that contains what we searched we will print the Car and the Description.
            PopulateListBoxWithCarsDetails(ModelBox, carList.CurrentCars);

            //if the user empties the search box then we want to refill the listbox with the array of models.
            if (text.Text.Equals(""))
            {
                carList.CurrentCars = carList.CarsFromManufacturer;
                PopulateListBoxWithCarsDetails(ModelBox, carList.CurrentCars);
            }

            return(carList);
        }
Ejemplo n.º 3
0
        /*Function that takes in:
         * a. the ListBox for the model.
         * b. the manufactuerer selected from the ManufacturerBox.
         * c. the current Listed object.
         * d. the pictureBox we want to update with the selected manufacturers logo.
         * then returns all the cars from this selected manufacturer.*/
        public Listed ManufactuerSelected(ListBox ModelBox, string manufacturer, Listed carList, PictureBox LogoBox)
        {
            CarListReader listReader = new CarListReader();

            /*If the item is not all then do the following*/
            if (!manufacturer.Equals("All"))
            {
                /*Getting the models*/
                //contstructor that takes in a manufactorer and searches the array for cars that match the manufactorer.
                carList.CarsFromManufacturer = listReader.searchCars(carList.Cars, manufacturer);

                /*As we've only just drew the list of models we should assume that
                 * the CurrentCars is the CarsFromManufacturer*/
                carList.CurrentCars = carList.CarsFromManufacturer;

                carList.CurrentCarsWithoutRestrictions = carList.CurrentCars;

                /*Loading the manufacturers logo in the form.*/
                CarBadge badge = new CarBadge();
                string   url   = badge.getBadge(manufacturer);
                try
                {
                    LogoBox.Image    = Image.FromFile(url);
                    LogoBox.SizeMode = PictureBoxSizeMode.StretchImage;
                } catch (Exception error)
                {
                    Console.WriteLine(error.ToString());
                }
                PopulateListBoxWithCarsDetails(ModelBox, carList.CarsFromManufacturer);
            }
            else
            {
                /*As we've selected all, just set the manufacturers to each available car in the
                 * Listed object.*/
                carList.CarsFromManufacturer           = carList.Cars;
                carList.CurrentCars                    = carList.CarsFromManufacturer;
                carList.CurrentCarsWithoutRestrictions = carList.CurrentCars;

                PopulateListBoxWithCarsDetails(ModelBox, carList.CarsFromManufacturer);
            }

            /*Returning the carList after updating the carLists CarsFromManufacturer*/
            return(carList);
        }
Ejemplo n.º 4
0
        public Listed DefaultForm1ToLoad()
        {
            CarListReader reader = new CarListReader();

            Listed list = new Listed();

            /*Setting the cars in JSON reader to be that of the most recent year.*/
            JsonReader json = new JsonReader();

            /*Getting the list of cars from json.*/
            list.Cars = json.getCars();

            list.Manufacturers = reader.GetManufacturers(list.Cars);

            list.searchedManufacturers = list.Manufacturers;

            list.LatestFileYear = json.getMostRecent();

            return(list);
        }
Ejemplo n.º 5
0
        /*Function that takes in:
         * a. the textbox which contains the text.
         * b. the listed object so we can search through its manufacturers
         * c. the ListBox we wish to populate.
         * and then returns an updated Listed object that contains the new SearchedManufactuers
         * list.*/
        public Listed UpdateManufacturersThroughSearch(TextBox text, Listed carList, ListBox CarBox)
        {
            CarListReader listReader = new CarListReader();

            carList.searchedManufacturers =
                listReader.searchString(carList.Manufacturers, text.Text);

            /*Repopulating the listbox with what was searched rather than all the
             * manufacturers.*/
            PopulateListBoxWithManufacturers(CarBox, carList.searchedManufacturers);

            /*if the user has reset the search box ie. MakeBox.Text = "" then we will
             * repopulate the listbox with all the makes.*/
            if (text.Text.Equals(""))
            {
                carList.searchedManufacturers = carList.Manufacturers;
                PopulateListBoxWithManufacturers(CarBox, carList.searchedManufacturers);
            }

            return(carList);
        }
Ejemplo n.º 6
0
        /*Function that takes in:
         *   a. The ListBox of the year that we want to display.
         *   b. The Listed object we wish to update with the new cars.
         *   c. The ListBox we wish to update with the new manufacturers.
         * and switches the Listed object to display the specific years cars.*/
        private void SwitchingYear(ListBox year, Listed list, ListBox toUpdate)
        {
            //if the user has selected a year.
            if (year.SelectedIndex != -1)
            {
                CarListReader listReader = new CarListReader();

                //the year that the user has selected.
                string selectedYear = year.SelectedItem.ToString();

                JsonReader json = new JsonReader(selectedYear);
                list.Cars = json.getCars();

                list.Manufacturers = listReader.GetManufacturers(list.Cars);

                list.searchedManufacturers = list.Manufacturers;

                listBoxes.PopulateListBoxWithManufacturers(toUpdate, list.Manufacturers);
                //setting the year to be the year that was selected.
                //year = selectedYear;

                //drawListBox(json);
            }
        }
Ejemplo n.º 7
0
        /*Loading the car from the json file based on the strings that was saved to Settings.*/
        public IEnumerable <Car> Load()
        {
            //if there are properties saved.
            if (Properties.Settings.Default.Models != null &&
                Properties.Settings.Default.Manufacturers != null &&
                Properties.Settings.Default.Descriptions != null)
            {
                //getting the list of cars from the Json file.
                //JsonReader json = new JsonReader();
                List <Car> cars = new List <Car>();
                // cars = json.getCars();


                //creating a list of cars which will be displayed to the users.
                List <Car>    usersCars = new List <Car>();
                CarListReader reader    = new CarListReader();

                /*Getting each of the years that we saved so we know
                 * which one of the JSON files we should open to find the specific saved car.*/

                for (int i = 0; i < Properties.Settings.Default.Years.Count; i++)
                {
                    string year = Properties.Settings.Default.Years[i];

                    //Loading the JSON reader for the given year.
                    JsonReader json = new JsonReader(year);

                    //Getting the list of cars for this year.
                    List <Car> theCars = new List <Car>();
                    theCars = json.getCars();

                    //searching for the car based on the same properties.
                    Car car = reader.findCar(Properties.Settings.Default.Models[i],
                                             Properties.Settings.Default.Manufacturers[i],
                                             Properties.Settings.Default.Descriptions[i], theCars);
                    //adding the car that we've just found to the list of cars.
                    usersCars.Add(car);
                }



                //Going around a loop for as many cars the user has saved (maximum 5.)

                /*
                 * for (int i = 0; i < Properties.Settings.Default.Models.Count; i++)
                 * {
                 *  //searching for the car based on the same properties.
                 *  Car car = reader.findCar(Properties.Settings.Default.Models[i],
                 *                           Properties.Settings.Default.Manufacturers[i],
                 *                           Properties.Settings.Default.Descriptions[i], cars);
                 *
                 *  //adding the car that we've just found to the list of cars.
                 *  usersCars.Add(car);
                 *
                 * }
                 */



                return(usersCars);
            }
            //else return null as there is no saved car.
            else
            {
                return(null);
            }
        }