Esempio n. 1
0
        void BuildAmerceRecord(XmlDocument domOperLog,
                               out string strBodyXml,
                               out string strReaderBarcode,
                               out string strReaderRefID)
        {
            strBodyXml       = "";
            strReaderBarcode = "";
            strReaderRefID   = "";

            string strError = "";

            // string strOperation = DomUtil.GetElementText(domOperLog.DocumentElement, "operation");
            string strAction      = DomUtil.GetElementText(domOperLog.DocumentElement, "action");
            string strLibraryCode = DomUtil.GetElementText(domOperLog.DocumentElement, "libraryCode");

            string      strReaderRecord = DomUtil.GetElementText(domOperLog.DocumentElement, "readerRecord");
            XmlDocument readerdom       = new XmlDocument();

            readerdom.LoadXml(strReaderRecord);

            strReaderRefID   = DomUtil.GetElementText(readerdom.DocumentElement, "refID");
            strReaderBarcode = DomUtil.GetElementText(readerdom.DocumentElement, "barcode");

            // 构造内容
            XmlDocument bodydom = new XmlDocument();

            bodydom.LoadXml("<root />");

            if (strAction == "amerce")
            {
                DomUtil.SetElementText(bodydom.DocumentElement, "type", "交费");
            }
            else if (strAction == "undo")
            {
                DomUtil.SetElementText(bodydom.DocumentElement, "type", "撤销交费");
            }
            else if (strAction == "modifyprice")
            {
                // DomUtil.SetElementText(bodydom.DocumentElement, "type", "变更交费金额");
                strBodyXml = "";
                return;
            }
            else if (strAction == "expire")
            {
                DomUtil.SetElementText(bodydom.DocumentElement, "type", "以停代金到期");
            }
            else if (strAction == "modifycomment")
            {
                // DomUtil.SetElementText(bodydom.DocumentElement, "type", "修改交费注释");
                strBodyXml = "";
                return;
            }
            else
            {
#if NO
                strError = "无法识别的 strAction '" + strAction + "'";
                throw new Exception(strError);
#endif
                strBodyXml = "";
                return;
            }

            // 复制日志记录中的一级元素
            XmlNodeList nodes = domOperLog.DocumentElement.SelectNodes("*");
            foreach (XmlNode node in nodes)
            {
                if (node.Name == "readerRecord" ||
                    node.Name == "oldReaderRecord" ||
                    node.Name == "expireOverdues" ||
                    node.Name == "amerceItems" ||
                    node.Name == "amerceRecord")
                {
                    continue;
                }

                DomUtil.SetElementText(bodydom.DocumentElement, node.Name, node.InnerText);
            }

            {
                XmlElement record = bodydom.CreateElement("patronRecord");
                bodydom.DocumentElement.AppendChild(record);
                record.InnerXml = readerdom.DocumentElement.InnerXml;

                DomUtil.DeleteElement(record, "borrowHistory");
                DomUtil.DeleteElement(record, "password");
                DomUtil.DeleteElement(record, "fingerprint");
                DomUtil.DeleteElement(record, "face");
                DomUtil.SetElementText(record, "libraryCode", strLibraryCode);
            }

            // items
            XmlElement amerce_items = bodydom.DocumentElement.SelectSingleNode("items") as XmlElement;
            if (amerce_items == null)
            {
                amerce_items = bodydom.CreateElement("items");
                bodydom.DocumentElement.AppendChild(amerce_items);
            }

            XmlNodeList amerce_records = domOperLog.DocumentElement.SelectNodes("amerceRecord");
            foreach (XmlElement amerce_record in amerce_records)
            {
                string strAmercedXml = amerce_record.InnerText;
                if (string.IsNullOrEmpty(strAmercedXml))
                {
                    continue;
                }

                string strOverdueString = "";
                string strTemp          = "";
                int    nRet             = LibraryApplication.ConvertAmerceRecordToOverdueString(strAmercedXml,
                                                                                                out strTemp,
                                                                                                out strOverdueString,
                                                                                                out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }

                XmlDocumentFragment fragment = bodydom.CreateDocumentFragment();
                fragment.InnerXml = strOverdueString;

                amerce_items.AppendChild(fragment);
            }

            // expire 情况要把 expireOverdues/overdue 翻译为 items/overdue 元素
            if (strAction == "expire")
            {
                XmlElement expireOverdues = domOperLog.DocumentElement.SelectSingleNode("expiredOverdues") as XmlElement;
                if (expireOverdues != null)
                {
                    amerce_items.InnerXml = expireOverdues.InnerXml;
                }
            }
            else
            {
                // 留着 amerceItem 元素做测试对照
            }

            RmsChannel channel = this.RmsChannels.GetChannel(this.App.WsUrl);
            if (channel == null)
            {
                strError = "channel == null";
                throw new Exception(strError);
            }
            // 为 overdue 元素添加 summary 属性
            XmlNodeList overdues = bodydom.DocumentElement.SelectNodes("items/overdue");
            foreach (XmlElement overdue in overdues)
            {
                string strItemBarcode = overdue.GetAttribute("barcode");
                if (string.IsNullOrEmpty(strItemBarcode))
                {
                    continue;
                }

                // 加入书目摘要
                string strSummary          = "";
                string strBiblioRecPath    = "";
                LibraryServerResult result = this.App.GetBiblioSummary(
                    null,
                    channel,
                    strItemBarcode,
                    "", // strItemRecPath,
                    null,
                    out strBiblioRecPath,
                    out strSummary);
                if (result.Value == -1)
                {
                    // strSummary = result.ErrorInfo;
                }
                else
                {
                    overdue.SetAttribute("summary", strSummary);
                }
            }

            strBodyXml = bodydom.DocumentElement.OuterXml;
        }