public void PopulateArray(clsDataConnection DB)
        {
            //populates the array list based on the data table in the parameter DB
            //Variable for index
            Int32 Index = 0;
            //Variable to store the record count.
            Int32 RecordCount;

            RecordCount = DB.Count;
            //clear the private list array.
            mCarList = new List <clsCar>();
            //while there are records to process
            while (Index < RecordCount)
            {
                //Create a blank class
                clsCar AnCar = new clsCar();
                //read in the fields from the current record.
                AnCar.CarID                = Convert.ToInt32(DB.DataTable.Rows[Index]["CarID"]);
                AnCar.CarManufacturer      = Convert.ToString(DB.DataTable.Rows[Index]["CarManufacturer"]);
                AnCar.CarModel             = Convert.ToString(DB.DataTable.Rows[Index]["CarModel"]);
                AnCar.CarRegistrationPlate = Convert.ToString(DB.DataTable.Rows[Index]["CarRegistrationPlate"]);
                AnCar.CarColour            = Convert.ToString(DB.DataTable.Rows[Index]["CarColour"]);
                AnCar.CarNumberOfDoors     = Convert.ToInt32(DB.DataTable.Rows[Index]["NumOfDoors"]);
                AnCar.CarNumberOfSeats     = Convert.ToInt32(DB.DataTable.Rows[Index]["NumOfSeats"]);
                AnCar.SupplierID           = Convert.ToInt32(DB.DataTable.Rows[Index]["SupplierID"]);
                AnCar.CarNeedsRepair       = Convert.ToBoolean(DB.DataTable.Rows[Index]["CarNeedsRepair"]);
                AnCar.CarSold              = Convert.ToBoolean(DB.DataTable.Rows[Index]["CarSold"]);
                //add the record to the private data member.
                mCarList.Add(AnCar);
                //Point at the next record
                Index++;
            }
        }
예제 #2
0
        //public constructor for the class
        public clsCarCollection()
        {
            //create an instance of the car class to store a car
            clsCar ACar = new clsCar();

            //set the car to ford
            ACar.Car = "Ford";
            //add the car to the private list of cars
            mAllCars.Add(ACar);
            //re initialise the ACar object to accept a new item
            ACar = new clsCar();
            //set the car to BMW
            ACar.Car = "BMW";
            //add the second car to the private list of cars
            mAllCars.Add(ACar);
            //the private list now contains two countries
        }