public static BookingModel GetBookingModel(int bookingid) { BookingModel bk = null; using (SqlConnection conn = Connection.GetConnection()) { if (conn != null) { string sql = "SELECT * FROM dbo.Booking WHERE BookingID = @bookingid"; SqlCommand cm = new SqlCommand(sql, conn); cm.Parameters.AddWithValue("@bookingid", bookingid); var rs = cm.ExecuteReader(); if (rs.HasRows) { while (rs.Read()) { bk = new BookingModel(); bk.BookingID = rs[0] as int? ?? 0; bk.Guest = GuestDAO.GetGuest(rs[1] as int? ?? 0); bk.Room = RoomsDAO.GetRoomModel(rs[2] as int? ?? 0); bk.BookingDate = rs[3] as DateTime? ?? DateTime.MinValue; bk.CancelDate = rs[4] as DateTime? ?? DateTime.MinValue; bk.CheckInDate = rs[5] as DateTime? ?? DateTime.MinValue; bk.CheckOutDate = rs[6] as DateTime? ?? DateTime.MinValue; bk.Payment = PaymentDAO.GetPayment(rs[7] as int? ?? 0); bk.Deposit = rs[8] as int? ?? 0; bk.Amount = rs[9] as int? ?? 0; bk.Status = rs[10] as string; } } } } return(bk); }
public static List <Guest> GetALLGuestsOfBooking(int bookingid) { List <Guest> guests = new List <Guest>(); using (SqlConnection conn = Connection.GetConnection()) { if (conn != null) { SqlCommand cm = new SqlCommand("select GuestID from Stay WHERE BookingID = @bookingid", conn); cm.Parameters.AddWithValue("@bookingid", bookingid); var rs = cm.ExecuteReader(); while (rs.Read()) { Guest g = GuestDAO.GetGuest(rs.GetInt32(0)); guests.Add(g); } } } return(guests); }
public static List <BookingModel> GetBookingsViewModel(DateTime fromdate, DateTime todate) { List <BookingModel> list = new List <BookingModel>(); using (SqlConnection conn = Connection.GetConnection()) { if (conn != null) { string sql = "SELECT * FROM dbo.Booking WHERE CheckOutDate >= @fromdate and CheckInDate <= @todate"; SqlCommand cm = new SqlCommand(sql, conn); cm.Parameters.AddWithValue("@fromdate", fromdate); cm.Parameters.AddWithValue("@todate", todate); var rs = cm.ExecuteReader(); if (rs.HasRows) { while (rs.Read()) { BookingModel bk = new BookingModel(); bk.BookingID = rs[0] as int? ?? 0; bk.Guest = GuestDAO.GetGuest(rs[1] as int? ?? 0); bk.Room = RoomsDAO.GetRoomModel(rs[2] as int? ?? 0); bk.BookingDate = rs[3] as DateTime? ?? DateTime.MinValue; bk.CancelDate = rs[4] as DateTime? ?? DateTime.MinValue; bk.CheckInDate = rs[5] as DateTime? ?? DateTime.MinValue; bk.CheckOutDate = rs[6] as DateTime? ?? DateTime.MinValue; bk.Payment = PaymentDAO.GetPayment(rs[7] as int? ?? 0); bk.Deposit = rs[8] as int? ?? 0; bk.Amount = rs[9] as int? ?? 0; bk.Status = rs[10] as string; list.Add(bk); } } } } return(list); }