Beispiel #1
0
        // this method loads the list of rentals from the file.
        private void LoadRentalsFromFile()
        {
            // Load all and store the rental csv lines into string array
            RentalsCsvLines = File.ReadAllLines(RentalsFile);
            // Create datatable for rentals
            DataTable rentals = new DataTable();

            // load list of rentals and store into datable
            CsvOperations.CsvToTable(RentalsFile, rentals);
            // Store datatable fields in string arrays: registration and CustomerID
            string[] Registration = rentals.AsEnumerable().Select(row => row.Field <string>("Registration")).ToArray();
            string[] customerID   = rentals.AsEnumerable().Select(row => row.Field <string>("CustomerID")).ToArray();

            // Convert CustomerID to int array
            int[] CustomerID = Array.ConvertAll(customerID, int.Parse);

            for (int i = 0; i < customerID.Length; i++)
            {
                RentalListRego.Add(Registration[i]);
                RentalListID.Add(CustomerID[i]);
            }

            foreach (string rego in Registration)
            {
                DailyCost.Add(GetVehicle(rego).dailyRate);
            }
        }
Beispiel #2
0
        // this method loads the list of vehicles from the file.
        private void LoadVehiclesFromFile()
        {
            // Create datatable for fleet
            DataTable fleet = new DataTable();

            // load list of vehicles and store into datatable
            CsvOperations.CsvToTable(FleetFile, fleet);
            // Create string arrays for each attribute of a vehicle and store the data from the datable into the string arrays.
            // (Note that string array variables starting with lower case letters need to be converted to their appropriate
            //  Data type. When converted, they will encompass uppercase lettering.
            string[] Registration = fleet.AsEnumerable().Select(row => row.Field <string>("Registration")).ToArray();
            string[] grade        = fleet.AsEnumerable().Select(row => row.Field <string>("Grade")).ToArray();
            string[] Make         = fleet.AsEnumerable().Select(row => row.Field <string>("Make")).ToArray();
            string[] Model        = fleet.AsEnumerable().Select(row => row.Field <string>("Model")).ToArray();
            string[] year         = fleet.AsEnumerable().Select(row => row.Field <string>("Year")).ToArray();
            string[] numSeats     = fleet.AsEnumerable().Select(row => row.Field <string>("NumSeats")).ToArray();
            string[] transmission = fleet.AsEnumerable().Select(row => row.Field <string>("Transmission")).ToArray();
            string[] fuel         = fleet.AsEnumerable().Select(row => row.Field <string>("Fuel")).ToArray();
            string[] gps          = fleet.AsEnumerable().Select(row => row.Field <string>("GPS")).ToArray();
            string[] sunRoof      = fleet.AsEnumerable().Select(row => row.Field <string>("SunRoof")).ToArray();
            string[] dailyRate    = fleet.AsEnumerable().Select(row => row.Field <string>("DailyRate")).ToArray();
            string[] Colour       = fleet.AsEnumerable().Select(row => row.Field <string>("Colour")).ToArray();

            //Convert string arrays of grade, fuel and transmission into enum arrays
            Vehicle.VehicleGrade[]     Grade        = grade.Select(s => Enum.Parse(typeof(Vehicle.VehicleGrade), s)).Cast <Vehicle.VehicleGrade>().ToArray();
            Vehicle.TransmissionType[] Transmission = transmission.Select(s => Enum.Parse(typeof(Vehicle.TransmissionType), s)).Cast <Vehicle.TransmissionType>().ToArray();
            Vehicle.FuelType[]         Fuel         = fuel.Select(s => Enum.Parse(typeof(Vehicle.FuelType), s)).Cast <Vehicle.FuelType>().ToArray();
            // Convert string arrays of year and numSeats & dailyRate into type int and double, respectively.
            int[]    Year      = Array.ConvertAll(year, int.Parse);
            int[]    NumSeats  = Array.ConvertAll(numSeats, int.Parse);
            double[] DailyRate = Array.ConvertAll(dailyRate, double.Parse);
            // Convert string arrays of gps and sunRoof to boolean datatype
            bool[] GPS     = Array.ConvertAll(gps, bool.Parse);
            bool[] SunRoof = Array.ConvertAll(sunRoof, bool.Parse);

            // The number of vehicles in the fleet csv file is equal to the number of lines contained within the file.
            // Since registration is a mandatory field, it will not have missing entries, so we count the size of the registration array
            // to determine the number of vehicles in the csv file.
            int numVehicles = Registration.Length;

            // Using a loop, create a list of vehicles by instatiating the vehicle class.
            // Import values from the arrays above (taken from the csv file) into the constructor of vehicle class.
            for (int i = 0; i < numVehicles; i++)
            {
                VehicleList.Add(new Vehicle(Registration[i], Grade[i], Make[i], Model[i], Year[i], NumSeats[i],
                                            Transmission[i], Fuel[i], GPS[i], SunRoof[i], DailyRate[i], Colour[i]));
            }
        }
        // this method loads the list of rentals from the file.
        private void LoadRentalsFromFile()
        {
            // Create datatable for rentals
            DataTable rentals = new DataTable();

            // load list of rentals and store into datable
            CsvOperations.CsvToTable(RentalsFile, rentals);
            // Store datatable fields in string arrays: registration and CustomerID
            string[] Registration = rentals.AsEnumerable().Select(row => row.Field <string>("Registration")).ToArray();
            string[] customerID   = rentals.AsEnumerable().Select(row => row.Field <string>("CustomerID")).ToArray();

            // Convert CustomerID to int array
            int[] CustomerID = Array.ConvertAll(customerID, int.Parse);

            for (int i = 0; i < customerID.Length; i++)
            {
                Rentals.Add(Registration[i], CustomerID[i]);
            }
        }
