示例#1
0
        /// <summary>
        /// 插入节点
        /// </summary>
        /// <param name="ParentNode"></param>
        public ContractBoiNode InsertNode(ContractBoiNode ParentNode = null)
        {
            String          strParentCode;
            String          strMaxCode;
            String          strNewCode;
            int             iNewCode;
            ContractBoiNode nodeNew = new ContractBoiNode();

            if (ParentNode != null)
            {
                strParentCode = ParentNode.ItemCode;
                strMaxCode    = ParentNode.Children.Max(m => m.ItemCode);
                if (String.IsNullOrEmpty(strMaxCode))
                {
                    strNewCode = strParentCode + "001";
                }
                else
                {
                    iNewCode = System.Convert.ToInt32(strMaxCode.Substring(strMaxCode.Length - 3, 3)) + 1;
                    if (iNewCode > 999)
                    {
                        throw new BusinessException("清单项超出限制(子项不多余999项)");
                    }
                    strNewCode = strParentCode + iNewCode.ToString().PadLeft(3, '0');
                }
                ParentNode.Children.Add(nodeNew);
                nodeNew.ParentCode = ParentNode.ItemCode;
            }
            else
            {
                strMaxCode = RootList.Max(m => m.ItemCode);
                if (String.IsNullOrEmpty(strMaxCode))
                {
                    strNewCode = "01";
                }
                else
                {
                    iNewCode = System.Convert.ToInt32(strMaxCode) + 1;
                    if (iNewCode > 99)
                    {
                        throw new BusinessException("清单项超出限制(顶层项不多余99项)");
                    }
                    strNewCode = iNewCode.ToString().PadLeft(2, '0');
                }
                RootList.Add(nodeNew);
            }
            nodeNew.ItemCode      = strNewCode;
            nodeNew.ProjectNo     = ProjectNo;
            nodeNew.BoQNo         = Boq.BoQNo;
            nodeNew.ParentBoiNode = ParentNode;
            CalcNode(nodeNew);
            NodeList.Add(nodeNew);

            if (ListChanged != null)
            {
                ListChanged();
            }
            return(nodeNew);
        }