// 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(); }
// 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(); }
// retreives all information for a booking and reconstructs it into an object public static AbstractBooking RetreiveBooking(int bookingId) { Client customer = null; List <Person> guestList = new List <Person>(); int customerRef = DatabaseCalls.GetCustIdForBooking(bookingId); CustomerItem customerItem = DatabaseCalls.GetCustomersDetails(customerRef).ElementAt(0); BusinessFacadeSingleton businessFacade = BusinessFacadeSingleton.Instance(); customer = businessFacade.CreateClient(customerItem.Id, customerItem.Name, customerItem.Address); foreach (var guestItem in DatabaseCalls.GetGuestsDetails(0, bookingId)) { GuestDecorator guest = businessFacade.CreateGuest(guestItem.Name, guestItem.PassportNumber, guestItem.Age); if (DatabaseCalls.IsCustomer(guest.Name)) { guest.SetComponent(customer); } guestList.Add(guest); } BookingItem bookingItem = DatabaseCalls.GetBookingDetails(bookingId); CarHireItem carHireItem = DatabaseCalls.GetCarHireDetails(bookingId); bool carHire = false; string driver = ""; DateTime hireStart = DateTime.Today; DateTime hireEnd = DateTime.Today; if (carHireItem != null) { carHire = true; driver = carHireItem.Driver; hireStart = carHireItem.HireStart; hireEnd = carHireItem.HireEnd; } var booking = businessFacade.CreateBooking(bookingId, bookingItem.Arrival, bookingItem.Departure, customer, guestList, bookingItem.ChaletId, bookingItem.EveningMeal, bookingItem.Breakfast, carHire, hireStart, hireEnd, driver); return(booking); }
// 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; } }