Exemple #1
0
        //public delegate int OneStepTravers(MultTreeNode node);

        ///** 遍历一棵树,深度遍历 */
        //public void depthtraverse(OneStepTravers stepbef, OneStepTravers stepafter)
        //{
        //    if (stepbef != null)
        //        stepbef(this);

        //    if (childList != null)
        //    {
        //        int childNumber = childList.Count;
        //        for (int i = 0; i < childNumber; i++)
        //        {
        //            MultTreeNode child = childList.ElementAt(i);
        //            child.depthtraverse(stepbef, stepafter);
        //        }
        //    }
        //    if (stepafter != null)
        //        stepafter(this);
        //}
        #endregion loop

        #region node test  无用代码
        //public void print(String content)
        //{
        //    System.Diagnostics.Debug.WriteLine(content);
        //}

        //public void print(int content)
        //{
        //    System.Diagnostics.Debug.WriteLine(content.ToString());
        //}
        #endregion node test
        #endregion

        #region  无用代码
        #region set
        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="childList"></param>
        //public void setChildList(List<MultTreeNode> childList)
        //{
        //    this.childList = childList;
        //}

        /// <summary>
        /// 设置父节点的id
        /// </summary>
        /// <param name="Parent"></param>
        //public void setParent(string Parent)
        //{
        //    this.parentId = Parent;
        //}


        #region  无用代码
        //public void setParentId(int parentId)
        //{
        //    this.parentId = parentId;
        //}

        #endregion

        /// <summary>
        /// 设置节点的id
        /// </summary>
        /// <param name="selfId"></param>
        //public void setSelfId(string selfId)
        //{
        //    this.selfId = selfId;
        //}

        /// <summary>
        /// 设置当前节点的父节点
        /// </summary>
        /// <param name="parentNode"></param>
        //public void setParentNode(MultTreeNode parentNode)
        //{
        //    this.parentNode = parentNode;
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="nodeName"></param>
        //public void setNodeName(string nodeName)
        //{
        //    this.nodeName = nodeName;
        //}

        //public void setObj(Object obj)
        //{
        //    this.obj = obj;
        //}
        #endregion set
        #endregion
        #endregion

        #region find  查找节点

        #region  查找节点
        /// <summary>
        /// 通过id找到节点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MultTreeNode findNodeById(string id)
        {
            if (this.selfId == id)
            {
                return(this);
            }
            if (isLeaf())
            {
                return(null);
            }
            else
            {
                int childNumber = childList.Count;
                for (int i = 0; i < childNumber; i++)
                {
                    MultTreeNode child      = childList.ElementAt(i);
                    MultTreeNode resultNode = child.findNodeById(id);
                    if (resultNode != null)
                    {
                        return(resultNode);
                    }
                }
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 在当前的节点后面插入节点
        /// </summary>
        public void InsertNodeAfter(MultTreeNode treeNode)
        {
            int i = this.parentNode.childList.IndexOf(this);

            treeNode.ParentNode = this.ParentNode;
            this.parentNode.childList.Insert(i + 1, treeNode);
        }
Exemple #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="pNode">传入节点</param>
        public void init(MultTreeNode pNode = null)
        {
            if (childList == null)
            {
                childList = new List <MultTreeNode>();
            }
            //   parentId = "0";
            selfId   = "0";
            nodeName = "0";
            obj      = null;

            if (pNode != null)
            {
                nodeName = pNode.NodeName;
                selfId   = pNode.SelfId;

                if (pNode.Obj != null)
                {
                    //obj = new Hashtable((Hashtable)pNode.getObj());
                    obj = pNode.Obj;
                }

                if (pNode.getChildList() != null)
                {
                    childList = new List <MultTreeNode>(pNode.getChildList());
                }

                if (pNode.ParentNode != null)
                {
                    parentNode = pNode.ParentNode;
                    pNode.parentNode.childList.Add(this);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// 在当前节点出入子节点
 /// </summary>
 public void InsertChildNode(MultTreeNode treeNode)
 {
     if (childList == null)
     {
         childList = new List <MultTreeNode>();
     }
     treeNode.ParentNode = this;
     childList.Add(treeNode);
 }
Exemple #5
0
        /// <summary>
        ///  删除当前节点的某个子节点,当传入childId=""时删除,所有子节点
        /// </summary>
        /// <param name="childId"></param>
        public void deleteChildNode(string childId = "")
        {
            //  List<MultTreeNode> childList = this.getChildList();
            int childNumber = childList.Count;

            for (int i = 0; i < childNumber; i++)
            {
                MultTreeNode child = childList.ElementAt(i);
                if (child.SelfId == childId || childId == "")
                {
                    childList.RemoveAt(i);
                    return;
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="pNode">传入节点</param>
 public MultTreeNode(MultTreeNode pNode)
 {
     init(pNode);
 }