角色权限判断 判断用户是否拥有指定的角色 用法比如指定角色才能进指定模块


发布时间:2018/3/7 9:59:26  次浏览  作者:admin

bool temprole=UserBll.Instance.HasRole(SysVisitor.Instance.UserId, 33);//假如我们要判断是否拥有客服的角色权限



default:
                    List<int> powerlist = UserBll.Instance.GetDepIDs(SysVisitor.Instance.UserId, true);//得到用户数据权限(角色数据权限+用户数据权限)
                    string powerstring = string.Join(",", powerlist);//ist<int>: 1,2,3,4,5,6,7  转换成字符串:“1,2,3,4,5,6,7”
                    if (string.IsNullOrEmpty(powerstring))
                    {
                        powerstring = "0";
                    }

                    string sqlwhere = "(depid in (" + powerstring + "))";//根据后台数据权限(角色数据权限+用户数据权限)看信息
                    //string sqlwhere = "(depid in (" + SysVisitor.Instance.cookiesDepartments + "))";//当前用户可看当前部门信息
                    if (SysVisitor.Instance.cookiesIsAdmin == "True")
                    { //判断是否是超管如果是超管理,所有显示
                        sqlwhere = " 1=1 ";//如果是超管则不显示
                    }
                    if (!string.IsNullOrEmpty(rpm.Filter))//如果筛选不为空
                    {
                        string str = " and " + FilterTranslator.ToSql(rpm.Filter);
                        sqlwhere = sqlwhere + str;
                    }
                    //TableConvention.Resolve(typeof(MJUserModel)) 转换成表名
                    var pcp = new ProcCustomPage(TableConvention.Resolve(typeof(Wzsh_khxxModel)))
                    {
                        PageIndex = rpm.Pageindex,
                        PageSize = rpm.Pagesize,
                        OrderFields = rpm.Sort,
                        WhereString = sqlwhere
                    };
                    int recordCount;
                    DataTable dt = DbUtils.GetPageWithSp(pcp, out recordCount);
                    context.Response.Write(JSONhelper.FormatJSONForEasyuiDataGrid(recordCount, dt));
                    //context.Response.Write(Wzsh_khxxBll.Instance.GetJson(rpm.Pageindex, rpm.Pagesize, rpm.Filter, rpm.Sort, rpm.Order));
                    break;