// 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(); }
// savel all booking data in the database tables public static void SaveBooking(AbstractBooking booking, bool breakfast, bool eveningMeal) { DatabaseCalls.AddBooking(booking.BookingRefNo, booking.ArrivalDate, booking.DepartureDate, booking.ChaletId, breakfast, eveningMeal); DatabaseCalls.CreateCustomer(booking.Client.CustomerNumber, booking.Client.Name, booking.Client.Address); DatabaseCalls.LinkClientToBooking(booking.BookingRefNo, booking.Client.CustomerNumber); foreach (var guest in booking.GuestList) // each guest is saved separately in the database { GuestDecorator guestDec = (GuestDecorator)guest; DatabaseCalls.CreateGuest(guestDec.Name, guestDec.PassportNumber, guestDec.Age); DatabaseCalls.LinkGuestToBooking(booking.BookingRefNo, guestDec.PassportNumber); if (guestDec.Component != null) { DatabaseCalls.LinkCustomerGuest(booking.Client.CustomerNumber, guestDec.PassportNumber); } } if (booking.GetType() == typeof(CarHireDecorator)) { DatabaseCalls.AddCarHire(((CarHireDecorator)booking).Driver, booking.BookingRefNo, ((CarHireDecorator)booking).StartDate, ((CarHireDecorator)booking).EndDate); } }
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; }