예제 #1
0
        public void PlaceLock(BALBookingLock balBookingLock)
        {
            try
            {
                if (balBookingLock == null || balBookingLock.LockRooms == null)
                {
                    return;
                }

                SqlConnection cn = new SqlConnection(strCon);
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandType = CommandType.Text;

                foreach (var lockRoom in balBookingLock.LockRooms)
                {
                    string query = string.Format("insert into tblBookingLock(AccomId, LockIdentifier, RoomCategoryId, RoomNo, LockExpireAt) values ({0},'{1}',{2},'{3}','{4}')",
                                                 balBookingLock.AccomId,
                                                 balBookingLock.LockIdentifier,
                                                 lockRoom.RoomCategoryId,
                                                 lockRoom.RoomNo,
                                                 balBookingLock.LockExpireAt);

                    cmd.CommandText = query;
                    var exists = cmd.ExecuteNonQuery();
                }
                cn.Close();
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
예제 #2
0
        public void ReleaseLock(BALBookingLock balBookingLock)
        {
            try
            {
                string query = string.Format("delete from tblBookingLock where AccomId = {0} and LockIdentifier = '{1}'",
                                             balBookingLock.AccomId,
                                             balBookingLock.LockIdentifier);

                SqlConnection cn  = new SqlConnection(strCon);
                SqlCommand    cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;
                cn.Open();

                int rowsDeleted = cmd.ExecuteNonQuery();

                #region Also Delete All the expired locks, if there are any.
                query = string.Format("delete from tblBookingLock where LockExpireAt < '{0}'",
                                      DateTime.Now);
                rowsDeleted = cmd.ExecuteNonQuery();
                #endregion

                cn.Close();
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
예제 #3
0
        public bool IsLocked(BALBookingLock balBookingLock)
        {
            bool lockFound = false;

            try
            {
                SqlConnection cn  = new SqlConnection(strCon);
                SqlCommand    cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandType = CommandType.Text;
                cn.Open();

                foreach (var lockRoom in balBookingLock.LockRooms)
                {
                    string query = string.Format("select Id from tblBookingLock where LockIdentifier <> '{0}' and AccomId = {1} and RoomCategoryId = {2} and RoomNo = {3} and LockExpireAt > '{4}'",
                                                 balBookingLock.LockIdentifier,
                                                 balBookingLock.AccomId,
                                                 lockRoom.RoomCategoryId,
                                                 lockRoom.RoomNo,
                                                 DateTime.Now);
                    // string query = string.Format("select Id from tblBookingLock where LockIdentifier <> '{0}' and AccomId = {1} and RoomCategoryId = {2} and RoomNo = {3} and LockExpireAt between CONVERT(date, getdate()) and '{4}'",
                    //balBookingLock.LockIdentifier,
                    //balBookingLock.AccomId,
                    //lockRoom.RoomCategoryId,
                    //lockRoom.RoomNo,
                    //DateTime.Now);
                    cmd.CommandText = query;
                    var exists = cmd.ExecuteScalar();

                    if (exists != null)
                    {
                        lockFound = true;
                        break;
                    }
                }
                cn.Close();
                return(lockFound);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
예제 #4
0
    public void LockTheBooking(string roomno, int accoid, int roomcatid)
    {
        try
        {
            int lockDuration = ConfigurationManager.AppSettings["LockDuration"] != null?Convert.ToInt16(ConfigurationManager.AppSettings["LockDuration"]) : 10;

            BALBookingLock bl = new BALBookingLock();

            int accomId = accoid;

            Guid uniqueIdentifier = Guid.NewGuid();

            bl.AccomId        = accomId;
            bl.LockIdentifier = uniqueIdentifier.ToString();
            bl.LockExpireAt   = DateTime.Now.AddMinutes(lockDuration);
            bl.rooms          = roomno;
            bl.roocatid       = roomcatid;

            bl.LockRooms = new List <LockRoom>();
            //foreach (var lockRoom in bl.LockRooms)
            //{

            LockRoom lr = new LockRoom {
                RoomCategoryId = Convert.ToInt16(roomcatid), RoomNo = roomno.ToString()
            };
            bl.LockRooms.Add(lr);

            //}
            //foreach (var lockRoom in bl.LockRooms)
            //{
            DALBookingLock dbl = new DALBookingLock();
            dbl.PlaceLock(bl);
            //}
        }
        catch (Exception exp)
        {
            throw exp;
        }
    }