Example #1
0
        // 将 OrderStorage 对象的信息合并到本对象
        public void Merge(OrderStore order)
        {
            string strError = "";

            if (this.Orders == null)
            {
                this.Orders = new List <OrderStore>();
            }

            if (this.Orders.IndexOf(order) != -1)
            {
                throw new Exception("order 对象已经在 Orders 中存在了,不允许重复合并");
            }

            this.Orders.Add(order);

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(order.Xml);

            Hashtable value_table = GetValues(order);
            string    strSeller   = (string)value_table["seller"];

            if (string.IsNullOrEmpty(this.Seller))
            {
                this.Seller = strSeller;
            }
            else
            {
                if (this.Seller != strSeller)
                {
                    throw new Exception("this.Seller '" + this.Seller + "' 和即将合并的 order.Seller '" + strSeller + "' 不一致");
                }
            }

            string strCatalogNo = (string)value_table["catalogNo"];

            if (string.IsNullOrEmpty(this.CatalogNo))
            {
                this.CatalogNo = strCatalogNo;
            }
            else
            {
                if (this.CatalogNo != strCatalogNo)
                {
                    throw new Exception("this.CatalogNo '" + this.CatalogNo + "' 和即将合并的 order.CatalogNo '" + strCatalogNo + "' 不一致");
                }
            }

            string strPrice = (string)value_table["price"];

            if (string.IsNullOrEmpty(this.Price))
            {
                this.Price = strPrice;
            }
            else
            {
                if (this.Price != strPrice)
                {
                    throw new Exception("this.Price '" + this.Price + "' 和即将合并的 order.Price '" + strPrice + "' 不一致");
                }
            }

            string strAcceptPrice = (string)value_table["acceptPrice"];

            if (string.IsNullOrEmpty(this.AcceptPrice))
            {
                this.AcceptPrice = strAcceptPrice;
            }
            else
            {
                if (this.AcceptPrice != strAcceptPrice)
                {
                    throw new Exception("this.AcceptPrice '" + this.AcceptPrice + "' 和即将合并的 order.AcceptPrice '" + strAcceptPrice + "' 不一致");
                }
            }

            string strIssueCount = (string)value_table["issueCount"];

            if (string.IsNullOrEmpty(this.IssueCount))
            {
                this.IssueCount = strIssueCount;
            }
            else
            {
                if (this.IssueCount != strIssueCount)
                {
                    throw new Exception("this.IssueCount '" + this.IssueCount + "' 和即将合并的 order.IssueCount '" + strIssueCount + "' 不一致");
                }
            }

            string strRange = (string)value_table["range"];

            if (string.IsNullOrEmpty(this.Range))
            {
                this.Range = strRange;
            }
            else
            {
                if (this.Range != strRange)
                {
                    throw new Exception("this.Range '" + this.Range + "' 和即将合并的 order.Range '" + strRange + "' 不一致");
                }
            }

            int nSubCopy = (int)value_table["subcopy"];

            if (this.SubCopy == 0)
            {
                this.SubCopy = nSubCopy;
            }
            else
            {
                if (this.SubCopy != nSubCopy)
                {
                    throw new Exception("this.SubCopy '" + this.SubCopy + "' 和即将合并的 order.SubCopy '" + nSubCopy + "' 不一致");
                }
            }

            string strSellerAddress = (string)value_table["sellerAddress"];

            if (string.IsNullOrEmpty(this.SellerAddress))
            {
                this.SellerAddress = strSellerAddress;
            }

            // 以下是需要累加的字段
            if (this.MergeComment == null)
            {
                this.MergeComment = new List <string>();
            }

            int nCopy = (int)value_table["copy"];

            this.Copy += nCopy;

            string strSource = DomUtil.GetElementText(dom.DocumentElement,
                                                      "source");
            string strMergeComment = strSource + ", " + nCopy.ToString() + "册 (" + order.RecPath + ")";

            this.MergeComment.Add(strMergeComment);

            int nIssueCount = 1;

            if (string.IsNullOrEmpty(strIssueCount) == false)
            {
                Int32.TryParse(strIssueCount, out nIssueCount);
            }

            // 汇总价格
            List <string> totalprices = new List <string>();

            if (string.IsNullOrEmpty(this.TotalPrice) == false)
            {
                totalprices.Add(this.TotalPrice);
            }

            string strTotalPrice = "";

            if (String.IsNullOrEmpty(strPrice) == false)
            {
                int nRet = PriceUtil.MultiPrice(strPrice,
                                                nCopy * nIssueCount,
                                                out strTotalPrice,
                                                out strError);
                if (nRet == -1)
                {
                    strError = "原始数据事项 " + order.RecPath + " 内价格字符串 '" + strPrice + "' 格式不正确: " + strError;
                    throw new Exception(strError);
                }

                totalprices.Add(strTotalPrice);
            }

            if (totalprices.Count > 1)
            {
                List <string> sum_prices = null;
                int           nRet       = PriceUtil.TotalPrice(totalprices,
                                                                out sum_prices,
                                                                out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }

                // Debug.Assert(sum_prices.Count == 1, "");
                // this.TotalPrice = sum_prices[0];
                this.TotalPrice = PriceUtil.JoinPriceString(sum_prices);
            }
            else if (totalprices.Count == 1)
            {
                this.TotalPrice = totalprices[0];
            }

            // 汇总注释
            if (this.Comments == null)
            {
                this.Comments = new List <string>();
            }

            string strComment = DomUtil.GetElementText(dom.DocumentElement,
                                                       "comment");

            if (String.IsNullOrEmpty(strComment) == false)
            {
                this.Comments.Add(strComment + " @" + order.RecPath);
            }

            // 汇总馆藏分配字符串
            string strDistribute = DomUtil.GetElementText(dom.DocumentElement,
                                                          "distribute");

            if (String.IsNullOrEmpty(strDistribute) == false)
            {
                if (String.IsNullOrEmpty(this.Distribute) == true)
                {
                    this.Distribute = strDistribute;
                }
                else
                {
                    string strLocationString = "";
                    int    nRet = LocationCollection.MergeTwoLocationString(this.Distribute,
                                                                            strDistribute,
                                                                            false,
                                                                            out strLocationString,
                                                                            out strError);
                    if (nRet == -1)
                    {
                        throw new Exception(strError);
                    }
                    this.Distribute = strLocationString;
                }
            }
        }