Beispiel #4
0
        // This method loads the state of the CRM from file.
        public void LoadFromFile()
        {
            // Store all the lines of the customers csv in a string array
            CustomersCsvLines = File.ReadAllLines(CrmFile);
            // create customers datatable
            DataTable customers = new DataTable();

            // load list of rentals and store into datable
            CsvOperations.CsvToTable(CrmFile, customers);

            // Create string arrays for each attribute of a customer and store the data from the datable into the string arrays.
            // (Note that string array variables starting with lower case letters need to be converted to their appropriate
            //  Data type. When converted, they will encompass uppercase lettering.
            string[] id        = customers.AsEnumerable().Select(row => row.Field <string>("ID")).ToArray();
            string[] Title     = customers.AsEnumerable().Select(row => row.Field <string>("Title")).ToArray();
            string[] FirstName = customers.AsEnumerable().Select(row => row.Field <string>("FirstName")).ToArray();
            string[] LastName  = customers.AsEnumerable().Select(row => row.Field <string>("LastName")).ToArray();
            string[] gender    = customers.AsEnumerable().Select(row => row.Field <string>("Gender")).ToArray();
            string[] dob       = customers.AsEnumerable().Select(row => row.Field <string>("DOB")).ToArray();
            //Convert id string arr to int Array
            int[] CustomerID = Array.ConvertAll(id, int.Parse);
            // Convert gender string arr to Enum array
            Customer.Gender[] Gender = gender.Select(s => Enum.Parse(typeof(Customer.Gender), s)).Cast <Customer.Gender>().ToArray();
            // Convert dob string arr to DateTime array
            DateTime[] DOB = Array.ConvertAll(dob, DateTime.Parse);

            // The number of customers in the customers csv file is equal to the number of lines contained within the file.
            // Since ID is a primary field, it will not have missing entries, so we count the size of the ID array
            // to determine the number of customers in the csv file.
            int numCustomers = CustomerID.Length;

            // Using a loop, create a list of customer by instatiating the customer class and add to list.
            // Import values from the arrays above (taken from the csv file) into the constructor of customer class.
            for (int i = 0; i < numCustomers; i++)
            {
                CustomerList.Add(new Customer(CustomerID[i], Title[i], FirstName[i], LastName[i], Gender[i], DOB[i]));
            }
        }