// 根据册条码号,检索出其册记录路径和从属的书目记录路径。 public static int SearchTwoRecPathByBarcode( Stop stop, LibraryChannel Channel, string strBarcode, out string strItemRecPath, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; strItemRecPath = ""; string strItemText = ""; string strBiblioText = ""; byte[] item_timestamp = null; long lRet = 0; #if NO Debug.Assert(this.DbType == "item", ""); if (this.DbType == "item") { lRet = Channel.GetItemInfo( stop, strBarcode, null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); } else { throw new Exception("SearchTwoRecPathByBarcode()只能在DbType=='item'时使用"); } #endif lRet = Channel.GetItemInfo( stop, strBarcode, null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) { return(-1); // error } return((int)lRet); // not found }
GetItemXmlResult GetItemXml(string pii) { LibraryChannel channel = this.GetChannel(); try { long lRet = channel.GetItemInfo(null, pii, "xml", out string strItemXml, "xml", out string strBiblio, out string strError); if (lRet == -1) { return new GetItemXmlResult { Value = -1, ErrorCode = channel.ErrorCode.ToString(), ErrorInfo = strError } } ; return(new GetItemXmlResult { Value = 0, ItemXml = strItemXml }); } finally { this.ReturnChannel(channel); } }
// 填充所有的册记录信息 void FillEntityInfo() { LibraryChannel channel = this.GetChannel(); try { var items = (List <ListViewItem>) this.Invoke(new Func <List <ListViewItem> >(() => { List <ListViewItem> results = new List <ListViewItem>(); results.AddRange(this.listView_tags.Items.Cast <ListViewItem>()); return(results); })); foreach (ListViewItem item in items) { ItemInfo item_info = (ItemInfo)item.Tag; var tag_info = item_info.OneTag.TagInfo; if (tag_info == null) { continue; } LogicChip chip = LogicChip.From(tag_info.Bytes, (int)tag_info.BlockSize); string pii = chip.FindElement(ElementOID.PII)?.Text; if (string.IsNullOrEmpty(pii)) { continue; } long lRet = channel.GetItemInfo(null, pii, "xml", out string xml, "", out string biblio, out string strError); if (lRet == -1) { // TODO: 给 item 设置出错状态 continue; } item_info.Xml = xml; } } catch (Exception ex) { // TODO: 如何报错?让操作者从册信息界面上可以看出报错 } finally { this.ReturnChannel(channel); } }
// 根据册条码号,检索出其册记录路径和从属的书目记录路径。 public static int SearchTwoRecPathByBarcode( Stop stop, LibraryChannel Channel, string strBarcode, out string strItemRecPath, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; strItemRecPath = ""; string strItemText = ""; string strBiblioText = ""; byte[] item_timestamp = null; long lRet = 0; #if NO Debug.Assert(this.DbType == "item", ""); if (this.DbType == "item") lRet = Channel.GetItemInfo( stop, strBarcode, null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); else throw new Exception("SearchTwoRecPathByBarcode()只能在DbType=='item'时使用"); #endif lRet = Channel.GetItemInfo( stop, strBarcode, null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) return -1; // error return (int)lRet; // not found }
// 根据册条码号,检索出其册记录路径和从属的书目记录路径,以及馆藏地点信息。 public static int SearchTwoRecPathByBarcode( Stop stop, LibraryChannel Channel, string strBarcode, out string strItemRecPath, out string strLocation, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; strItemRecPath = ""; strLocation = ""; string strItemText = ""; string strBiblioText = ""; byte[] item_timestamp = null; long lRet = 0; #if NO Debug.Assert(this.DbType == "item", ""); if (this.DbType == "item") lRet = Channel.GetItemInfo( stop, strBarcode, "xml", out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); else throw new Exception("SearchTwoRecPathByBarcode()只能在DbType=='item'时使用"); #endif lRet = Channel.GetItemInfo( stop, strBarcode, "xml", out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) return -1; // error if (lRet == 0) return 0; // not found XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strItemText); } catch (Exception ex) { strError = "item XML装入DOM时出错: " + ex.Message; return -1; } strLocation = DomUtil.GetElementText(dom.DocumentElement, "location"); return (int)lRet; }
// // return: // -1 error // 0 not found // 1 found /// <summary> /// 根据册条码号,装入册记录和书目记录 /// </summary> /// <param name="bEnableControls">是否在处理过程中禁止界面元素</param> /// <param name="strBarcode">册条码号</param> /// <param name="strError">返回出错信息</param> /// <returns> /// -1 出错 /// 0 没有找到 /// 1 找到 /// </returns> public int LoadRecord( bool bEnableControls, string strBarcode, out string strError) { strError = ""; if (bEnableControls == true) { EnableControls(false); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在初始化浏览器组件 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); } this.entityEditControl1.Clear(); this.m_webExternalHost_biblio.StopPrevious(); this.webBrowser_biblio.Stop(); Global.ClearHtmlPage(this.webBrowser_biblio, this.MainForm.DataDir); this.textBox_message.Text = ""; stop.SetMessage("正在装入册记录 " + strBarcode + " ..."); try { string strItemText = ""; string strBiblioText = ""; string strItemRecPath = ""; string strBiblioRecPath = ""; byte[] item_timestamp = null; long lRet = Channel.GetItemInfo( stop, strBarcode, "xml", out strItemText, out strItemRecPath, out item_timestamp, "html", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) { goto ERROR1; } if (lRet == 0) { return(0); } if (lRet > 1) { strError = "册条码号 " + strBarcode + " 发现被下列多个册记录所使用: \r\n" + strItemRecPath + "\r\n\r\n这是一个严重错误,请求助于系统管理员尽快排除。"; goto ERROR1; } this.BiblioRecPath = strBiblioRecPath; int nRet = this.entityEditControl1.SetData(strItemText, strItemRecPath, item_timestamp, out strError); if (nRet == -1) { goto ERROR1; } Debug.Assert(this.entityEditControl1.Changed == false, ""); this.entityEditControl1.SetReadOnly("librarian"); #if NO Global.SetHtmlString(this.webBrowser_biblio, strBiblioText, this.MainForm.DataDir, "quickchangeentityform_biblio"); #endif this.m_webExternalHost_biblio.SetHtmlString(strBiblioText, "quickchangeentityform_biblio"); this.textBox_message.Text = "册记录路径: " + strItemRecPath + " ;其从属的种(书目)记录路径: " + strBiblioRecPath; } finally { if (bEnableControls == true) { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); EnableControls(true); } } return(1); ERROR1: strError = "装载册条码号为 " + strBarcode + "的记录发生错误: " + strError; // MessageBox.Show(this, strError); return(-1); }
// 获得册记录信息和书目摘要信息 // parameters: // style 风格。network 表示只从网络获取册记录;否则优先从本地获取,本地没有再从网络获取册记录。无论如何,书目摘要都是尽量从本地获取 // .Value // 0 没有找到 // 1 找到 public static async Task <GetEntityDataResult> GetEntityDataAsync(string pii, string style) { bool network = StringUtil.IsInList("network", style); try { using (var releaser = await _channelLimit.EnterAsync()) using (BiblioCacheContext context = new BiblioCacheContext()) { if (_cacheDbCreated == false) { context.Database.EnsureCreated(); _cacheDbCreated = true; } LibraryChannel channel = App.CurrentApp.GetChannel(); TimeSpan old_timeout = channel.Timeout; channel.Timeout = TimeSpan.FromSeconds(10); try { GetEntityDataResult result = null; List <NormalResult> errors = new List <NormalResult>(); EntityItem entity_record = null; // *** // 第一步:获取册记录 if (network == false) { // 先尝试从本地实体库中获得记录 entity_record = context.Entities.Where(o => o.PII == pii).FirstOrDefault(); // EntityItem entity_record = null; // testing } if (entity_record != null) { result = new GetEntityDataResult { Value = 1, ItemXml = entity_record.Xml, ItemRecPath = entity_record.RecPath, Title = "", } } ; else { // 再尝试从 dp2library 服务器获取 // TODO: ItemXml 和 BiblioSummary 可以考虑在本地缓存一段时间 int nRedoCount = 0; REDO_GETITEMINFO: long lRet = channel.GetItemInfo(null, "item", pii, "", "xml", out string item_xml, out string item_recpath, out byte[] timestamp, "", out _, out _, out string strError); if (lRet == -1) { if ((channel.ErrorCode == ErrorCode.RequestError || channel.ErrorCode == ErrorCode.RequestTimeOut) && nRedoCount < 2) { nRedoCount++; goto REDO_GETITEMINFO; } // TODO: 这里不着急返回,还需要尝试获得书目摘要 errors.Add(new NormalResult { Value = -1, ErrorInfo = strError, ErrorCode = channel.ErrorCode.ToString() }); /* * return new GetEntityDataResult * { * Value = -1, * ErrorInfo = strError, * ErrorCode = channel.ErrorCode.ToString() * }; */ } else { result = new GetEntityDataResult { Value = 1, ItemXml = item_xml, ItemRecPath = item_recpath, Title = "", }; // 保存到本地数据库 await AddOrUpdateAsync(context, new EntityItem { PII = pii, Xml = item_xml, RecPath = item_recpath, Timestamp = timestamp, }); #if NO context.Entities.Add(new EntityItem { PII = pii, Xml = item_xml, RecPath = item_recpath, Timestamp = timestamp, }); try { await context.SaveChangesAsync(); } catch (Exception ex) { SqliteException sqlite_exception = ex.InnerException as SqliteException; if (sqlite_exception != null && sqlite_exception.SqliteErrorCode == 19) { // PII 发生重复了 } else { throw ex; } } #endif } } // *** /// 第二步:获取书目摘要 // 先尝试从本地书目库中获取书目摘要 var item = context.BiblioSummaries.Where(o => o.PII == pii).FirstOrDefault(); if (item != null && string.IsNullOrEmpty(item.BiblioSummary) == false) { if (result == null) { result = new GetEntityDataResult(); } result.Title = item.BiblioSummary; } else { // 从 dp2library 服务器获取书目摘要 int nRedoCount = 0; REDO_GETBIBLIOSUMMARY: long lRet = channel.GetBiblioSummary( null, pii, "", // strConfirmItemRecPath, null, out _, out string strSummary, out string strError); if (lRet == -1) { if ((channel.ErrorCode == ErrorCode.RequestError || channel.ErrorCode == ErrorCode.RequestTimeOut) && nRedoCount < 2) { nRedoCount++; goto REDO_GETBIBLIOSUMMARY; } errors.Add(new NormalResult { Value = -1, ErrorInfo = strError, ErrorCode = channel.ErrorCode.ToString() }); /* * return new GetEntityDataResult * { * Value = -1, * ErrorInfo = strError, * ErrorCode = channel.ErrorCode.ToString(), * }; */ } else { strSummary = strSummary?.Replace(". -- ", "\r\n"); // .Replace("/", "\r\n"); if (result == null) { result = new GetEntityDataResult(); } result.Title = strSummary; // 存入数据库备用 if (lRet == 1 && string.IsNullOrEmpty(strSummary) == false) { try { var exist_item = context.BiblioSummaries.Where(o => o.PII == pii).FirstOrDefault(); if (exist_item != null) { if (exist_item.BiblioSummary != strSummary) { exist_item.BiblioSummary = strSummary; context.BiblioSummaries.Update(exist_item); } } else { context.BiblioSummaries.Add(new BiblioSummaryItem { PII = pii, BiblioSummary = strSummary }); } await context.SaveChangesAsync(); } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"GetEntityDataAsync() 中保存 summary 时(PII 为 '{pii}')出现异常:{ExceptionUtil.GetDebugText(ex)}"); } } } /* * return new GetEntityDataResult * { * Value = (int)lRet, * ItemXml = item_xml, * ItemRecPath = item_recpath, * Title = strSummary, * ErrorInfo = strError, * ErrorCode = channel.ErrorCode.ToString() * }; */ } // 完全成功 if (result != null && errors.Count == 0) { return(result); } if (result == null) { return new GetEntityDataResult { Value = errors[0].Value, ErrorInfo = errors[0].ErrorInfo, ErrorCode = errors[0].ErrorCode } } ; result.ErrorInfo = errors[0].ErrorInfo; result.ErrorCode = errors[0].ErrorCode; return(result); } finally { channel.Timeout = old_timeout; App.CurrentApp.ReturnChannel(channel); } } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"GetEntityDataAsync() 出现异常: {ExceptionUtil.GetDebugText(ex)}"); return(new GetEntityDataResult { Value = -1, ErrorInfo = $"GetEntityDataAsync() 出现异常: {ex.Message}", ErrorCode = ex.GetType().ToString() }); } }
// 提前获得记录体,然后可以获得parentid public int LoadRecord(string strItemRecPath, out string strParentID, out string strError) { int nRet = 0; strError = ""; strParentID = ""; this.EnsureChildControls(); OpacApplication app = (OpacApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; string strXml = ""; // LibraryChannel channel = sessioninfo.Channel; LibraryChannel channel = sessioninfo.GetChannel(true); try { string strBiblio = ""; string strBiblioRecPath = ""; byte[] timestamp = null; string strOutputPath = ""; long lRet = // sessioninfo.Channel. channel.GetItemInfo( null, "@path:" + strItemRecPath, "xml", // strResultType out strXml, out strOutputPath, out timestamp, "", // "recpath", // strBiblioType out strBiblio, out strBiblioRecPath, out strError); if (lRet == -1) { goto ERROR1; } } finally { sessioninfo.ReturnChannel(channel); } XmlDocument itemdom = null; nRet = OpacApplication.LoadToDom(strXml, out itemdom, out strError); if (nRet == -1) { // text-level: 内部错误 strError = "装载册记录进入XML DOM时发生错误: " + strError; goto ERROR1; } strParentID = DomUtil.GetElementText(itemdom.DocumentElement, "parent"); // 册条码号 SetValue(itemdom, "barcode", "itembarcode"); // 右上角记录路径 string strUrl = "./book.aspx?ItemRecPath=" + HttpUtility.UrlEncode(strItemRecPath) + "#active"; LiteralControl recpath = (LiteralControl)this.FindControl("recpath"); recpath.Text = "<div class='recpath'><a href='" + strUrl + "' target='_blank' title='" + this.GetString("记录路径") + "'>" + strItemRecPath + "</a></div>"; // 状态 SetValue(itemdom, "state"); // 馆藏地点 SetValue(itemdom, "location"); // 册价格 SetValue(itemdom, "price"); // 出版时间 SetValue(itemdom, "publishTime", "publishtime"); // 渠道 SetValue(itemdom, "seller"); // 经费来源 SetValue(itemdom, "source"); // 索取号 SetValue(itemdom, "accessNo", "callnumber"); // 卷 SetValue(itemdom, "volume"); // 册类型 SetValue(itemdom, "bookType", "booktype"); // 登录号 SetValue(itemdom, "registerNo", "registerno"); // 注释 SetValue(itemdom, "comment"); // 批次号 SetValue(itemdom, "batchNo", "batchno"); LoginState loginstate = GlobalUtil.GetLoginState(this.Page); // 借者 string strBorrower = DomUtil.GetElementText(itemdom.DocumentElement, "borrower"); if (String.IsNullOrEmpty(strBorrower) == false) { string strBorrowDate = DomUtil.GetElementText(itemdom.DocumentElement, "borrowDate"); strBorrowDate = DateTimeUtil.LocalDate(strBorrowDate); string strBorrowPeriod = DomUtil.GetElementText(itemdom.DocumentElement, "borrowPeriod"); strBorrowPeriod = app.GetDisplayTimePeriodStringEx(strBorrowPeriod); string strBorrowerText = ""; if (loginstate == LoginState.Librarian) { strBorrowerText = "<a href='./readerinfo.aspx?barcode=" + strBorrower + "' target='_blank'>" + strBorrower + "</a>"; } else if (loginstate == LoginState.Reader && sessioninfo.ReaderInfo.Barcode == strBorrower) { strBorrowerText = strBorrower + "(" + this.GetString("我自己") + ")"; } else { strBorrowerText = new string('*', strBorrower.Length); } LiteralControl text = (LiteralControl)this.FindControl("borrower"); text.Text = this.GetString("借阅者") + ": " + strBorrowerText + " " + this.GetString("借阅日期") + ":" + strBorrowDate + " " + this.GetString("借阅期限") + ":" + strBorrowPeriod; } // 参考ID SetValue(itemdom, "refID", "refid"); this.ItemRecPath = strItemRecPath; this.m_bLoaded = true; return(1); ERROR1: return(-1); }
// 获得一个册的题名字符串 // .Value // 0 没有找到 // 1 找到 public static GetEntityDataResult GetEntityData(string pii) { LibraryChannel channel = App.CurrentApp.GetChannel(); TimeSpan old_timeout = channel.Timeout; channel.Timeout = TimeSpan.FromSeconds(10); try { // TODO: ItemXml 和 BiblioSummary 可以考虑在本地缓存一段时间 int nRedoCount = 0; REDO_GETITEMINFO: long lRet = channel.GetItemInfo(null, "item", pii, "", "xml", out string item_xml, out string item_recpath, out _, "", out _, out _, out string strError); if (lRet == -1) { if ((channel.ErrorCode == ErrorCode.RequestError || channel.ErrorCode == ErrorCode.RequestTimeOut) && nRedoCount < 2) { nRedoCount++; goto REDO_GETITEMINFO; } return new GetEntityDataResult { Value = -1, ErrorInfo = strError }; } nRedoCount = 0; REDO_GETBIBLIOSUMMARY: lRet = channel.GetBiblioSummary( null, pii, "", // strConfirmItemRecPath, null, out _, out string strSummary, out strError); if (lRet == -1) { if ((channel.ErrorCode == ErrorCode.RequestError || channel.ErrorCode == ErrorCode.RequestTimeOut) && nRedoCount < 2) { nRedoCount++; goto REDO_GETBIBLIOSUMMARY; } return new GetEntityDataResult { Value = -1, ErrorInfo = strError }; } strSummary = strSummary?.Replace(". -- ", "\r\n"); // .Replace("/", "\r\n"); return new GetEntityDataResult { Value = (int)lRet, ItemXml = item_xml, ItemRecPath = item_recpath, Title = strSummary, ErrorInfo = strError, ErrorCode = channel.ErrorCode.ToString() }; } finally { channel.Timeout = old_timeout; App.CurrentApp.ReturnChannel(channel); } }
//return: // -1 出错 // 0 没有找到 // 1 找到 static int GetRecord( LibraryChannel channel, Stop stop, string strDbType, string strRecPath, out string strXml, out byte[] baTimestamp, out string strError) { strError = ""; strXml = ""; baTimestamp = null; string strOutputRecPath = ""; string strBiblio = ""; string strBiblioRecPath = ""; // 获得册记录 long lRet = 0; if (strDbType == "item") { lRet = channel.GetItemInfo( stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (strDbType == "order") { lRet = channel.GetOrderInfo( stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (strDbType == "issue") { lRet = channel.GetIssueInfo( stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (strDbType == "comment") { lRet = channel.GetCommentInfo( stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else { strError = "未知的 strDbType '" + strDbType + "'"; return(-1); } if (lRet == 0) { return(0); // 是否设定为特殊状态? } if (lRet == -1) { return(-1); } return(1); }
// 装载数据 public override bool LoadData() { string strError = ""; int nRet = 0; BiblioInfo info = this.BiblioInfo; string strRecPath = this.BiblioInfo.RecPath; if (string.IsNullOrEmpty(info.OldXml) == true) { lock (syncRoot) { channel = Program.MainForm.GetChannel(); } try { // 显示 正在处理 this.HTML = GetWaitingHtml("正在获取 " + this.DbType + " 记录 " + strRecPath); ShowData(); byte [] baTimestamp = null; string strOutputRecPath = ""; string strBiblio = ""; string strBiblioRecPath = ""; string strXml = ""; // 获得记录 channel.Timeout = new TimeSpan(0, 0, 5); long lRet = 0; if (this.DbType == "item") { lRet = channel.GetItemInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "order") { lRet = channel.GetOrderInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "issue") { lRet = channel.GetIssueInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "comment") { lRet = channel.GetCommentInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "patron") { string[] results = null; // 获得读者记录 lRet = channel.GetReaderInfo( this.Stop, "@path:" + strRecPath, "xml", out results, out strOutputRecPath, out baTimestamp, out strError); if (lRet == 1) { if (results == null || results.Length == 0) { strError = "results error"; nRet = -1; } else { strXml = results[0]; } } } else { lRet = -1; strError = "无法识别的 DbType '" + this.DbType + "'"; } if (lRet == 0) { nRet = -1; strError = "获取记录 " + strRecPath + " 时出错: " + strError; } else if (lRet == -1) { nRet = -1; strError = "获取记录 " + strRecPath + " 时出错: " + strError; } else { info.OldXml = strXml; info.Timestamp = baTimestamp; info.RecPath = strRecPath; } } finally { LibraryChannel temp_channel = channel; lock (syncRoot) { channel = null; } Program.MainForm.ReturnChannel(temp_channel); } } string strXml1 = ""; string strHtml2 = ""; if (nRet == -1) { strHtml2 = HttpUtility.HtmlEncode(strError); } else { nRet = ItemSearchForm.GetXmlHtml(info, out strXml1, out strHtml2, out strError); if (nRet == -1) { throw new Exception(strError); } } this.HTML = "<html>" + Program.MainForm.GetMarcHtmlHeadString(true) + "<body>" + strHtml2 + EntityForm.GetTimestampHtml(info.Timestamp) + "</body></html>"; this.XML = strXml1; return(true); }
// 根据册记录路径,检索出从属的书目记录路径。 public static int SearchBiblioRecPath( Stop stop, LibraryChannel Channel, string strDbType, string strItemRecPath, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; string strItemText = ""; string strBiblioText = ""; byte[] item_timestamp = null; long lRet = 0; if (strDbType == "item") { lRet = Channel.GetItemInfo( stop, "@path:" + strItemRecPath, null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); } else if (strDbType == "comment") { lRet = Channel.GetCommentInfo( stop, "@path:" + strItemRecPath, // "", null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); } else if (strDbType == "order") { lRet = Channel.GetOrderInfo( stop, "@path:" + strItemRecPath, // "", null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); } else if (strDbType == "issue") { lRet = Channel.GetIssueInfo( stop, "@path:" + strItemRecPath, // "", null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); } else { throw new Exception("未知的DbType '" + strDbType + "'"); } if (lRet == -1) { return(-1); // error } return((int)lRet); // not found }
// 根据册条码号,检索出其册记录路径和从属的书目记录路径,以及馆藏地点信息。 public static int SearchTwoRecPathByBarcode( Stop stop, LibraryChannel Channel, string strBarcode, out string strItemRecPath, out string strLocation, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; strItemRecPath = ""; strLocation = ""; string strItemText = ""; string strBiblioText = ""; byte[] item_timestamp = null; long lRet = 0; #if NO Debug.Assert(this.DbType == "item", ""); if (this.DbType == "item") { lRet = Channel.GetItemInfo( stop, strBarcode, "xml", out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); } else { throw new Exception("SearchTwoRecPathByBarcode()只能在DbType=='item'时使用"); } #endif lRet = Channel.GetItemInfo( stop, strBarcode, "xml", out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); if (lRet == -1) { return(-1); // error } if (lRet == 0) { return(0); // not found } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strItemText); } catch (Exception ex) { strError = "item XML装入DOM时出错: " + ex.Message; return(-1); } strLocation = DomUtil.GetElementText(dom.DocumentElement, "location"); return((int)lRet); }
// parameters: // bAdvanceXml 是否为 AdvanceXml 情况 static void OutputBorrowHistory(LibraryChannel channel, XmlDocument reader_dom, ChargingHistoryLoader history_loader, CacheableBiblioLoader summary_loader, ref int nRowIndex, ref Patron patron) { int nStartRow = nRowIndex; // 第一笔借书的时间 string firstBorrowDate = ""; string history = "<table>" + "<tr>" + "<td>序号</td><td>借书日期</td><td>册条码号</td>" + "<td>书刊名称</td><td>索取号</td>" + "</tr>"; Hashtable clcHash = new Hashtable(); Hashtable yearHash = new Hashtable(); int nItemIndex = 0; foreach (ChargingItemWrapper wrapper in history_loader) { ChargingItem item = wrapper.Item; ChargingItem rel = wrapper.RelatedItem; string strItemBarcode = item.ItemBarcode; string strBorrowDate = rel == null ? "" : rel.OperTime; if (strBorrowDate.Length > 10) { strBorrowDate = strBorrowDate.Substring(0, 10); } // ==加到每年借书数量hashtable if (strBorrowDate.Length > 4) { string year = strBorrowDate.Substring(0, 4); int yearCouter = 0; if (yearHash.ContainsKey(year) == true) { yearCouter = (int)yearHash[year]; } yearCouter++; yearHash[year] = yearCouter; } // ==加入书目摘要,一次一条记录 string strSummary = ""; List <string> item_barcodes = new List <string>(); item_barcodes.Add("@itemBarcode:" + strItemBarcode); summary_loader.RecPaths = item_barcodes; foreach (BiblioItem biblio in summary_loader) { strSummary = biblio.Content; strSummary = GetShortSummary(strSummary); } // ==获取索取号 string accessNo = ""; // 获取册记录 string strItemXml = ""; string strBiblio = ""; string strError = ""; long lRet = channel.GetItemInfo(//null, strItemBarcode, "xml", out strItemXml, "xml", out strBiblio, out strError); if (-1 >= lRet) { accessNo = "获得'" + strItemBarcode + "'发生错误: " + strError; } else if (0 == lRet) { accessNo = strItemBarcode + " 记录不存在"; } else if (1 < lRet) { accessNo = strItemBarcode + " 记录重复,需馆员处理"; } else { // 获取索取号 XmlDocument itemDom = new XmlDocument(); try { itemDom.LoadXml(strItemXml); //accessNo accessNo = DomUtil.GetElementInnerText(itemDom.DocumentElement, "accessNo"); string bigClass = ""; if (string.IsNullOrEmpty(accessNo) == true) { bigClass = "[空]"; } else { bigClass = accessNo.Substring(0, 1); } int value = 0; if (clcHash.ContainsKey(bigClass) == true) { value = (int)clcHash[bigClass]; } value++; clcHash[bigClass] = value; } catch (Exception ex) { accessNo = strItemBarcode + " 加载到dom出错:" + ex.Message; } } nItemIndex++; string uiClass = ""; if (nItemIndex % 2 == 1) { uiClass = " class='grayline' "; } history += "<tr " + uiClass + ">" + "<td>" + nItemIndex + "</td><td>" + strBorrowDate + "</td><td>" + strItemBarcode + "</td>" + "<td>" + strSummary + "</td><td>" + accessNo + "</td>" + "</tr>"; // 由于是倒序,集合中最后一笔记录是第1次的借书记录 firstBorrowDate = strBorrowDate; } history += "</table>"; // 借书历史 patron.historyTable = history; patron.firstBorrowDate = firstBorrowDate; // ==每个类别数量== // 先借助ArrayList排序一下 List <string> list = new List <string>(); foreach (System.Collections.DictionaryEntry item in clcHash) { list.Add(item.Key.ToString()); } list.Sort(); string classTable = "<table class='clcTable'><tr><td>图书种类</td><td>借阅数量</td></tr>"; foreach (string k in list) { classTable += "<tr>" + "<td>" + k + "</td><td>" + (int)clcHash[k] + "</td>" + "</tr>"; } classTable += "</table>"; patron.clcTable = classTable; patron.covertClcCount = list.Count; //==每年借书数量== ArrayList al = new ArrayList(yearHash.Keys); al.Sort(); string yearTable = "<table class='yearTable'><tr><td>借阅时段</td><td>借阅数量</td></tr>"; foreach (string k in al) { yearTable += "<tr>" + "<td>" + k + "</td><td>" + (int)yearHash[k] + "</td>" + "</tr>"; } yearTable += "</table>"; patron.yearTable = yearTable; }
// 根据册记录路径,检索出从属的书目记录路径。 public static int SearchBiblioRecPath( Stop stop, LibraryChannel Channel, string strDbType, string strItemRecPath, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; string strItemText = ""; string strBiblioText = ""; byte[] item_timestamp = null; long lRet = 0; if (strDbType == "item") lRet = Channel.GetItemInfo( stop, "@path:" + strItemRecPath, null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); else if (strDbType == "comment") lRet = Channel.GetCommentInfo( stop, "@path:" + strItemRecPath, // "", null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); else if (strDbType == "order") lRet = Channel.GetOrderInfo( stop, "@path:" + strItemRecPath, // "", null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); else if (strDbType == "issue") lRet = Channel.GetIssueInfo( stop, "@path:" + strItemRecPath, // "", null, out strItemText, out strItemRecPath, out item_timestamp, "recpath", out strBiblioText, out strBiblioRecPath, out strError); else throw new Exception("未知的DbType '" + strDbType + "'"); if (lRet == -1) return -1; // error return (int)lRet; // not found }
private void button_search_Click(object sender, EventArgs e) { string strError = ""; this.listView_results.Items.Clear(); MainForm mainForm = null; if (this.MdiParent is MainForm) { mainForm = this.MdiParent as MainForm; } Debug.Assert(mainForm != null, "MdiParent 父窗口为 null"); mainForm.SetMessage(""); string strQueryWord = this.textBox_queryWord.Text; string strFrom = "读者证条码号"; string strMatchStyle = "exact"; if (string.IsNullOrEmpty(strQueryWord)) { strFrom = "__id"; strMatchStyle = "left"; } string strQueryXml = "<target list='" + mainForm.ArrivedDbName + ":" + strFrom + "'>" + "<item>" + "<word>" + strQueryWord + "</word>" + "<match>" + strMatchStyle + "</match>" + "<relation>=</relation>" + "<dataType>string</dataType>" + "</item>" + "<lang>zh</lang>" + "</target>"; LibraryChannel channel = mainForm.GetChannel(); try { string strOutputStyle = ""; SearchResponse searchResponse = channel.Search(strQueryXml, "", strOutputStyle); long lRet = searchResponse.SearchResult.Value; if (lRet == -1) { strError = "检索发生错误:" + strError; goto ERROR1; } else if (lRet == 0) { strError = "读者'" + strQueryWord + "'没有到书信息"; goto ERROR1; } long lHitCount = lRet; long lStart = 0; long lCount = lHitCount; Record[] searchresults = null; for (; ;) { Application.DoEvents(); lRet = channel.GetSearchResult("", lStart, lCount, "id,xml",// cols, "zh", out searchresults, out strError); if (lRet == -1) { strError = "获得检索结果发生错误:" + strError; goto ERROR1; } else if (lRet == 0) { strError = "没有获得到 0 条检索结果"; goto ERROR1; } int i = 0; foreach (Record record in searchresults) { // string[] cols = record.Cols; string strPath = record.Path; string strXML = record.RecordBody.Xml; XmlDocument dom = new XmlDocument(); dom.LoadXml(strXML); string strState = DomUtil.GetElementText(dom.DocumentElement, "state"); if ("arrived" == strState) { strState = "图书在馆"; } else if ("outof" == strState) { strState = "超过保留期"; } string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location"); string strAccessNo = DomUtil.GetElementText(dom.DocumentElement, "accessNo"); string strItemBarcode = DomUtil.GetElementText(dom.DocumentElement, "itemBarcode"); if (string.IsNullOrEmpty(strItemBarcode)) { continue; } GetItemInfoResponse itemInfoResponse = channel.GetItemInfo(strItemBarcode, "xml", // "xml:noborrowhistory", // resultType (itemType) "xml" // biblioType ); lRet = itemInfoResponse.GetItemInfoResult.Value; string strErrorInfo = itemInfoResponse.GetItemInfoResult.ErrorInfo; if (lRet != 1) { MessageBox.Show(strErrorInfo); continue; } string strOutMarcSyntax = ""; string strMARC = ""; string strMarcXml = itemInfoResponse.strBiblio; int nRet = MarcUtil.Xml2Marc(strMarcXml, false, "", // 自动识别 MARC 格式 out strOutMarcSyntax, out strMARC, out strError); if (nRet == -1) { continue; } MarcRecord marcRecord = new MarcRecord(strMARC); string strISBN = marcRecord.select("field[@name='010']/subfield[@name='a']").FirstContent; string strTitle = marcRecord.select("field[@name='200']/subfield[@name='a']").FirstContent; string strAuthor = marcRecord.select("field[@name='200']/subfield[@name='f']").FirstContent; string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode"); GetReaderInfoResponse readerInfoResponse = channel.GetReaderInfo(strReaderBarcode, "xml:noborrowhistory"); lRet = readerInfoResponse.GetReaderInfoResult.Value; strErrorInfo = readerInfoResponse.GetReaderInfoResult.ErrorInfo; if (lRet != 1) { MessageBox.Show(strErrorInfo); continue; } string strReaderXml = readerInfoResponse.results[0]; dom.LoadXml(strReaderXml); string strName = DomUtil.GetElementText(dom.DocumentElement, "name"); string strDept = DomUtil.GetElementText(dom.DocumentElement, "department"); // MessageBox.Show(strXML); string[] cols = new string[this.listView_results.Columns.Count]; cols[0] = strItemBarcode; cols[1] = strISBN; cols[2] = strTitle; cols[3] = strAuthor; cols[4] = strAccessNo; cols[5] = strLocation; cols[6] = strReaderBarcode; cols[7] = strName; cols[8] = strDept; cols[9] = strState; cols[10] = "未打印"; AppendNewLine(this.listView_results, strPath, cols); mainForm.SetMessage((lStart + i + 1).ToString() + " / " + lHitCount); i++; } lStart += searchresults.Length; lCount -= searchresults.Length; if (lStart >= lHitCount || lCount <= 0) { break; } } // this.listView_results.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } finally { mainForm.ReturnChannel(channel); } return; ERROR1: MessageBox.Show(strError); }
string[] FillListViewItem(LibraryChannel channel, Record record) { string strErrorInfo = ""; string strError = ""; string[] cols = new string[11]; long lRet = 0; string strXML = record.RecordBody.Xml; XmlDocument dom = new XmlDocument(); dom.LoadXml(strXML); string strState = DomUtil.GetElementText(dom.DocumentElement, "state"); if ("arrived" == strState) { strState = "图书在馆"; } else if ("outof" == strState) { strState = "超过保留期"; } string strLocation = DomUtil.GetElementText(dom.DocumentElement, "location"); string strAccessNo = DomUtil.GetElementText(dom.DocumentElement, "accessNo"); string strItemBarcode = DomUtil.GetElementText(dom.DocumentElement, "itemBarcode"); if (!string.IsNullOrEmpty(strItemBarcode)) { GetItemInfoResponse itemInfoResponse = channel.GetItemInfo(strItemBarcode, "xml", // "xml:noborrowhistory", // resultType (itemType) "xml"); lRet = itemInfoResponse.GetItemInfoResult.Value; strErrorInfo = itemInfoResponse.GetItemInfoResult.ErrorInfo; if (lRet == 1) { string strOutMarcSyntax = ""; string strMARC = ""; string strMarcXml = itemInfoResponse.strBiblio; int nRet = MarcUtil.Xml2Marc(strMarcXml, false, "", // 自动识别 MARC 格式 out strOutMarcSyntax, out strMARC, out strError); if (nRet != -1) { MarcRecord marcRecord = new MarcRecord(strMARC); string strISBN = marcRecord.select("field[@name='010']/subfield[@name='a']").FirstContent; string strTitle = marcRecord.select("field[@name='200']/subfield[@name='a']").FirstContent; string strAuthor = marcRecord.select("field[@name='200']/subfield[@name='f']").FirstContent; cols[1] = strISBN; cols[2] = strTitle; cols[3] = strAuthor; } } } string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "readerBarcode"); GetReaderInfoResponse readerInfoResponse = channel.GetReaderInfo(strReaderBarcode, "xml:noborrowhistory"); lRet = readerInfoResponse.GetReaderInfoResult.Value; strErrorInfo = readerInfoResponse.GetReaderInfoResult.ErrorInfo; if (lRet == 1) { string strReaderXml = readerInfoResponse.results[0]; dom.LoadXml(strReaderXml); string strName = DomUtil.GetElementText(dom.DocumentElement, "name"); string strDept = DomUtil.GetElementText(dom.DocumentElement, "department"); cols[6] = strReaderBarcode; cols[7] = strName; cols[8] = strDept; } cols[0] = strItemBarcode; cols[4] = strAccessNo; cols[5] = strLocation; cols[9] = strState; cols[10] = "未打印"; return(cols); }
// 获得一个册的题名字符串 // .Value // 0 没有找到 // 1 找到 public static GetEntityDataResult GetEntityData(string pii) { /* * title = ""; * item_xml = ""; * item_recpath = ""; */ LibraryChannel channel = App.CurrentApp.GetChannel(); try { long lRet = channel.GetItemInfo(null, "item", pii, "", "xml", out string item_xml, out string item_recpath, out byte[] item_timestamp, "", out string biblio_xml, out string biblio_recpath, out string strError); if (lRet == -1) { return new GetEntityDataResult { Value = -1, ErrorInfo = strError } } ; lRet = channel.GetBiblioSummary( null, pii, "", // strConfirmItemRecPath, null, out string strBiblioRecPath, out string strSummary, out strError); if (lRet == -1) { return new GetEntityDataResult { Value = -1, ErrorInfo = strError } } ; strSummary = strSummary.Replace(". -- ", "\r\n"); // .Replace("/", "\r\n"); return(new GetEntityDataResult { Value = (int)lRet, ItemXml = item_xml, ItemRecPath = item_recpath, Title = strSummary, ErrorInfo = strError, ErrorCode = channel.ErrorCode.ToString() }); } finally { App.CurrentApp.ReturnChannel(channel); } }
// 为一行装载数据 int LoadItemData(ListViewItem item, out string strError) { Debug.Assert(item.Tag == null, ""); strError = ""; string strRecPath = item.Text; string strItemXml = ""; string strBiblioHtml = ""; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在获取路径为 '" + strRecPath + "' 的册信息和书目信息 ..."); stop.BeginLoop(); Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { long lRet = Channel.GetItemInfo( stop, "@path:" + strRecPath, "xml", out strItemXml, "html", out strBiblioHtml, out strError); if (lRet == -1) { goto ERROR1; // error } if (lRet == 0) { strError = "路径为 '" + strRecPath + "' 的册记录没有找到"; goto ERROR1; // not found } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); this.Cursor = oldCursor; } ItemInfo info = new ItemInfo(); info.BiblioHtml = strBiblioHtml; info.ItemXml = strItemXml; info.RecPath = strRecPath; item.Tag = info; // 储存起来 return(0); ERROR1: return(-1); }
// 装载数据 public override bool LoadData() { string strError = ""; int nRet = 0; BiblioInfo info = this.BiblioInfo; string strRecPath = this.BiblioInfo.RecPath; if (string.IsNullOrEmpty(info.OldXml) == true) { lock (syncRoot) { channel = this.Container.MainForm.GetChannel(); } try { // 显示 正在处理 this.HTML = GetWaitingHtml("正在获取 "+this.DbType+" 记录 " + strRecPath); ShowData(); byte [] baTimestamp = null; string strOutputRecPath = ""; string strBiblio = ""; string strBiblioRecPath = ""; string strXml = ""; // 获得记录 channel.Timeout = new TimeSpan(0, 0, 5); long lRet = 0; if (this.DbType == "item") { lRet = channel.GetItemInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "order") { lRet = channel.GetOrderInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "issue") { lRet = channel.GetIssueInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "comment") { lRet = channel.GetCommentInfo( this.Stop, "@path:" + strRecPath, "xml", out strXml, out strOutputRecPath, out baTimestamp, "", out strBiblio, out strBiblioRecPath, out strError); } else if (this.DbType == "patron") { string[] results = null; // 获得读者记录 lRet = channel.GetReaderInfo( this.Stop, "@path:" + strRecPath, "xml", out results, out strOutputRecPath, out baTimestamp, out strError); if (lRet == 1) { if (results == null || results.Length == 0) { strError = "results error"; nRet = -1; } else strXml = results[0]; } } else { lRet = -1; strError = "无法识别的 DbType '"+this.DbType+"'"; } if (lRet == 0) { nRet = -1; strError = "获取记录 " + strRecPath + " 时出错: " + strError; } else if (lRet == -1) { nRet = -1; strError = "获取记录 " + strRecPath + " 时出错: " + strError; } else { info.OldXml = strXml; info.Timestamp = baTimestamp; info.RecPath = strRecPath; } } finally { LibraryChannel temp_channel = channel; lock (syncRoot) { channel = null; } this.Container.MainForm.ReturnChannel(temp_channel); } } string strXml1 = ""; string strHtml2 = ""; if (nRet == -1) { strHtml2 = HttpUtility.HtmlEncode(strError); } else { nRet = ItemSearchForm.GetXmlHtml(info, out strXml1, out strHtml2, out strError); if (nRet == -1) throw new Exception(strError); } this.HTML = "<html>" + this.Container.MainForm.GetMarcHtmlHeadString(true) + "<body>" + strHtml2 + EntityForm.GetTimestampHtml(info.Timestamp) + "</body></html>"; this.XML = strXml1; return true; }
// 获得一个册的题名字符串 NormalResult GetEntityData(string pii, out string title, out string item_xml, out string item_recpath) { title = ""; item_xml = ""; item_recpath = ""; LibraryChannel channel = App.CurrentApp.GetChannel(); try { #if NO GetItemInfo( stop, "item", strBarcode, "", strResultType, out strResult, out strItemRecPath, out item_timestamp, strBiblioType, out strBiblio, out strBiblioRecPath, out strError); #endif long lRet = channel.GetItemInfo(null, "item", pii, "", "xml", out item_xml, out item_recpath, out byte[] item_timestamp, "", out string biblio_xml, out string biblio_recpath, out string strError); if (lRet == -1) { return new NormalResult { Value = -1, ErrorInfo = strError } } ; lRet = channel.GetBiblioSummary( null, pii, "", // strConfirmItemRecPath, null, out string strBiblioRecPath, out string strSummary, out strError); if (lRet == -1) { return new NormalResult { Value = -1, ErrorInfo = strError } } ; title = strSummary; return(new NormalResult()); } finally { App.CurrentApp.ReturnChannel(channel); } }