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

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

📁 使用存储过程实现用户的权限管理
💻 TXT
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BankInnerMag.DataModel.UserManager;
using BankInnerMag.IDBALayer.UserManager;

namespace BankInnerMag.SqlServerDBALayer.UserManager
{
    public class ManageRight :IRightSet
    {
        string SqlConnString;//定义连接字符串
        /// <summary>
        /// 数据库连接
        /// </summary>
        public ManageRight()
        {
            SqlConnString=DBDealHelp.SqlHelper.ConnectionStringLocalTransaction;//获取字符串值
            //SqlConnection SqlConn;//定义数据库连接对象;
            //SqlConn = new SqlConnection(SqlConnString);//实例化数据库连接对象;
        }
        //权限组操作
        /// <summary>
        /// 增加权限组信息
        /// </summary>
        /// <param name="Obj_RightTeam">权限组对象</param>
        /// <returns>是否操作成功</returns>
        public Boolean AddRightTeam(RightTeam obj_RightTeam)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值的变量
            //定义参数SqlParameter列表并赋值
            SqlParameter[] InsParm = new SqlParameter[5];
            InsParm[0] = new SqlParameter("@RightTeam_Name", SqlDbType.VarChar, 50);
            InsParm[1] = new SqlParameter("@RightTeam_Code", SqlDbType.VarChar, 50);
            InsParm[2] = new SqlParameter("@RightTeam_Memo", SqlDbType.VarChar, 200);
            InsParm[3] = new SqlParameter("@Type", SqlDbType.Int);
            InsParm[4] = new SqlParameter("@TeamID", SqlDbType.VarChar,200);
            InsParm[0].SqlValue = obj_RightTeam.Name;
            InsParm[1].SqlValue = obj_RightTeam.Code;
            InsParm[2].SqlValue = obj_RightTeam.Memo;
            InsParm[3].SqlValue = 2;
            InsParm[4].SqlValue = "0";
            InsParm[0].Direction = ParameterDirection.Input;
            InsParm[1].Direction = ParameterDirection.Input;
            InsParm[2].Direction = ParameterDirection.Input;
            InsParm[3].Direction = ParameterDirection.Input;
            InsParm[4].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val =(int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightTeam", InsParm);
            if (val > 0)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
        /// <summary>
        /// 批量删除权限组信息
        /// </summary>
        /// <param name="TeamID">指定权限组ID列表</param>
        /// <returns>是否操作成功</returns>
        public Boolean RemoveRightTeam(List<int> TeamID)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值得变量
            string TeamIDListStr = "";//定义权限组ID列表字符串
            //循环获取List列表中的值
            for (int i = 0; i < TeamID.Count; i++)
            {
                TeamIDListStr += TeamID[i].ToString() + ",";
            }
            TeamIDListStr=TeamIDListStr.Substring(0, (TeamIDListStr.Length - 1));
            //定义参数SqlParameter列表并赋值
            SqlParameter[] DelParm = new SqlParameter[5];
            DelParm[0] = new SqlParameter("@TeamID", SqlDbType.VarChar,200);
            DelParm[0].SqlValue = TeamIDListStr;
            DelParm[0].Direction = ParameterDirection.Input;
            DelParm[1] = new SqlParameter("@RightTeam_Name", SqlDbType.VarChar, 50);
            DelParm[1].SqlValue = "";
            DelParm[1].Direction = ParameterDirection.Input;
            DelParm[2] = new SqlParameter("@RightTeam_Code", SqlDbType.VarChar, 50);
            DelParm[2].SqlValue = "";
            DelParm[2].Direction = ParameterDirection.Input;
            DelParm[3] = new SqlParameter("@RightTeam_Memo", SqlDbType.VarChar, 50);
            DelParm[3].SqlValue = "";
            DelParm[3].Direction = ParameterDirection.Input;
            DelParm[4] = new SqlParameter("@Type", SqlDbType.Int);
            DelParm[4].SqlValue = 1;
            DelParm[4].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightTeam", DelParm);
            if (val == 1)
            {
                IsSuccess = true;
            }
            return IsSuccess; 
        }
        /// <summary>
        /// 更新权限组对象
        /// </summary>
        /// <param name="obj_RightTeam">准备权限组信息对象</param>
        /// <returns>是否操作成功</returns>
        public Boolean UpdateRightTeam(RightTeam obj_RightTeam)
        {
            bool IsSuccess;//定义返回值变量
            IsSuccess = false;
            int val;//定义获取返回值的变量
            //定义参数SqlParameter列表并赋值
            SqlParameter[] UpdParm = new SqlParameter[5];
            UpdParm[0] = new SqlParameter("@RightTeam_Name", SqlDbType.VarChar, 50);
            UpdParm[1] = new SqlParameter("@RightTeam_Code", SqlDbType.VarChar, 50);
            UpdParm[2] = new SqlParameter("@RightTeam_Memo", SqlDbType.VarChar, 200);
            UpdParm[3] = new SqlParameter("@TeamID", SqlDbType.VarChar,200);
            UpdParm[4] = new SqlParameter("@Type", SqlDbType.Int);
            UpdParm[0].SqlValue = obj_RightTeam.Name;
            UpdParm[1].SqlValue = obj_RightTeam.Code;
            UpdParm[2].SqlValue = obj_RightTeam.Memo;
            UpdParm[3].SqlValue = obj_RightTeam.ID.ToString();
            UpdParm[4].SqlValue = 3;
            UpdParm[0].Direction = ParameterDirection.Input;
            UpdParm[1].Direction = ParameterDirection.Input;
            UpdParm[2].Direction = ParameterDirection.Input;
            UpdParm[3].Direction = ParameterDirection.Input;
            UpdParm[4].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            val = (int)DBDealHelp.SqlHelper.ExecuteScalar(SqlConnString, CommandType.StoredProcedure, "p_ab_ContrlRightTeam", UpdParm);
            if (val > 0)
            {
                IsSuccess = true;
            }
            return IsSuccess;
        }
        /// <summary>
        /// 通过权限组ID获得权限组对象
        /// </summary>
        /// <param name="TeamID">权限组ID</param>
        /// <returns>权限组对象</returns>
        public List<RightTeam> GetRightTeamByID(List<int> TeamListID)
        {
            List<RightTeam> ORightTeamList = new List<RightTeam>();
            RightTeam ORightTeam;
            SqlDataReader reader;//定义读取器
            string TeamID = "";
            if (TeamListID.Count > 0)
            {
                for (int i = 0; i < TeamListID.Count; i++)
                {
                    TeamID += TeamListID[i].ToString()+ ",";
                }
            }
            //定义参数SqlParameter列表并赋值
            SqlParameter[] SelParm = new SqlParameter[2];
            SelParm[0] = new SqlParameter("@TeamIDList", SqlDbType.VarChar, 200);
            SelParm[0].SqlValue = TeamID;
            SelParm[0].Direction = ParameterDirection.Input;
            SelParm[1] = new SqlParameter("@Type", SqlDbType.Int);
            SelParm[1].SqlValue = 1;
            SelParm[1].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            reader = DBDealHelp.SqlHelper.ExecuteReader(SqlConnString, CommandType.StoredProcedure, "p_ab_SelectRightTeamOrFunInfo", SelParm);
            while(reader.Read())//循环读取查询所得值
            {
                ORightTeam = new RightTeam();
                ORightTeam.ID =Convert.ToInt32(reader[0]);
                ORightTeam.Name = reader[1].ToString();
                ORightTeam.Code = reader[2].ToString();
                ORightTeam.Memo = reader[3].ToString();
                ORightTeamList.Add(ORightTeam);
            }
            reader.Close();//关闭读取器
            return ORightTeamList;
        }
        /// <summary>
        /// 通过权限功能ID获得功能对象
        /// </summary>
        /// <param name="TeamID">权限功能ID</param>
        /// <returns>权限功能对象</returns>
        public List<RightTeamFun> GetRightTeamFunByID(List<int> TeamFunListID)
        {
            List<RightTeamFun> ORightTeamFunList = new List<RightTeamFun>();
            RightTeamFun ORightTeamFun;
            SqlDataReader reader;//定义读取器
            string TeamID = "";
            if (TeamFunListID.Count > 0)
            {
                for (int i = 0; i < TeamFunListID.Count; i++)
                {
                    TeamID += TeamFunListID[i].ToString() + ",";
                }
            }
            //定义参数SqlParameter列表并赋值
            SqlParameter[] SelParm = new SqlParameter[2];
            SelParm[0] = new SqlParameter("@TeamIDList", SqlDbType.VarChar, 200);
            SelParm[0].SqlValue = TeamID;
            SelParm[0].Direction = ParameterDirection.Input;
            SelParm[1] = new SqlParameter("@Type", SqlDbType.Int);
            SelParm[1].SqlValue = 2;
            SelParm[1].Direction = ParameterDirection.Input;
            //调用函数执行数据库操作
            reader = DBDealHelp.SqlHelper.ExecuteReader(SqlConnString, CommandType.StoredProcedure, "p_ab_SelectRightTeamOrFunInfo", SelParm);
            while (reader.Read())//循环读取查询所得值
            {
                ORightTeamFun = new RightTeamFun();
                ORightTeamFun.ID = Convert.ToInt32(reader[0]);
                ORightTeamFun.Name = reader[1].ToString();
                ORightTeamFun.ParentID = Convert.ToInt32(reader[2]);
                ORightTeamFun.Code = reader[3].ToString();
                ORightTeamFunList.Add(ORightTeamFun);
            }
            reader.Close();//关闭读取器
            return ORightTeamFunList;
        }
        /// <summary>
        /// 通过权限组ID获得该权限组的所有权限功能
        /// </summary>
        /// <param name="TeamID">权限组ID</param>
        /// <returns>属于该权限组的权限功能码</returns>
        public List<string> GetRightFunCodeByTeamID(int TeamID)
        {
            List<string> FunList = new List<string>();
            SqlDataReader reader;//定义读取器

⌨️ 快捷键说明

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