Пример #1
0
        //Method Loads all the records from the CSV files into appropriate objects
        public void LoadAllRecords()
        {
            ListOfCostumers costumerList = ListOfCostumers.Instance();       //Get an instance of the ListOfCustomer (Singleton) class

            if (File.Exists(csvCostumerPath))                                //check if customer.csv file exists
            {
                GetCostumers();                                              //cal the GetCostumers() method
            }
            if (File.Exists(csvBookingPath))                                 //check if booking.csv file exists
            {
                foreach (Costumer aCostumer in costumerList.CostumerList)    //Iterates through all the costumers in the list
                {
                    GetBookings(aCostumer);                                  //Call the GetBooking method (Populates the booking list (of each customer) with all its bookings)
                }
                foreach (Costumer aCostumer in costumerList.CostumerList)    //Iterates through all the costumers in the list
                {
                    foreach (Booking aBooking in aCostumer.CostumerBookings) //Iterates through all the bookings for a specific customer
                    {
                        if (File.Exists(csvGuestsPath))                      //check if guests.csv file exists
                        {
                            GetGuests(aBooking);                             //Call the GetGuests method
                        }
                        if (File.Exists(csvExtrasPath))                      //check if extras.csv file exists
                        {
                            GetExtras(aBooking);                             //Call the GetExtras method
                        }
                    }
                }
            }
        }
Пример #2
0
        // Loads all the customers from the CSV into a list of customers (ListOfCostumer Singleton Class)
        public void GetCostumers()
        {
            // Create a streamReader object to access the file
            StreamReader    reader       = new StreamReader(File.OpenRead(csvCostumerPath));
            ListOfCostumers costumerList = ListOfCostumers.Instance();//Get an instance of the ListOfCustomer (Singleton) class

            // Create a streamReader object to access the file
            while (!reader.EndOfStream)
            {
                var      line      = reader.ReadLine();
                var      values    = line.Split(',');
                Costumer aCostumer = new Costumer(Int32.Parse(values[0]), values[1], values[2]); //Create a new customer and sets its properties to the values on the csv
                costumerList.AddCostumer(aCostumer);                                             //adds the customer to the custumer list (in the ListOfCustumers in the singleton class)
            }
            reader.Dispose();
        }
Пример #3
0
        //Method Saves all the objects (customers, booking, guests and extras) in the system to the csv files
        public void SaveAllRecords()
        {
            //Delete all the csv files (to write back from scratch)
            File.Delete(csvCostumerPath);
            File.Delete(csvBookingPath);
            File.Delete(csvGuestsPath);
            File.Delete(csvExtrasPath);
            ListOfCostumers costumerList = ListOfCostumers.Instance();

            foreach (Costumer aCostumer in costumerList.CostumerList)
            {
                WriteCostumer(aCostumer);
                foreach (Booking aBooking in aCostumer.CostumerBookings)
                {
                    WriteBooking(aCostumer.ReferenceNumber, aBooking);
                }
            }
        }