Esempio n. 1
0
        /// <summary>
        /// 禁用和启用项
        /// </summary>
        /// <param name="Node"></param>
        /// <param name="Stat">true-启用项,false-禁用项</param>
        public void ChangeNodeStat(ContractBoiNode Node, Boolean Stat)
        {
            if (Node.Children.Count > 0)
            {
                for (int i = Node.Children.Count - 1; i >= 0; i--)
                {
                    ChangeNodeStat(Node.Children[i], Stat);
                    if (!Stat && !Node.Children[i].IsUse)
                    {
                        Node.Children.RemoveAt(i);
                        RecursionDeleteNode(Node.Children[i]);
                    }
                }
            }
            if (Node.IsUse)
            {
                Node.StatId = Stat ? 1 : 0;
            }
            else
            {
                if (Node.ParentBoiNode != null)
                {
                    Node.ParentBoiNode.Children.Remove(Node);
                }
                RecursionDeleteNode(Node);
            }

            if (ListChanged != null)
            {
                ListChanged();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 递归删除子节点
        /// </summary>
        /// <param name="NodeList"></param>
        /// <param name="Node"></param>
        private void RecursionDeleteNode(ContractBoiNode Node)
        {
            List <ContractBoiNode> lstChildren = Node.Children.ToList();

            if (lstChildren.Count > 0)
            {
                lstChildren.ForEach(m =>
                {
                    RecursionDeleteNode(m);
                    if (NodeList.Contains(m))
                    {
                        NodeList.Remove(m);
                    }
                    if (updateList.Contains(m))
                    {
                        updateList.Remove(m);
                    }
                });
            }
            if (NodeList.Contains(Node))
            {
                NodeList.Remove(Node);
            }
            if (updateList.Contains(Node))
            {
                updateList.Remove(Node);
            }
            if (Node.ParentBoiNode != null && Node.ParentBoiNode.Children.Contains(Node))
            {
                Node.ParentBoiNode.Children.Remove(Node);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 /// <summary>
 /// 清单父项值计算
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CalcParentNode(ContractBoiNode ParentNode)
 {
     if (ParentNode.Children.Count == 0)
     {
         ParentNode.CtrctAmount = Math.Round(ObjectHelper.GetDefaultDecimal(ParentNode.CtrctQty) * ObjectHelper.GetDefaultDecimal(ParentNode.CtrctPrjPrice), 2, MidpointRounding.AwayFromZero);
     }
     else
     {
         ParentNode.CtrctQty      = null;
         ParentNode.CtrctPrjPrice = null;
         ParentNode.CtrctAmount   = ParentNode.Children.Sum(m => m.StatId == 1 ? m.CtrctAmount : 0);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 列表项更改处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnNodeList_ListChanged(object sender, ListChangedEventArgs e)
 {
     //修改项
     if (e.ListChangedType == ListChangedType.ItemChanged)
     {
         ContractBoiNode boiNode = NodeList[e.NewIndex];
         CalcNode(boiNode);
         if (!String.IsNullOrEmpty(boiNode.ItemNo) && !updateList.Contains(boiNode))
         {
             updateList.Add(boiNode);
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 递归创建父子关系
        /// </summary>
        /// <param name="NodeList"></param>
        /// <param name="Parent"></param>
        private void RecursionNode(List <ContractBoiNode> NodeList, ContractBoiNode Parent)
        {
            List <ContractBoiNode> lstChildren = NodeList.FindAll(m => m.ParentCode == Parent.ItemCode);

            if (lstChildren.Count > 0)
            {
                Parent.Children.AddRange(lstChildren);
                lstChildren.ForEach(m =>
                {
                    m.ParentBoiNode = Parent;
                    RecursionNode(NodeList, m);
                });
            }
        }
Esempio n. 7
0
        private void ChangeCode(ContractBoiNode node, String newCode)
        {
            String strOldCode = node.ItemCode;

            node.ItemCode = newCode;
            if (node.Children.Count > 0)
            {
                node.Children.ForEach(m =>
                {
                    m.ParentCode = newCode;
                    ChangeCode(m, newCode + m.ItemCode.Substring(m.ItemCode.Length - 3, 3));
                });
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 将Boi列表转换为Node列表
        /// </summary>
        /// <param name="BoiList"></param>
        /// <returns></returns>
        private List <ContractBoiNode> Convert(List <ContractBoi> BoiList)
        {
            List <ContractBoiNode> lstBoiNode;
            List <ContractBoiNode> lstRoot;

            lstBoiNode = BoiList.ConvertAll <ContractBoiNode>(m =>
            {
                ContractBoiNode node = HDAutoMapper.DynamicMap <ContractBoiNode>(m);
                node.OriginalBoi     = m;
                return(node);
            });
            lstRoot = lstBoiNode.FindAll(m => String.IsNullOrEmpty(m.ParentCode));
            RootList.AddRange(lstRoot);
            lstRoot.ForEach(m =>
            {
                RecursionNode(lstBoiNode, m);
            });
            return(lstBoiNode);
        }
Esempio n. 9
0
        private ContractBoiNode RowToNode(DataRow ImportRow)
        {
            List <ContractBoiNode> lstNewNode = new List <ContractBoiNode>();
            decimal iItemQty   = 0;
            decimal iItemPrice = 0;
            String  strIItemCode;
            String  strItemCode = "";
            String  strItemName;
            String  strItemUom;

            if (ImportRow.Table.Columns.Contains("系统编号"))
            {
                strItemCode = String.Format("{0}", ImportRow["系统编号"]);
            }
            strIItemCode = String.Format("{0}", ImportRow["清单编号"]);
            strItemName  = String.Format("{0}", ImportRow["清单名称"]);
            strItemUom   = String.Format("{0}", ImportRow["单位"]);
            ContractBoiNode nodeNew = new ContractBoiNode();

            nodeNew.ItemCode      = strItemCode;
            nodeNew.ProjectNo     = ProjectNo;
            nodeNew.BoQNo         = Boq.BoQNo;
            nodeNew.ParentBoiNode = null;
            nodeNew.ItemName      = strItemName;
            nodeNew.Uom           = strItemUom;
            nodeNew.IItemCoe      = strIItemCode;
            if (ImportRow["数量"] != null && Decimal.TryParse(String.Format("{0}", ImportRow["数量"]), out iItemQty))
            {
                nodeNew.CtrctQty = iItemQty;
            }
            if (ImportRow["单价"] != null && Decimal.TryParse(String.Format("{0}", ImportRow["单价"]), out iItemPrice))
            {
                nodeNew.CtrctPrjPrice = iItemPrice;
            }
            return(nodeNew);
        }
Esempio n. 10
0
        /// <summary>
        /// 导入DataTable到清单中
        /// </summary>
        /// <param name="ImportTable"></param>
        public void ImportBoqByCode(DataTable ImportTable)
        {
            bool   validityFormat = true;
            String strParentCode  = null;

            //if (!ImportTable.Columns.Contains("系统编号"))
            //{
            //    validityFormat = false;
            //}
            if (!ImportTable.Columns.Contains("清单名称"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("清单编号"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("数量"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("单价"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("单位"))
            {
                validityFormat = false;
            }
            if (!validityFormat)
            {
                throw new BusinessException("文件格式不正确,格式:清单名称|清单编号|数量|单价|单位");
            }
            List <ContractBoiNode> lstNewNode = new List <ContractBoiNode>();
            List <ContractBoiNode> lstTemp    = new List <ContractBoiNode>();
            List <ContractBoiNode> lstExist   = NodeList.ToList();
            ContractBoiNode        nodeParent = null;

            for (int i = 0; i < ImportTable.Rows.Count; i++)
            {
                DataRow dr = ImportTable.Rows[i];
                lstNewNode.Add(RowToNode(dr));
            }
            #region 生成系统编号
            string   lastCode = lstExist.Count > 0 ? lstExist[lstExist.Count - 1].ItemCode : "";
            NodeInfo nodeInfo = new NodeInfo(lastCode);
            foreach (ContractBoiNode node in lstNewNode)
            {
                int      lv0       = -1;
                string[] pathNodes = node.IItemCoe.Split('-');
                if (pathNodes.Length == 1 && int.TryParse(pathNodes[0], out lv0) && lv0 % 100 == 0) //根节点
                {
                    if (nodeInfo.levelRecord == null)
                    {
                        nodeInfo.levelRecord = new List <string>();
                        nodeInfo.levelRecord.Add("01");
                        nodeInfo.lastCode = "01";
                    }
                    else
                    {
                        nodeInfo.ClearLevelBehind(0);  //清除第一级以后的记录,并将当前根节点向后移动一位
                        int root = 1;
                        if (int.TryParse(nodeInfo.levelRecord[0], out root))
                        {
                            root += 1;
                            nodeInfo.levelRecord[0] = root.ToString("d2");
                            nodeInfo.lastCode       = nodeInfo.levelRecord[0];
                        }
                    }
                }
                else
                {
                    int nodeLv = pathNodes.Length;
                    if (nodeInfo.level < nodeLv /* || nodeInfo.level == nodeLv && lv0 % 100 != 0*/) //这个节点是上一个节点的子节点
                    {
                        nodeInfo.SetLevelValue(nodeLv, "001");
                    }
                    else if (nodeInfo.level == nodeLv)                                       //这个节点和上一个节点是兄弟节点
                    {
                        int lastValue = int.Parse(nodeInfo.levelRecord[nodeInfo.level]) + 1; //获取上一个节点的最后一个等级的记录并加一
                        nodeInfo.SetLevelValue(nodeLv, lastValue.ToString("d3"));
                    }
                    else  //如果层次降低,则清空当前节点等级以后的记录,并将当前等级记录加一
                    {
                        nodeInfo.ClearLevelBehind(nodeLv);
                        int lastValue = int.Parse(nodeInfo.levelRecord[nodeLv]) + 1;
                        nodeInfo.SetLevelValue(nodeLv, lastValue.ToString("d3"));
                    }
                }
                nodeInfo.lastCode = nodeInfo.GenerateCode();
                node.ItemCode     = nodeInfo.lastCode;
            }
            #endregion
            #region 检查编号是否连续
            //检查编号是否连续
            lstTemp.Clear();
            for (int i = 0; i < lstNewNode.Count; i++)
            {
                if (lstNewNode[i].ItemCode.Length % 3 != 2)
                {
                    throw new BusinessException(String.Format("编号长度不正确,根项长度为2,子项编号=父项编号+3位数字,错误编号:{0}", lstNewNode[i].ItemCode));
                }
                else if (lstNewNode[i].ItemCode.Length == 2)
                {
                    strParentCode            = null;
                    lstNewNode[i].ParentCode = strParentCode;
                }
                else if (lstNewNode[i].ItemCode.Length > 2)
                {
                    strParentCode            = lstNewNode[i].ItemCode.Substring(0, lstNewNode[i].ItemCode.Length - 3);
                    lstNewNode[i].ParentCode = strParentCode;
                }
                //查找父节点
                nodeParent = lstExist.FirstOrDefault(m => m.ItemCode == lstNewNode[i].ParentCode);
                if (nodeParent == null)
                {
                    nodeParent = lstTemp.FirstOrDefault(m => m.ItemCode == lstNewNode[i].ParentCode);
                }

                //有父节点的情况
                if (strParentCode != null && ((lstExist.Exists(m => m.ItemCode == lstNewNode[i].ParentCode) &&
                                               !lstExist.Exists(m => m.ItemCode == lstNewNode[i].ItemCode) &&
                                               !lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ItemCode)) ||
                                              (lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ParentCode) &&
                                               !lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ItemCode))))
                {
                    lstNewNode[i].ParentBoiNode = nodeParent;
                    nodeParent.Children.Add(lstNewNode[i]);
                }
                else if (strParentCode == null && !lstExist.Exists(m => m.ItemCode == lstNewNode[i].ItemCode) &&
                         !lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ItemCode))
                {
                    //无父节点的情况
                    lstNewNode[i].ParentBoiNode = null;
                    RootList.Add(lstNewNode[i]);
                }
                else
                {
                    //不符合条件
                    throw new BusinessException(String.Format("编号不正确,错误编号:{0},可能的原因是 1、无法找到父项,2、编号重复", lstNewNode[i].ItemCode));
                }
                lstTemp.Add(lstNewNode[i]);
            }
            #endregion
            lstNewNode.ForEach(m =>
            {
                CalcNode(m);
                NodeList.Add(m);
            });

            if (ListChanged != null)
            {
                ListChanged();
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 导入DataTable到清单中
        /// </summary>
        /// <param name="ImportTable"></param>
        public void ImportBoq(DataTable ImportTable)
        {
            bool   validityFormat = true;
            String strParentCode  = null;

            if (!ImportTable.Columns.Contains("系统编号"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("清单名称"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("清单编号"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("数量"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("单价"))
            {
                validityFormat = false;
            }
            if (!ImportTable.Columns.Contains("单位"))
            {
                validityFormat = false;
            }
            if (!validityFormat)
            {
                throw new BusinessException("文件格式不正确,格式:系统编号|清单名称|清单编号|数量|单价|单位");
            }
            List <ContractBoiNode> lstNewNode = new List <ContractBoiNode>();
            List <ContractBoiNode> lstTemp    = new List <ContractBoiNode>();
            List <ContractBoiNode> lstExist   = NodeList.ToList();
            ContractBoiNode        nodeParent = null;

            for (int i = 0; i < ImportTable.Rows.Count; i++)
            {
                DataRow dr = ImportTable.Rows[i];
                lstNewNode.Add(RowToNode(dr));
            }
            //检查编号是否连续
            for (int i = 0; i < lstNewNode.Count; i++)
            {
                if (lstNewNode[i].ItemCode.Length % 3 != 2)
                {
                    throw new BusinessException(String.Format("编号长度不正确,根项长度为2,子项编号=父项编号+3位数字,错误编号:{0}", lstNewNode[i].ItemCode));
                }
                else if (lstNewNode[i].ItemCode.Length == 2)
                {
                    strParentCode            = null;
                    lstNewNode[i].ParentCode = strParentCode;
                }
                else if (lstNewNode[i].ItemCode.Length > 2)
                {
                    strParentCode            = lstNewNode[i].ItemCode.Substring(0, lstNewNode[i].ItemCode.Length - 3);
                    lstNewNode[i].ParentCode = strParentCode;
                }
                //查找父节点
                nodeParent = lstExist.FirstOrDefault(m => m.ItemCode == lstNewNode[i].ParentCode);
                if (nodeParent == null)
                {
                    nodeParent = lstTemp.FirstOrDefault(m => m.ItemCode == lstNewNode[i].ParentCode);
                }

                //有父节点的情况
                if (strParentCode != null && ((lstExist.Exists(m => m.ItemCode == lstNewNode[i].ParentCode) &&
                                               !lstExist.Exists(m => m.ItemCode == lstNewNode[i].ItemCode) &&
                                               !lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ItemCode)) ||
                                              (lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ParentCode) &&
                                               !lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ItemCode))))
                {
                    lstNewNode[i].ParentBoiNode = nodeParent;
                    nodeParent.Children.Add(lstNewNode[i]);
                }
                else if (strParentCode == null && !lstExist.Exists(m => m.ItemCode == lstNewNode[i].ItemCode) &&
                         !lstTemp.Exists(m => m.ItemCode == lstNewNode[i].ItemCode))
                {
                    //无父节点的情况
                    lstNewNode[i].ParentBoiNode = null;
                    RootList.Add(lstNewNode[i]);
                }
                else
                {
                    //不符合条件
                    throw new BusinessException(String.Format("编号不正确,错误编号:{0},可能的原因是 1、无法找到父项,2、编号重复", lstNewNode[i].ItemCode));
                }
                lstTemp.Add(lstNewNode[i]);
            }
            lstNewNode.ForEach(m =>
            {
                CalcNode(m);
                NodeList.Add(m);
            });

            if (ListChanged != null)
            {
                ListChanged();
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="Node"></param>
        public void DeleteNode(ContractBoiNode Node)
        {
            //已删除过,则返回
            if (!NodeList.Contains(Node))
            {
                return;
            }
            // RecursionDeleteNode(Node);
            List <ContractBoiNode> lstChildren = Node.Children.ToList();

            for (int i = lstChildren.Count - 1; i >= 0; i--)
            {
                DeleteNode(lstChildren[i]);
            }
            if (NodeList.Contains(Node))
            {
                NodeList.Remove(Node);
            }
            if (updateList.Contains(Node))
            {
                updateList.Remove(Node);
            }
            String strCode = null;
            int    iCode   = 0;

            if (Node.ParentBoiNode != null)
            {
                //删除节点的序号
                int iIndex = Node.ParentBoiNode.Children.IndexOf(Node);
                //删除节点不是最后一个
                if (iIndex < Node.ParentBoiNode.Children.Count - 1)
                {
                    //移除节点
                    Node.ParentBoiNode.Children.Remove(Node);
                    for (int i = iIndex; i < Node.ParentBoiNode.Children.Count; i++)
                    {
                        //对后面的节点的序号 统一减1
                        strCode = Node.ParentBoiNode.Children[i].ItemCode;
                        iCode   = System.Convert.ToInt32(strCode.Substring(strCode.Length - 3, 3));
                        iCode   = iCode - 1;
                        strCode = Node.ParentBoiNode.ItemCode + iCode.ToString().PadLeft(3, '0');
                        ChangeCode(Node.ParentBoiNode.Children[i], strCode);
                    }
                }
                else
                {
                    Node.ParentBoiNode.Children.Remove(Node);
                }
                CalcParentNode(Node.ParentBoiNode);
            }
            else
            {
                int iIndex = RootList.IndexOf(Node);
                //删除节点不是最后一个
                if (iIndex < RootList.Count - 1)
                {
                    //移除节点
                    RootList.Remove(Node);
                    for (int i = iIndex; i < RootList.Count; i++)
                    {
                        //对后面的节点的序号 统一减1
                        strCode = RootList[i].ItemCode;
                        iCode   = System.Convert.ToInt32(strCode);
                        iCode   = iCode - 1;
                        strCode = iCode.ToString().PadLeft(2, '0');
                        ChangeCode(RootList[i], strCode);
                    }
                }
                else
                {
                    RootList.Remove(Node);
                }
            }
            if (ListChanged != null)
            {
                ListChanged();
            }
        }