Ejemplo n.º 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();
        }
Ejemplo n.º 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 = "";
                }
            }
        }
Ejemplo n.º 3
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
         }
     }
 }
Ejemplo n.º 4
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
                }
            }
        }