示例#1
0
        /// <summary>
        /// 强制清除所有锁
        /// </summary>
        /// <returns>是否清除成功</returns>
        public bool ClearLockScript(string id)
        {
            object[] keys = new object[] { id }; // 主键

            try
            {
                if (conn.State == ConnectionState.Closed) // 打开sql连接
                {
                    conn.Open();
                }

                RecordLockEx recordLock = new RecordLockEx(conn, "sys_script_script", keys, 0);
                if (!recordLock.ForceClearLock(keys))
                {
                    return(false);
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在清除脚本记录时产生sql异常: " + ex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("在处理锁时产生异常: " + ex.ToString());
            }
            finally
            {
                if (conn.State == ConnectionState.Open) // 关闭sql连接
                {
                    conn.Close();
                }
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// 锁定脚本记录
        /// </summary>
        /// <param name="id">脚本id</param>
        /// <returns>是否锁定成功</returns>
        public bool LockScript(string id)
        {
            object[] keys   = new object[] { id }; // 主键
            bool     result = true;                // 返回值

            try
            {
                if (conn.State == ConnectionState.Closed) // 打开sql连接
                {
                    conn.Open();
                }

                RecordLockEx recordLock = new RecordLockEx(conn, "sys_script_script", keys, 0);
                recordLock.UpdateLocalVersion(keys);
                if (!recordLock.Lock(keys))
                {
                    MessageBox.Show(string.Format("该脚本已被{0}锁定!", recordLock.GetServerLastLockUser(keys)));
                    result = false;
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在锁定脚本记录时产生sql异常: " + ex.ToString());
                result = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("在处理锁时产生异常: " + ex.ToString());
                result = false;
            }
            finally
            {
                if (conn.State == ConnectionState.Open) // 关闭sql连接
                {
                    conn.Close();
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// 解锁脚本记录
        /// </summary>
        /// <param name="id">脚本id</param>
        /// <returns>是否解锁成功</returns>
        public bool UnLockScript(string id)
        {
            object[] keys   = new object[] { id }; // 主键
            bool     result = true;                // 返回值

            try
            {
                if (conn.State == ConnectionState.Closed) // 打开sql连接
                {
                    conn.Open();
                }

                RecordLockEx recordLock = new RecordLockEx(conn, "sys_script_script", keys, 0);
                recordLock.UpdateLocalVersion(keys);
                if (recordLock.UnLock(keys) < 0)
                {
                    result = false;
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在解锁脚本记录时产生sql异常: " + ex.ToString());
                result = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("在处理锁时产生异常: " + ex.ToString());
                result = false;
            }
            finally
            {
                if (conn.State == ConnectionState.Open) // 关闭sql连接
                {
                    conn.Close();
                }
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// 强制清除所有锁
        /// </summary>
        /// <returns>是否清除成功</returns>
        public bool ClearLockScript(string id)
        {
            object[] keys = new object[] { id }; // 主键

            try
            {
                if (conn.State == ConnectionState.Closed) // 打开sql连接
                {
                    conn.Open();
                }

                RecordLockEx recordLock = new RecordLockEx(conn, "sys_script_script", keys, 0);
                if (!recordLock.ForceClearLock(keys))
                {
                    return false;
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在清除脚本记录时产生sql异常: " + ex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("在处理锁时产生异常: " + ex.ToString());
            }
            finally
            {
                if (conn.State == ConnectionState.Open) // 关闭sql连接
                {
                    conn.Close();
                }
            }
            return true;
        }
示例#5
0
        /// <summary>
        /// 解锁脚本记录
        /// </summary>
        /// <param name="id">脚本id</param>
        /// <returns>是否解锁成功</returns>
        public bool UnLockScript(string id)
        {
            object[] keys = new object[] { id }; // 主键
            bool result = true; // 返回值

            try
            {
                if (conn.State == ConnectionState.Closed) // 打开sql连接
                {
                    conn.Open();
                }

                RecordLockEx recordLock = new RecordLockEx(conn, "sys_script_script", keys, 0);
                recordLock.UpdateLocalVersion(keys);
                if (recordLock.UnLock(keys) < 0)
                {
                    result = false;
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("在解锁脚本记录时产生sql异常: " + ex.ToString());
                result = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("在处理锁时产生异常: " + ex.ToString());
                result = false;
            }
            finally
            {
                if (conn.State == ConnectionState.Open) // 关闭sql连接
                {
                    conn.Close();
                }
            }
            return result;
        }
示例#6
0
        /// <summary>
        /// 锁定脚本记录
        /// </summary>
        /// <param name="id">脚本id</param>
        /// <returns>是否锁定成功</returns>
        public bool LockScript(string id)
        {
            object[] keys = new object[] { id }; // 主键
            bool result = true; // 返回值

            try
            {
                if(conn.State == ConnectionState.Closed) // 打开sql连接
                {
                    conn.Open();
                }

                RecordLockEx recordLock = new RecordLockEx(conn, "sys_script_script", keys, 0);
                recordLock.UpdateLocalVersion(keys);
                if (!recordLock.Lock(keys))
                {
                    MessageBox.Show(string.Format("该脚本已被{0}锁定!", recordLock.GetServerLastLockUser(keys)));
                    result = false;
                }
            }
            catch(SqlException ex)
            {
                MessageBox.Show("在锁定脚本记录时产生sql异常: " + ex.ToString());
                result = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("在处理锁时产生异常: " + ex.ToString());
                result = false;
            }
            finally
            {
                if(conn.State == ConnectionState.Open) // 关闭sql连接
                {
                    conn.Close();
                }
            }

            return result;
        }