Ejemplo n.º 1
0
        internal List <IBooking> CreateBookings(List <IAvaliableRoom> selectedRoomList, DateTime start, DateTime end, string reservetime, string contractid, string reservationid)
        {
            List <IBooking> bookinglist = new List <IBooking>();

            foreach (IAvaliableRoom room in selectedRoomList)
            {
                IRoomPrice roomprice = dbCon.GetRoomPrice(room.RType);
                for (int i = 1; i <= room.ChosenNum; i++)
                {
                    var booking = new Booking();
                    dbCon.UpdateClock();
                    bookinglist.Add(dbCon.CreateBooking(booking.ID, start, end, reservetime, contractid, room.RType, roomprice.Price, reservationid));
                }
            }
            LCon.Log_Booked(dbCon.GetCustomer(contractid), bookinglist);
            return(bookinglist);
        }
Ejemplo n.º 2
0
        //Return a list of available room types
        internal List <IAvaliableRoom> GetAvailableRooms(RoomType?roomtype, DateTime?startdate, DateTime?enddate)
        {
            List <IBooking> bookings = dbCon.GetBookings();
            List <IRoom>    rooms    = GetRooms();

            List <IAvaliableRoom> avaliablerooms = new List <IAvaliableRoom>(), temp;

            foreach (IRoom room in rooms)
            {
                bool foundroom = false;
                foreach (AvaliableRoom avaliroom in avaliablerooms)
                {
                    if (avaliroom.RType == room.RType)
                    {
                        foundroom = true;
                        avaliroom.Add();
                    }
                }
                if (foundroom == false)
                {
                    IRoomPrice rmp = dbCon.GetRoomPrice(room.RType);
                    if (rmp == null)
                    {
                        MessageBox.Show("房间价格未初始化!", "查询价格错误");
                        return(avaliablerooms);
                    }
                    avaliablerooms.Add(new AvaliableRoom(room.RType, rmp.Price));
                }
            }

            if (roomtype != null)
            {
                temp = new List <IAvaliableRoom>();
                foreach (IAvaliableRoom avaliroom in avaliablerooms)
                {
                    if (avaliroom.RType == roomtype)
                    {
                        temp.Add(avaliroom);
                    }
                }
                avaliablerooms = temp;
            }

            if (startdate != null && enddate != null)
            {
                foreach (AvaliableRoom avaliroom in avaliablerooms)
                {
                    foreach (IBooking booking in bookings)
                    {
                        if (booking.Roomtype == avaliroom.RType)
                        {
                            bool overlap = startdate <booking.EndDate && enddate> booking.StartDate;
                            if (overlap)
                            {
                                avaliroom.Reduce();
                            }
                        }
                    }
                }
            }

            return(avaliablerooms);
        }