Example #1
0
        public Facade(EditBooking editor)
        {
            _customer  = UserTracker.Instance;
            _booker    = BookingTracker.Instance;
            _guests    = GuestTracker.Instance;
            _directory = DirectoryManager.Instance;

            this.editor = editor; //bring in reference to the booking editor
        }
        //call the BookingTracker to delte the booking
        private void delButton_Click(object sender, RoutedEventArgs e)
        {
            int            bookingId = Int32.Parse(lookupBox.Text);
            BookingTracker del       = BookingTracker.Instance;

            del.Delete(currentCustomer, bookingId);

            HubPage hub = new HubPage(currentCustomer);

            //clear the box in case they try to load a new booking which will need to put it's guests here
            guestsBox.Text = "";
        }
        private void loadButton_Click(object sender, RoutedEventArgs e)
        {
            guestsBox.Text = "";

            BookingTracker loader = BookingTracker.Instance;
            int            id     = Int32.Parse(lookupBox.Text);

            loader.ReadBooking(currentBooking, id);

            //set dates
            inDatePick.SelectedDate  = currentBooking.ArrivalDate;
            outDatePick.SelectedDate = currentBooking.DepartureDate;
            dietBox.Text             = currentBooking.Diet;

            //these if else statements set UI elements according to the state of the parameters they correspond to
            if (currentBooking.Breakfast == true)
            {
                breakfastBox.IsChecked = true;
            }
            else
            {
                breakfastBox.IsChecked = false;
            }

            if (currentBooking.Meals == true)
            {
                mealsBox.IsChecked = true;
            }
            else
            {
                breakfastBox.IsChecked = false;
            }

            if (currentBooking.CarHire == true)
            {
                carHireBox.IsChecked = true;
            }
            else
            {
                carHireBox.IsChecked = false;
            }

            //if checkbox unchecked change to false and disable care hire inputs
            if (carHireBox.IsChecked == false)
            {
                driverNameBox.IsEnabled   = false;
                driveDay1Picker.IsEnabled = false;
                driveDay2Picker.IsEnabled = false;
            }
            else //if checkbox is checked change to true and enable care hire inputs
            {
                driverNameBox.IsEnabled   = true;
                driveDay1Picker.IsEnabled = true;
                driveDay2Picker.IsEnabled = true;

                driverNameBox.Text           = currentBooking.DriverName;
                driveDay1Picker.SelectedDate = currentBooking.HireStart;
                driveDay2Picker.SelectedDate = currentBooking.HireEnd;
            }

            GuestTracker guestLoader = GuestTracker.Instance;

            guestLoader.Read(currentBooking, id);

            //print each guest into the box to show the user which guests are in the booking
            foreach (Guest printG in currentBooking.GuestList)
            {
                guestsBox.Text += "Passport: " + printG.Passport + ", Name: " + printG.Name + ", Age: " + printG.Age + "\n";
            }
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            bool success = false;

            currentBooking = new Booking();
            BookingTracker reader = BookingTracker.Instance;

            try
            {
                int searchNum = Int32.Parse(numBox.Text);
                reader.ReadBooking(currentBooking, searchNum);
                success = true;
            }
            catch
            {
                MessageBox.Show("You must enter a number... and yes I know you aren't booking number 2,147,483,647 + x.", "Missing data.", // reason for error
                                MessageBoxButton.OK, MessageBoxImage.Error);                                                               //get BONKED
            }

            if (success == true)
            {
                double nightsCost;
                double breakfastCost;
                double mealCost;
                double hireCost;

                //cost due to length of stay
                int stayLength = (currentBooking.DepartureDate - currentBooking.ArrivalDate).Days;
                nightsCost = 50 * stayLength;

                //cost due to breakfast extra
                if (currentBooking.Breakfast == true)
                {
                    breakfastCost = 5 * currentBooking.GuestList.Count * stayLength;
                }
                else
                {
                    breakfastCost = 0;
                }

                //cost due to evening meals
                if (currentBooking.Meals == true)
                {
                    int count = currentBooking.GuestList.Count;
                    mealCost = 15 * count;
                }

                else
                {
                    mealCost = 0;
                }

                //cost due to car hire time
                int hireLength = (currentBooking.HireEnd - currentBooking.HireStart).Days;
                hireCost = 50 * hireLength;

                costLabel.Content += "Cost for Night's stayed: £" + nightsCost + "\n";
                costLabel.Content += "Breakfasts: £" + breakfastCost + "\n";
                costLabel.Content += "Evening Meals: £" + mealCost + "\n";
                costLabel.Content += "Car hire for " + hireLength + " days: £" + hireCost + "\n";
            }
            else
            {
                //error already shown, another is unnecessary
            }
        }
