Example #1
0
 // logic for amend guest save button. Saves the changes in the current object and the database
 private void btnAmengGuestSave_Click(object sender, RoutedEventArgs e)
 {
     btnAmendGuestSave.Visibility = Visibility.Hidden;
     txtBoxEditAge.Visibility     = Visibility.Hidden;
     txtBoxEditName.Visibility    = Visibility.Hidden;
     txtBoxEditPassp.Visibility   = Visibility.Hidden;
     DataLayerFacade.AmendGuest(txtBoxEditName.Text, txtBoxEditPassp.Text,
                                Convert.ToInt32(txtBoxEditAge.Text), selectedGuest.PassportNumber);
     if (selectedGuest.Component != null)
     {
         if (selectedGuest.Component.GetType() == typeof(Client))
         {
             selectedGuest.Component.Name = txtBoxEditName.Text;
             DataLayerFacade.AmendCustomer(((Client)selectedGuest.Component).CustomerNumber,
                                           txtBoxEditName.Text, ((Client)selectedGuest.Component).Address);
         }
     }
     selectedGuest.Name           = txtBoxEditName.Text;
     selectedGuest.PassportNumber = txtBoxEditPassp.Text;
     selectedGuest.Age            = Convert.ToInt32(txtBoxEditAge.Text);
     txtBoxEditAge.Text           = "";
     txtBoxEditName.Text          = "";
     txtBoxEditPassp.Text         = "";
     listBoxGuests.Items.Clear();
     foreach (var guest in booking.GuestList)
     {
         listBoxGuests.Items.Add(guest.Name);
     }
 }
Example #2
0
        public BookingList()
        {
            InitializeComponent();
            GridView gridView = new GridView();

            listViewBookings.View = gridView;
            gridView.Columns.Add(new GridViewColumn {
                Header = "Booking Ref No ", DisplayMemberBinding = new Binding("Id")
            });
            gridView.Columns.Add(new GridViewColumn {
                Header = " Customer's name  ", DisplayMemberBinding = new Binding("Name")
            });
            gridView.Columns.Add(new GridViewColumn {
                Header = " Arrival Date  ", DisplayMemberBinding = new Binding("Start")
            });
            gridView.Columns.Add(new GridViewColumn {
                Header = " Departure Date  ", DisplayMemberBinding = new Binding("End")
            });

            // adds each booking to the listView
            foreach (var item in DataLayerFacade.GetBasicBookingInfo())
            {
                listViewBookings.Items.Add(item);
            }
        }
Example #3
0
        string oldPassportNo; // used when updating guest's passport number
        public CustomerDetails()
        {
            InitializeComponent();
            // below code retreives customer's details from database and displays it in the window
            List <Person> clientList = DataLayerFacade.GetCustomer(CustomerL.customerNumber);

            this.Topmost = true;
            Client client = (Client)clientList.ElementAt(0);

            textBoxName.Text         = client.Name;
            textBoxAddress.Text      = client.Address;
            textBoxPassNo.MaxLength  = 10;
            textBoxAddress.MaxLength = 150;
            textBoxName.MaxLength    = 50;
            lblCustNumb.Content      = client.CustomerNumber;
            List <Person> guestDecorator = DataLayerFacade.GetGuestDecorator(CustomerL.customerNumber, 0);

            if (guestDecorator.Count == 0)
            {
                textBoxPassNo.Visibility = Visibility.Hidden;
                textBoxAge.Visibility    = Visibility.Hidden;
                lblPassNo.Visibility     = Visibility.Hidden;
                lblAge.Visibility        = Visibility.Hidden;
            }
            else
            {
                // if the customer is also a guest, the guest's details are also displayed
                GuestDecorator guest = (GuestDecorator)guestDecorator.ElementAt(0);
                guest.SetComponent(client);
                textBoxPassNo.Text = guest.PassportNumber;
                oldPassportNo      = guest.PassportNumber;
                textBoxAge.Text    = guest.Age.ToString();
            }
        }
        // logic for confirm booking button. Creates a booking object and saves all its details in the database
        private void btnConfirmBooking_Click(object sender, RoutedEventArgs e)
        {
            if (guests.Count == 0)
            {
                MessageBox.Show("Please enter guests.");
                return;
            }
            if (comBoxChaletId.SelectedItem == null)
            {
                MessageBox.Show("Please choose a chalet.");
                return;
            }
            if (checkBoxCarHire.IsChecked == true)
            {
                if (datePickerCarFrom.SelectedDate == null || datePickerCarTo.SelectedDate == null ||
                    comBoxDriver.SelectionBoxItem.ToString() == String.Empty)
                {
                    MessageBox.Show("Please provide all car hire details.");
                    return;
                }
            }
            if (client == null)
            {
                MessageBox.Show("Please provide client's details.");
                return;
            }

            var      facade      = BusinessFacadeSingleton.Instance();
            DateTime startDate   = datePickerStartDate.SelectedDate.Value.Date;
            DateTime endDate     = datePickerEndDate.SelectedDate.Value.Date;
            bool     eveningMeal = checkBoxEvMeals.IsChecked.Value;
            bool     breakfast   = checkBoxBreakfast.IsChecked.Value;
            bool     carHire     = checkBoxCarHire.IsChecked.Value;
            DateTime hireStart   = DateTime.Today;
            DateTime hireEnd     = DateTime.Today;
            string   driver      = comBoxDriver.SelectionBoxItem.ToString();


            int chaletId   = Convert.ToInt32(comBoxChaletId.SelectionBoxItem.ToString());
            int bookingRef = DataLayerFacade.GetNextBookingRef();

            if (existingClient != null) // sets the client as an existing client to avoid duplicaiton
            {
                client = existingClient;
            }
            AbstractBooking booking = facade.CreateBooking(bookingRef, startDate, endDate, client, guests, chaletId, eveningMeal,
                                                           breakfast, carHire, hireStart, hireEnd, driver);

            DataLayerFacade.SaveBooking(booking, breakfast, eveningMeal);
            // add the booking to the database
            Reset();
            MessageBox.Show("The booking has been created. The booking reference number is: " + booking.BookingRefNo);
            this.Close();
        }
        // populates customer details when an existing customer is selected from combobox
        private void comBoxSearchResult_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (comBoxSearchResult.SelectedIndex == -1)
            {
                return;
            }
            string       selectedCustomer = Convert.ToString(comBoxSearchResult.SelectedItem);
            CustomerItem customer         = DataLayerFacade.GetOneCustomerDetails(selectedCustomer);

            txtBoxCustName.Text    = customer.Name;
            txtBoxCustAddress.Text = customer.Address;
        }
