Beispiel #1
0
    public void init(MultTreeNode pNode = null)
    {
        if (childList == null)
        {
            childList = new List <MultTreeNode>();
        }
        parentId = 0;
        selfId   = 0;
        nodeName = "";
        obj      = null;

        if (pNode != null)
        {
            nodeName = pNode.getNodeName();
            if (pNode.getObj() != null)
            {
                obj = new Hashtable((Hashtable)pNode.getObj());
            }
            parentNode = pNode.getParentNode();
            if (pNode.getChildList() != null)
            {
                childList = new List <MultTreeNode>(pNode.getChildList());
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// find one note in tree.
    /// 2016-03-04 16:21:34
    /// modify when empty path .return this instead of null.
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public MultTreeNode findNodeByPath(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(this);
        }
        //path = StrUtils.FormatPath(path);
        //path = StrUtils.GetSDirString(path);
        string[] pathArr = path.Split(new char[] { '\\' }); //StrUtils.Split(path, "\\"); //path.Split('\\');
        if (pathArr[0] == null)
        {
            pathArr[0] = path;
        }

        // make sure this is root path.
        if (nodeName != pathArr[0])
        {
            return(null);
        }

        MultTreeNode node = this;

        for (int i = 0; i < pathArr.Count(); i++)
        {
            // 说明:注释。不知道为什么要加这句 可能会影响代码生成。需要注意
            // 修改为 break; => continue; \ 查找具有 相同节点名称的 子节点 逻辑
            // 短暂测试是正常的。
            // 修改日期:2014-8-5 14:20:28
            if (string.IsNullOrEmpty(pathArr[i]))
            {
                List <MultTreeNode> list = node.getChildList();
                if (i < pathArr.Count() - 1)
                {
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (list[j].getNodeName() == pathArr[i + 1])
                        {
                            node = list[j];
                        }
                    }
                }
                continue;
            }
            // use path to avoid error like 0\0\0
            // 2016-07-11 21:34:54
            string nodePath = node.getPath();
            string testPath = StrUtils.FromArr(ArrayUtils.SplitArray <string>(pathArr, 0, i - 1), "\\");

            if (node.getNodeName() == pathArr[i] && nodePath == testPath)
            {
                List <MultTreeNode> list = node.getChildList();
                for (int j = 0; j < list.Count; j++)
                {
                    if (i + 1 < pathArr.Length && list[j].getNodeName() == pathArr[i + 1])
                    {
                        node = list[j];
                    }
                }
            }
            else
            {
                node = null;
                break;
            }
        }
        return(node);
    }