// 将两个订购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); }
// 是否全部订购信息片断中的馆藏地点都在当前用户管辖之下? // 那些没有名字的(馆藏地点)分配事项,算在分馆用户的管辖范围以外。没有名字的馆藏地点,在订购时视为地点未定 // return: // -1 出错 // 0 不是全部都在管辖范围内 // 1 都在管辖范围内 int IsAllOrderControlled(XmlNode nodeOrderInfo, string strLibraryCodeList, out string strError) { strError = ""; if (SessionInfo.IsGlobalUser(strLibraryCodeList) == true) { return(1); } // 对新提交的记录中的每个订购片断进行循环 XmlNodeList nodes = nodeOrderInfo.SelectNodes("*"); foreach (XmlNode node in nodes) { string strDistribute = DomUtil.GetElementText(node, "distribute"); if (string.IsNullOrEmpty(strDistribute) == true) { continue; } // 观察一个馆藏分配字符串,看看是否在当前用户管辖范围内 // return: // -1 出错 // 0 超过管辖范围。strError中有解释 // 1 在管辖范围内 int nRet = DistributeInControlled(strDistribute, strLibraryCodeList, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { return(0); } #if NO LocationCollcetion locations = new LocationCollcetion(); 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 = ""; // 解析 LibraryApplication.ParseCalendarName(location.Name, out strLibraryCode, out strPureName); if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false) { strError = "馆代码 '" + strLibraryCode + "' 不在范围 '" + strLibraryCodeList + "' 内"; return(0); } } #endif } return(1); }