Example #6
0
        // logic for add new guest button. Adds a new guest to the current booking object and to the database
        private void btnNewGuestConf_Click(object sender, RoutedEventArgs e)
        {
            BusinessFacadeSingleton businessFacase = BusinessFacadeSingleton.Instance();
            var newguest = businessFacase.CreateGuest(txtBoxEditName.Text, txtBoxEditPassp.Text,
                                                      Convert.ToInt32(txtBoxEditAge.Text));

            booking.GuestList.Add(newguest);
            listBoxGuests.Items.Add(newguest.Name);
            DataLayerFacade.AddGuestToBooking(bookingRef, txtBoxEditName.Text,
                                              txtBoxEditPassp.Text, Convert.ToInt32(txtBoxEditAge.Text));
            txtBoxEditAge.Text   = "";
            txtBoxEditName.Text  = "";
            txtBoxEditPassp.Text = "";
            HideAddNewGuestControls();
        }
        // logic for find existing customer button. Returns a list of existing customers in a combo box
        // that match specified name
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            comBoxSearchResult.Items.Clear();
            if (txtBoxSearchName.Text == String.Empty)
            {
                MessageBox.Show("Please proivde a name you wish to search for.");
                return;
            }
            string findCustomer = txtBoxSearchName.Text.ToLower();

            foreach (var customer in DataLayerFacade.FindCustomerByName(findCustomer))
            {
                comBoxSearchResult.Items.Add(customer.Name);
            }
            comBoxSearchResult.IsDropDownOpen = true;
        }
 // populates guest details if client is also a guest
 private void checkBoxGuest_Checked(object sender, RoutedEventArgs e)
 {
     txtBoxGuestName.Text = txtBoxCustName.Text;
     if (checkBoxExistCust.IsChecked == true)
     {
         // for an existing customer a check is done if he/she was also a guest so the
         // guest details can be used in a new booking
         var selectedCustomer = DataLayerFacade.GetOneCustomerDetails(txtBoxCustName.Text);
         var guestDetailsList = DataLayerFacade.GetGuestDecorator(selectedCustomer.Id, 0);
         if (guestDetailsList.Count != 0)
         {
             GuestDecorator guest = (GuestDecorator)guestDetailsList.ElementAt(0);
             txtBoxGuestAge.Text     = guest.Age.ToString();
             txtBoxGuestPasspNo.Text = guest.PassportNumber;
         }
     }
 }
