private void AddBooking_Click(object sender, RoutedEventArgs e) { string userFullName; int numberOfBeds; DateTime checkInDate; DateTime checkOutdate; try { numberOfBeds = int.Parse(NumberOfBedsTextBox.Text); userFullName = CustomerNameTextBox.Text; checkInDate = DateTime.Parse(CheckInDateBox.Text); checkOutdate = DateTime.Parse(CheckOutDateBox.Text); var c = dac.Customer.FirstOrDefault(cu => cu.Name == userFullName); List <Room> avaliableRooms = dac.Room.Where(ro => ro.NumberOfBeds >= numberOfBeds).ToList <Room>(); Room room = null; foreach (var r in avaliableRooms) { if (checkDate(checkInDate, checkOutdate, r.RoomId)) { room = r; break; } } if (room != null) { try { Booking booking = new Booking//(id(auto), username, numberOfBeds, checkInDate, checkOutdate) { CustomerUsername = c.Username, RoomId = room.RoomId, CheckInDate = checkInDate, CheckOutDate = checkOutdate }; dac.Booking.Add(booking); dac.SaveChanges(); this.Close(); }catch (NullReferenceException ex) { Console.WriteLine(e); MessageBox.Show("user not found"); } } else { MessageBox.Show("No room found"); } } catch (FormatException ex) { Console.WriteLine(ex); MessageBox.Show("Check your input"); } }
// Legger til en room service ServiceTask, henter roomid fra room number input -t private void OrderRoomServiceButton_Click(object sender, RoutedEventArgs e) { int roomInput = 0; Int32.TryParse(ServiceTaskEntryRoomNumber.Text, out roomInput); try { var roomId = ( from r in room where r.RoomNumber == roomInput select r ).First <Room>().RoomId; ServiceTask t = new ServiceTask { RoomId = roomId, TimeIssued = DateTime.Now, TypeOfService = "Room Service", Status = "Pending", Description = ServiceTaskEntryDescription.Text.Trim(),// sjekker at strengen ikke er for lang TimeCompleted = null }; dac.ServiceTask.Add(t); try { dac.SaveChanges(); } catch (Exception er) { new ErrorWindow(er).ShowDialog(); throw; } ICollectionView view = CollectionViewSource.GetDefaultView(ServiceTaskListView.ItemsSource); view.Refresh(); } catch (InvalidOperationException ex) { MessageBox.Show("Room number does not exist!", "Room entry error", MessageBoxButton.OK); } }
private void CheckOutCustomer_Click(object sender, RoutedEventArgs e) { string userFullName; int roomNr; try { userFullName = CustomerNameTextBox.Text; roomNr = int.Parse(RoomNumberTextBox.Text); var c = dac.Customer.FirstOrDefault(cu => cu.Name == userFullName); var b = dac.Booking.FirstOrDefault(bo => bo.Customer.Username == c.Username && bo.RoomId == roomNr); dac.Booking.Remove(b); dac.SaveChanges(); CustomerNameTextBox.Text = RoomNumberTextBox.Text = ""; } catch (Exception exc) { Console.WriteLine(exc); MessageBox.Show("Denne kunden finnes ikke! Prøv igjen"); } }