Esempio n. 1
0
        // 根据读者记录中 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");
                }
            }
        }
Esempio n. 2
0
        // 根据 amerceRecord 元素内容填充 line 的各个成员
        // parameters:
        //      strAction   amerce / undo
        static void FillRecord(
            string strAction,
            XmlElement record,
            AmerceOper line,
            StringBuilder debugInfo)
        {
            if (record == null)
            {
                return;
            }

            string strError = "";

            line.AmerceRecPath = DomUtil.GetAttr(record,
                                                 "recPath");
            line.Action = strAction;    //  "amerce"; 2016/12/6 修改为 strAction
            string      strRecord  = record.InnerText;
            XmlDocument amerce_dom = new XmlDocument();

            try
            {
                amerce_dom.LoadXml(strRecord);
                line.ReaderBarcode = DomUtil.GetElementText(amerce_dom.DocumentElement,
                                                            "readerBarcode");
                line.ItemBarcode = DomUtil.GetElementText(amerce_dom.DocumentElement,
                                                          "itemBarcode");
                line.ID = DomUtil.GetElementText(amerce_dom.DocumentElement,
                                                 "id");

                string strPrice = DomUtil.GetElementText(amerce_dom.DocumentElement,
                                                         "price");
                int nRet = ParsePriceString(strPrice,
                                            out decimal value,
                                            out string strUnit,
                                            out strError);
                if (nRet == -1)
                {
                    if (debugInfo != null)
                    {
                        debugInfo.Append("FillRecord() 解析金额字符串 '" + strPrice + "' 时出错(已被当作 0 处理): " + strError + "\r\n");
                    }

                    line.Unit  = "";
                    line.Price = 0;
                }
                else
                {
                    line.Unit  = strUnit;
                    line.Price = value;
                }

                line.Reason = DomUtil.GetElementText(amerce_dom.DocumentElement,
                                                     "reason");
            }
            catch (Exception ex)
            {
                if (debugInfo != null)
                {
                    debugInfo.Append("FillRecord() 出现异常: " + ExceptionUtil.GetExceptionText(ex) + "\r\n");
                }
            }
        }
Esempio n. 3
0
        // 根据日志 XML 记录填充数据
        public override int SetData(XmlDocument dom,
                                    string strDate,
                                    long lIndex,
                                    out List <OperBase> lines,
                                    out string strError)
        {
            strError = "";

            int nRet = base.SetData(dom, strDate, lIndex, out lines, out strError);

            if (nRet == -1)
            {
                return(-1);
            }

            StringBuilder debugInfo = new StringBuilder();

            this.ReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode");

            string strAction = DomUtil.GetElementText(dom.DocumentElement, "action");

            // 建立交费记录
            int i = 0;

            if (strAction == "amerce" ||
                strAction == "undo")    // 2016/12/6 增加
            {
                XmlNodeList records = dom.DocumentElement.SelectNodes("amerceRecord");
                foreach (XmlElement record in records)
                {
                    if (i == 0)
                    {
                        FillRecord(strAction, record, this, debugInfo);
                    }
                    else
                    {
                        if (lines == null)
                        {
                            lines = new List <OperBase>();
                        }
                        AmerceOper line = new AmerceOper();
                        (this as OperBase).CopyTo(line);
                        line.SubNo = i;
                        FillRecord(strAction, record, line, debugInfo);
                        lines.Add(line);
                    }

                    i++;
                }
            }

            // 建立价格变更记录
            {
                // modifyprice 动作,并没有对应的 amerceRecord 元素,因为尚未交费,只是修改了金额
                // 所以需要选出全部 amerceItem 元素
                XmlNodeList       temp_items = dom.DocumentElement.SelectNodes("amerceItems/amerceItem");
                List <XmlElement> items      = new List <XmlElement>();
                foreach (XmlElement item in temp_items)
                {
                    if (item.GetAttributeNode("newPrice") != null)
                    {
                        items.Add(item);
                    }
                    else
                    {
                        if (strAction == "modifyprice")
                        {
                            strError = "action 为 modifyprice 的日志记录中,出现了 amerceItem 元素缺乏 newPrice 属性的情况,格式错误";
                            return(-1);
                        }
                        continue;   // action 为 amerce 则有可能并不修改金额
                    }
                }

                if (items.Count > 0)
                {
                    string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode");
                    string strOldRecord     = DomUtil.GetElementText(dom.DocumentElement, "oldReaderRecord");
                    if (string.IsNullOrEmpty(strOldRecord))
                    {
                        // strError = "amerce 类型的日志记录要求具备 oldReaderRecord 元素文本内容,需要用详细级获取日志信息";
                        // return -1;
                        strError = "ReportForm SetData(): amerce 类型的日志记录要求具备 oldReaderRecord 元素文本内容,此日志记录并不具备(可能属于早期的不完备的日志记录)。因此无法计算修改金额的差值。strDate=" + strDate + ", lIndex=" + lIndex;
                        // MainForm.WriteErrorLog(strError);
                    }
                    else
                    {
                        foreach (XmlElement item in items)
                        {
                            string strID       = item.GetAttribute("id");
                            string strNewPrice = null;
                            if (item.GetAttributeNode("newPrice") != null)
                            {
                                strNewPrice = item.GetAttribute("newPrice");
                            }
                            else
                            {
                                if (strAction == "modifyprice")
                                {
                                    strError = "action 为 modifyprice 的日志记录中,出现了 amerceItem 元素缺乏 newPrice 属性的情况,格式错误";
                                    return(-1);
                                }
                                continue;   // action 为 amerce 则有可能并不修改金额
                            }

                            // oldPrice 需要从 oldReaderRecord 元素中获得
                            XmlElement overdue = GetOverdueByID(strOldRecord, strID);
                            if (overdue == null)
                            {
                                strError = "日志记录格式错误: 根据id '" + strID + "' 在日志记录<oldReaderRecord>元素内没有找到对应的<overdue>元素";
                                return(-1);
                            }

                            if (i == 0)
                            {
                                FillRecordByOverdue(overdue,
                                                    strReaderBarcode,
                                                    strNewPrice,
                                                    this,
                                                    debugInfo);
                            }
                            else
                            {
                                if (lines == null)
                                {
                                    lines = new List <OperBase>();
                                }
                                AmerceOper line = new AmerceOper();
                                (this as OperBase).CopyTo(line);
                                line.SubNo = i;
                                FillRecordByOverdue(overdue,
                                                    strReaderBarcode,
                                                    strNewPrice,
                                                    line,
                                                    debugInfo);
                                lines.Add(line);
                            }

                            i++;
                        }
                    }
                }
            }

            // 2016/12/6
            if (debugInfo.Length > 0)
            {
                strError = debugInfo.ToString();
            }
            return(0);
        }