Beispiel #1
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");

            // 比较两个复本字符串
            {
                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);
        }