//递归遍历 protected void GetTreeNodes(ReasonCodeNode startNode, ReasonCodeNode father) { startNode.ParentNode = father; startNode.SonNodes = NodeData.Where(x => x.ParentSysNo.HasValue && x.ParentSysNo.Value == startNode.SysNo).ToList(); foreach (ReasonCodeNode node in startNode.SonNodes) { GetTreeNodes(node, startNode); } }
//节点数据转成树 public void BuildTreeByData() { if (NodeData != null) { //RootNode NodeTree = new ReasonCodeNode { SonNodes = new List <ReasonCodeNode>(), SysNo = 0 }; //BuildTree GetTreeNodes(NodeTree, null); this.tvNodeTree.ItemsSource = NodeTree.SonNodes; } }
//查找数据 private void FindNodes(Func <ReasonCodeNode, bool> predicate, ReasonCodeNode node, List <ReasonCodeNode> result) { if (predicate(node)) { result.Add(node); } if (node.SonNodes != null) { foreach (ReasonCodeNode son in node.SonNodes) { FindNodes(predicate, son, result); } } }
//遍历获取Path private string GetReasonCodePath(ReasonCodeNode node, string path) { if (node == null) { return(string.Empty); } string sonpath = string.IsNullOrEmpty(path)?"":">" + path; string currentPath = node.Description + sonpath; if (node.ParentNode != null) { currentPath = GetReasonCodePath(node.ParentNode, currentPath); } return(currentPath); }