public ActionResult List() { using (var db = DbAccess.DbFrameworkContext.Create()) { //获取全部机构数据 var items = db.T_QWF_Org.AsNoTracking().Where(w => w.IsDelete == 0).OrderBy(o => o.SortId).ThenBy(o => o.OrgName).AsQueryable().ToList(); var tree = new Web.UI.TreeConverter <DbAccess.T_QWF_Org>(); tree.GetId = m => { return(m.OrgId.ToString()); }; tree.GetParentId = m => { return(m.ParentId.ToString()); }; var result = tree.ConvertTo(item => { var node = new Models.OrganizactionTreeGrid(); node.id = item.OrgId.ToString(); node.OrgId = item.OrgId; node.ParentId = item.ParentId; node.OrgName = item.OrgName; node.OrgCode = item.OrgCode; node.IsOutName = item.IsOut == 1 ? "外部" : "内部"; node.IsOut = item.IsOut == 1?true:false; node.Remarks = item.Remarks; node.CreateTime = item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"); node.UpdateTime = item.UpdateTime == null ? string.Empty : item.UpdateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); node.OrgAttribute = item.OrgAttribute; node.OrgAttributeName = ((QWF.Framework.Services.SvrModels.SvrOrgInfo.OrgAttributeEnum)item.OrgAttribute).ToString(); return(node); }, items, "0"); return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(result))); } }
/// <summary> /// QWebFramework/Common/GetOrgTree /// </summary> /// <returns></returns> public ActionResult GetOrgTree() { using (var db = DbAccess.DbFrameworkContext.Create()) { var rows = db.T_QWF_Org.AsNoTracking().Where(w => w.IsDelete == 0).OrderBy(o => o.SortId).ThenBy(o => o.OrgName).ToList(); var tree = new Web.UI.TreeConverter <DbAccess.T_QWF_Org>(); tree.ClosedLayer = 2;//这里要全部展开。否则是会异步加载 tree.GetId = m => { return(m.OrgId.ToString()); }; tree.GetParentId = m => { return(m.ParentId.ToString()); }; //映射字段 var treeList = tree.ConvertTo(item => { var node = new Web.UI.BaseTreeNode(); node.id = item.OrgId.ToString(); node.text = item.OrgName; return(node); }, rows, "0"); return(this.Content(JsonConvert.SerializeObject(treeList))); } }
public ActionResult GetConfigTreeGrid() { using (var db = DbAccess.DbFrameworkContext.Create()) { var rows = db.T_QWF_Config.AsNoTracking().Where(w => w.IsDelete == 0).OrderBy(o => o.SortId).ToList(); var tree = new Web.UI.TreeConverter <DbAccess.T_QWF_Config>(); tree.ClosedLayer = 2;//这里要全部展开。否则是会异步加载 tree.GetId = m => { return(m.ConfigId.ToString()); }; tree.GetParentId = m => { return(m.ParentId.ToString()); }; //映射字段 var treeList = tree.ConvertTo(item => { var node = new Models.ConfigTreeGrid(); node.id = item.ConfigId.ToString(); node.text = item.ConfigName; node.ConfigId = item.ConfigId; node.ConfigName = item.ConfigName; node.ConfigCode = item.ConfigResourceCode; node.ConfigValue = item.ConfigValue; node.Remarks = item.ConfigRemarks; node.ValueType = item.ConfigValueType; node.CreateTime = item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"); node.UpdateTime = item.UpdateTime == null ? string.Empty : item.UpdateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); return(node); }, rows, "0"); return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(treeList))); } }
public ActionResult GetMenuTree() { var roleId = this.Request["roleId"].SafeConvert().ToInt32(0); using (var db = DbAccess.DbFrameworkContext.Create()) { var rows = (from a in db.T_QWF_Menu join b in db.T_QWF_RoleInMenu on new { a.MenuId, RoleId = roleId } equals new { b.MenuId, b.RoleId } into cc from d in cc.DefaultIfEmpty() orderby a.SortId select new Models.RoleInMenu { IsSubNode = a.IsSubNode, MenuName = a.MenuName, ParentId = a.ParentId, MenuId = a.MenuId, RoleId = d.RoleId, }).ToList(); var tree = new Web.UI.TreeConverter <Models.RoleInMenu>(); tree.GetId = m => { return(m.MenuId.ToString()); }; tree.GetParentId = m => { return(m.ParentId.ToString()); }; tree.GetCheckbox = m => { return(m.RoleId != null && m.IsSubNode == 0 ? true : (bool?)null); }; //映射字段 var treeList = tree.ConvertTo(item => { var node = new Web.UI.BaseTreeNode(); node.id = item.MenuId.ToString(); //node.checkbox = item.RoleId node.text = item.MenuName; return(node); }, rows.ToList(), "0"); return(this.Content(Newtonsoft.Json.JsonConvert.SerializeObject(treeList))); } }
// GET: QWebFramework/Common/GetUserLeftMenu public ActionResult GetUserLeftMenu() { var curUser = QWF.Framework.Web.UserContext.GetCurrentInfo(); using (var db = QWF.Framework.DbAccess.DbFrameworkContext.Create()) { //权限过滤 var qryMenuIds = (from a in db.T_QWF_RoleInMenu join b in db.T_QWF_UserInRole on a.RoleId equals b.RoleId join c in db.T_QWF_Menu on a.MenuId equals c.MenuId where b.UserId == curUser.CurrentUserId && c.IsShow == 1 select c.MenuIdList).ToList(); List <int> menuIds = new List <int>(); foreach (var ids in qryMenuIds) { ids.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => { if (id.Length > 0) { menuIds.Add(id.SafeConvert().ToInt32()); } }); } menuIds = menuIds.Distinct().ToList(); var rows = db.T_QWF_Menu.Where(w => menuIds.Contains(w.MenuId)).OrderBy(o => o.SortId).Select(s => new Models.LeftMenuTree { MenuId = s.MenuId, ParentId = s.ParentId, MenuName = s.MenuName, DefaultUrl = s.DefaultUrl, IconCls = s.IconCls, Target = s.Target }).ToList(); var tree = new Web.UI.TreeConverter <Models.LeftMenuTree>(); //设置树属性 tree.ClosedLayer = 1; tree.GetId = m => { return(m.MenuId.ToString()); }; tree.GetParentId = m => { return(m.ParentId.ToString()); }; //tree.SetSelectedId = "100005"; //转化 var treeList = tree.ConvertTo(item => { //设置每个树节点的数据 var node = new Web.UI.BaseTreeNode(); node.id = item.MenuId.ToString(); node.text = item.MenuName; node.iconCls = item.IconCls; //扩展属性 dynamic attributes = new ExpandoObject(); attributes.url = ConvertUrl(item.DefaultUrl); attributes.menuId = item.MenuId; attributes.target = item.Target; node.attributes = attributes; return(node); }, rows, "100000"); return(this.Content(JsonConvert.SerializeObject(treeList))); } }