Beispiel #1
0
        // 从 XML 记录变换
        // parameters:
        //      strLogCreateTime    日志操作记载的创建时间。若不是创建动作的其他时间,不要放在这里
        public static int FromXml(XmlDocument dom,
                                  string strItemRecPath,
                                  string strBiblioRecPath,
                                  string strLogCreateTime,
                                  ref Item line,
                                  out string strError)
        {
            strError = "";
            int nRet = 0;

            if (line == null)
            {
                line = new Item();
            }

            line.ItemRecPath = strItemRecPath;
            line.ItemBarcode = DomUtil.GetElementText(dom.DocumentElement,
                                                      "barcode");

            if (string.IsNullOrEmpty(line.ItemBarcode))
            {
                string strRefID = DomUtil.GetElementText(dom.DocumentElement, "refID");
                line.ItemBarcode = "@refID:" + strRefID;
            }

            string location = StringUtil.GetPureLocationString(
                DomUtil.GetElementText(dom.DocumentElement,
                                       "location")); // 要变为纯净的地点信息,即不包含 #reservation 之类

            line.Location = Item.CanonicalizeLocationString(location);

            line.AccessNo = DomUtil.GetElementText(dom.DocumentElement,
                                                   "accessNo");
            line.BiblioRecPath = strBiblioRecPath;
            line.State         = DomUtil.GetElementText(dom.DocumentElement,
                                                        "state");

            line.Borrower = DomUtil.GetElementText(dom.DocumentElement,
                                                   "borrower");
            line.BorrowTime = Replication.GetLocalTime(DomUtil.GetElementText(dom.DocumentElement,
                                                                              "borrowDate"));
            line.BorrowPeriod = DomUtil.GetElementText(dom.DocumentElement,
                                                       "borrowPeriod");
            // line.ReturningTime = GetLocalTime(DomUtil.GetElementText(dom.DocumentElement, "returningDate"));

            if (line.BorrowTime != DateTime.MinValue)
            {
                // parameters:
                //      strBorrowTime   借阅起点时间。u 格式
                //      strReturningTime    返回应还时间。 u 格式
                nRet = Replication.BuildReturingTimeString(line.BorrowTime,
                                                           line.BorrowPeriod,
                                                           out DateTime returningTime,
                                                           out strError);
                if (nRet == -1)
                {
                    line.ReturningTime = DateTime.MinValue;
                }
                else
                {
                    line.ReturningTime = returningTime;
                }
            }
            else
            {
                line.ReturningTime = DateTime.MinValue;
            }

            string strPrice = DomUtil.GetElementText(dom.DocumentElement,
                                                     "price");

            nRet = Replication.ParsePriceString(strPrice,
                                                out decimal value,
                                                out string strUnit,
                                                out strError);
            if (nRet == -1)
            {
                line.Price = 0;
                line.Unit  = "";
            }
            else
            {
                line.Price = value;
                line.Unit  = strUnit;
            }

            string  strTime = "";
            XmlNode node    = dom.DocumentElement.SelectSingleNode("operations/operation[@name='create']");

            if (node != null)
            {
                strTime = DomUtil.GetAttr(node, "time");
                try
                {
                    // TODO: Replication 里是否已经有特定函数?
                    strTime = DateTimeUtil.Rfc1123DateTimeStringToLocal(strTime, "u");
                }
                catch
                {
                }
            }
            if (string.IsNullOrEmpty(strTime) == true)
            {
                // 如果 operations 里面没有信息
                // 采用日志记录的时间
                try
                {
                    strTime = DateTimeUtil.Rfc1123DateTimeStringToLocal(strLogCreateTime, "u");
                }
                catch
                {
                }
            }

            if (DateTime.TryParse(strTime, out DateTime createTime) == true)
            {
                line.CreateTime = createTime;
            }
            return(0);
        }