// 根据日志 XML 记录填充数据 // 本函数负责填充基类的数据成员 public virtual int SetData(XmlDocument dom, string strDate, long lIndex, out List <OperBase> lines, out string strError) { strError = ""; lines = null; if (string.IsNullOrEmpty(strDate) == true || strDate.Length != 8) { strError = "strDate 的值 '" + strDate + "' 格式错误,应该为 8 字符的数字"; return(-1); } string strOperation = DomUtil.GetElementText(dom.DocumentElement, "operation"); string strAction = DomUtil.GetElementText(dom.DocumentElement, "action"); string strOperator = DomUtil.GetElementText(dom.DocumentElement, "operator"); string strOperTime = DomUtil.GetElementText(dom.DocumentElement, "operTime"); string strLibraryCode = DomUtil.GetElementText(dom.DocumentElement, "libraryCode"); Debug.Assert(strDate.Length == 8, ""); this.Date = strDate; this.No = lIndex; this.SubNo = 0; this.LibraryCode = "," + strLibraryCode + ","; // 这样便于构造 SQL like 语句 this.Operation = strOperation; this.Action = strAction; this.OperTime = Replication.GetLocalTime(strOperTime); this.Operator = strOperator; return(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); }