Ejemplo n.º 1
0
        //实例化树形
        public string InitTree(int InfoID)
        {
            string result = "";
            IList <E_tb_Action>    list           = tAction.GetModelList("ParentID=0").ToList();
            List <E_tb_RoleAction> RoleActionList = tRoleAction.GetModelList("RoleID=" + InfoID);

            foreach (E_tb_Action node in list)
            {
                result += Recursion(node, RoleActionList) + ",";
            }
            return("[" + result.TrimEnd(',') + "]");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重新基类在Action执行之前的事情
        /// </summary>
        /// <param name="filterContext">重写方法的参数</param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            //得到用户登录的信息
            CurrentUserInfo = Session["UserInfo"] as E_tb_InPersonnel;
            //判断用户是否为空
            if (CurrentUserInfo == null)
            {
                Response.Redirect("/Login/Login");
            }


            //权限按钮控制
            T_tb_Action     tAction     = new T_tb_Action();
            T_tb_UserRole   tUserRole   = new T_tb_UserRole();
            T_tb_RoleAction tRoleAction = new T_tb_RoleAction();

            //获取用户对应角色
            List <E_tb_UserRole> UserRoleList = new List <E_tb_UserRole>();

            if (CurrentUserInfo != null)
            {
                UserRoleList = tUserRole.GetModelList("PersonnelID=" + CurrentUserInfo.PersonnelID);
            }
            string RoleIDS = "";

            UserRoleList.ForEach(p => {
                RoleIDS += p.RoleID + ",";
            });
            RoleIDS = RoleIDS.TrimEnd(',');

            if (CurrentUserInfo != null)
            {
                CurrentUserInfo.RoleIDS = RoleIDS;
                if (RoleIDS.IndexOf(',') < 0)
                {
                    CurrentUserInfo.RoleID = Convert.ToInt32(RoleIDS);
                }
            }

            //获取角色对应操作
            List <E_tb_RoleAction> RoleActionList = new List <E_tb_RoleAction>();

            if (RoleIDS.Length > 0)
            {
                RoleActionList = tRoleAction.GetModelList("RoleID in (" + RoleIDS + ")");
            }

            //加载所有权限代码
            List <E_tb_Action> ActionList = tAction.GetModelList("");

            ActionList.ForEach(p =>
            {
                ViewData[p.ActionCode] = (RoleActionList.Where(o => o.ActionID == p.ActionID).Count() > 0);
                //ViewData[p.ActionCode] =true;
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 重新基类在Action执行之前的事情
        /// </summary>
        /// <param name="filterContext">重写方法的参数</param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            //得到用户登录的信息
            CurrentUserInfo = Session["UserInfo"] as E_tb_InPersonnel;
            //判断用户是否为空
            if (CurrentUserInfo == null)
            {
                if (HttpContext.Request.Cookies["lims.userinfo"] == null || string.IsNullOrEmpty(HttpContext.Request.Cookies["lims.userinfo"].Value))
                {
                    filterContext.Result = new RedirectResult("/Login/login");
                }
                else
                {
                    HttpCookie       cookie       = HttpContext.Request.Cookies.Get("lims.userinfo");
                    string           passportinfo = cookie["passport"].ToString();
                    int              uid          = Convert.ToInt32(cookie["uid"]);
                    E_tb_InPersonnel eInPersonnel = new T_tb_InPersonnel().GetModel(uid);
                    if (passportinfo == Utils.Md5(eInPersonnel.PersonnelID + eInPersonnel.UserName + eInPersonnel.PassWord))
                    {
                        CurrentUserInfo = new T_tb_InPersonnel().Login(eInPersonnel.UserName, eInPersonnel.PassWord);
                        filterContext.HttpContext.Session["UserInfo"] = CurrentUserInfo;
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult("/Login/login");
                    }
                }
            }


            //权限按钮控制
            T_tb_Action     tAction     = new T_tb_Action();
            T_tb_UserRole   tUserRole   = new T_tb_UserRole();
            T_tb_RoleAction tRoleAction = new T_tb_RoleAction();

            //获取用户对应角色
            List <E_tb_UserRole> UserRoleList = new List <E_tb_UserRole>();

            if (CurrentUserInfo != null)
            {
                UserRoleList = tUserRole.GetModelList("PersonnelID=" + CurrentUserInfo.PersonnelID);
            }
            string RoleIDS = "";

            UserRoleList.ForEach(p => {
                RoleIDS += p.RoleID + ",";
            });
            RoleIDS = RoleIDS.TrimEnd(',');

            if (CurrentUserInfo != null)
            {
                CurrentUserInfo.RoleIDS = RoleIDS;
                if (RoleIDS.IndexOf(',') < 0)
                {
                    CurrentUserInfo.RoleID = Convert.ToInt32(RoleIDS);
                }
            }

            //获取角色对应操作
            List <E_tb_RoleAction> RoleActionList = new List <E_tb_RoleAction>();

            if (RoleIDS.Length > 0)
            {
                RoleActionList = tRoleAction.GetModelList("RoleID in (" + RoleIDS + ")");
            }

            //加载所有权限代码
            List <E_tb_Action> ActionList = tAction.GetModelList("");

            ActionList.ForEach(p =>
            {
                ViewData[p.ActionCode] = (RoleActionList.Where(o => o.ActionID == p.ActionID).Count() > 0);
                //ViewData[p.ActionCode] =true;
            });
        }