Example #9
0
 // logic for delete guest button. Removes the guest from the current object and from the database
 private void btnDelGuest_Click(object sender, RoutedEventArgs e)
 {
     if (listBoxGuests.SelectedIndex == -1)
     {
         return;
     }
     booking.GuestList.Remove(selectedGuest);
     DataLayerFacade.DeleteGuest(selectedGuest.PassportNumber);
     listBoxGuests.SelectedIndex = -1;
     listBoxGuests.Items.Remove(selectedGuest.Name);
     MessageBox.Show("Guest has been deleted.");
     btnDelGuest.IsEnabled        = false;
     btnAmendGuest.IsEnabled      = false;
     btnAmendGuestSave.Visibility = Visibility.Hidden;
     txtBoxEditAge.Visibility     = Visibility.Hidden;
     txtBoxEditName.Visibility    = Visibility.Hidden;
     txtBoxEditPassp.Visibility   = Visibility.Hidden;
 }
        // logic for check availability button. Returns a list of chalets that are available during the period specified
        private void btnCheckAvailability_Click(object sender, RoutedEventArgs e)
        {
            if (datePickerStartDate.SelectedDate == null)
            {
                MessageBox.Show("Please provide Check In date");
                return;
            }
            if (datePickerEndDate.SelectedDate == null)
            {
                MessageBox.Show("Please provide Departure date");
                return;
            }
            if (datePickerStartDate.SelectedDate >= datePickerEndDate.SelectedDate)
            {
                MessageBox.Show("Please note that departure date must be after arrival date");
                return;
            }
            DateTime startDate = datePickerStartDate.SelectedDate.Value.Date;
            DateTime endDate   = datePickerEndDate.SelectedDate.Value.Date;

            datePickerCarFrom.DisplayDateStart = startDate;
            datePickerCarFrom.DisplayDateEnd   = endDate.Subtract(TimeSpan.FromDays(1));
            datePickerCarTo.DisplayDateStart   = startDate.Add(TimeSpan.FromDays(1));
            datePickerCarTo.DisplayDateEnd     = endDate;
            List <int> availableChalets = DataLayerFacade.AvailableChalets(startDate, endDate, 0);

            if (availableChalets.Count == 0)
            {
                MessageBox.Show("There are no chalets available during this period. Please choose different dates");
                return;
            }
            else
            {
                MessageBox.Show("There are " + availableChalets.Count + " chalets available");
                comBoxChaletId.Items.Clear(); // Clears prevoius items
                foreach (var chalet in availableChalets)
                {
                    comBoxChaletId.Items.Add(chalet);
                }

                ShowFields();
                Application.Current.MainWindow.Height = 650;
            }
        }
Example #11
0
        // logic for update details button. updates the customer details in the database
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxName.Text == String.Empty || textBoxAddress.Text == String.Empty)
            {
                MessageBox.Show(@"Please provide all details.");
                return;
            }
            string name       = textBoxName.Text;
            string address    = textBoxAddress.Text;
            int    curtNumber = Convert.ToInt32(lblCustNumb.Content);

            DataLayer.DataLayerFacade.AmendCustomer(curtNumber, name, address);
            if (textBoxPassNo.Visibility == Visibility.Visible)
            {
                if (textBoxAge.Text == String.Empty || textBoxPassNo.Text == String.Empty)
                {
                    MessageBox.Show(@"Please provide all details.");
                    return;
                }
                string passportNo = textBoxPassNo.Text;
                int    age;
                try
                {
                    age = Convert.ToInt32(textBoxAge.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Please enter age as a number.");
                    return;
                }
                if (age < 0 || age > 101)
                {
                    MessageBox.Show("Please provide age between 0 and 101.");
                    return;
                }
                DataLayerFacade.AmendGuest(name, passportNo, age, oldPassportNo);
            }

            CustomerL CustomerList = new CustomerL();

            CustomerList.Show();
            this.Close();
            MessageBox.Show("Customer details have been updated.");
        }
