Exemplo n.º 1
0
 public static Booking getBooking(int bookingID)
 {
     using (var context = new HotelDBEntities())
     {
         return context.Bookings.Find(bookingID);
     }
 }
Exemplo n.º 2
0
 public void addRoom(int numSingleBeds, int numDoubleBeds, int maxGuests, int singlePrice, int doublePrice, int extraPrice, int roomNumber, String extraFeatures)
 {
     using (var context = new HotelDBEntities()) {
         Room newRoom = new Room { numSingleBeds = numSingleBeds, numDoubleBeds = numDoubleBeds, maxGuests = maxGuests, singePrice = singlePrice, doublePrice = doublePrice, extraPrice = extraPrice, roomNumber = roomNumber, extraFeatures = extraFeatures};
         context.Rooms.Add(newRoom);
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void getRooms(DataGridView dgv)
 {
     using (var context = new HotelDBEntities())
     {
        dgv.DataSource = context.Rooms.ToList();
        dgv.Columns[dgv.ColumnCount-1].Visible = false;//remove last column, reference to the booking of the room.
     }
 }
Exemplo n.º 4
0
        public static Room getRoom(int roomID)
        {
            using (var context = new HotelDBEntities())
            {
                return context.Rooms.Find(roomID);

            }
        }
Exemplo n.º 5
0
 public void createBilling(int guestPK, int roomCharge)
 {
     using (var context = new HotelDBEntities())
     {
         Billing guestBilling = new Billing{guestIDFK = guestPK, roomCharge = roomCharge};
         context.Billings.Add(guestBilling);
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public Guest addGuest(string name, int age, int bookingPK,string address, string comment)
 {
     using (var context = new HotelDBEntities())
     {
         Guest newGuest = new Guest {name = name, age = age, bookingIDFK = bookingPK, address = address, comment = comment};
         context.Guests.Add(newGuest);
         context.SaveChanges();
         return newGuest;
     }
 }
Exemplo n.º 7
0
 public Booking addBooking(int roomPK, string startDate, string endDate, int numGuests)
 {
     using (var context = new HotelDBEntities())
     {
         Booking booking = new Booking {bookingStart = startDate, bookingEnd = endDate, roomIDFK = roomPK, numGuests = numGuests};
         context.Bookings.Add(booking);
         context.SaveChanges();
         return booking;
     }
 }
Exemplo n.º 8
0
 public static bool checkOut(int guestID)
 {
     using (var context = new HotelDBEntities()) {
          DateTime date = DateTime.Today;
          Guest guest = context.Guests.Find(guestID);
          context.Guests.Find(guestID).checkOutDate = date.ToShortDateString();
          context.Guests.Find(guestID).Booking.bookingEnd = date.ToShortDateString();
          context.SaveChanges();
             return true;
      }
 }
Exemplo n.º 9
0
 public static void payBill(int guestPK)
 {
     using (var context = new HotelDBEntities()) {
         int billID = -1;
         foreach (var billing in context.Billings)
             if (billing.guestIDFK == guestPK) {
                 billID = billing.billingID;
                 break;
             }
         context.Billings.Find(billID).paid = true;
         context.SaveChanges();
     }
 }
Exemplo n.º 10
0
 public static int getTotalBill(int guestPK)
 {
     using (var context = new HotelDBEntities())
     {
         foreach (var billing in context.Billings)
             if (billing.guestIDFK == guestPK)
             {
                 Billing bill = context.Billings.Find(billing.billingID);
                 return bill.roomCharge + bill.billingExtras;
             }
     }
     MessageBox.Show("error calculating bill");
     return 0;
 }
Exemplo n.º 11
0
 public static void addExtras(int guestPK, int extraCharges)
 {
     using (var context = new HotelDBEntities())
     {
         int billID = -1;//out of range default initilization
         foreach (var billing in context.Billings)
             if (billing.guestIDFK == guestPK)
             {
                 billID = billing.billingID;
                 break;
             }
         context.Billings.Find(billID).billingExtras = extraCharges;
         context.SaveChanges();
     }
 }
Exemplo n.º 12
0
        //
        public Room[] getAvailiableRooms(DateTime startDate, DateTime endDate)
        {
            using (var context = new HotelDBEntities())
            {
                //modified to support LINQ to entity but still use LINQs, could be troublsome for massive databases (toArray will return everything)
                var filteredBookings = context.Bookings.ToArray().Where(b => (DateUtil.compare(startDate.ToShortDateString(), b.bookingEnd) && DateUtil.compare(b.bookingStart, endDate.ToShortDateString())));
                int[] bookedRooms = filteredBookings.Select(booking => booking.roomIDFK).ToArray(); //the resulting array of booked room primary keys
                List<Room> avRooms = context.Rooms.ToList();
                var roomsToRemove = from room in avRooms from t in bookedRooms where room.roomID == t select room;//single line nesting. Returns rooms that the meet the condition.
                roomsToRemove = roomsToRemove.ToArray();//more friendly than IEnumerable
                foreach (var room in roomsToRemove) //remove all booked rooms from list of all rooms
                    avRooms.Remove(room);

                return avRooms.ToArray();
            }
        }
Exemplo n.º 13
0
 public static bool checkIn(int guestID)
 {
     using (var context = new HotelDBEntities())
     {
         DateTime date = DateTime.Today;
         Guest guest = context.Guests.Find(guestID);
         if (DateUtil.compare(guest.Booking.bookingStart, date.ToShortDateString()))
         {
             context.Guests.Find(guestID).checkInDate = date.ToShortDateString();
             context.SaveChanges();
             MessageBox.Show("guest checked in");
             return true;
         }
             MessageBox.Show("Please come back anytime after: " + guest.Booking.bookingStart);
             return false;
     }
 }
Exemplo n.º 14
0
        //remove a guest and other tables asscociated with it
        public static bool removeGuest(int guestId)
        {
            using (var context = new HotelDBEntities())
            {
                foreach (var bill in context.Billings)
                {
                    if (bill.guestIDFK == guestId)
                    {
                        context.Billings.Remove(bill);
                        break;
                    }
                }
                Guest g = context.Guests.Find(guestId);
                if (g != null)
                {
                    context.Bookings.Remove(g.Booking);
                    context.Guests.Remove(g);
                    context.SaveChanges();
                    return true;
                }

            }
            return false;
        }
Exemplo n.º 15
0
 public void removeEverything()
 {
     using (var context = new HotelDBEntities())
     {
         context.Billings.RemoveRange(context.Billings);
         context.Bookings.RemoveRange(context.Bookings);
         context.Guests.RemoveRange(context.Guests);
         context.Rooms.RemoveRange(context.Rooms);
         context.SaveChanges();
     }
 }
Exemplo n.º 16
0
 public Guest[] getGuests(DataGridView dgv)
 {
     using (var context = new HotelDBEntities())
     {
         var guests = context.Guests;
         dgv.DataSource = guests.ToList();
         dgv.Columns[dgv.ColumnCount - 1].Visible = dgv.Columns[dgv.ColumnCount - 2].Visible = false; //removes links to booking and billing tables
         return guests.ToArray();
     }
 }
Exemplo n.º 17
0
 public bool removeAllGuests()
 {
     using (var context = new HotelDBEntities())
     {
         context.Billings.RemoveRange(context.Billings.ToArray());
         context.Bookings.RemoveRange(context.Bookings.ToArray());
         context.Guests.RemoveRange(context.Guests.ToArray());
         context.SaveChanges();
         if (context.Guests.Count(g => true) == 0)
             return true;
     }
     return false;
 }
Exemplo n.º 18
0
 public bool removeRoom(int roomId)
 {
     using (var context = new HotelDBEntities()) {
         Room room = context.Rooms.Find(roomId);//find entity by primary key
         if (room != null)//just incase!
         {
             context.Rooms.Remove(room);
             context.SaveChanges();
             return true;//return true if succsessful removal of guest
         }
     }
     return false;
 }
Exemplo n.º 19
0
 public Guest[] findByName(String name)
 {
     using (var context = new HotelDBEntities())
     {
         return context.Guests.Where(g => g.name == name).ToArray();
     }
 }
Exemplo n.º 20
0
 public static Guest getGuest(int guestID)
 {
     using (var context = new HotelDBEntities()) { return context.Guests.Find(guestID); }
 }