//actions to take whie editing or adding new guest public void btnSaveGuest_Click(object sender, RoutedEventArgs e) { bookingWindow = (BookingWin)this.Owner; guestInUse = new Guest(); //checking if all the fields are filled in if (txtAge.Text != "" && txtGuestName.Text != "" && txtPassport.Text != "") { bool correctAge = guestInUse.ageInRange(txtAge.Text); bool correctName = guestInUse.nameFormat(txtGuestName.Text); guestInUse.PassportNumber = txtPassport.Text.ToUpper(); //if age and anme are in correct format we proceed further if (correctAge && correctName) { //adding guest to the list of guests for this booking bookingInUse.addEditGuest(guestInUse, guestNumber); //updating the list of guests in the booking window. bookingWindow.lstGuests.Items[guestNumber] = guestInUse.Name + ", " + guestInUse.PassportNumber + ", " + guestInUse.Age; bookingWindow.lstGuestsCanvas.Items[guestNumber] = guestInUse.Name + ", " + guestInUse.PassportNumber + ", " + guestInUse.Age; this.Close(); //bookingWindow = (BookingWin)this.Owner; //bookingWindow.lstGuests.Items.Refresh(); } } else { MessageBox.Show("Please fill in all fields before saving.", "Missing Details.", MessageBoxButton.OK, MessageBoxImage.Stop); } }
//actions for adding new booking directly from customer's window private void btnAddBooking_Click(object sender, RoutedEventArgs e) { BookingWin bookingWindow = new BookingWin(); bookingWindow.canvBookingMainWindow.Visibility = Visibility.Hidden; bookingWindow.canvNewBooking.Visibility = Visibility.Visible; bookingWindow.setBookingWindow(customerInUse); bookingWindow.Owner = this; bookingWindow.ShowDialog(); }
//actions for editing existing booking private void btnEditBooking_Click(object sender, RoutedEventArgs e) { try { //this line will look for reference number in the selected item string reference = Regex.Match(lstBookings.SelectedItem.ToString(), @"\d+").Value; BookingWin bookingWin = new BookingWin(); //this method uses reference number to setup the new window with proper data bookingWin.setBookingWindow(reference); bookingWin.ShowDialog(); } catch (Exception) { MessageBox.Show("Please select a Booking from the list in order to edit it", "Make selection first.", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
//this method will open booking window after doubleclick on the list private void lstBookings_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { //this line will look for reference number part in the whole line to put the correct details in booking window string reference = Regex.Match(lstBookings.SelectedItem.ToString(), @"\d+").Value; BookingWin bookingWin = new BookingWin(); bookingWin.Owner = this; //this method uses reference number to setup the new window with proper data bookingWin.setBookingWindow(reference); bookingWin.ShowDialog(); } catch (Exception) { //If booking is on the list but missing in DB we want to search again and inform user MessageBox.Show("This Booking no longer exists.", "Missing booking", MessageBoxButton.OK, MessageBoxImage.Exclamation); this.btnBookSearch_Click(sender, e); } }
//actions to take when removing Guest private void btnDelete_Click(object sender, RoutedEventArgs e) { bookingWindow = (BookingWin)this.Owner; //making sure you cannot delete a Guest if there's last one if (bookingInUse.Guests.Count > 1) { try { bookingInUse.Guests.RemoveAt(guestNumber); //replacing Guest's details with add new bookingWindow.lstGuests.Items[guestNumber] = "add new..."; } catch (ArgumentOutOfRangeException) { } } else { MessageBox.Show("Unable to delete this Guest. There has to be at least one Guest.", "Minumum Guests", MessageBoxButton.OK, MessageBoxImage.Information); } this.Close(); //bookingWindow = (BookingWin)this.Owner; //bookingWindow.lstGuests.Items.Refresh(); }