⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 新建 文本文档 (3).txt

📁 使用存储过程实现用户的权限管理
💻 TXT
📖 第 1 页 / 共 3 页
字号:
            Parm[1].SqlValue = TeamIDListStr;
            Parm[1].Direction = ParameterDirection.Input;
            Parm[2] = new SqlParameter("@Type", SqlDbType.Int);
            Parm[2].SqlValue = Type;
            Parm[2].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlUserLinkRightTeam", Parm);
            if (val == 1)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
        /// <summary>
        /// 通过用户ID获得该用户权限组ID的列表
        /// </summary>
        /// <param name="TeamID">用户ID</param>
        /// <returns>权限ID列表</returns>
        public List<int> GetUserByUserID(int UserID)
        {
            List<int> IDList = new List<int>();
            SqlDataReader reader;//定义读取器
            string SelString = "select * from UserMag_l_RightTeamUser where Userinfo_ID=@Userinfo_ID";
            //定义参数SqlParameter列表并赋值
            SqlParameter[] SelParm = new SqlParameter[1];
            SelParm[0] = new SqlParameter("@Userinfo_ID", SqlDbType.Int);
            SelParm[0].SqlValue = UserID;
            SelParm[0].Direction = ParameterDirection.Input;
            reader = DBDealHelp.SqlHelper.ExecuteReader(SqlConnString, CommandType.Text, SelString, SelParm);
            while (reader.Read())//循环读取查询所得值
            {
                IDList.Add(Convert.ToInt32(reader[1]));
            }
            reader.Close();
            return IDList;
        }
        //权限功能操作
        /// <summary>
        /// 增加权限功能信息
        /// </summary>
        /// <param name="obj_RightFun">权限组功能对象</param>
        /// <returns>是否操作成功</returns>
        public Boolean AddRightFunItem(RightTeamFun obj_RightFun)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值得变量
            //定义参数SqlParameter列表并赋值
            SqlParameter[] InsParm = new SqlParameter[3];
            InsParm[0] = new SqlParameter("@TeamID", SqlDbType.Int);
            InsParm[0].SqlValue = 0;
            InsParm[0].Direction = ParameterDirection.Input;
            InsParm[1] = new SqlParameter("@Function_Name", SqlDbType.VarChar, 50);
            InsParm[1].SqlValue = obj_RightFun.Name;
            InsParm[1].Direction = ParameterDirection.Input;
            InsParm[2] = new SqlParameter("@Type", SqlDbType.Int);
            InsParm[2].SqlValue = 2;
            InsParm[2].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightFunItem", InsParm);
            if (val == 1)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
        /// <summary>
        /// 根据权限信息ID删除权限功能信息
        /// </summary>
        /// <param name="RightFunID">权限功能信息ID</param>
        /// <returns>是否操作成功</returns>
        public Boolean RemoveRightFunItem(RightTeamFun RightFunID)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值的变量
            //定义参数SqlParameter列表并赋值
            SqlParameter[] DelParm = new SqlParameter[3];
            DelParm[0] = new SqlParameter("@TeamID", SqlDbType.Int);
            DelParm[0].SqlValue = RightFunID.ID;
            DelParm[0].Direction = ParameterDirection.Input;
            DelParm[1] = new SqlParameter("@Type", SqlDbType.Int);
            DelParm[1].SqlValue = 1;
            DelParm[1].Direction = ParameterDirection.Input;
            DelParm[2] = new SqlParameter("@Function_Name", SqlDbType.VarChar, 50);
            DelParm[2].SqlValue = "";
            DelParm[2].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = DBDealHelp.SqlHelper.ExecuteNonQuery(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightFunItem", DelParm);
            if (val > 0)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
        /// <summary>
        /// 更新权限功能信息
        /// </summary>
        /// <param name="obj_RightFun">权限功能对象</param>
        /// <returns>是否操作成功</returns>
        public Boolean UpdateRightFunItem(RightTeamFun obj_RightFun)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值得变量
            //定义参数SqlParameter列表并赋值
            SqlParameter[] UpdParm = new SqlParameter[3];
            UpdParm[0] = new SqlParameter("@TeamID", SqlDbType.Int);
            UpdParm[0].SqlValue = obj_RightFun.ID;
            UpdParm[0].Direction = ParameterDirection.Input;
            UpdParm[1] = new SqlParameter("@Function_Name", SqlDbType.VarChar, 50);
            UpdParm[1].SqlValue = obj_RightFun.Name;
            UpdParm[1].Direction = ParameterDirection.Input;
            UpdParm[2] = new SqlParameter("@Type", SqlDbType.Int);
            UpdParm[2].SqlValue = 3;
            UpdParm[2].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightFunItem", UpdParm);
            if (val == 1)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
        /// <summary>
        /// 通过权限组ID获得该权限组的所有权限功能ID
        /// </summary>
        /// <param name="TeamID">权限组ID</param>
        /// <returns>属于该权限组的权限功能ID列表</returns>
        public List<int> GetRightFunByTeamIDItem(int TeamID)
        {

            List<int> FunList = new List<int>();
            SqlDataReader reader;//定义读取器
            string SelString = "select Function_ID from UserMag_l_RightTeamFunItem where RightTeam_ID=@RightTeam_ID";
            //定义参数SqlParameter列表并赋值
            SqlParameter[] SelParm = new SqlParameter[1];
            SelParm[0] = new SqlParameter("@RightTeam_ID", SqlDbType.Int);
            SelParm[0].SqlValue = TeamID;
            SelParm[0].Direction = ParameterDirection.Input;
            reader = DBDealHelp.SqlHelper.ExecuteReader(SqlConnString, CommandType.Text, SelString, SelParm);
            while (reader.Read())//循环读取查询所得值
            {
                FunList.Add(Convert.ToInt32(reader["Function_ID"]));
            }
            reader.Close();
            return FunList;
        }
        /// <summary>
        /// 将权限功能列表里面的权限功能对象统一插入一个权限组
        /// </summary>
        /// <param name="TeamID">将要加入的权限组ID</param>
        /// <param name="RightFunList">权限功能列表</param>
        /// <returns>是否操作成功</returns>
        public Boolean AddRightFunToTeamItem(int TeamID, List<int> RightFunList)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值得变量
            string RightFunListStr = "";//定义权限功能列表字符串
            //循环获取List列表中的值
            for (int i = 0; i < RightFunList.Count; i++)
            {
                RightFunListStr += RightFunList[i].ToString() + ",";
            }
            //定义参数SqlParameter列表并赋值
            SqlParameter[] InsParm = new SqlParameter[3];
            InsParm[0] = new SqlParameter("@RightTeam_ID", SqlDbType.Int);
            InsParm[0].SqlValue = TeamID;
            InsParm[0].Direction = ParameterDirection.Input;
            InsParm[1] = new SqlParameter("@FunctionIDList", SqlDbType.VarChar, 500);
            InsParm[1].SqlValue = RightFunListStr;
            InsParm[1].Direction = ParameterDirection.Input;
            InsParm[2] = new SqlParameter("@Type", SqlDbType.Int);
            InsParm[2].SqlValue = 1;
            InsParm[2].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightFunTeamItem", InsParm);
            if (val == 1)
            {
                IsSuccess = true;
            }
            return IsSuccess;

        }        
        /// <summary>
        /// 从指定的权限组中删除权限功能
        /// </summary>
        /// <param name="TeamID">权限组ID</param>
        /// <param name="RightFunList">权限功能列表</param>
        /// <returns>是否操作成功</returns>
        public Boolean RemoveRightFunFromTeamItem(int TeamID, List<int> RightFunList)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值得变量
            string RightFunListStr = "";//定义权限功能列表字符串
            //循环获取List列表中的值
            for (int i = 0; i < RightFunList.Count; i++)
            {
                RightFunListStr += RightFunList[i].ToString() + ",";
            }
            //定义参数SqlParameter列表并赋值
            SqlParameter[] DelParm = new SqlParameter[3];
            DelParm[0] = new SqlParameter("@RightTeam_ID", SqlDbType.Int);
            DelParm[0].SqlValue = TeamID;
            DelParm[0].Direction = ParameterDirection.Input;
            DelParm[1] = new SqlParameter("@FunctionIDList", SqlDbType.VarChar, 500);
            DelParm[1].SqlValue = RightFunListStr;
            DelParm[1].Direction = ParameterDirection.Input;
            DelParm[2] = new SqlParameter("@Type", SqlDbType.Int);
            DelParm[2].SqlValue = 2;
            DelParm[2].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightFunTeamItem", DelParm);
            if (val == 1)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -