private IEnumerable <dynamic> GetMenuColumns(MenuColumnType ctype) { string key = ServiceConst.MenuColumnListCache; var list = CacheHelper.Get <IEnumerable <dynamic> >(key); if (list == null || list.Count() < 1) { var columnSql = this.GetSqlLam <MenuColumn>(); columnSql.Where(m => m.ENABLED == true); columnSql.SelectAll(); var tableSql = columnSql.Join <MenuTable>((c, t) => c.TABLEID == t.ID, aliasName: "b"); tableSql.Select(m => new { m.ALIASNAME }); list = this.GetDynamicList(columnSql.GetSql(), columnSql.GetParameters()); CacheHelper.Add(key, list); } if (list != null) { int type = (int)ctype; list = list.Where(m => m.TYPE == type); } return(list); }
public IEnumerable <MenuColumn> GetAuthColumnList(int menuId, int uid, MenuColumnType type) { // string sqlText = @";WITH //TREE AS( //SELECT ID,PARENTID,OBJECTID FROM dbo.SYS_MENU //WHERE ID =@mid AND ENABLED=1 //UNION ALL //SELECT a.ID,a.PARENTID,a.OBJECTID FROM dbo.SYS_MENU AS a ,TREE AS b //WHERE b.ID=a.PARENTID AND a.ENABLED=1) //SELECT b.* FROM TREE AS a LEFT JOIN dbo.SYS_MENUCOLUMN AS b ON a.OBJECTID=b.ID LEFT JOIN dbo.SYS_ROLEMENU AS c ON c.MENUID=a.ID AND ROLEID IN(SELECT ROLEID FROM dbo.SYS_ROLEUSER WHERE USERID=@uid) //WHERE a.OBJECTID IS NOT NULL AND b.ENABLED=1 AND c.ID IS NOT NULL AND b.TYPE=@type //ORDER BY b.SORTID"; string sqlText = @" SELECT * FROM dbo.SYS_MENUCOLUMN AS a WHERE MENUID IN( SELECT OBJECTID FROM ( SELECT OBJECTID,ID FROM dbo.SYS_MENU WHERE ID=@mid AND OBJECTID IS NOT NULL UNION SELECT OBJECTID,ID FROM dbo.SYS_MENU WHERE PARENTID=@mid AND OBJECTID IS NOT NULL ) AS a LEFT JOIN dbo.SYS_ROLEMENU AS b ON a.ID=b.MENUID WHERE b.ROLEID IN(SELECT ROLEID FROM dbo.SYS_ROLEUSER AS a WHERE USERID=@uid) ) AND a.ENABLED=1 AND a.TYPE=@type "; Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("@mid", menuId); dic.Add("@uid", uid); dic.Add("@type", (int)type); return(base.GetList <MenuColumn>(sqlText, dic)); }
public AuthMenu GetAuthMenuList(string url, MenuType type = MenuType.Menu, MenuColumnType columnType = MenuColumnType.CONDITION) { if (string.IsNullOrEmpty(url)) { return(new AuthMenu()); } url = url.ToLower(); var list = this.GetAuthList(); if (list != null && list.Count() > 0) { var tempList = list.Where(m => { if (string.IsNullOrEmpty(m.URL)) { return(false); } string[] urls = m.URL.Split('|'); bool flag = false; foreach (var item in urls) { flag = string.Equals(item, url, StringComparison.InvariantCultureIgnoreCase); if (flag) { break; } } return(flag); }); if (type == MenuType.Menu) { return(new AuthMenu(tempList)); } else if (type == MenuType.Button) { AuthMenu am = new AuthMenu(); int menuId = 0; if (tempList != null && tempList.Count() > 0) { int menuType = (int)type; var menu = tempList.FirstOrDefault(); am.Menus = list.Where(m => m.PARENTID == menu.ID && m.TYPE == menuType); //查找 按钮 为 查询 或 下载的 菜单 if (am.Menus != null) { string btn_code = columnType == MenuColumnType.CONDITION ? WebConst.MENU_BUTTON_CODE_CONDITION : WebConst.MENU_BUTTON_CODE_REPORT; var obj = am.Menus.FirstOrDefault(m => string.Equals(m.CODE, btn_code, StringComparison.InvariantCultureIgnoreCase)); if (obj != null) { menuId = obj.ID; } } } int uid = log.User.ID; if (menuId > 0) { am.Columns = menuRep.GetAuthColumnList(menuId, uid, columnType); } return(am); } } return(new AuthMenu()); }