Пример #1
0
        public ActionResult MainMenus()
        {
            List <B_Menu> menus = B_Menu.GetEntitysAll().OrderBy(s => s.Sort).ToList();

            menus = menus.FindAll(m => m.ParentID == 0);
            return(View(menus));
        }
Пример #2
0
        public ContentResult MenusToAdd(B_Menu menu)
        {
            menu.IsShow  = Request["IsShow"] != null && Request["IsShow"].ToString() == "on" ? true : false;
            menu.IsValid = Request["IsValid"] != null && Request["IsValid"].ToString() == "on" ? true : false;
            menu.IsRobot = Request["IsRobot"] != null && Request["IsRobot"].ToString() == "on" ? false : true;

            if (string.IsNullOrWhiteSpace(menu.MenuName))
            {
                return(Content("名称不能为空"));
            }
            if (RepeatHelper.NoRepeat("B_Menu", "MenuName", menu.MenuName, menu.ID) > 0)
            {
                return(Content("菜单名已存在"));
            }
            if (!string.IsNullOrWhiteSpace(menu.MenuUrl) && RepeatHelper.NoRepeat("B_Menu", "MenuUrl", menu.MenuUrl, menu.ID) > 0)
            {
                return(Content("菜单链接已存在"));
            }

            int rtn = menu.InsertAndReturnIdentity();

            if (rtn > 0)
            {
                bool hasMainMenuTag          = false;
                bool hasError                = false;
                List <B_MenuRights> muRights = null;
                if (string.IsNullOrWhiteSpace(menu.MenuUrl) == false)
                {
                    menu.MenuUrl = menu.MenuUrl.Trim().TrimEnd('/');
                    try
                    {
                        string[] arrUrl = menu.MenuUrl.TrimStart('/').Split('/');
                        Type     type   = Type.GetType("WeBusiness.Controllers." + arrUrl[0] + "Controller");
                        muRights = BaseAuthorizeHelper.GetBOMenuRightsByControllerType(type, arrUrl[1], out hasMainMenuTag);
                    }
                    catch (Exception ex)
                    {
                        DAL.Log.Instance.Write(ex.ToString(), "BOMenu_Add");
                        hasError = true;
                    }
                }

                if (hasMainMenuTag && muRights != null)
                {
                    B_MenuRights.RelevanceList(rtn, muRights);
                }
                if (hasError)
                {
                    return(Content("添加菜单成功,但菜单没有添加权限!"));
                }


                return(Content("ok"));
            }
            return(Content("添加出错"));
        }
Пример #3
0
        public ContentResult MenusToDel(int id)
        {
            if (B_Menu.DeleteAll(id))
            {
                B_MenuRights.ClearHashMenuRights();

                return(Content("ok"));
            }
            return(Content("删除出错"));
        }
Пример #4
0
        public ContentResult IsModuleShow(int id)
        {
            B_Menu menu = B_Menu.GetEntityByID(id);

            menu.IsValid = true;
            menu.IsShow  = true;
            menu.IsRobot = false;
            if (menu.UpdateByID() > 0)
            {
                return(Content("ok"));
            }
            return(Content("启用出错"));
        }
Пример #5
0
        public ContentResult MenusToUnValid(int id)
        {
            B_Menu menu = B_Menu.GetEntityByID(id);

            menu.IsValid = false;
            menu.IsShow  = false;
            menu.IsRobot = true;
            if (menu.UpdateByID() > 0)
            {
                return(Content("ok"));
            }
            return(Content("停用出错"));
        }
Пример #6
0
 public ContentResult UpdateAllRights()
 {
     try
     {
         List <B_Menu> menus    = B_Menu.GetEntitysAll();
         string        ErrorStr = "";
         foreach (B_Menu menu in menus)
         {
             if (menu.ParentID == 0)
             {
                 continue;
             }
             bool hasMainMenuTag          = false;
             List <B_MenuRights> muRights = null;
             if (string.IsNullOrWhiteSpace(menu.MenuUrl) == false)
             {
                 menu.MenuUrl = menu.MenuUrl.Trim().TrimEnd('/');
                 try
                 {
                     string   tmpUrl = menu.MenuUrl.TrimStart('/').Split('?')[0];
                     string[] arrUrl = tmpUrl.Split('/');
                     Type     type   = Type.GetType("WeBusiness.Controllers." + arrUrl[0] + "Controller");
                     muRights = BaseAuthorizeHelper.GetBOMenuRightsByControllerType(type, arrUrl[1], out hasMainMenuTag);
                 }
                 catch (Exception ex)
                 {
                     DAL.Log.Instance.Write(ex.ToString(), "BOMenu_Update");
                     ErrorStr += "【" + menu.MenuName + "】";
                 }
             }
             if (hasMainMenuTag && muRights != null)
             {
                 B_MenuRights.RelevanceList(menu.ID, muRights);
             }
             B_MenuRights.ClearHashMenuRights();
         }
         if (!string.IsNullOrWhiteSpace(ErrorStr))
         {
             return(Content("更新失败的菜单:" + ErrorStr));
         }
         return(Content("ok"));
     }
     catch (Exception ex)
     {
         DAL.Log.Instance.Write(ex.ToString(), "B_Menu_UpdateAllRights_error");
         return(Content("更新失败"));
     }
 }