Example #12
0
        // logic for the save changes button. Saves other changes to the booking in the current object and
        // in the database
        private void btnSaveCh_Click(object sender, RoutedEventArgs e)
        {
            DateTime arrivalDate      = datePickArrival.SelectedDate.Value.Date;
            DateTime departureDate    = datePickDepart.SelectedDate.Value.Date;
            int      chaletId         = Convert.ToInt32(comBoxChaletId.SelectionBoxItem);
            bool     isBreakfastDec   = checkBoxBreakfast.IsChecked.Value;
            bool     isEveningMealDec = checkBoxEvMeal.IsChecked.Value;

            DataLayerFacade.AmendBooking(bookingRef, arrivalDate, departureDate,
                                         chaletId, isBreakfastDec, isEveningMealDec);
            bool isCarHireDec = checkBoxCarHire.IsChecked.Value;

            if (isCarHireDec)
            {
                DateTime hireStart = datePickHireStart.SelectedDate.Value.Date;
                DateTime hireEnd   = datePickHireEnd.SelectedDate.Value.Date;
                string   driver    = comBoxDriver.SelectionBoxItem.ToString();
                if (booking.GetType() == typeof(CarHireDecorator))
                {
                    DataLayerFacade.AmendCarHire(driver, bookingRef,
                                                 hireStart, hireEnd);
                }
                else
                {
                    DataLayerFacade.AddCarHire(driver, bookingRef,
                                               hireStart, hireEnd);
                }
            }
            else
            {
                if (booking.GetType() == typeof(CarHireDecorator))
                {
                    DataLayerFacade.RemoveCarHire(bookingRef);
                }
            }
            this.Close();
            MessageBox.Show("The booking has been amended.");
        }
Example #13
0
 // deletes a customer provided that he/she has no outstanding bookings
 private void btnDeleteCust_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         int bookings = DataLayer.DataLayerFacade.OutstandingBookings(Convert.ToInt32(lblCustNumb.Content));
         if (bookings == 0)
         {
             DataLayerFacade.DeleteCustomer(Convert.ToInt32(lblCustNumb.Content));
             CustomerL CustomerList = new CustomerL();
             CustomerList.Show();
             this.Close();
             MessageBox.Show("Customer has been deleted");
         }
         else
         {
             MessageBox.Show("The customer has outstanding bookings. Please cancel those bookings if you want to remove the customer");
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Unable to delete the customer at the moment. Please try again later.");
     }
 }
Example #14
0
        public static int customerNumber; // customer number that will be used in the CustomerDetails windos
        public CustomerL()
        {
            InitializeComponent();

            GridView gridView = new GridView();

            listViewCustomers.View = gridView;
            gridView.Columns.Add(new GridViewColumn {
                Header = "Customer Ref No ", DisplayMemberBinding = new Binding("Id")
            });
            gridView.Columns.Add(new GridViewColumn {
                Header = "Customer's Name  ", DisplayMemberBinding = new Binding("Name")
            });
            gridView.Columns.Add(new GridViewColumn {
                Header = "Customer's Address ", DisplayMemberBinding = new Binding("Address")
            });

            // iterates through all customers and adds them to the lisView
            foreach (var customer in DataLayerFacade.GelAllCustomersInfo())
            {
                listViewCustomers.Items.Add(customer);
            }
        }
Example #15
0
 // logic for delete booking button. Deletes booking from the database and closes the window
 private void btnCancel_Click_1(object sender, RoutedEventArgs e)
 {
     DataLayerFacade.DeleteBooking(bookingRef);
     this.Close();
     MessageBox.Show("The booking has been deleted");
 }
