private decimal CalculateAmount() { decimal amount; using (var context = new HotelBookingsEntities()) { var room = context.Rooms.Find(Booking.RoomID); int days = (Booking.EndDate - Booking.StartDate).Days; amount = room.Price * days; } return(amount); }
private void cmdSave_Click(object sender, EventArgs e) { using (var context = new HotelBookingsEntities()) { var booking = context.Bookings.Find(Booking.BookingID); booking.StartDate = dtpStartDate.Value.Date; booking.EndDate = dtpEndDate.Value.Date; booking.TotalPrice = CalculateAmount(); context.SaveChanges(); } MessageBox.Show("Booking dates updated."); Close(); }
private void cmdSave_Click(object sender, EventArgs e) { using (var context = new HotelBookingsEntities()) { var guest = (from g in context.Guests where g.GuestID == Guest.GuestID select g).SingleOrDefault(); guest.Name = txtName.Text; guest.Email = txtEmail.Text; guest.Phone = txtPhone.Text; context.SaveChanges(); } Close(); }
private void cmdSubmit_Click(object sender, EventArgs e) { using (var context = new HotelBookingsEntities()) { var booking = Booking; { booking.Time = DateTime.Now; booking.GuestID = Guest.GuestID; }; context.Bookings.Add(booking); context.SaveChanges(); } Close(); }
private void cmdSave_Click(object sender, EventArgs e) { using (var context = new HotelBookingsEntities()) { var guest = new Guest() { Name = txtName.Text, Email = txtEmail.Text, Phone = txtPhone.Text }; context.Guests.Add(guest); context.SaveChanges(); } Close(); }
private void LoadBookings() { using (var ctx = new HotelBookingsEntities()) { Bookings = ctx.Bookings.ToList <Booking>(); } var query = from b in Bookings where b.GuestID == Guest.GuestID select b; Bookings = query.ToList(); lstBookings.DataSource = Bookings; lstBookings.DisplayMember = "Time"; lstBookings.ValueMember = "BookingID"; }
public frmMain() { InitializeComponent(); using (var ctx = new HotelBookingsEntities()) { RoomList = ctx.Rooms.ToList <Room>(); } using (var ctx = new HotelBookingsEntities()) { Bookings = ctx.Bookings.ToList <Booking>(); } CheckValidBooking(); PopulateComboBox(); }
private void CheckValidBooking() { using (var context = new HotelBookingsEntities()) { foreach (var booking in Bookings) { Booking b = context.Bookings.Find(booking.BookingID); if ((DateTime.Now.Date - booking.Time.Date).Days > 10 && b.Invoices.Count() == 0) { context.Invoices.RemoveRange(b.Invoices); context.Bookings.Remove(b); context.SaveChanges(); } } } }
private void cmdLogIn_Click(object sender, EventArgs e) { if (txtEmail.Text == null || txtEmail.Text == "") { MessageBox.Show("Please type in your email address"); } else { var ctx = new HotelBookingsEntities(); Guest = (from g in ctx.Guests where g.Email == txtEmail.Text select g).SingleOrDefault(); txtGuestID.Text = Guest.GuestID.ToString(); txtName.Text = Guest.Name; txtPhone.Text = Guest.Phone; } }
private void cmdDeleteBooking_Click(object sender, EventArgs e) { Booking selectedBooking = (Booking)lstBookings.SelectedItem; using (var context = new HotelBookingsEntities()) { var booking = (from b in context.Bookings where b.BookingID == selectedBooking.BookingID select b).SingleOrDefault(); context.Invoices.RemoveRange(booking.Invoices); context.Bookings.Remove(booking); context.SaveChanges(); } MessageBox.Show("Booking cancelled."); }
private void cmdPay_Click(object sender, EventArgs e) { Invoice = new Invoice(); using (var context = new HotelBookingsEntities()) { var invoice = Invoice; { invoice.BookingID = Booking.BookingID; invoice.Amount = Booking.TotalPrice; invoice.Date = DateTime.Now; }; context.Invoices.Add(invoice); context.SaveChanges(); } Close(); }
private void cmdDeleteAccount_Click(object sender, EventArgs e) { if (Bookings.Count > 0) { MessageBox.Show("You cannot delete an account with bookings!"); } else { using (var context = new HotelBookingsEntities()) { var guest = context.Guests.Find(Guest.GuestID); context.Guests.Remove(guest); context.SaveChanges(); } MessageBox.Show("Account successfully removed."); Close(); } }
private bool FindPayment() { bool isPaid = false; Booking booking = (Booking)lstBookings.SelectedItem; using (var ctx = new HotelBookingsEntities()) { var query = (from i in ctx.Invoices where i.BookingID == booking.BookingID select i).SingleOrDefault(); if (query == null) { return(isPaid); } else { return(isPaid = true); } } }
public frmNewBooking(int roomID, DateTime startDate, DateTime endDate) { InitializeComponent(); Booking = new Booking(); Booking.StartDate = startDate; Booking.EndDate = endDate; Booking.RoomID = roomID; txtStartDate.Text = Booking.StartDate.ToShortDateString(); txtEndDate.Text = Booking.EndDate.ToShortDateString(); var ctx = new HotelBookingsEntities(); Room = ctx.Rooms.Find(Booking.RoomID); txtRoom.Text = Room.Title; Booking.TotalPrice = CalculateAmount(); txtTotalPrice.Text = Booking.TotalPrice.ToString(); PopulateComboBox(); }