Пример #7
0
        //Metodo para crear la información principal de los Balanced Scorecards en el Menu Dinámicamente
        public void CreateInfoMenu(string idbsc)
        {
            PnlTitulo.Controls.Clear();
            PnlContainer.Controls.Clear();
            int IdBSC = Convert.ToInt32(idbsc);

            objB_Menu = new B_Menu();
            E_BalancedScorecard ObjBSCMenu = new E_BalancedScorecard();

            ObjBSCMenu = objB_Menu.B_BSC_Menu(IdBSC);
            CreateTitle(ObjBSCMenu.BSNombre);
            CreateEnterprise(ObjBSCMenu.N_Empresa);
            CreateVision(ObjBSCMenu.Vision);
            CreateMision(ObjBSCMenu.Mision);
            CreateAgno(ObjBSCMenu.Agno);
            CreateActive(ObjBSCMenu.Active);
        }
Пример #8
0
        //
        // GET: /Home/

        public ActionResult Index(string url)
        {
            try
            {
                BaseAuthorizeModel auth = BaseAuthorizeHelper.GetAuthorizeModel(this.HttpContext);
                if (string.IsNullOrWhiteSpace(auth.TempDataMsg) == false)
                {
                    TempData["Msg"] = auth.TempDataMsg;
                }
                if (auth.IsAuthorize == false)
                {
                    string userAgent = Request.UserAgent;
                    return(RedirectToAction("Login", "Home", new { url = Request.Url.ToString() }));
                }
                B_User        user  = auth.CurrentSYSUser;
                List <B_Menu> menus = B_Menu.GetShowMenus();

                if (user.UserName != WeConfig.robot)
                {
                    menus.RemoveAll(m => m.IsRobot);
                }

                List <B_Role>       roles     = B_Role.GetUserRoles(user.UserName);
                List <B_MenuRights> rolerignt = B_MenuRights.GetRoleUser(roles[0].ID);
                ViewData["role"]     = (roles != null && roles.Count > 0) ? roles[0] : null;
                ViewData["menus"]    = menus;
                ViewData["url"]      = url;
                ViewData["UserRole"] = rolerignt;

                return(View(user));
            }
            catch (Exception ex)
            {
                DAL.Log.Instance.Write(ex.ToString());
                return(View(ErrorPage.ViewName, new ErrorPage {
                    Message = ex.ToString()
                }));
            }
        }
Пример #9
0
        public ActionResult B_RoleRight(int id)
        {
            B_Role dbBORoles = B_Role.GetEntityByID(id);

            if (dbBORoles == null)
            {
                return(View(ErrorPage.ViewName, new ErrorPage {
                    Message = "分配角色权限失败,角色不存在或已删除!"
                }));
            }

            List <B_Menu> Menus = B_Menu.GetValidMenus(true);

            if (CurrentUser.UserName != WeConfig.robot)
            {
                Menus.RemoveAll(m => m.IsRobot);

                foreach (var item in Menus)
                {
                    if (item.SubMenuList != null)
                    {
                        item.SubMenuList.RemoveAll(m => m.IsRobot);
                    }
                }
            }
            ViewBag.Menus      = Menus;
            ViewBag.MenuRights = B_MenuRights.GetEntitysDictionary();

            List <B_RoleRights> roRightsList = B_RoleRights.GetEntitysByRoleID(id);
            HashSet <int>       setRights    = new HashSet <int>();

            foreach (B_RoleRights roRights in roRightsList)
            {
                setRights.Add(roRights.RightID);
            }
            ViewBag.HashRights = setRights;
            ViewBag.dbBORoles  = dbBORoles;
            return(View());
        }
Пример #10
0
        //Metodo para crear los botones Dinámicamente según los Balanced Scorecards que el usuario tenga creados
        public void CreateButtonsBSC()
        {
            objB_Menu = new B_Menu();
            int labelcount = 0;

            foreach (E_BalancedScorecard record in objB_Menu.BalancedScorecards(Business_Logic_Layer.Credentials.CurUser.Username))
            {
                //Se crear la instancia del boton
                Button temp = new Button();

                //Se asignan las propiedades
                temp.Height    = 40;
                temp.Width     = 275;
                temp.Location  = new Point(0, y);
                y             += 46;
                temp.Name      = "Btn" + record.IdBalanced_Scorecard;
                temp.Text      = record.BSNombre;
                temp.FlatStyle = FlatStyle.Flat;
                temp.FlatAppearance.BorderSize         = 0;
                temp.FlatAppearance.MouseOverBackColor = Color.FromArgb(45, 45, 48);
                temp.ForeColor    = Color.White;
                temp.Font         = new Font("Century Gothic", 11, FontStyle.Italic);
                temp.Image        = Properties.Resources.BalancedScorecard;
                temp.ImageAlign   = ContentAlignment.MiddleLeft;
                temp.TextAlign    = ContentAlignment.MiddleRight;
                temp.AutoEllipsis = true;

                //Se adiciona el handler
                temp.Click += new EventHandler(ComunHandler_Click);

                //Se agrega el boton al panel vertical
                PnlVertical.Controls.Add(temp);

                labelcount++;
            }
            CreateLabelList(labelcount);
        }
Пример #11
0
        public ActionResult MenusEdit(int id)
        {
            B_Menu menu = B_Menu.GetEntityByID(id);

            return(View(menu));
        }
Пример #12
0
        public ActionResult Menus()
        {
            List <B_Menu> menus = B_Menu.GetEntitysAll();

            return(View(menus));
        }
Пример #13
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (CurrentUser != null)
            {
                var      tmpControllerName = ControllerName + "Controller";
                object[] arrObjects        = filterContext.ActionDescriptor.GetCustomAttributes(typeof(B_MenuRightsTagAttribute), false);
                if (arrObjects.Length > 0 && CurrentUser.UserName != WeConfig.robot)
                {
                    _MenuRightsTag = arrObjects[0] as B_MenuRightsTagAttribute;
                    if (_MenuRightsTag != null)
                    {
                        //如果不是主菜单则取主菜单方法名
                        string tmpActionName = _MenuRightsTag.IsMainMenu ? ActionName : _MenuRightsTag.MainMethod;
                        B_Menu menu          = B_MenuRights.GetMenu(tmpControllerName, tmpActionName);
                        string errMessage    = string.Empty;
                        if (menu != null && string.IsNullOrWhiteSpace(menu.MenuName) == false)
                        {
                            List <B_MenuRights> mrList = B_MenuRights.GetHashMenuRights(CurrentUser.UserName).FindAll(m => m.CodeOn == tmpControllerName);
                            bool isExists = false;
                            if (_MenuRightsTag.IsMainMenu)
                            {
                                isExists = mrList.Exists(m => m.MethodName == _MenuRightsTag.Name && m.MethodCode.ToLower() == ActionName.ToLower());
                            }
                            else
                            {
                                //继承主方法
                                isExists = mrList.Exists(m => m.MethodName == _MenuRightsTag.Name &&
                                                         (m.MethodCode == _MenuRightsTag.MainMethod || m.MethodCode.ToLower() == ActionName.ToLower() || m.HasInheritMethodCode(ActionName)));
                            }
                            if (isExists == false)
                            {
                                errMessage = "您没有" + menu.MenuName + _MenuRightsTag.Name + "权限的操作!";
                            }
                            if (menu.IsValid == false)
                            {
                                errMessage = "该页已停用,暂时不能访问";
                            }
                        }
                        else
                        {
                            //代码中已加权限标签,但菜单中没有添加该菜单或没获取到权限
                            errMessage = "您没有权限操作该页";
                        }

                        if (errMessage.Equals(string.Empty) == false)
                        {
                            filterContext.Result = GetErrorResult(errMessage);
                        }
                    }
                }
            }

            try
            {
                string filePath = AppDomain.CurrentDomain.BaseDirectory;
                if (!System.IO.Directory.Exists(filePath + "auth\\"))
                {
                    System.IO.Directory.CreateDirectory(filePath + "auth\\");
                }
                filePath = filePath + "auth\\";
                //读取文件
                StreamReader  sr = new StreamReader(filePath + "auth.log", Encoding.UTF8);
                String        line;
                List <string> auth = new List <string>();
                while ((line = sr.ReadLine()) != null)
                {
                    auth.Add(line.ToString());
                }
                sr.Close();

                if (auth[0] != auth[1])
                {
                    filterContext.Result = GetErrorResult(auth[2]);
                }
            }
            catch (Exception ex)
            {
            }
        }