public SumInfo GetSumInfo(List <RateItem> rate_table) { List <string> totalprices = new List <string>(); SumInfo info = new SumInfo(); info.Seller = this.Seller; foreach (OrderListItem item in _items) { info.BiblioCount++; info.CopyCount += item.Copy; totalprices.Add(item.TotalPrice); } if (totalprices.Count > 1) { string strError = ""; List <string> sum_prices = null; int nRet = PriceUtil.TotalPrice(totalprices, out sum_prices, out strError); if (nRet == -1) { info.TotalPrice = strError; } else { // Debug.Assert(sum_prices.Count == 1, ""); // info.TotalPrice = sum_prices[0]; info.TotalPrice = PriceUtil.JoinPriceString(sum_prices); } } else if (totalprices.Count == 1) { info.TotalPrice = totalprices[0]; } // 计算汇率 if (rate_table != null && string.IsNullOrEmpty(info.TotalPrice) == false) { try { string strRatePrice = RateItem.RatePrices( rate_table, info.TotalPrice); info.TotalPrice1 = strRatePrice; if (info.TotalPrice == info.TotalPrice1) { info.TotalPrice1 = ""; } } catch (Exception ex) { info.TotalPrice1 = ex.Message; } } return(info); }
static string ConcatPrice( IGrouping <string, ListViewItem> cl, int column_index) { // PrintOrderForm.RemoveChangedChar() string strList = ListViewUtil.GetItemText(cl.Aggregate((current, next) => { string s1 = ListViewUtil.GetItemText(current, column_index); string s2 = ListViewUtil.GetItemText(next, column_index); var r = new ListViewItem(); ListViewUtil.ChangeItemText(r, column_index, s1 + "," + s2); return(r); }), column_index); return(PriceUtil.TotalPrice(StringUtil.SplitList(strList))); }
static string ConcatLinePrice( IGrouping <string, PrintOrderForm.LineInfo> cl, string strFieldName) { // PrintOrderForm.RemoveChangedChar() string strList = (string)GetPropertyValue(cl.Aggregate((current, next) => { // TODO:单价应该乘以套数。或者还有期数也要乘上 string s1 = (string)GetPropertyValue(current, strFieldName); string s2 = (string)GetPropertyValue(next, strFieldName); var r = new PrintOrderForm.LineInfo(); SetPropertyValue(r, strFieldName, s1 + "," + s2); return(r); }), strFieldName); return(PriceUtil.TotalPrice(StringUtil.SplitList(strList))); }
static void Inc(Table table, string strEntry, int nColumn, string strPrice) { Line line = table.EnsureLine(strEntry); string strOldValue = (string)line[nColumn]; if (string.IsNullOrEmpty(strOldValue) == true) { line.SetValue(nColumn, strPrice); return; } // 连接两个价格字符串 string strPrices = PriceUtil.JoinPriceString(strOldValue, strPrice); string strError = ""; List <string> prices = null; // 将形如"-123.4+10.55-20.3"的价格字符串切割为单个的价格字符串,并各自带上正负号 // return: // -1 error // 0 succeed int nRet = PriceUtil.SplitPrices(strPrices, out prices, out strError); if (nRet == -1) { throw new Exception(strError); } string strResult = ""; nRet = PriceUtil.TotalPrice(prices, out strResult, out strError); if (nRet == -1) { throw new Exception(strError); } line.SetValue(nColumn, strResult); }
// 将形如"-CNY123.4+USD10.55-20.3"的价格字符串计算汇率 // parameters: public static string RatePrices( List <RateItem> rate_table, string strPrices) { string strError = ""; strPrices = strPrices.Trim(); if (String.IsNullOrEmpty(strPrices) == true) { return(""); } List <string> prices = null; // 将形如"-123.4+10.55-20.3"的价格字符串切割为单个的价格字符串,并各自带上正负号 // return: // -1 error // 0 succeed int nRet = PriceUtil.SplitPrices(strPrices, out prices, out strError); if (nRet == -1) { throw new Exception(strError); } List <string> changed_prices = new List <string>(); foreach (string price in prices) { CurrencyItem item = CurrencyItem.Parse(price); RateItem rate = FindBySource(rate_table, item.Prefix, item.Postfix); if (rate == null) { changed_prices.Add(price); continue; } CurrencyItem result = rate.Exchange(item); changed_prices.Add(result.ToString()); } List <string> results = new List <string>(); // 汇总价格 // 货币单位不同的,互相独立 // return: // -1 error // 0 succeed nRet = PriceUtil.TotalPrice(changed_prices, out results, out strError); if (nRet == -1) { throw new Exception(strError); } #if NO StringBuilder text = new StringBuilder(); for (int i = 0; i < results.Count; i++) { string strOnePrice = results[i]; if (String.IsNullOrEmpty(strOnePrice) == true) { continue; } if (strOnePrice[0] == '+') { text.Append("+" + strOnePrice.Substring(1)); } else if (strOnePrice[0] == '-') { text.Append("-" + strOnePrice.Substring(1)); } else { text.Append("+" + strOnePrice); // 缺省为正数 } } return(text.ToString().TrimStart(new char[] { '+' })); #endif return(PriceUtil.JoinPriceString(results)); }
// 根据读者记录中 overdue 内容填充 line 的各个成员 static void FillRecordByOverdue(XmlElement overdue, string strReaderBarcode, string strNewPrice, AmerceOper line, StringBuilder debugInfo) { if (overdue == null) { return; } string strError = ""; line.AmerceRecPath = ""; line.Action = "modifyprice"; try { line.ReaderBarcode = strReaderBarcode; line.ItemBarcode = overdue.GetAttribute("barcode"); line.ID = overdue.GetAttribute("id"); // 2016/12/6 // 变化的金额 string strOldPrice = overdue.GetAttribute("price"); List <string> prices = new List <string>(); if (string.IsNullOrEmpty(strNewPrice) == false) { prices.Add(strNewPrice); } if (string.IsNullOrEmpty(strOldPrice) == false) { prices.Add("-" + strOldPrice); } string strResult = ""; int nRet = PriceUtil.TotalPrice(prices, out strResult, out strError); if (nRet == -1) { // return -1; if (debugInfo != null) { debugInfo.Append("FillRecordByOverdue() TotalPrice() 解析金额字符串 '" + StringUtil.MakePathList(prices) + "' 时出错(已被当作 0 处理): " + strError + "\r\n"); } return; } nRet = ParsePriceString(strResult, out decimal value, out string strUnit, out strError); if (nRet == -1) { if (debugInfo != null) { debugInfo.Append("FillRecordByOverdue() 解析金额字符串 '" + strResult + "' 时出错(已被当作 0 处理): " + strError + "\r\n"); } line.Unit = ""; line.Price = 0; } else { line.Unit = strUnit; line.Price = value; } line.Reason = overdue.GetAttribute("reason"); } catch (Exception ex) { if (debugInfo != null) { debugInfo.Append("FillRecordByOverdue() 出现异常: " + ExceptionUtil.GetExceptionText(ex) + "\r\n"); } } }
// 将 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; } } }
private void button_currency_sum_Click(object sender, EventArgs e) { List <string> prices = new List <string>(this.textBox_currency_source.Lines); this.textBox_currency_target.Text = PriceUtil.TotalPrice(prices); }