Example #16
0
        public static AbstractBooking booking      = null; // booking from which all details are taken
        public BookingDetails()
        {
            InitializeComponent();
            disableControls();
            txtBoxEditPassp.MaxLength = 10;
            txtBoxEditName.MaxLength  = 50;

            // below code retreives booking information from the database and constructs a booking object
            // which is then used to populate booking details in the window
            booking = DataLayerFacade.RetreiveBooking(bookingRef);
            booking.BookingRefNo         = bookingRef;
            datePickArrival.SelectedDate = booking.ArrivalDate;
            datePickDepart.SelectedDate  = booking.DepartureDate;
            lblBookingRef1.Content       = bookingRef;
            lblCustName.Content          = booking.Client.Name;
            lblCustAddress.Content       = booking.Client.Address;
            foreach (var guest in booking.GuestList)
            {
                listBoxGuests.Items.Add(guest.Name);
                comBoxDriver.Items.Add(guest.Name);
            }
            if (booking.GetType() == typeof(CarHireDecorator))
            {
                checkBoxCarHire.IsChecked      = true;
                datePickHireStart.SelectedDate = ((CarHireDecorator)booking).StartDate;
                datePickHireEnd.SelectedDate   = ((CarHireDecorator)booking).EndDate;
                comBoxDriver.SelectedItem      = ((CarHireDecorator)booking).Driver;
                lblHireFrom.Visibility         = Visibility.Visible;
                lblHireTo.Visibility           = Visibility.Visible;
                lblDriver.Visibility           = Visibility.Visible;
                datePickHireStart.Visibility   = Visibility.Visible;
                datePickHireEnd.Visibility     = Visibility.Visible;
                comBoxDriver.Visibility        = Visibility.Visible;
                var carDecorator = (CarHireDecorator)booking;
                if (carDecorator.Component.GetType() == typeof(BreakfastDecorator))
                {
                    checkBoxBreakfast.IsChecked = true;
                    var breakfasrDecorator = (BreakfastDecorator)carDecorator.Component;
                    if (breakfasrDecorator.Component.GetType() == typeof(EveningMealDecorator))
                    {
                        checkBoxEvMeal.IsChecked = true;
                    }
                }
                if (carDecorator.Component.GetType() == typeof(EveningMealDecorator))
                {
                    checkBoxEvMeal.IsChecked = true;
                }
            }
            if (booking.GetType() == typeof(BreakfastDecorator))
            {
                checkBoxBreakfast.IsChecked = true;
                var breakfasrDecorator = (BreakfastDecorator)booking;
                if (breakfasrDecorator.Component.GetType() == typeof(EveningMealDecorator))
                {
                    checkBoxEvMeal.IsChecked = true;
                }
            }
            if (booking.GetType() == typeof(EveningMealDecorator))
            {
                checkBoxEvMeal.IsChecked = true;
            }

            comBoxChaletId.Items.Add(booking.ChaletId);
            comBoxChaletId.SelectedItem = booking.ChaletId;
        }
        // logic for add guest button. Adds a guest to guest list
        private void btnAddGuest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtBoxGuestName.Text.Equals(String.Empty) ||
                    txtBoxGuestAge.Text.Equals(String.Empty) ||
                    txtBoxGuestPasspNo.Text.Equals(String.Empty))
                {
                    MessageBox.Show("Please provide all guest's details");
                    return;
                }
                string guestName  = txtBoxGuestName.Text;
                string passportNo = txtBoxGuestPasspNo.Text;
                int    age;
                try
                {
                    age = Convert.ToInt32(txtBoxGuestAge.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Please provide age up to 101 as a number.");
                    return;
                }

                string         address = txtBoxCustAddress.Text;
                var            facade  = BusinessFacadeSingleton.Instance();
                GuestDecorator guest   = null;
                // below code checks retreives details of an existing customer(s) if an existing customer
                // wished to make a new booking
                if (checkBoxAddAsGuest.IsChecked == true && checkBoxExistCust.IsChecked == false)
                {
                    if (txtBoxCustName.Text == String.Empty || txtBoxCustAddress.Text == String.Empty)
                    {
                        MessageBox.Show("Please provide customer details.");
                        return;
                    }
                    int customerNumber = DataLayerFacade.GetNextCustomerNumber();
                    client = facade.CreateClient(customerNumber, guestName, address);
                    guest  = facade.CreateClientGuest(client, passportNo, age);
                }
                else
                {
                    guest = facade.CreateGuest(guestName, passportNo, age);
                    if (client == null)
                    {
                        // checks if the existing customer was also a guest so the guest details can be used
                        if (checkBoxExistCust.IsChecked == true)
                        {
                            var existingCustomerDetails = DataLayerFacade.GetOneCustomerDetails(txtBoxCustName.Text);
                            existingClient = new Client(existingCustomerDetails.Id, existingCustomerDetails.Name, existingCustomerDetails.Address);
                            if (existingClient == null)
                            {
                                MessageBox.Show("Please provide client's details.");
                                return;
                            }
                            client = existingClient;
                        }
                        else
                        {
                            if (txtBoxCustName.Text == String.Empty || txtBoxCustAddress.Text == String.Empty)
                            {
                                MessageBox.Show("Please provide customer details.");
                                return;
                            }
                            int    customerNumber = DataLayerFacade.GetNextCustomerNumber();
                            string clientName     = txtBoxCustName.Text;
                            string clinetAddress  = txtBoxCustAddress.Text;
                            client = facade.CreateClient(customerNumber, clientName, clinetAddress);
                        }
                    }
                }
                guests.Add(guest);
                if (guests.Count == 6)
                {
                    MessageBox.Show("You have reached the maxumum number of guests");
                    txtBoxGuestName.IsReadOnly    = true;
                    txtBoxGuestAge.IsReadOnly     = true;
                    txtBoxGuestPasspNo.IsReadOnly = true;
                }

                listBoxGuestList.Items.Add(guestName);
                comBoxDriver.Items.Add(guestName);// ads the name to a combo box so it can be selected as a driver
                txtBoxGuestName.Text         = "";
                txtBoxGuestPasspNo.Text      = "";
                txtBoxGuestAge.Text          = "";
                checkBoxAddAsGuest.IsChecked = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }