Beispiel #1
0
        /// <summary>
        /// 根据指定的类型,将对应的对象集合转换为 List<SelfReferentialItem>。
        /// </summary>
        /// <param name="pCollection">对象集合</param>
        /// <param name="useSpace">返回的数据中,是否在 Name 属性前面,根据层次添加空格</param>
        /// <returns></returns>
        public static List <SelfReferentialItem> GetCollection(List <T> pCollection, bool useSpace)
        {
            PropertyInfo[] properties     = typeof(T).GetProperties();
            var            parentProperty = properties.FirstOrDefault(x => x.PropertyType.Name == typeof(T).Name);
            var            pItems         = new List <SelfReferentialItem>();

            foreach (var item in pCollection)
            {
                var pItem = new SelfReferentialItem
                {
                    ID          = item.ID.ToString(),
                    DisplayName = item.Name,
                    SortCode    = item.SortCode
                };

                var pObject = (T)parentProperty.GetValue(item);
                pItem.ParentID = pObject.ID.ToString();

                pItems.Add(pItem);
            }

            if (useSpace)
            {
                return(SetHierarchical(pItems));
            }
            else
            {
                return(pItems);
            }
        }
Beispiel #2
0
        public static async Task <List <SelfReferentialItem> > GetCollectionAsyn(IEntityRepository <T> boRepository, Expression <Func <T, bool> > predicate, bool useSpace)
        {
            var pCollection = await boRepository.GetBoCollectionAsyn(predicate);

            PropertyInfo[] properties     = typeof(T).GetProperties();
            var            parentProperty = properties.FirstOrDefault(x => x.PropertyType.Name == typeof(T).Name);
            var            pItems         = new List <SelfReferentialItem>();

            foreach (var item in pCollection.OrderBy(s => s.SortCode))
            {
                var pItem = new SelfReferentialItem
                {
                    ID          = item.ID.ToString(),
                    DisplayName = item.Name,
                    SortCode    = item.SortCode
                };

                var pObject = (T)parentProperty.GetValue(item);
                pItem.ParentID = pObject.ID.ToString();

                pItems.Add(pItem);
            }

            if (useSpace)
            {
                return(SetHierarchical(pItems));
            }
            else
            {
                return(pItems);
            }
        }
Beispiel #3
0
        public static TreeNodeForJsTree GetTreeRootNode(string id, SelfReferentialItem selfReferentialItem)
        {
            var node = new TreeNodeForJsTree();

            node.Id     = id;
            node.Parent = "#";
            node.Text   = selfReferentialItem.DisplayName;
            node.Icon   = "far fa-edit";
            return(node);
        }
Beispiel #4
0
        private static void _GetCollectionToRoot(SelfReferentialItem currentNode, List <SelfReferentialItem> source, List <SelfReferentialItem> result)
        {
            result.Add(currentNode);
            var nextItem = source.Where(x => x.ID == currentNode.ParentID).FirstOrDefault();

            if (currentNode.ID != currentNode.ParentID)
            {
                _GetCollectionToRoot(nextItem, source, result);
            }
        }
        public static TreeNodeForBootStrapTreeView GetTreeNode(SelfReferentialItem selfReferentialItem)
        {
            var node = new TreeNodeForBootStrapTreeView();

            node.Text = selfReferentialItem.DisplayName;
            node.Icon = "glyphicons glyphicons-folder-minus";
            //node.SelectedIcon = "glyphicons glyphicons-folder-plus";
            //node.Href = "gotoTypePage(\"" + selfReferentialItem.ID + "\")";
            return(node);
        }
Beispiel #6
0
        /// <summary>
        /// 递归处理
        /// </summary>
        /// <param name="rootTreeNode"></param>
        /// <param name="rootSourceNode"></param>
        /// <param name="sourceItems"></param>
        private static void _GetSubNodes(TreeNodeForJsTree rootTreeNode, SelfReferentialItem rootSourceNode, List <SelfReferentialItem> sourceItems)
        {
            var subItems = sourceItems.Where(sn => sn.ParentID == rootSourceNode.ID && sn.ID != rootSourceNode.ParentID).OrderBy(o => o.SortCode);

            foreach (var item in subItems)
            {
                var treeNode = _GetSubTreeNode(item);
                rootTreeNode.Nodes.Add(treeNode);
                _GetSubNodes(treeNode, item, sourceItems);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 递归构建层次节点
        /// </summary>
        /// <param name="rootNode"></param>
        /// <param name="spaceNumber"></param>
        /// <param name="source"></param>
        /// <param name="result"></param>
        private static void _GetHierarchicalStyleSubItems(SelfReferentialItem rootNode, int spaceNumber, List <SelfReferentialItem> source, List <SelfReferentialItem> result)
        {
            var subItems = source.Where(sn => sn.ParentID == rootNode.ID && sn.ID != rootNode.ParentID).OrderBy(o => o.SortCode);

            foreach (var subItem in subItems.OrderBy(s => s.SortCode))
            {
                var ttt = _SpaceLength(spaceNumber);
                subItem.DisplayName = _SpaceLength(spaceNumber) + subItem.DisplayName;
                result.Add(subItem);
                _GetHierarchicalStyleSubItems(subItem, spaceNumber + 1, source, result);
            }
        }
Beispiel #8
0
        private static TreeNodeForJsTree _GetSubTreeNode(SelfReferentialItem selfReferentialItem)
        {
            var node = new TreeNodeForJsTree
            {
                Id     = selfReferentialItem.ID,
                Parent = "#",
                Text   = selfReferentialItem.DisplayName,
                Icon   = "glyphicons glyphicons-folder-minus"
            };

            return(node);
        }
Beispiel #9
0
        /// <summary>
        /// 根据指定的类型,直接转换为 SelfReferentialItem
        /// </summary>
        /// <param name="bo"></param>
        /// <returns></returns>
        public static SelfReferentialItem Get(T bo)
        {
            PropertyInfo[] properties     = typeof(T).GetProperties();
            var            parentProperty = properties.Where(x => x.PropertyType.Name == typeof(T).Name).FirstOrDefault();

            var pItem = new SelfReferentialItem()
            {
                ID = bo.ID.ToString()
            };
            var pObject = (T)parentProperty.GetValue(bo);

            pItem.ParentID    = pObject.ID.ToString();
            pItem.DisplayName = pObject.Name;
            pItem.SortCode    = pObject.SortCode;

            return(pItem);
        }