private void btnChangeCheckOutDate_Click(object sender, RoutedEventArgs e) { try { if (tbChangeDateGuestName.Text == "") { throw new Exception("Select guest please."); } var guestsRep = new SqlGuestRepository(connection); var id = ((Guest)dgGuests.SelectedItem).Id; var guest = guestsRep.GetAllGuests().Where(g => g.Id == id).Single(); var newDate = (DateTime)dpChangeCheckOutDate.SelectedDate; if (newDate <= guest.CheckInDate || newDate < DateTime.Now.Date) { throw new Exception("New check out date isn't correct."); } guestsRep.ChangeCheckOutDate(id, newDate); guests = guestsRep.GetAllGuests(); dgGuests.ItemsSource = guests; dpChangeCheckOutDate.SelectedDate = newDate; expChangeCheckOutDate.IsExpanded = false; MessageBox.Show("Check out date was successfully changed.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void btnCheckOut_Click(object sender, RoutedEventArgs e) { var id = ((Guest)dgGuests.SelectedItem).Id; var guestRep = new SqlGuestRepository(connection); var roomsRep = new SqlRoomRepository(connection); var guest = guestRep.GetAllGuests().Where(g => g.Id == id).Single(); var sb = new StringBuilder(); sb.AppendLine("Hotel «Epam»"); sb.AppendLine("Lviv"); sb.AppendLine("221 Volodymyra Velykoho st."); sb.AppendLine(); sb.AppendLine("Administrator " + CurrentAdministrator.Name); sb.AppendLine("----------------------------------"); sb.AppendLine("Days of accomodation: " + guestRep.CalculateTheLengthOfStay(id)); sb.AppendLine("X"); sb.AppendLine("Room's price: " + roomsRep.GetInfoAboutRoom(guest.Room).ToArray()[3]); sb.AppendLine("----------------------------------"); sb.AppendLine("Sum " + guestRep.CalculatePriceOfStay(id)); sb.AppendLine("----------------------------------"); sb.AppendLine(DateTime.Now.ToString()); tbBill.Text = sb.ToString(); btnPrintBill.IsEnabled = true; btnEvictGuest.IsEnabled = true; }
private void tbSearchGuests_TextChanged(object sender, TextChangedEventArgs e) { var guestsRep = new SqlGuestRepository(connection); if (tbSearchGuests.Text == "") { guests = guestsRep.GetAllGuests(); } guests = guestsRep.GetGuestsByName(tbSearchGuests.Text); dgGuests.ItemsSource = guests; }
private void btnEvictGuest_Click(object sender, RoutedEventArgs e) { try { int id = 0; try { id = ((Guest)dgGuests.SelectedItem).Id; } catch { throw new Exception("Select guest please."); } if (MessageBox.Show("Do you really want to evict this guest?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { var guestsRep = new SqlGuestRepository(connection); var roomsRep = new SqlRoomRepository(connection); guestsRep.EvictGuest(id); guests = guestsRep.GetAllGuests(); rooms = roomsRep.GetAllRooms(); dgGuests.ItemsSource = guests; dgRooms.ItemsSource = rooms; tbInfoAboutGuest2.Text = ""; btnCheckOut.IsEnabled = false; btnPrintBill.IsEnabled = false; btnEvictGuest.IsEnabled = false; tbChangeDateGuestName.Text = ""; dpChangeCheckOutDate.ClearValue(DatePicker.SelectedDateProperty); MessageBox.Show("Guest was successfully evicted.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void btnShowLeavingSoonGuests_Click(object sender, RoutedEventArgs e) { try { var days = int.Parse(cbLeavingSoonGuests.SelectedValue.ToString()); var guestsRep = new SqlGuestRepository(connection); var leavingGuests = guestsRep.GetListOfLeaveSoonGuests(days); dgLeavingSoonGuests.ItemsSource = leavingGuests; dgLeavingSoonGuests.Visibility = Visibility.Visible; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public MainWindow() { InitializeComponent(); var roomsRep = new SqlRoomRepository(connection); var guestsRep = new SqlGuestRepository(connection); rooms = roomsRep.GetAllRooms(); guests = guestsRep.GetAllGuests(); dgRooms.ItemsSource = rooms; dgGuests.ItemsSource = guests; var sb = new StringBuilder(); sb.AppendLine("№"); sb.AppendLine("Category"); sb.AppendLine("Places"); sb.AppendLine("Prices"); sb.AppendLine("TV"); sb.AppendLine("Conditioner"); sb.AppendLine("Internet"); sb.AppendLine("Jacuzzi"); tbInfoAboutRoom1.Text = sb.ToString(); sb = new StringBuilder(); sb.AppendLine("Name"); sb.AppendLine("Passport"); sb.AppendLine("Room"); sb.AppendLine("Price"); sb.AppendLine("Check in date"); sb.AppendLine("Check out date"); tbInfoAboutGuest.Text = sb.ToString(); dpCheckOutDate.SelectedDate = DateTime.Now.AddDays(1); }
private void dgGuests_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { if (dgGuests.SelectedIndex >= 0) { var id = ((Guest)dgGuests.SelectedItem).Id; var guestsRep = new SqlGuestRepository(connection); var guest = guestsRep.GetAllGuests().Where(g => g.Id == id).Single(); tbChangeDateGuestName.Text = guest.Name; dpChangeCheckOutDate.SelectedDate = guest.CheckOutDate; WriteInfoAboutGuest(id); btnCheckOut.IsEnabled = true; btnPrintBill.IsEnabled = false; btnEvictGuest.IsEnabled = false; tbBill.Text = ""; } }
private void btnSettleGuest_Click(object sender, RoutedEventArgs e) { try { if (tbSettleRoomId.Text == "") { throw new Exception("Select room please."); } var id = 0; var name = ""; var passport = ""; var checkIn = DateTime.Now; var checkOut = DateTime.Now; try { id = int.Parse(tbSettleRoomId.Text); name = tbSettleGuestName.Text; passport = tbSettleGuestPassport.Text; checkOut = (DateTime)dpCheckOutDate.SelectedDate; } catch { throw new Exception("Some problem occured. Check input please."); } if (name == "" || passport == "") { throw new Exception("'Name' and 'passport' fields can't be empty."); } if (checkIn >= checkOut) { throw new Exception("Check in date must be greater than check out."); } var guestsRep = new SqlGuestRepository(connection); var roomsRep = new SqlRoomRepository(connection); if (!((Room)dgRooms.SelectedItem).IsFree) { throw new Exception("Room isn't free currently. You can't settle guest here."); } guestsRep.SettleGuestInTheRoom(id, name, passport, checkIn, checkOut); rooms = roomsRep.GetAllRooms(); guests = guestsRep.GetAllGuests(); dgRooms.ItemsSource = rooms; dgGuests.ItemsSource = guests; expSettleGuest.IsExpanded = false; MessageBox.Show("Guest was successfully settled.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }