Beispiel #1
0
        // Reads from extras.csv file to populate the a booking list of extras  (creates extra objects (Breakfasts, MealHire, CarHire) and adds it to the list)
        public void GetExtras(Booking aBooking)
        {
            StreamReader reader = new StreamReader(File.OpenRead(csvExtrasPath));

            while (!reader.EndOfStream)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (Int32.Parse(values[0]) == aBooking.ReferenceNumber)
                {
                    if (values[1] == "HollydayBooking.Breakfast") //Check if extra is a breakfast
                    {
                        Breakfast aBreakfast = new Breakfast();
                        aBooking.Extras.Add(aBreakfast);
                    }
                    else if (values[1] == "HollydayBooking.EveningMeal") //Check if extra is an EveningMeal
                    {
                        EveningMeal anEveningMeal = new EveningMeal();
                        aBooking.Extras.Add(anEveningMeal);
                    }
                    else if (values[1] == "HollydayBooking.CarHire") //Check if extra is CarHire
                    {
                        CarHire aCarHire = new CarHire();
                        aCarHire.DriverName = values[2];
                        aCarHire.StartDate  = DateTime.Parse(values[3]);
                        aCarHire.ReturnDate = DateTime.Parse(values[4]);
                        aBooking.Extras.Add(aCarHire);
                    }
                }
            }
            reader.Dispose();
        }