Example #5
0
        public void EditBooking(Booking currentBooking, Customer currentCustomer)
        {
            bool passed = true;

            try
            {
                BookingTracker booker = BookingTracker.Instance;                            //instanciate current booking
                currentBooking.ArrivalDate   = editor.inDatePick.SelectedDate.Value.Date;   //set arrival dat eto chosen datepicker vaule
                currentBooking.DepartureDate = editor.outDatePick.SelectedDate.Value.Date;  //ditto for departure date
                currentBooking.Diet          = editor.dietBox.Text;                         //diet requirements setter

                //validate for bad dates
                try
                {
                    int hireLength = (currentBooking.HireEnd - currentBooking.HireStart).Days;
                    if (Convert.ToDateTime(hireLength) <= DateTime.MinValue)
                    {
                        passed = false;
                        MessageBox.Show("Make sure you get here before you leave.", "Invalid inout.", // reason for error
                                        MessageBoxButton.OK, MessageBoxImage.Error);                  //give 'em a BONK
                    }
                }
                catch
                {
                    passed = false;
                }


                //check if extra: breakfast is selected                                     //please forgive lack of brakets but this part is insanely long for what it is with them
                if (editor.breakfastBox.IsChecked == true)
                {
                    currentBooking.Breakfast = true;
                }
                else
                {
                    currentBooking.Breakfast = false;
                }

                //check if extra: meals is selected
                if (editor.mealsBox.IsChecked == true)
                {
                    currentBooking.Meals = true;
                }
                else
                {
                    currentBooking.Meals = false;
                }

                //check if extra: hire car is selected
                if (editor.carHireBox.IsChecked == true)
                {
                    currentBooking.CarHire = true;
                }
                else
                {
                    currentBooking.CarHire = false;
                }

                //make sure that null values never end up being attempted to be printed for the car hire fields
                if (editor.carHireBox.IsChecked == false)
                {
                    currentBooking.DriverName = "N/A";
                    currentBooking.HireStart  = DateTime.MinValue;
                    currentBooking.HireEnd    = DateTime.MinValue;
                }
                else
                {
                    currentBooking.DriverName = editor.driverNameBox.Text;
                    currentBooking.HireStart  = editor.driveDay1Picker.SelectedDate.Value.Date;
                    currentBooking.HireEnd    = editor.driveDay2Picker.SelectedDate.Value.Date;
                }

                booker.IncrementCount();                                                    //increment the
                booker.Store(currentBooking, currentCustomer);                              // call the Store method in the booking manager


                GuestTracker gPrint = GuestTracker.Instance;
                gPrint.Store(currentBooking);                                               //write guests from the list in booking to a file


                MessageBox.Show("Your Booking reference number is: " + (currentBooking.BookingRef) + "\n You will need this later.");


                UserTracker addBooking = UserTracker.Instance;
                addBooking.AddBooking(currentBooking, currentCustomer);

                if (passed == true)
                {
                    HubPage hub = new HubPage(currentCustomer);
                    hub.Show();
                    editor.Close();
                }
            }
            catch
            {
                MessageBox.Show("You must enter data in all compulsory (*) fields.", "Missing data.", // reason for error
                                MessageBoxButton.OK, MessageBoxImage.Error);                          //give 'em a BONK
            }
        }