Esempio n. 1
0
        private async Task <IEnumerable <Depts> > LL(long?parentId, long?targetId)
        {
            using (var db = new DbContext())
            {
                var   rep    = db.CreateTreeRepository <Depts>();
                Depts parent = parentId == null ? null : db.Depts.Get(parentId);
                var   list   = await rep.QueryChildren(parent)
                               .Select(s => s.ExtendAs <Depts>(() => new Depts
                {
                    HasChildren = rep.HasChildren(s, null)
                }))
                               .ToListAsync();

                if (targetId != null && !TreeNodeExpandChecker.IsExpanded())
                {
                    var target = await db.Depts.GetAsync(targetId);

                    var parents = await rep.RecurrenceParent(target).Select(s => s.DeptID).ToListAsync();

                    await list.ExpandAsync(parents, async childId => await LL(childId, targetId),
                                           parents.Count - 1);
                }

                return(list);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取模块列表。
        /// </summary>
        /// <param name="parentId">父节点ID。</param>
        /// <param name="targetId">目标节点ID,即要展开并选定的节点。</param>
        /// <param name="currentId">当前节点,在添加节点的时候要把当前节点排除。</param>
        /// <param name="state">状态。</param>
        /// <returns></returns>
        public virtual List <SysModule> GetModules(int?parentId, int?targetId, int?currentId, StateFlags?state)
        {
            SysModule parent = null;

            if (parentId != null)
            {
                parent = context.SysModules.FirstOrDefault(s => s.ModuleID == parentId);
            }

            var treeOper = context.CreateTreeRepository <SysModule>();
            var result   = treeOper.QueryChildren(parent)
                           //如果指定currentId,则需要排除
                           .AssertWhere(currentId != null, s => s.ModuleID != currentId)
                           .OrderBy(s => s.OrderNo)
                           //把HasChildren属性扩展出来
                           .Select(s => s.ExtendAs <SysModule>(() => new SysModule
            {
                HasChildren = treeOper.HasChildren(s, null),
            }))
                           .ToList();

            //如果要定位到指定的节点,则递归处理
            if (targetId != null && !TreeNodeExpandChecker.IsExpanded())
            {
                var target  = context.SysModules.Get(targetId);
                var parents = treeOper.RecurrenceParent(target).Select(s => s.ModuleID).ToList();

                result.Expand(parents, childId => GetModules(childId, targetId, currentId, state),
                              parents.Count - 1);
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">父id。</param>
        /// <param name="targetId">目标id,按它所在的路径进行展开,以便选中它。</param>
        /// <param name="currentId">当前修改的id,防止树中列出它。</param>
        /// <returns></returns>
        private List <Dept> GetDepts(int?id, int?targetId, int?currentId)
        {
            var result = new List <Dept>();

            using (var context = new DbContext())
            {
                Dept parent = null;
                if (id != null)
                {
                    parent = context.Depts.Get(id);
                }

                var persister = context.CreateTreePersister <Dept>();

                //获得孩子的同时再判断是否有孙子
                var children = from s in persister.QueryChildren(parent)
                               select new { s, HasChildren = persister.HasChildren(s, null) };

                foreach (var child in children)
                {
                    if (child.s.Id == currentId)
                    {
                        continue;
                    }

                    result.Add(child.s);
                    child.s.HasChildren = child.HasChildren;
                    child.s.Children    = new List <Dept>();
                }


                if (targetId != null && !TreeNodeExpandChecker.IsExpanded())
                {
                    //获得它的所有父id,根据编码000100010001这样从后往前递归
                    var target = context.Depts.Get(targetId);
                    if (target != null)
                    {
                        var parents = persister.RecurrenceParent(target).Select(s => s.Id).ToList();
                        result.Expand(parents, s => GetDepts(s, targetId, currentId), parents.Count - 1);
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取机构列表
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="targetId"></param>
        /// <param name="currentId"></param>
        /// <param name="state"></param>
        /// <param name="keyword"></param>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public virtual List <SysOrg> GetOrgs(int?parentId, int?targetId, int?currentId, StateFlags?state, string keyword, OrgAttribute?attribute)
        {
            if (!string.IsNullOrEmpty(keyword))
            {
                return(context.SysOrgs
                       .Where(s => (s.Name.Contains(keyword)) && !s.Code.StartsWith("99"))
                       .AssertWhere(attribute != null, s => s.Attribute <= attribute && s.Attribute != 0)
                       .AssertWhere(state != null, s => s.State == state)
                       .ToList());
            }

            SysOrg parent = null;

            if (parentId != null)
            {
                parent = context.SysOrgs.FirstOrDefault(s => s.OrgID == parentId);
            }

            var treeOper = context.CreateTreeRepository <SysOrg>();
            var result   = treeOper.QueryChildren(parent)
                           .AssertWhere(attribute != null, s => s.Attribute <= attribute && s.Attribute != 0)
                           //如果指定currentId,则需要排除
                           .AssertWhere(currentId != null, s => s.OrgID != currentId)
                           .AssertWhere(state != null, s => s.State == state)
                           .Where(s => !s.Code.StartsWith("99"))
                           .OrderBy(s => s.OrderNo)
                           //把HasChildren属性扩展出来
                           .Select(s => s.ExtendAs <SysOrg>(() => new SysOrg
            {
                HasChildren   = treeOper.HasChildren(s, t => attribute == null || (attribute != null && t.Attribute <= attribute && t.Attribute != 0)),
                AttributeName = s.Attribute.GetDescription()
            }))
                           .ToList();

            if (targetId != null && !TreeNodeExpandChecker.IsExpanded())
            {
                var target  = context.SysOrgs.Get(targetId);
                var parents = treeOper.RecurrenceParent(target).Select(s => s.OrgID).ToList();

                result.Expand(parents, childId => GetOrgs(childId, targetId, currentId, state, string.Empty, attribute),
                              parents.Count - 1);
            }

            return(result);
        }