public static List <SelfReferentialItem> GetCollection(IEntityRepository <T> boService, bool useSpace) { var pCollection = boService.GetAll().OrderBy(s => s.SortCode); 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); } }
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 TreeNode GetTreeNode(SelfReferentialItem selfReferentialItem) { var node = new TreeNode(); node.Text = selfReferentialItem.DisplayName; node.Icon = "glyphicons glyphicons-folder-minus"; node.SelectedIcon = "glyphicons glyphicons-folder-plus"; node.Href = "gotoTypePage(\"" + selfReferentialItem.ID + "\")"; return(node); }
private static TreeNode _GetTreeNode(SelfReferentialItem selfReferentialItem) { var node = new TreeNode(); node.Id = selfReferentialItem.ID; node.Text = selfReferentialItem.DisplayName; node.Icon = "glyphicons glyphicons-folder-minus"; node.SelectedIcon = "glyphicons glyphicons-folder-plus"; node.Href = "javascript:gotoTypePage('" + selfReferentialItem.ID + "')"; return(node); }
/// <summary> /// 递归处理 /// </summary> /// <param name="rootTreeNode"></param> /// <param name="rootSourceNode"></param> /// <param name="sourceItems"></param> private static void _GetSubNodes(TreeNode 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 = _GetTreeNode(item); rootTreeNode.Nodes.Add(treeNode); _GetSubNodes(treeNode, item, sourceItems); } }
/// <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); } }
/// <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); }