Beispiel #2
0
        // Amends the selected extra
        private void btn_amendExtra_Click(object sender, RoutedEventArgs e)
        {
            Booking aBooking = facade.CurrentBooking;
            Extra   anExtra  = facade.GetExtra(cmb_bookingExtras.SelectedIndex);

            if (anExtra.GetType().ToString() == "HollydayBooking.Breakfast") //Check if extra is of type Brekfast
            {
                Breakfast aBreakfast = (Breakfast)anExtra;
                aBooking.DietaryRequirements        = txt_extraDietaryRequirements.Text;
                txt_bookingDietaryRequirements.Text = txt_extraDietaryRequirements.Text;
                MessageBox.Show("Extra details have been successfully updated!");
            }
            else if (anExtra.GetType().ToString() == "HollydayBooking.EveningMeal") //Check if extra is of type EveningMeal
            {
                EveningMeal anEveningMeal = (EveningMeal)anExtra;
                aBooking.DietaryRequirements        = txt_extraDietaryRequirements.Text;
                txt_bookingDietaryRequirements.Text = txt_extraDietaryRequirements.Text;
                MessageBox.Show("Extra details have been successfully updated!");
            }
            else if (anExtra.GetType().ToString() == "HollydayBooking.CarHire") //Check if extra is of type CarHire
            {
                DateTime arrivalDate;
                DateTime departureDate;
                if (DateTime.TryParse(txt_extraStartDate.Text, out arrivalDate))
                {
                    if (DateTime.TryParse(txt_extraEndDate.Text, out departureDate))
                    {
                        try
                        {
                            CarHire aCarHire = (CarHire)anExtra;
                            aCarHire.DriverName = txt_extraDriverName.Text;
                            aCarHire.StartDate  = arrivalDate;
                            aCarHire.ReturnDate = departureDate;
                            MessageBox.Show("Extra details have been successfully updated!");
                        }
                        catch (Exception excep)
                        {
                            MessageBox.Show(excep.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter a valid return date. (YYYY-MM-DD)");
                        txt_extraEndDate.Text = "";
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid pick-up date. (YYYY-MM-DD)");
                    txt_extraStartDate.Text = "";
                }
            }
        }
Beispiel #3
0
        public void WriteBooking(int costumerRef, Booking aBooking)
        {
            StringBuilder sb = new StringBuilder();

            // Write booking details to booking.csv
            string line = costumerRef.ToString() + ","
                          + aBooking.ReferenceNumber.ToString() + ","
                          + aBooking.ArrivalDate.ToString(aBooking.DatePattern) + ","
                          + aBooking.DepartureDate.ToString(aBooking.DatePattern) + ","
                          + aBooking.DietaryRequirements.ToString();
            string filepath = csvBookingPath;

            sb.AppendLine(line);
            System.IO.File.AppendAllText(filepath, sb.ToString());
            sb.Clear(); //Clears the buffer's current content

            //Write Guest details to guests.csv
            filepath = csvGuestsPath; //write guest details to guests.csv
            foreach (Guest guest in aBooking.Guests)
            {
                line = aBooking.ReferenceNumber.ToString() + ","
                       + guest.Name.ToString() + ","
                       + guest.PassportNumber.ToString() + ","
                       + guest.Age.ToString();
                sb.AppendLine(line);
            }
            System.IO.File.AppendAllText(filepath, sb.ToString());
            sb.Clear();

            //Write Extra details to extras.csv
            filepath = csvExtrasPath; //write extra details to extra.csv
            foreach (Extra extra in aBooking.Extras)
            {
                if (extra.GetType().ToString() == "HollydayBooking.Breakfast" || extra.GetType().ToString() == "HollydayBooking.EveningMeal")
                {
                    line = aBooking.ReferenceNumber.ToString() + "," + extra.GetType().ToString();
                    sb.AppendLine(line);
                }
                else
                {
                    CarHire aCarHire = new CarHire();
                    aCarHire = (CarHire)extra;
                    line     = aBooking.ReferenceNumber.ToString() + ","
                               + extra.GetType().ToString() + ","
                               + aCarHire.DriverName.ToString() + ","
                               + aCarHire.StartDate.ToString(aBooking.DatePattern) + ","
                               + aCarHire.ReturnDate.ToString(aBooking.DatePattern);
                    sb.AppendLine(line);
                }
            }
            System.IO.File.AppendAllText(filepath, sb.ToString());
        }
Beispiel #4
0
        // Opens a new window and prints a detailed invoice for the selected booking
        private void btn_invoice_Click(object sender, RoutedEventArgs e)
        {
            Invoice  inv       = new Invoice();
            Costumer aCostumer = facade.CurrentCostumer;
            Booking  aBooking  = facade.CurrentBooking;

            inv.lbl_invoiceDateOutput.Content           = DateTime.Now.ToString("yyyy-MM-dd");
            inv.lbl_invoiceBookingIDOutput.Content      = aBooking.ReferenceNumber;
            inv.lbl_invoiceNumberOfGuestsOutput.Content = aBooking.Guests.Count();
            inv.lbl_customerIDOutput.Content            = aCostumer.ReferenceNumber;
            inv.lbl_customerNameOutput.Content          = aCostumer.Name;
            inv.lbl_customerAddressOutput.Content       = aCostumer.Address;
            foreach (Guest aGuest in aBooking.Guests)
            {
                if (aGuest.Age <= 18)
                {
                    inv.lbl_bookingDescription.Content += "Guest" + (aBooking.Guests.IndexOf(aGuest) + 1) + ": £30.00 (child rate) x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += 30.00 * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
                else
                {
                    inv.lbl_bookingDescription.Content += "Guest" + (aBooking.Guests.IndexOf(aGuest) + 1) + ": £50.00 (adult rate) x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += 50.00 * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
            }
            foreach (Extra anExtra in aBooking.Extras)
            {
                if (anExtra.GetType().ToString() == "HollydayBooking.Breakfast")
                {
                    inv.lbl_bookingDescription.Content += "Breakfast: " + "£5.00 x " + aBooking.Guests.Count() + " guests x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += anExtra.Price * aBooking.Guests.Count() * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
                else if (anExtra.GetType().ToString() == "HollydayBooking.EveningMeal")
                {
                    inv.lbl_bookingDescription.Content += "Evening Meal: " + "£15.00 x " + aBooking.Guests.Count() + " guests x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += anExtra.Price * aBooking.Guests.Count() * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
                else if (anExtra.GetType().ToString() == "HollydayBooking.CarHire")
                {
                    CarHire aCarHire = (CarHire)anExtra;
                    inv.lbl_bookingDescription.Content += "Car Hire: " + "£50.00 x " + (aCarHire.ReturnDate - aCarHire.StartDate).TotalDays + " days\n";
                    inv.lbl_bookingAmount.Content      += aCarHire.Price * ((aCarHire.ReturnDate - aCarHire.StartDate).TotalDays) + "£\n";
                }
            }
            inv.lbl_invoiceTotalAmountOutput.Content = aBooking.GetCost() + "£";
            inv.ShowDialog();
        }
Beispiel #5
0
        // Loads the extra selected extra details to Mainwindow
        private void cmb_bookingExtras_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Extra selectedExtra = null;

            if (cmb_bookingExtras.SelectedItem != null)
            {
                selectedExtra = facade.GetExtra(cmb_bookingExtras.SelectedIndex);
            }

            if (selectedExtra != null)
            {
                if (cmb_bookingExtras.SelectedItem.ToString() == "Breakfast" || cmb_bookingExtras.SelectedItem.ToString() == "Evening meal")
                {
                    lbl_extraDietaryRequirements.Visibility = System.Windows.Visibility.Visible;
                    txt_extraDietaryRequirements.Visibility = System.Windows.Visibility.Visible;
                    lbl_extraDriverName.Visibility          = System.Windows.Visibility.Hidden;
                    txt_extraDriverName.Visibility          = System.Windows.Visibility.Hidden;
                    lbl_extraStartDate.Visibility           = System.Windows.Visibility.Hidden;
                    txt_extraStartDate.Visibility           = System.Windows.Visibility.Hidden;
                    lbl_extraEndDate.Visibility             = System.Windows.Visibility.Hidden;
                    txt_extraEndDate.Visibility             = System.Windows.Visibility.Hidden;
                    txt_extraDietaryRequirements.Text       = txt_bookingDietaryRequirements.Text;
                }
                else if (cmb_bookingExtras.SelectedItem.ToString() == "Car hire")
                {
                    CarHire aCarHire = (CarHire)selectedExtra;
                    lbl_extraDietaryRequirements.Visibility = System.Windows.Visibility.Hidden;
                    txt_extraDietaryRequirements.Visibility = System.Windows.Visibility.Hidden;
                    lbl_extraDriverName.Visibility          = System.Windows.Visibility.Visible;
                    txt_extraDriverName.Visibility          = System.Windows.Visibility.Visible;
                    lbl_extraStartDate.Visibility           = System.Windows.Visibility.Visible;
                    txt_extraStartDate.Visibility           = System.Windows.Visibility.Visible;
                    lbl_extraEndDate.Visibility             = System.Windows.Visibility.Visible;
                    txt_extraEndDate.Visibility             = System.Windows.Visibility.Visible;
                    txt_extraDriverName.Text = aCarHire.DriverName;
                    txt_extraStartDate.Text  = aCarHire.StartDate.ToString("yyyy-MM-dd");
                    txt_extraEndDate.Text    = aCarHire.ReturnDate.ToString("yyyy-MM-dd");
                }
                btn_deleteExtra.IsEnabled = true;
                btn_amendExtra.IsEnabled  = true;
            }
            else
            {
                btn_deleteExtra.IsEnabled = false;
                btn_amendExtra.IsEnabled  = false;
            }
        }
Beispiel #6
0
        //Gets the total cost for a booking (adding the total stay charge + extras)
        public double GetCost()
        {
            double totalCost = 0;

            // Get the total amount (for the stay) for each of the guests guests
            foreach (Guest guest in guests)
            {
                //If guest is child
                if (guest.Age <= 18)
                {
                    // Then, cost for the guest is £30.00 (child rate) * number of nights
                    totalCost += (30.00 * (this.departureDate - this.arrivalDate).TotalDays); //add value to totalCost
                }
                else
                {
                    // otherwise, cost for the guest is £50.00 (adult rate) * number of nights
                    totalCost += (50.00 * (this.departureDate - this.arrivalDate).TotalDays); //add value to totalCost
                }
            }
            // Get the total amount (for each extra) for all extras
            foreach (Extra extra in extras)
            {
                // If extra is of type brekfast
                if (extra is Breakfast)
                {
                    //Add to totalCost the price of a Brekfast * the number of nights * number of Guests
                    totalCost += extra.Price * (this.DepartureDate - this.ArrivalDate).Days * guests.Count();
                }
                else if (extra is EveningMeal)
                {
                    //Add to totalCost the price of an Evening Meal * the number of nights * number of Guests
                    totalCost += extra.Price * (this.DepartureDate - this.ArrivalDate).Days * guests.Count();
                }
                else if (extra is CarHire)
                {
                    CarHire aCarHire = (CarHire)extra; // Cast from extra to CarHire object in order to access CarHire specific properties
                    //Add to totalCost the price of Hiring a car per night * the number of days Hired
                    totalCost += aCarHire.Price * (aCarHire.ReturnDate - aCarHire.StartDate).TotalDays;
                }
            }
            return(totalCost); // Returns the totalCost of the Booking
        }
Beispiel #7
0
 //Method called when add extra button is clicked. Gets user input to create a new extra and add it to the global list of extras (tempExtras)
 private void btn_extras_Click(object sender, RoutedEventArgs e)
 {
     //If Brekfast extra is selected...
     if (cmb_selectExtraType.SelectedItem.ToString() == "Breakfast")
     {
         Breakfast aBreakfast = new Breakfast();                            //Create new Breakfast object
         tempExtras.Add(aBreakfast);                                        //Add Breakfast Object to the booking list of extras
         dietaryRequirements          = txt_dietaryRequirements.Text;       //Set the booking dietary requirements from user input
         txt_dietaryRequirements.Text = "";                                 //clears the textbox
         cmb_extras.IsEnabled         = true;                               //Enable the extras combobox
         cmb_extras.Items.Add(cmb_selectExtraType.SelectedItem.ToString()); //Add the new extra (type Breakfast) to the extras comboBox
         MessageBox.Show("Breakfast has been successfully added");          //Informs the user that Breakfast extra was added successfuly
     }
     //If Evening Meal extra is selected...
     else if (cmb_selectExtraType.SelectedItem.ToString() == "Evening meal")
     {
         EveningMeal anEveningMeal = new EveningMeal();                     //Create new EveningMeal object
         tempExtras.Add(anEveningMeal);                                     //Add Evening Meal Object to the booking list of extras
         dietaryRequirements          = txt_dietaryRequirements.Text;       //Set the booking dietary requirements from user input
         txt_dietaryRequirements.Text = "";                                 //clears the textbox
         cmb_extras.IsEnabled         = true;                               //Enable the extras combobox
         cmb_extras.Items.Add(cmb_selectExtraType.SelectedItem.ToString()); //Add the new extra (type EveningMeal) to the extras comboBox
         MessageBox.Show("Evening meal has been successfully added");       //Informs the user that EveningMeal extra was added successfuly
     }
     else if (cmb_selectExtraType.SelectedItem.ToString() == "Car hire")
     {
         DateTime arrivalDate;                                           //local variable to hold a DateTime value (Car Hire pick-up date)
         DateTime departureDate;                                         //local variable to hold a DateTime value (Car Hire return date)
         if (DateTime.TryParse(txt_startDate.Text, out arrivalDate))     //Check if pick-up date input by the user is a valid DateTime format
         {
             if (DateTime.TryParse(txt_endDate.Text, out departureDate)) //Check if return date input by the user is a valid DateTime format
             {
                 //Try to assign CarHire properties from user input and create a CarHire extra
                 try
                 {
                     CarHire aCarHire = new CarHire();                                  //Create new CarHire object
                     aCarHire.DriverName = txt_driverName.Text;                         // (try to) Set driver name from user input
                     aCarHire.StartDate  = arrivalDate;                                 // (try to) Set pick-up date name from user input
                     aCarHire.ReturnDate = departureDate;                               // (try to) Set return date from user input
                     tempExtras.Add(aCarHire);                                          //Add Car Hire Object to the booking list of extras
                     txt_driverName.Text  = "";                                         //clear the textbox
                     txt_startDate.Text   = "";                                         //clear the textbox
                     txt_endDate.Text     = "";                                         //clear the textbox
                     cmb_extras.IsEnabled = true;                                       //enable comboBox with the extras
                     cmb_extras.Items.Add(cmb_selectExtraType.SelectedItem.ToString()); //Add the new extra (type CarHire) to the extras comboBox
                     MessageBox.Show("Car hire has been successfully added");           //Informs the user that CarHire extra was added successfuly
                 }
                 // Catch exception messages if the assignemt of CarHire properties fail
                 catch (Exception excep)
                 {
                     MessageBox.Show(excep.Message);//Print message in Message Box
                 }
             }
             else
             {
                 MessageBox.Show("Please enter a valid return date date. (YYYY-MM-DD)"); //Promp user to input a valid DateTime showing the correct format
                 txt_endDate.Text = "";                                                  //clear the textbox
             }
         }
         else
         {
             MessageBox.Show("Please enter a valid pick-up date. (YYYY-MM-DD)"); //Promp user to input a valid DateTime showing the correct format
             txt_startDate.Text = "";                                            //clear the textbox
         }
     }
 }
Beispiel #8
0
        private void btn_addExtra_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWin   = Owner as MainWindow;    //Create a reference to the main window (in order to have access to its properties)
            Costumer   aCostumer = facade.CurrentCostumer; //Get the currentCostumer object
            Booking    aBooking  = facade.CurrentBooking;  //Get the currentBooking object

            //If Brekfast extra is selected...
            if (cmb_extraTypes.SelectedItem.ToString() == "Breakfast")
            {
                Breakfast aBreakfast = new Breakfast();                                      //Create new Breakfast object
                aBooking.Extras.Add(aBreakfast);                                             //Add Breakfast Object to the booking list of extras
                aBooking.DietaryRequirements = txt_dietaryRequirements.Text;                 //Set the booking dietary requirements from user input
                mainWin.txt_bookingDietaryRequirements.Text = aBooking.DietaryRequirements;  //update the dietary requirement of booking on main window textbox
                txt_dietaryRequirements.Text        = "";                                    //clear the textbox
                mainWin.cmb_bookingExtras.IsEnabled = true;                                  //enable comboBox with the extras on main window
                mainWin.cmb_bookingExtras.Items.Add(cmb_extraTypes.SelectedItem.ToString()); //Add extra Type (Breakfast) to the extra comboBox in main window
                MessageBox.Show("Breakfast has been successfully added");                    //Prompt user that Breakfast extra has been created
                this.Close();
            }
            //If Evening Meal extra is selected...
            else if (cmb_extraTypes.SelectedItem.ToString() == "Evening meal")
            {
                EveningMeal anEveningMeal = new EveningMeal();                               //Create new Evening Meal object
                aBooking.Extras.Add(anEveningMeal);                                          //Add Evening Meal Object to the booking list of extras
                aBooking.DietaryRequirements = txt_dietaryRequirements.Text;                 //Set the booking dietary requirements from user input
                mainWin.txt_bookingDietaryRequirements.Text = aBooking.DietaryRequirements;  //update the dietary requirement of booking on main window textbox
                txt_dietaryRequirements.Text        = "";                                    //clear the textbox
                mainWin.cmb_bookingExtras.IsEnabled = true;                                  //enable comboBox with the extras on main window
                mainWin.cmb_bookingExtras.Items.Add(cmb_extraTypes.SelectedItem.ToString()); //Add extra Type (Evening Meal) to the extra comboBox in main window
                MessageBox.Show("Evening Meal has been successfully added");                 //Prompt user that Evening Meal extra has been created
                this.Close();
            }
            //If Car Hire extra is selected...
            else if (cmb_extraTypes.SelectedItem.ToString() == "Car hire")
            {
                DateTime arrivalDate;                                           //local variable to hold a DateTime value (Car Hire pick-up date)
                DateTime departureDate;                                         //local variable to hold a DateTime value (Car Hire return Date)
                if (DateTime.TryParse(txt_startDate.Text, out arrivalDate))     //Check if pick-up date input is a valid DateTime value
                {
                    if (DateTime.TryParse(txt_endDate.Text, out departureDate)) //Check if return date input is a valid DateTime value
                    {
                        // Try to assign input values to CarHire object
                        try
                        {
                            CarHire aCarHire = new CarHire();                                            //Create new Car Hire object
                            aCarHire.DriverName = txt_driverName.Text;                                   // (try to) Set driver name from user input
                            aCarHire.StartDate  = arrivalDate;                                           // (try to) Set pick-up date from user input
                            aCarHire.ReturnDate = departureDate;                                         // (try to) Set return date from user input
                            aBooking.Extras.Add(aCarHire);                                               //Add Car Hire Object to the booking list of extras
                            txt_driverName.Text = "";                                                    //clear the textbox
                            txt_startDate.Text  = "";                                                    //clear the textbox
                            txt_endDate.Text    = "";                                                    //clear the textbox
                            mainWin.cmb_bookingExtras.IsEnabled = true;                                  //enable comboBox with the extras on main window
                            mainWin.cmb_bookingExtras.Items.Add(cmb_extraTypes.SelectedItem.ToString()); //Add extra Type (Car Hire) to the extra comboBox in main window
                            MessageBox.Show("Car hire has been successfully added");                     //Prompt user that Car Hire extra has been created
                            this.Close();
                        }
                        // Catch exception messages if the assignemt of CarHire properties fail
                        catch (Exception excep)
                        {
                            MessageBox.Show(excep.Message);//Print message in Message Box
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter a valid return date date. (YYYY-MM-DD)"); //Promp user to input a valid DateTime showing the correct format
                        txt_endDate.Text = "";                                                  //clear the textbox
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid pick-up date. (YYYY-MM-DD)"); //Promp user to input a valid DateTime showing the correct format
                    txt_startDate.Text = "";                                            //clear the textbox
                }
            }
        }