// 检查各个字段内容是否正确 // return: // -1 有错 // 0 正确 public int VerifyFields(out string strError) { strError = ""; int nRet = 0; string strRange = this.Range; string strOrderTime = this.OrderTime; if (string.IsNullOrEmpty(strRange) == false) { // 检查出版时间范围字符串是否合法 // 如果使用单个出版时间来调用本函数,也是可以的 // return: // -1 出错 // 0 正确 nRet = LibraryServerUtil.CheckPublishTimeRange(strRange, true, // TODO: 期刊要用 false out strError); if (nRet == -1) { return(-1); } } if (string.IsNullOrEmpty(strOrderTime) == false) { try { DateTime time = DateTimeUtil.FromRfc1123DateTimeString(strOrderTime); if (time.Year == 1753) { strError = "订购时间字符串 '" + strOrderTime + "' 这是一个不太可能的时间"; return(-1); } } catch (Exception ex) { strError = "订购时间字符串 '" + strOrderTime + "' 格式错误: " + ex.Message; return(-1); } } // 验证馆藏分配字符串 string strDistribute = this.Distribute; if (string.IsNullOrEmpty(strDistribute) == false) { LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strDistribute + "' 格式错误: " + strError; return(-1); } } return(0); }
// 更换 orderInfo 元素里的 distribute 元素中的 refid 字符串 // return: // -1 出错 // >=0 发生替换的个数 public static int ReplaceOrderInfoItemRefID(Hashtable item_refid_change_table, XmlElement root, out string strError) { strError = ""; int nRet = 0; int nChangedCount = 0; XmlNodeList nodes = root.SelectNodes("*/distribute"); for (int i = 0; i < nodes.Count; i++) { string strDistribute = nodes[i].InnerText; if (String.IsNullOrEmpty(strDistribute) == true) { continue; } LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { return(-1); } bool bChanged = false; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; if (item_refid_change_table.Contains(location.RefID) == true) { location.RefID = (string)item_refid_change_table[location.RefID]; bChanged = true; } } if (bChanged == true) { nodes[i].InnerText = locations.ToString(true); nChangedCount++; } } return(nChangedCount); }
// // return: // -1 出错 // 0 没有发生替换修改 // >0 共修改了多少个<distribute>元素内容 /// <summary> /// 更换 orderInfo 元素里的 distribute 元素中的 refid 字符串 /// </summary> /// <param name="item_refid_change_table">参考 ID 对照表</param> /// <param name="strError">返回出错信息</param> /// <returns>-1 出错; 0 没有发生替换修改; >0 共修改了多少个 distribute 元素内容</returns> public int ReplaceOrderInfoItemRefID(Hashtable item_refid_change_table, out string strError) { strError = ""; int nRet = 0; string strOrderInfo = this.OrderInfo; if (String.IsNullOrEmpty(strOrderInfo) == true) return 0; XmlDocument dom = new XmlDocument(); dom.LoadXml("<orderInfo/>"); try { dom.DocumentElement.InnerXml = strOrderInfo; } catch (Exception ex) { strError = "load inner xml error: " + ex.Message; return -1; } int nChangedCount = 0; XmlNodeList nodes = dom.DocumentElement.SelectNodes("*/distribute"); for (int i = 0; i < nodes.Count; i++) { string strDistribute = nodes[i].InnerText; if (String.IsNullOrEmpty(strDistribute) == true) continue; LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) return -1; bool bChanged = false; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; if (item_refid_change_table.Contains(location.RefID) == true) { location.RefID = (string)item_refid_change_table[location.RefID]; bChanged = true; } } if (bChanged == true) { nodes[i].InnerText = locations.ToString(true); nChangedCount++; } } if (nChangedCount > 0) this.OrderInfo = dom.DocumentElement.InnerXml; return nChangedCount; }
// 检查各个字段内容是否正确 // return: // -1 有错 // 0 正确 public int VerifyFields(out string strError) { strError = ""; int nRet = 0; string strRange = this.Range; string strOrderTime = this.OrderTime; if (string.IsNullOrEmpty(strRange) == false) { // 检查出版时间范围字符串是否合法 // 如果使用单个出版时间来调用本函数,也是可以的 // return: // -1 出错 // 0 正确 nRet = LibraryServerUtil.CheckPublishTimeRange(strRange, true, // TODO: 期刊要用 false out strError); if (nRet == -1) { return(-1); } } if (string.IsNullOrEmpty(strOrderTime) == false) { try { DateTime time = DateTimeUtil.FromRfc1123DateTimeString(strOrderTime); if (time.Year == 1753) { strError = "订购时间字符串 '" + strOrderTime + "' 这是一个不太可能的时间"; return(-1); } } catch (Exception ex) { strError = "订购时间字符串 '" + strOrderTime + "' 格式错误: " + ex.Message; return(-1); } } // 验证馆藏分配字符串 string strDistribute = this.Distribute; if (string.IsNullOrEmpty(strDistribute) == false) { LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strDistribute + "' 格式错误: " + strError; return(-1); } } if (this.FixedPrice.StartsWith("@") == false && this.Price.StartsWith("@") == false && string.IsNullOrEmpty(this.FixedPrice) == false && string.IsNullOrEmpty(this.Price) == false) { // 检查码洋、折扣和单价之间的关系 // return: // -2 码洋和订购价货币单位不同,无法进行校验。 // -1 校验过程出错 // 0 校验发现三者关系不正确 // 1 校验三者关系正确 nRet = OrderDesignControl.VerifyOrderPriceByFixedPricePair( this.FixedPrice, this.Discount, this.Price, "both", out strError); if (nRet != 1 && nRet != -2) { strError = "校验码洋、折扣和单价三者之间关系时出现错误: " + strError; return(-1); } } return(0); }
// 将两个订购XML片断合并 // 当旧的和新的都是全管辖范围内,就允许新的全部替换旧的;否则只允许替换<distribute>元素内容 // parameters: // strLibraryCodeList 当前用户管辖的分馆代码列表 // strMergedXml [out]范围订购<root>元素的InnerXml // return: // -1 出错 // 0 正常 // 1 发生了超越范围的修改 public static int MergeOrderNode(XmlNode exist_node, XmlNode new_node, string strLibraryCodeList, out string strMergedXml, out string strError) { strError = ""; strMergedXml = ""; int nRet = 0; Debug.Assert(SessionInfo.IsGlobalUser(strLibraryCodeList) == false, "全局用户不应调用函数 MergeOrderNode()"); string strExistDistribute = DomUtil.GetElementText(exist_node, "distribute"); string strNewDistribute = DomUtil.GetElementText(new_node, "distribute"); bool bExistControlled = true; bool bNewControlled = true; if (string.IsNullOrEmpty(strExistDistribute) == false) { // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 nRet = DistributeInControlled(strExistDistribute, strLibraryCodeList, out strError); if (nRet == -1) return -1; if (nRet == 0) bExistControlled = false; } if (string.IsNullOrEmpty(strNewDistribute) == false) { // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 nRet = DistributeInControlled(strNewDistribute, strLibraryCodeList, out strError); if (nRet == -1) return -1; if (nRet == 0) bNewControlled = false; } if (bExistControlled == true && bNewControlled == true) { // 当旧的和新的都是全管辖范围内,就允许新的全部替换旧的 strMergedXml = new_node.InnerXml; return 0; } string strExistCopy = DomUtil.GetElementText(exist_node, "copy"); string strExistPrice = DomUtil.GetElementText(exist_node, "price"); string strChangedCopy = DomUtil.GetElementText(new_node, "copy"); string strChangedPrice = DomUtil.GetElementText(new_node, "price"); // 比较两个复本字符串 { string strExistOldValue = ""; string strExistNewValue = ""; ParseOldNewValue(strExistCopy, out strExistOldValue, out strExistNewValue); string strChangedOldValue = ""; string strChangedNewValue = ""; ParseOldNewValue(strChangedCopy, out strChangedOldValue, out strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购套数(方括号左边的部分)不允许修改。(原来='"+strExistCopy+"',新的='"+strChangedCopy+"')"; return 1; } // 检查验收套数的改变,是否正好和distribute字符串内的改变吻合 } // 比较两个价格字符串 { string strExistOldValue = ""; string strExistNewValue = ""; ParseOldNewValue(strExistPrice, out strExistOldValue, out strExistNewValue); string strChangedOldValue = ""; string strChangedNewValue = ""; ParseOldNewValue(strChangedPrice, out strChangedOldValue, out strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购价(方括号左边的部分)不允许修改。(原来='" + strExistPrice + "',新的='" + strChangedPrice + "')"; return 1; } if (strExistNewValue != strChangedNewValue) { strError = "验收价(方括中的部分)不允许修改。(原来='" + strExistPrice + "',新的='" + strChangedPrice + "')"; return 1; } } LocationCollection new_locations = new LocationCollection(); nRet = new_locations.Build(strNewDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strNewDistribute + "' 格式不正确"; return -1; } LocationCollection exist_locations = new LocationCollection(); nRet = exist_locations.Build(strExistDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strExistDistribute + "' 格式不正确"; return -1; } if (exist_locations.Count != new_locations.Count) { strError = "馆藏分配事项个数发生了改变(原来=" + exist_locations.Count.ToString() + ",新的=" + new_locations.Count.ToString() + ")"; return 1; } for (int i = 0; i < exist_locations.Count; i++) { Location exist_location = exist_locations[i]; Location new_location = new_locations[i]; if (exist_location.Name != new_location.Name) { // 进一步检查是否馆代码部分改变了 string strCode1 = ""; string strPureName = ""; string strCode2 = ""; // 解析 LibraryApplication.ParseCalendarName(exist_location.Name, out strCode1, out strPureName); LibraryApplication.ParseCalendarName(new_location.Name, out strCode2, out strPureName); // 只要馆代码部分不改变即可 if (strCode1 != strCode2) { strError = "第 " + (i + 1).ToString() + " 个馆藏分配事项的名字(的馆代码部分)发生改变 (原来='" + exist_location.Name + "',新的='" + new_location.Name + "')"; return 1; } } if (exist_location.RefID != new_location.RefID) { string strLibraryCode = ""; string strPureName = ""; // 解析 LibraryApplication.ParseCalendarName(exist_location.Name, out strLibraryCode, out strPureName); if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false) { strError = "馆代码 '" + strLibraryCode + "' 不在范围 '" + strLibraryCodeList + "' 内,不允许进行收登操作。"; return 1; } } } // 将旧的XML片断装入,只修改里面的三个元素值。这样可以保证三个元素以外的原记录内容不被修改 XmlDocument dom = new XmlDocument(); try { dom.LoadXml(exist_node.OuterXml); } catch (Exception ex) { strError = "exist_node.OuterXml装入XMLDOM失败: " + ex.Message; return -1; } DomUtil.SetElementText(dom.DocumentElement, "copy", strChangedCopy); DomUtil.SetElementText(dom.DocumentElement, "price", strChangedPrice); DomUtil.SetElementText(dom.DocumentElement, "distribute", strNewDistribute); strMergedXml = dom.DocumentElement.InnerXml; return 0; }
// // return: // -1 出错 // 0 没有任何部分在管辖范围 // 1 至少部分在管辖范围内 /// <summary> /// 观察一个馆藏分配字符串,看看是否部分在当前用户管辖范围内 /// </summary> /// <param name="strDistribute">馆藏分配字符串</param> /// <param name="strLibraryCodeList">当前用户的馆代码列表字符串</param> /// <param name="strError">返回出错信息</param> /// <returns>-1: 出错; 0: 没有任何部分在管辖范围; 1: 至少部分在管辖范围内</returns> public static int DistributeCross(string strDistribute, string strLibraryCodeList, out string strError) { strError = ""; if (IsGlobalUser(strLibraryCodeList) == true) return 1; LocationCollection locations = new LocationCollection(); int nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strDistribute + "' 格式不正确"; return -1; } foreach (Location location in locations) { // 空的馆藏地点被视为不在分馆用户管辖范围内 if (string.IsNullOrEmpty(location.Name) == true) continue; string strLibraryCode = ""; string strPureName = ""; // 解析 ParseCalendarName(location.Name, out strLibraryCode, out strPureName); if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == true) return 1; } return 0; }
// /// <summary> /// 获得一个馆藏分配字符串里面的所有 参考 ID /// </summary> /// <param name="strDistribute">馆藏分配字符串</param> /// <param name="refids">返回参考 ID 字符串集合</param> /// <param name="strError">返回出错信息</param> /// <returns>-1: 出错; 0: 成功</returns> public static int GetRefIDs(string strDistribute, out List<string> refids, out string strError) { strError = ""; refids = new List<string>(); LocationCollection locations = new LocationCollection(); int nRet = locations.Build(strDistribute, out strError); if (nRet == -1) return -1; foreach (Location location in locations) { if (string.IsNullOrEmpty(location.RefID) == true) continue; string[] parts = location.RefID.Split(new char[] { '|' }); foreach (string text in parts) { string strRefID = text.Trim(); if (string.IsNullOrEmpty(strRefID) == true) continue; refids.Add(strRefID); } } return 0; }
// 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 public static int DistributeInControlled(string strDistribute, string strLibraryCodeList, out string strError) { strError = ""; if (SessionInfo.IsGlobalUser(strLibraryCodeList) == true) return 1; LocationCollection locations = new LocationCollection(); int nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strDistribute + "' 格式不正确"; return -1; } foreach (Location location in locations) { // 空的馆藏地点被视为不在分馆用户管辖范围内 if (string.IsNullOrEmpty(location.Name) == true) { strError = "馆代码 '' 不在范围 '" + strLibraryCodeList + "' 内"; return 0; } string strLibraryCode = ""; string strPureName = ""; // 解析 LibraryApplication.ParseCalendarName(location.Name, out strLibraryCode, out strPureName); if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false) { strError = "馆代码 '" + strLibraryCode + "' 不在范围 '" + strLibraryCodeList + "' 内"; return 0; } } return 1; }
// 检查各个字段内容是否正确 // return: // -1 有错 // 0 正确 public int VerifyFields(out string strError) { strError = ""; int nRet = 0; string strRange = this.Range; string strOrderTime = this.OrderTime; if (string.IsNullOrEmpty(strRange) == false) { // 检查出版时间范围字符串是否合法 // 如果使用单个出版时间来调用本函数,也是可以的 // return: // -1 出错 // 0 正确 nRet = LibraryServerUtil.CheckPublishTimeRange(strRange, out strError); if (nRet == -1) return -1; } if (string.IsNullOrEmpty(strOrderTime) == false) { try { DateTime time = DateTimeUtil.FromRfc1123DateTimeString(strOrderTime); if (time.Year == 1753) { strError = "订购时间字符串 '" + strOrderTime + "' 这是一个不太可能的时间"; return -1; } } catch (Exception ex) { strError = "订购时间字符串 '" + strOrderTime + "' 格式错误: " + ex.Message; return -1; } } // 验证馆藏分配字符串 string strDistribute = this.Distribute; if (string.IsNullOrEmpty(strDistribute) == false) { LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strDistribute + "' 格式错误: " + strError; return -1; } } return 0; }
// 从期记录中获得和一个refid有关的订购记录片段 // parameters: // -1 error // 0 not found // 1 found static int GetSubOrderRecord(XmlDocument dom, string strRefID, out string strOrderXml, out string strError) { strError = ""; strOrderXml = ""; XmlNodeList nodes = dom.DocumentElement.SelectNodes("orderInfo/*/distribute"); for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; string strDistribute = node.InnerText.Trim(); if (String.IsNullOrEmpty(strDistribute) == true) continue; LocationCollection locations = new LocationCollection(); int nRet = locations.Build(strDistribute, out strError); if (nRet == -1) return -1; for (int j = 0; j < locations.Count; j++) { DigitalPlatform.Location location = locations[j]; if (location.RefID == strRefID) { strOrderXml = node.ParentNode.OuterXml; return 1; } } } return 0; }
// 进行检查 // return: // -1 函数运行出错 // 0 检查没有发现错误 // 1 检查发现了错误 public int Check(out string strError) { strError = ""; int nRet = 0; bool bStrict = true; // 是否严格检查 // 检查是否每行都输入了价格、份数 for (int i = 0; i < this.Items.Count; i++) { Item item = this.Items[i]; // 只检查新规划的事项 if ((item.State & ItemState.ReadOnly) != 0) continue; // 跳过未曾修改过的事项 if ((item.State & ItemState.New) == 0 && (item.State & ItemState.Changed) == 0) continue; // 进行检查 // return: // -1 函数运行出错 // 0 检查没有发现错误 // 1 检查发现了错误 nRet = item.location.Check(out strError); if (nRet != 0) { strError = "第 " + (i + 1).ToString() + " 行: 去向 格式有问题: " + strError; return 1; } // 2009/11/9 string strTotalPrice = ""; try { strTotalPrice = item.TotalPrice; } catch (Exception ex) { strError = "获取item.TotalPrice时出错: " + ex.Message; return -1; } if (String.IsNullOrEmpty(strTotalPrice) == true) { if (String.IsNullOrEmpty(item.Price) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入价格"; return 1; } } else { if (String.IsNullOrEmpty(item.StateString) == true && String.IsNullOrEmpty(item.Price) == false) { strError = "第 " + (i + 1).ToString() + " 行: 当输入了价格 ('"+item.Price+"') 时,必须把总价格设置为空 (但现在为 '"+strTotalPrice+"')"; return 1; } } if (this.ArriveMode == false) // 2009/2/4 { // 订购模式 if (String.IsNullOrEmpty(item.CopyString) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入复本数"; return 1; } } else { // 验收模式 // 不一定每一行都要验收 // TODO: 是否检查一下至少有一行验收了?不太好检查。 } if (this.SeriesMode == true) { if (String.IsNullOrEmpty(item.RangeString) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入时间范围"; return 1; } if (item.RangeString.Length != (2*8 + 1)) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入完整的时间范围"; return 1; } // return: // -1 error // 0 succeed nRet = VerifyDateRange(item.RangeString, out strError); if (nRet == -1) { strError = "第 " + (i + 1).ToString() + " 行: " + strError; return 1; } if (String.IsNullOrEmpty(item.IssueCountString) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入期数"; return 1; } } if (bStrict == true) { if (String.IsNullOrEmpty(item.Source) == true && item.Seller != "交换" && item.Seller != "赠") { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入经费来源"; return 1; } // 2009/2/15 if (item.Seller == "交换" || item.Seller == "赠") { if (String.IsNullOrEmpty(item.Source) == false) { strError = "第 " + (i + 1).ToString() + " 行: 如果渠道为 交换 或 赠,则经费来源必须为空"; return 1; } } if (String.IsNullOrEmpty(item.Seller) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入渠道"; return 1; } /* if (String.IsNullOrEmpty(item.CatalogNo) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入书目号"; return 1; } * */ if (String.IsNullOrEmpty(item.Class) == true) { strError = "第 " + (i + 1).ToString() + " 行: 尚未输入类别"; return 1; } } } if (bStrict == true) { // 检查 渠道 + 经费来源 + 价格 3元组是否有重复 for (int i = 0; i < this.Items.Count; i++) { Item item = this.Items[i]; // 只检查新规划的事项 if ((item.State & ItemState.ReadOnly) != 0) continue; // 2009/2/4 只检查新输入的订购事项 if (String.IsNullOrEmpty(item.StateString) == false) continue; string strLocationString = item.location.Value; LocationCollection locations = new LocationCollection(); nRet = locations.Build(strLocationString, out strError); if (nRet == -1) { strError = "第 " + (i + 1).ToString() + " 行: 去向字符串 '"+strLocationString+"' 格式错误: " + strError; return -1; } string strUsedLibraryCodes = StringUtil.MakePathList(locations.GetUsedLibraryCodes()); // 检查馆代码是否在管辖范围内 // 只检查修改过的事项 if (IsChangedItem(item) == true && this.VerifyLibraryCode != null) { VerifyLibraryCodeEventArgs e = new VerifyLibraryCodeEventArgs(); e.LibraryCode = strUsedLibraryCodes; this.VerifyLibraryCode(this, e); if (string.IsNullOrEmpty(e.ErrorInfo) == false) { strError = "第 " + (i + 1).ToString() + " 行: 去向错误: " + e.ErrorInfo; return -1; } } for (int j = i + 1; j < this.Items.Count; j++) { Item temp_item = this.Items[j]; // 只检查新规划的事项 if ((temp_item.State & ItemState.ReadOnly) != 0) continue; // 跳过未曾修改过的事项 if (IsChangedItem(temp_item) == false) continue; // 2009/2/4 只检查新输入的订购事项 if (String.IsNullOrEmpty(temp_item.StateString) == false) continue; string strTempLocationString = temp_item.location.Value; LocationCollection temp_locations = new LocationCollection(); nRet = temp_locations.Build(strTempLocationString, out strError); if (nRet == -1) { strError = "第 " + (j + 1).ToString() + " 行: 去向字符串 '" + strTempLocationString + "' 格式错误: " + strError; return -1; } string strTempUsedLibraryCodes = StringUtil.MakePathList(temp_locations.GetUsedLibraryCodes()); if (this.CheckDupItem == true) { if (this.SeriesMode == false) { // 对图书检查四元组 if (item.Seller == temp_item.Seller && item.Source == temp_item.Source && item.Price == temp_item.Price && strUsedLibraryCodes == strTempUsedLibraryCodes) { strError = "第 " + (i + 1).ToString() + " 行 和 第 " + (j + 1) + " 行之间 渠道/经费来源/价格/去向(中所含的馆代码) 四元组重复,需要将它们合并为一行"; return 1; } } else { // 对期刊检查五元组 if (item.Seller == temp_item.Seller && item.Source == temp_item.Source && item.Price == temp_item.Price && item.RangeString == temp_item.RangeString && strUsedLibraryCodes == strTempUsedLibraryCodes) { strError = "第 " + (i + 1).ToString() + " 行 和 第 " + (j + 1) + " 行之间 渠道/经费来源/时间范围/价格/去向(中所含的馆代码) 五元组重复,需要将它们合并为一行"; return 1; } } } } } } return 0; }
// 根据订购记录路径,检索出订购记录,并且获得相关联的已验收册记录路径 // parameters: // strRecPath 订购库记录路径 // return: // -1 出错 // 1 成功 int LoadOrderItem(string strRecPath, out List<string> itemrecpaths, out string strError) { strError = ""; itemrecpaths = new List<string>(); int nRet = 0; string strOrderXml = ""; string strBiblioText = ""; string strOutputOrderRecPath = ""; string strOutputBiblioRecPath = ""; byte[] item_timestamp = null; long lRet = Channel.GetOrderInfo( stop, "@path:" + strRecPath, // "", "xml", out strOrderXml, out strOutputOrderRecPath, out item_timestamp, "recpath", out strBiblioText, out strOutputBiblioRecPath, out strError); if (lRet == -1 || lRet == 0) { strError = "获取订购记录 " + strRecPath + " 时出错: " + strError; return -1; } // 剖析一个订购xml记录,取出有关信息 XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strOrderXml); } catch (Exception ex) { strError = "订购记录XML装入DOM时出错: " + ex.Message; return -1; } // 观察订购库是不是期刊库类型 // return: // -1 不是订购库 // 0 图书类型 // 1 期刊类型 nRet = this.MainForm.IsSeriesTypeFromOrderDbName(Global.GetDbName(strRecPath)); if (nRet == -1) { strError = "IsSeriesTypeFromOrderDbName() '" + strRecPath + "' error"; return -1; } List<string> distributes = new List<string>(); if (nRet == 1) { string strRefID = DomUtil.GetElementText(dom.DocumentElement, "refID"); if (string.IsNullOrEmpty(strRefID) == true) { strError = "订购记录 '" + strRecPath + "' 中没有<refID>元素"; return -1; } string strBiblioDbName = this.MainForm.GetBiblioDbNameFromOrderDbName(Global.GetDbName(strRecPath)); string strIssueDbName = this.MainForm.GetIssueDbName(strBiblioDbName); // 如果是期刊的订购库,还需要通过订购记录的refid获得期记录,从期记录中才能得到馆藏分配信息 string strOutputStyle = ""; lRet = Channel.SearchIssue(stop, strIssueDbName, // "<全部>", strRefID, -1, "订购参考ID", "exact", this.Lang, "tempissue", "", strOutputStyle, out strError); if (lRet == -1 || lRet == 0) { strError = "检索 订购参考ID 为 " + strRefID + " 的期记录时出错: " + strError; return -1; } long lHitCount = lRet; long lStart = 0; long lCount = lHitCount; DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null; // 获取命中结果 for (; ; ) { Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } lRet = Channel.GetSearchResult( stop, "tempissue", lStart, lCount, "id", this.Lang, out searchresults, out strError); if (lRet == -1) { strError = "获取结果集时出错: " + strError; return -1; } if (lRet == 0) { strError = "获取结果集时出错: lRet = 0"; return -1; } for (int i = 0; i < searchresults.Length; i++) { DigitalPlatform.LibraryClient.localhost.Record searchresult = searchresults[i]; string strIssueRecPath = searchresult.Path; string strIssueXml = ""; string strOutputIssueRecPath = ""; lRet = Channel.GetIssueInfo( stop, "@path:" + strIssueRecPath, // "", "xml", out strIssueXml, out strOutputIssueRecPath, out item_timestamp, "recpath", out strBiblioText, out strOutputBiblioRecPath, out strError); if (lRet == -1 || lRet == 0) { strError = "获取期记录 " + strIssueRecPath + " 时出错: " + strError; return -1; } // 剖析一个期刊xml记录,取出有关信息 XmlDocument issue_dom = new XmlDocument(); try { issue_dom.LoadXml(strIssueXml); } catch (Exception ex) { strError = "期记录 '" + strOutputIssueRecPath + "' XML装入DOM时出错: " + ex.Message; return -1; } // 寻找 /orderInfo/* 元素 XmlNode nodeRoot = issue_dom.DocumentElement.SelectSingleNode("orderInfo/*[refID/text()='" + strRefID + "']"); if (nodeRoot == null) { strError = "期记录 '" + strOutputIssueRecPath + "' 中没有找到<refID>元素值为 '" + strRefID + "' 的订购内容节点..."; return -1; } string strDistribute = DomUtil.GetElementText(nodeRoot, "distribute"); distributes.Add(strDistribute); } lStart += searchresults.Length; lCount -= searchresults.Length; if (lStart >= lHitCount || lCount <= 0) break; } } else { string strDistribute = DomUtil.GetElementText(dom.DocumentElement, "distribute"); distributes.Add(strDistribute); } if (distributes.Count == 0) return 0; foreach (string strDistribute in distributes) { LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) return -1; for (int i = 0; i < locations.Count; i++) { Location location = locations[i]; if (string.IsNullOrEmpty(location.RefID) == true) continue; // 2012/9/4 string[] parts = location.RefID.Split(new char[] { '|' }); foreach (string text in parts) { string strRefID = text.Trim(); if (string.IsNullOrEmpty(strRefID) == true) continue; // 根据册记录的refid装入册记录 string strItemXml = ""; string strOutputItemRecPath = ""; lRet = Channel.GetItemInfo( stop, "@refID:" + strRefID, "", // "xml", out strItemXml, out strOutputItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strOutputBiblioRecPath, out strError); if (lRet == -1 || lRet == 0) { strError = "获取册记录 " + strRefID + " 时出错: " + strError; } itemrecpaths.Add(strOutputItemRecPath); } } } return 1; }
// 获得册参考ID列表 public int GetItemRefIDs(out List<string> ids, out string strError) { strError = ""; ids = new List<string>(); XmlNodeList nodes = this.dom.DocumentElement.SelectNodes("orderInfo/*/distribute"); for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; string strDistribute = node.InnerText.Trim(); if (String.IsNullOrEmpty(strDistribute) == true) continue; LocationCollection locations = new LocationCollection(); int nRet = locations.Build(strDistribute, out strError); if (nRet == -1) return -1; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; // 尚未创建过的事项,跳过 if (location.RefID == "*" || String.IsNullOrEmpty(location.RefID) == true) continue; ids.Add(location.RefID); } } return 0; }
// 复制新增 void menu_appendCopyElement_Click(object sender, EventArgs e) { int nPos = this.Container.Items.IndexOf(this); if (nPos == -1) { throw new Exception("not found myself"); } string strError = ""; string strXml = ""; Item source = this.Container.Items[nPos]; // 获得表示事项全部内容的XML记录 int nRet = BuildXml(out strXml, out strError); if (nRet == -1) throw new Exception(strError); string strBatchNo = ""; { string strDefaultXml = this.Container.GetDefaultXml(); if (string.IsNullOrEmpty(strDefaultXml) == false) { XmlDocument dom = new XmlDocument(); dom.LoadXml(strDefaultXml); strBatchNo = DomUtil.GetElementText(dom.DocumentElement, "batchNo"); } } // 修改一些字段 { XmlDocument dom = new XmlDocument(); dom.LoadXml(strXml); // 如果单价和总价都有,则要把总价清空 string strPrice = DomUtil.GetElementText(dom.DocumentElement, "price"); string strTotalPrice = DomUtil.GetElementText(dom.DocumentElement, "totalPrice"); if (string.IsNullOrEmpty(strPrice) == false && string.IsNullOrEmpty(strTotalPrice) == false) DomUtil.SetElementText(dom.DocumentElement, "totalPrice", ""); // 把 location 中的已验收信息清除 string strDistributeString = DomUtil.GetElementText(dom.DocumentElement, "distribute"); if (string.IsNullOrEmpty(strDistributeString) == false) { LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistributeString, out strError); if (nRet == -1) throw new Exception("馆藏分配去向字符串 '" + strDistributeString + "' 格式错误: " + strError); strDistributeString = locations.ToString(false); DomUtil.SetElementText(dom.DocumentElement, "distribute", strDistributeString); } DomUtil.SetElementText(dom.DocumentElement, "state", ""); DomUtil.SetElementText(dom.DocumentElement, "refID", ""); DomUtil.SetElementText(dom.DocumentElement, "range", ""); DomUtil.SetElementText(dom.DocumentElement, "batchNo", strBatchNo); strXml = dom.DocumentElement.OuterXml; } Item target = this.Container.InsertNewItem(nPos + 1, strXml); #if NO target.StateString = ""; target.RefID = ""; target.RangeString = ""; // TODO: 可以从上一个事项的时候后面自动计算延展 #endif target.EnsureVisible(); }
// // return: // -1 出错 // 0 没有发生替换修改 // >0 共修改了多少个<distribute>元素内容 /// <summary> /// 更换 orderInfo 元素里的 distribute 元素中的 refid 字符串 /// </summary> /// <param name="item_refid_change_table">参考 ID 对照表</param> /// <param name="strError">返回出错信息</param> /// <returns>-1 出错; 0 没有发生替换修改; >0 共修改了多少个 distribute 元素内容</returns> public int ReplaceOrderInfoItemRefID(Hashtable item_refid_change_table, out string strError) { strError = ""; int nRet = 0; string strOrderInfo = this.OrderInfo; if (String.IsNullOrEmpty(strOrderInfo) == true) { return(0); } XmlDocument dom = new XmlDocument(); dom.LoadXml("<orderInfo/>"); try { dom.DocumentElement.InnerXml = strOrderInfo; } catch (Exception ex) { strError = "load inner xml error: " + ex.Message; return(-1); } int nChangedCount = 0; XmlNodeList nodes = dom.DocumentElement.SelectNodes("*/distribute"); for (int i = 0; i < nodes.Count; i++) { string strDistribute = nodes[i].InnerText; if (String.IsNullOrEmpty(strDistribute) == true) { continue; } LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { return(-1); } bool bChanged = false; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; if (item_refid_change_table.Contains(location.RefID) == true) { location.RefID = (string)item_refid_change_table[location.RefID]; bChanged = true; } } if (bChanged == true) { nodes[i].InnerText = locations.ToString(true); nChangedCount++; } } if (nChangedCount > 0) { this.OrderInfo = dom.DocumentElement.InnerXml; } return(nChangedCount); }
// 将两个订购XML片断合并 // 当旧的和新的都是全管辖范围内,就允许新的全部替换旧的;否则只允许替换<distribute>元素内容 // parameters: // strLibraryCodeList 当前用户管辖的分馆代码列表 // strMergedXml [out]范围订购<root>元素的InnerXml // return: // -1 出错 // 0 正常 // 1 发生了超越范围的修改 public static int MergeOrderNode(XmlNode exist_node, XmlNode new_node, string strLibraryCodeList, out string strMergedXml, out string strError) { strError = ""; strMergedXml = ""; int nRet = 0; Debug.Assert(SessionInfo.IsGlobalUser(strLibraryCodeList) == false, "全局用户不应调用函数 MergeOrderNode()"); string strExistDistribute = DomUtil.GetElementText(exist_node, "distribute"); string strNewDistribute = DomUtil.GetElementText(new_node, "distribute"); bool bExistControlled = true; bool bNewControlled = true; if (string.IsNullOrEmpty(strExistDistribute) == false) { // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 nRet = DistributeInControlled(strExistDistribute, strLibraryCodeList, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { bExistControlled = false; } } if (string.IsNullOrEmpty(strNewDistribute) == false) { // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 nRet = DistributeInControlled(strNewDistribute, strLibraryCodeList, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { bNewControlled = false; } } if (bExistControlled == true && bNewControlled == true) { // 当旧的和新的都是全管辖范围内,就允许新的全部替换旧的 strMergedXml = new_node.InnerXml; return(0); } string strExistCopy = DomUtil.GetElementText(exist_node, "copy"); string strExistPrice = DomUtil.GetElementText(exist_node, "price"); string strChangedCopy = DomUtil.GetElementText(new_node, "copy"); string strChangedPrice = DomUtil.GetElementText(new_node, "price"); // 比较两个复本字符串 { ParseOldNewValue(strExistCopy, out string strExistOldValue, out string strExistNewValue); ParseOldNewValue(strChangedCopy, out string strChangedOldValue, out string strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购套数(方括号左边的部分)不允许修改。(原来='" + strExistCopy + "',新的='" + strChangedCopy + "')"; return(1); } // 检查验收套数的改变,是否正好和distribute字符串内的改变吻合 } // 比较两个价格字符串 { ParseOldNewValue(strExistPrice, out string strExistOldValue, out string strExistNewValue); ParseOldNewValue(strChangedPrice, out string strChangedOldValue, out string strChangedNewValue); // 避免用 == 判断。用 IsEqual 判断,可以把 CNY10.00 和 10.00 视作等同 if (PriceUtil.IsEqual(strExistOldValue, strChangedOldValue) == false) { strError = "订购价(方括号左边的部分)不允许修改。(原来='" + strExistPrice + "',新的='" + strChangedPrice + "')"; return(1); } if (PriceUtil.IsEqual(strExistNewValue, strChangedNewValue) == false) { strError = "验收价(方括号中的部分)不允许修改。(原来='" + strExistPrice + "',新的='" + strChangedPrice + "')"; return(1); } } LocationCollection new_locations = new LocationCollection(); nRet = new_locations.Build(strNewDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strNewDistribute + "' 格式不正确"; return(-1); } LocationCollection exist_locations = new LocationCollection(); nRet = exist_locations.Build(strExistDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strExistDistribute + "' 格式不正确"; return(-1); } if (exist_locations.Count != new_locations.Count) { strError = "馆藏分配事项个数发生了改变(原来=" + exist_locations.Count.ToString() + ",新的=" + new_locations.Count.ToString() + ")"; return(1); } for (int i = 0; i < exist_locations.Count; i++) { Location exist_location = exist_locations[i]; Location new_location = new_locations[i]; if (exist_location.Name != new_location.Name) { // 进一步检查是否馆代码部分改变了 // 解析 LibraryApplication.ParseCalendarName(exist_location.Name, out string strCode1, out string strPureName); LibraryApplication.ParseCalendarName(new_location.Name, out string strCode2, out strPureName); // 只要馆代码部分不改变即可 if (strCode1 != strCode2) { strError = "第 " + (i + 1).ToString() + " 个馆藏分配事项的名字(的馆代码部分)发生改变 (原来='" + exist_location.Name + "',新的='" + new_location.Name + "')"; return(1); } } if (exist_location.RefID != new_location.RefID) { // 解析 LibraryApplication.ParseCalendarName(exist_location.Name, out string strLibraryCode, out string strPureName); if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false) { strError = "馆代码 '" + strLibraryCode + "' 不在范围 '" + strLibraryCodeList + "' 内,不允许进行收登操作。"; return(1); } } } // 将旧的XML片断装入,只修改里面的三个元素值。这样可以保证三个元素以外的原记录内容不被修改 XmlDocument dom = new XmlDocument(); try { dom.LoadXml(exist_node.OuterXml); } catch (Exception ex) { strError = "exist_node.OuterXml装入XMLDOM失败: " + ex.Message; return(-1); } DomUtil.SetElementText(dom.DocumentElement, "copy", strChangedCopy); DomUtil.SetElementText(dom.DocumentElement, "price", strChangedPrice); DomUtil.SetElementText(dom.DocumentElement, "distribute", strNewDistribute); strMergedXml = dom.DocumentElement.InnerXml; return(0); }
// 将两个订购XML片断合并 // 当旧的和新的都是全管辖范围内,就允许新的全部替换旧的;否则只允许替换<distribute>元素内容 // parameters: // strLibraryCodeList 当前用户管辖的分馆代码列表 // strMergedXml [out]范围订购<root>元素的InnerXml // return: // -1 出错 // 0 正常 // 1 发生了超越范围的修改 // 2 有部分修改需求没有兑现 // 3 全部修改都没有兑现 (2018/10/9) public int MergeOrderNode(XmlNode exist_node, XmlNode new_node, string strLibraryCodeList, out string strMergedXml, out string strError) { strError = ""; strMergedXml = ""; int nRet = 0; Debug.Assert(SessionInfo.IsGlobalUser(strLibraryCodeList) == false, "全局用户不应调用函数 MergeOrderNode()"); string strExistDistribute = DomUtil.GetElementText(exist_node, "distribute"); string strNewDistribute = DomUtil.GetElementText(new_node, "distribute"); bool bExistControlled = true; bool bNewControlled = true; if (string.IsNullOrEmpty(strExistDistribute) == false) { // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 nRet = DistributeInControlled(strExistDistribute, strLibraryCodeList, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { bExistControlled = false; } } if (string.IsNullOrEmpty(strNewDistribute) == false) { // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 nRet = DistributeInControlled(strNewDistribute, strLibraryCodeList, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { bNewControlled = false; } } if (bExistControlled == true && bNewControlled == true) { // 当旧的和新的都是全管辖范围内,就允许新的全部替换旧的 strMergedXml = new_node.InnerXml; return(0); } string strExistCopy = DomUtil.GetElementText(exist_node, "copy"); string strExistPrice = DomUtil.GetElementText(exist_node, "price"); string strExistFixedPrice = DomUtil.GetElementText(exist_node, "fixedPrice"); string strExistDiscount = DomUtil.GetElementText(exist_node, "discount"); string strChangedCopy = DomUtil.GetElementText(new_node, "copy"); string strChangedPrice = DomUtil.GetElementText(new_node, "price"); string strChangedFixedPrice = DomUtil.GetElementText(new_node, "fixedPrice"); string strChangedDiscount = DomUtil.GetElementText(new_node, "discount"); // 比较两个复本字符串 { IssueItemDatabase.ParseOldNewValue(strExistCopy, out string strExistOldValue, out string strExistNewValue); IssueItemDatabase.ParseOldNewValue(strChangedCopy, out string strChangedOldValue, out string strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购套数(方括号左边的部分)不允许修改。(原来='" + strExistCopy + "',新的='" + strChangedCopy + "')"; return(1); } // 检查验收套数的改变,是否正好和distribute字符串内的改变吻合 } // 比较两个价格字符串 { IssueItemDatabase.ParseOldNewValue(strExistPrice, out string strExistOldValue, out string strExistNewValue); IssueItemDatabase.ParseOldNewValue(strChangedPrice, out string strChangedOldValue, out string strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购价(方括号左边的部分)不允许修改。(原来='" + strExistPrice + "',新的='" + strChangedPrice + "')"; return(1); } if (strExistNewValue != strChangedNewValue) { // strError = "验收价(方括号中的部分)不允许修改。(原来='" + strExistPrice + "',新的='" + strChangedPrice + "')"; return(1); } } // 2018/7/31 // 比较两个码洋字符串 { IssueItemDatabase.ParseOldNewValue(strExistFixedPrice, out string strExistOldValue, out string strExistNewValue); IssueItemDatabase.ParseOldNewValue(strChangedFixedPrice, out string strChangedOldValue, out string strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购码洋(方括号左边的部分)不允许修改。(原来='" + strExistPrice + "', 新的='" + strChangedPrice + "')"; return(1); } if (strExistNewValue != strChangedNewValue) { strError = "验收码洋(方括号中的部分)不允许修改。(原来='" + strExistPrice + "', 新的='" + strChangedPrice + "')"; return(1); } } // 2018/7/31 // 比较两个折扣字符串 { IssueItemDatabase.ParseOldNewValue(strExistDiscount, out string strExistOldValue, out string strExistNewValue); IssueItemDatabase.ParseOldNewValue(strChangedDiscount, out string strChangedOldValue, out string strChangedNewValue); if (strExistOldValue != strChangedOldValue) { strError = "订购折扣(方括号左边的部分)不允许修改。(原来='" + strExistCopy + "', 新的='" + strChangedCopy + "')"; return(1); } } LocationCollection new_locations = new LocationCollection(); nRet = new_locations.Build(strNewDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strNewDistribute + "' 格式不正确"; return(-1); } LocationCollection exist_locations = new LocationCollection(); nRet = exist_locations.Build(strExistDistribute, out strError); if (nRet == -1) { strError = "馆藏分配字符串 '" + strExistDistribute + "' 格式不正确"; return(-1); } if (exist_locations.Count != new_locations.Count) { strError = "馆藏分配事项个数发生了改变(原来=" + exist_locations.Count.ToString() + ",新的=" + new_locations.Count.ToString() + ")"; return(1); } bool bDistributeChanged = false; for (int i = 0; i < exist_locations.Count; i++) { Location exist_location = exist_locations[i]; Location new_location = new_locations[i]; if (exist_location.Name != new_location.Name) { // 进一步检查是否馆代码部分改变了 string strCode1 = ""; string strPureName = ""; string strCode2 = ""; // 解析 LibraryApplication.ParseCalendarName(exist_location.Name, out strCode1, out strPureName); LibraryApplication.ParseCalendarName(new_location.Name, out strCode2, out strPureName); // 只要馆代码部分不改变即可 if (strCode1 != strCode2) { strError = "第 " + (i + 1).ToString() + " 个馆藏分配事项的名字(的馆代码部分)发生改变 (原来='" + exist_location.Name + "',新的='" + new_location.Name + "')"; return(1); } bDistributeChanged = true; } if (exist_location.RefID != new_location.RefID) { string strLibraryCode = ""; string strPureName = ""; // 解析 LibraryApplication.ParseCalendarName(exist_location.Name, out strLibraryCode, out strPureName); if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false) { strError = "馆代码 '" + strLibraryCode + "' 不在范围 '" + strLibraryCodeList + "' 内,不允许进行收登操作。"; return(1); } bDistributeChanged = true; } } // 将旧的XML片断装入,只修改里面的三个元素值。这样可以保证三个元素以外的原记录内容不被修改 XmlDocument dom = new XmlDocument(); try { dom.LoadXml(exist_node.OuterXml); } catch (Exception ex) { strError = "exist_node.OuterXml 装入 XMLDOM 失败: " + ex.Message; return(-1); } DomUtil.SetElementText(dom.DocumentElement, "copy", strChangedCopy); DomUtil.SetElementText(dom.DocumentElement, "price", strChangedPrice); DomUtil.SetElementText(dom.DocumentElement, "distribute", strNewDistribute); strMergedXml = dom.DocumentElement.InnerXml; List <string> skips = new List <string>(); List <string> differents = null; skips.Add("distribute"); skips.Add("operations"); // parameters: // skips 要跳过的、不参与比较的元素名 // return: // 0 没有差异 // 1 有差异。differents数组里面返回了有差异的元素名 nRet = IsItemInfoChanged(new_node, dom.DocumentElement, skips, out differents); if (nRet == 1) { strError = "对下列元素的修改没有兑现: " + StringUtil.MakePathList(differents); if (bDistributeChanged) { return(2); // 部分修改兑现 } return(3); // 所有修改都没有兑现 } if (nRet == 0 && bDistributeChanged == false) { // 没有任何修改发生 } return(0); }
void DoItems(List<string> item_xmls, ProcessInfo info) { string strError = ""; List<EntityInfo> entityArray = new List<EntityInfo>(); string strRootElementName = ""; foreach (string xml in item_xmls) { if (string.IsNullOrEmpty(xml)) continue; XmlDocument item_dom = new XmlDocument(); item_dom.LoadXml(xml); strRootElementName = item_dom.DocumentElement.LocalName; string strPath = item_dom.DocumentElement.GetAttribute("path"); string strTimestamp = item_dom.DocumentElement.GetAttribute("timestamp"); EntityInfo item = new EntityInfo(); string strRefID = DomUtil.GetElementText(item_dom.DocumentElement, "refID"); if (strRootElementName == "item") { RefreshRefID(info.ItemRefIDTable, ref strRefID); } else if (strRootElementName == "order") { RefreshRefID(info.OrderRefIDTable, ref strRefID); // 记录中 distribute 元素中的 refid 要被替换 string strDistribute = DomUtil.GetElementText(item_dom.DocumentElement, "distribute"); if (string.IsNullOrEmpty(strDistribute) == false) { LocationCollection collection = new LocationCollection(); int nRet = collection.Build(strDistribute, out strError); if (nRet != -1) { collection.RefreshRefIDs(ref info.ItemRefIDTable); } string strNewDistribute = collection.ToString(); if (strNewDistribute != strDistribute) { DomUtil.SetElementText(item_dom.DocumentElement, "distribute", strNewDistribute); } } } else { RefreshRefID(null, ref strRefID); } item.RefID = strRefID; DomUtil.SetElementText(item_dom.DocumentElement, "refID", strRefID); DomUtil.SetElementText(item_dom.DocumentElement, "parent", Global.GetRecordID(info.BiblioRecPath)); string strXml = item_dom.DocumentElement.OuterXml; item.Action = "new"; item.NewRecord = strXml; item.NewTimestamp = ByteArray.GetTimeStampByteArray(strTimestamp); item.OldRecord = ""; item.OldTimestamp = null; entityArray.Add(item); } info.stop.SetMessage("正在为书目记录 '" + info.BiblioRecPath + "' 上传 "+info.UploadedSubItems+"+" + entityArray.Count + " 个下属 " + strRootElementName + " 记录 ..."); info.UploadedSubItems += entityArray.Count; EntityInfo[] errorinfos = null; long lRet = 0; if (strRootElementName == "item") lRet = info.Channel.SetEntities( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else if (strRootElementName == "order") lRet = info.Channel.SetOrders( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else if (strRootElementName == "issue") lRet = info.Channel.SetIssues( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else if (strRootElementName == "comment") lRet = info.Channel.SetComments( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else { strError = "未知的 strRootElementName '" + strRootElementName + "'"; throw new Exception(strError); } if (lRet == -1) throw new Exception(strError); if (errorinfos == null || errorinfos.Length == 0) return; StringBuilder text = new StringBuilder(); foreach (EntityInfo error in errorinfos) { if (String.IsNullOrEmpty(error.RefID) == true) throw new Exception("服务器返回的EntityInfo结构中RefID为空"); // 正常信息处理 if (error.ErrorCode == ErrorCodeValue.NoError) continue; text.Append(error.RefID + "在提交保存过程中发生错误 -- " + error.ErrorInfo + "\r\n"); info.ItemErrorCount++; } if (text.Length > 0) { strError = "在为书目记录 '" + info.BiblioRecPath + "' 导入下属 '" + strRootElementName + "' 记录的阶段出现错误:\r\n" + text.ToString(); this.OutputText(strError, 2); // 询问是否忽略错误继续向后处理? 此后全部忽略? if (AskContinue(info, strError) == false) throw new Exception(strError); } }