// 将远程书目库名替换为本地书目库名 // return: // -1 出错 // 0 没有找到对应的本地书目库 // 1 找到,并已经替换 public int ReplaceBiblioRecPath( string strServer, ref string strRecPath, out string strError) { strError = ""; string strDbName = ResPath.GetDbName(strRecPath); string strID = ResPath.GetRecordId(strRecPath); foreach (ItemDbCfg cfg in this.ItemDbs) { if (cfg.ReplicationServer != strServer) { continue; } if (strDbName == cfg.ReplicationDbName) { strRecPath = cfg.BiblioDbName + "/" + strID; return(1); } } strRecPath = ""; return(0); }
public int BuildLocateParam(string strBiblioRecPath, string strIndex, out List <string> locateParam, out string strError) { strError = ""; locateParam = null; int nRet = 0; string strBiblioDbName = ResPath.GetDbName(strBiblioRecPath); string strOrderDbName = ""; // 根据书目库名, 找到对应的事项库名 // return: // -1 出错 // 0 没有找到(书目库) // 1 找到 nRet = this.GetItemDbName(strBiblioDbName, out strOrderDbName, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { strError = "书目库 '" + strBiblioDbName + "' 没有找到"; goto ERROR1; } if (String.IsNullOrEmpty(strOrderDbName) == true) { strError = "书目库名 '" + strBiblioDbName + "' 对应的" + this.ItemName + "库名没有定义"; goto ERROR1; } string strParentID = ResPath.GetRecordId(strBiblioRecPath); locateParam = new List <string>(); locateParam.Add(strOrderDbName); locateParam.Add(strParentID); locateParam.Add(strIndex); return(0); ERROR1: return(-1); }
// 通过册条码号检索察看相关种册信息 // 是否可以优化为:先看看当前窗口中是否有了要检索的条码号?不过这也等于放弃了查重功能。 void DoSearchFromBarcode(bool bDetectDup) { string strError = ""; // string strBiblioRecPath = ""; // string strItemRecPath = ""; EnableControls(false); try { this.Clear(); List <DoublePath> paths = null; int nRet = GetLinkInfoFromBarcode( this.textBox_itemBarcode.Text, true, out paths, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { goto NOTFOUND; } DoublePath dpath = null; if (nRet > 1) { // MessageBox.Show(this, "册条码号 " + this.textBox_itemBarcode.Text + " 出现重复现象,请及时解决。"); SelectDupItemRecordDlg dlg = new SelectDupItemRecordDlg(); dlg.MessageText = "册条码号 " + this.textBox_itemBarcode.Text + " 出现重复现象,这将会导致业务功能出现故障。\r\n\r\n请选择当前希望观察的一条册记录。"; dlg.Paths = paths; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) { return; // 放弃操作 } dpath = dlg.SelectedDoublePath; } else { dpath = paths[0]; } this.BiblioDbName = ResPath.GetDbName(dpath.BiblioRecPath); this.ItemDbName = ResPath.GetDbName(dpath.ItemRecPath); nRet = LoadBiblioRecord( dpath.BiblioRecPath, out strError); if (nRet == -1) { goto ERROR1; } // 突出显示所命中的册信息行 ListViewItem listitem = this.GetListViewItem( this.textBox_itemBarcode.Text, dpath.ItemRecPath); if (listitem == null) { strError = "册条码号为 '" + this.textBox_itemBarcode.Text + "' 册记录路径为 '" + dpath.ItemRecPath + "' 的ListViewItem居然不存在 ..."; goto ERROR1; } listitem.Selected = true; listitem.Focused = true; this.listView_items.EnsureVisible(this.listView_items.Items.IndexOf(listitem)); } finally { EnableControls(true); } this.textBox_itemBarcode.SelectAll(); this.textBox_itemBarcode.Focus(); return; ERROR1: MessageBox.Show(this, strError); return; NOTFOUND: MessageBox.Show(this, "册条码号 " + this.textBox_itemBarcode.Text + " 没有找到对应的记录。"); this.textBox_itemBarcode.SelectAll(); this.textBox_itemBarcode.Focus(); return; }
// 册登录 // 根据输入的册条码号新增一册信息,或者定位到已经存在的行 void DoRegisterBarcode() { string strError = ""; int nRet; if (this.textBox_itemBarcode.Text == "") { strError = "尚未输入册条码号"; goto ERROR1; } // 看看输入的条码号是否为ISBN条码号 if (IsISBnBarcode(this.textBox_itemBarcode.Text) == true) { // 保存当前册信息 EnableControls(false); nRet = this.SaveItems(out strError); EnableControls(true); if (nRet == -1) { goto ERROR1; } // 转而触发新种检索操作 this.textBox_queryWord.Text = this.textBox_itemBarcode.Text; this.textBox_itemBarcode.Text = ""; this.button_search_Click(null, null); return; } if (this.Items == null) { this.Items = new BookItemCollection(); } // 种内查重 BookItem item = this.Items.GetItem(this.textBox_itemBarcode.Text); ListViewItem listitem = null; // 如果该册条码号的事项已经存在 if (item != null) { listitem = this.GetListViewItem(this.textBox_itemBarcode.Text, null); if (listitem == null) { strError = "册条码号为 '" + this.textBox_itemBarcode.Text + "'的BookItem内存事项存在,但是没有对应的ListViewItem ..."; goto ERROR1; } UnselectListViewItems(); listitem.Selected = true; listitem.Focused = true; this.listView_items.EnsureVisible(this.listView_items.Items.IndexOf(listitem)); goto END1; } List <DoublePath> paths = null; // 种外全面查重 nRet = GetLinkInfoFromBarcode( this.textBox_itemBarcode.Text, true, out paths, out strError); if (nRet == -1) { strError = "册条码号查重操作出现错误:" + strError; goto ERROR1; } if (nRet > 0) { // MessageBox.Show(this, "册条码号 " + this.textBox_itemBarcode.Text + " 出现重复现象,请及时解决。"); SelectDupItemRecordDlg dlg = new SelectDupItemRecordDlg(); dlg.MessageText = "册条码号 " + this.textBox_itemBarcode.Text + " 已经被登录过了,情况如下。\r\n\r\n如果想详细观察,请选择当前希望观察的一条册记录;否则请按“取消”按钮。"; dlg.Paths = paths; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) { return; // 放弃操作 } if (this.BiblioRecPath != dlg.SelectedDoublePath.BiblioRecPath) { MessageBox.Show(this, "请注意软件即将自动装入新种 " + dlg.SelectedDoublePath.BiblioRecPath + " 到窗口中,如稍候您想继续对原种 " + this.BiblioRecPath + " 进行册登录,请切记重新装入原种后再行册登录 ..."); } // 先保存本种 nRet = this.SaveItems(out strError); if (nRet == -1) { goto ERROR1; } this.textBox_queryWord.Text = ""; // qingchu yuanlai de jiansuoci , bimian wuhui DoublePath dpath = dlg.SelectedDoublePath; this.BiblioDbName = ResPath.GetDbName(dpath.BiblioRecPath); this.ItemDbName = ResPath.GetDbName(dpath.ItemRecPath); nRet = LoadBiblioRecord( dpath.BiblioRecPath, out strError); if (nRet == -1) { goto ERROR1; } // 突出显示所命中的册信息行 listitem = this.GetListViewItem( this.textBox_itemBarcode.Text, dpath.ItemRecPath); if (listitem == null) { strError = "册条码号为 '" + this.textBox_itemBarcode.Text + "' 册记录路径为 '" + dpath.ItemRecPath + "' 的ListViewItem居然不存在 ..."; goto ERROR1; } listitem.Selected = true; listitem.Focused = true; this.listView_items.EnsureVisible(this.listView_items.Items.IndexOf(listitem)); this.textBox_itemBarcode.SelectAll(); this.textBox_itemBarcode.Focus(); return; } item = new BookItem(); item.Barcode = this.textBox_itemBarcode.Text; item.Changed = true; // 表示这是新事项 this.Items.Add(item); listitem = item.AddToListView(this.listView_items); // 加上选择标记 UnselectListViewItems(); listitem.Focused = true; this.listView_items.EnsureVisible(this.listView_items.Items.IndexOf(listitem)); END1: this.textBox_itemBarcode.SelectAll(); return; ERROR1: MessageBox.Show(this, strError); }
// parameters: // strBackupFileName 备份文件名。扩展名应为 .dp2bak // return: // -1 出错 // 0 处理被中断 // 1 成功 int BackupDatabase( RmsChannel channel, string strRecPathFileName, BreakPointInfo info, string strBackupFileName, out BreakPointInfo breakpoint, out string strError) { strError = ""; breakpoint = new BreakPointInfo(); breakpoint.BackupFileName = strBackupFileName; this._stop.BeginLoop(); try { ExportUtil export_util = new ExportUtil(); export_util.SafeMode = true; export_util.TempDir = this.App.TempDir; int nRet = export_util.Begin(null, strBackupFileName, out strError); if (nRet == -1) { return(-1); } try { List <string> lines = new List <string>(); using (StreamReader sr = new StreamReader(strRecPathFileName, Encoding.UTF8)) { long lTotalLength = sr.BaseStream.Length; // 跳过断点位置前,以前已经处理过的行 if (info != null && string.IsNullOrEmpty(info.DbName) == false && string.IsNullOrEmpty(info.RecID) == false) { while (true) { if (this.Stopped == true) { strError = "中断"; WriteStateFile(strBackupFileName, "abort"); // 表示文件创建过程被中断。文件内容不完整 return(0); } string line = sr.ReadLine(); if (line == null) { break; } string strDbName = ResPath.GetDbName(line); string strID = ResPath.GetRecordId(line); if (info.DbName == strDbName && info.RecID == strID) { break; } } } this.AppendResultText("开始写入大备份文件" + strBackupFileName + "\r\n"); while (true) { if (this.Stopped == true) { strError = "中断"; WriteStateFile(strBackupFileName, "abort"); // 表示文件创建过程被中断。文件内容不完整 return(0); } string line = sr.ReadLine(); if (line != null) { lines.Add(line); } if (lines.Count >= BATCH_SIZE || (line == null && lines.Count > 0)) { RmsBrowseLoader loader = new RmsBrowseLoader(); loader.Channel = channel; loader.Format = "id,xml,timestamp,metadata"; loader.RecPaths = lines; foreach (Record record in loader) { if (this.Stopped == true) { strError = "中断"; WriteStateFile(strBackupFileName, "abort"); // 表示文件创建过程被中断。文件内容不完整 return(0); } // TODO: 检查 RecordBody 是否为 null nRet = export_util.ExportOneRecord( channel, this._stop, this.App.WsUrl, record.Path, record.RecordBody.Xml, record.RecordBody.Metadata, record.RecordBody.Timestamp, out strError); if (nRet == -1) { WriteStateFile(strBackupFileName, "error"); // 表示文件创建过程出错 return(-1); } breakpoint.DbName = ResPath.GetDbName(record.Path); breakpoint.RecID = ResPath.GetRecordId(record.Path); long lCurrent = sr.BaseStream.Position; SetProgressText(m_nRecordCount.ToString() + " " + record.Path + " " + GetPercent((double)lCurrent, lTotalLength)); // 每 100 条显示一行 if ((m_nRecordCount % 100) == 0) { this.AppendResultText("已输出记录 " + record.Path + " " + (m_nRecordCount + 1).ToString() + "\r\n"); } m_nRecordCount++; } lines.Clear(); } if (line == null) { break; } } Debug.Assert(lines.Count == 0, ""); breakpoint = null; } } finally { export_util.End(); } WriteStateFile(strBackupFileName, "finish"); // 表示文件已经创建完成 return(1); } catch (Exception ex) { strError = "BackupDatabase() 出现异常: " + ExceptionUtil.GetDebugText(ex); WriteStateFile(strBackupFileName, "error"); // 表示文件创建过程出错 return(-1); } finally { this._stop.EndLoop(); } }
public LibraryServerResult GetZhongcihaoSearchResult( SessionInfo sessioninfo, string strZhongcihaoGroupName, string strResultSetName, long lStart, long lCount, string strBrowseInfoStyle, string strLang, out ZhongcihaoSearchResult[] searchresults) { string strError = ""; searchresults = null; LibraryServerResult result = new LibraryServerResult(); int nRet = 0; long lRet = 0; if (String.IsNullOrEmpty(strZhongcihaoGroupName) == true) { strError = "strZhongcihaoGroupName参数值不能为空"; goto ERROR1; } if (strZhongcihaoGroupName[0] == '!') { string strTemp = GetZhongcihaoGroupName(strZhongcihaoGroupName.Substring(1)); if (strTemp == null) { strError = "书目库名 " + strZhongcihaoGroupName.Substring(1) + " 没有找到对应的种次号组名"; goto ERROR1; } strZhongcihaoGroupName = strTemp; } RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl); if (channel == null) { result.Value = -1; result.ErrorInfo = "get channel error"; result.ErrorCode = ErrorCode.SystemError; return(result); } // XmlNode nodeNsTable = this.LibraryCfgDom.DocumentElement.SelectSingleNode("//zhongcihao/nstable"); XmlNamespaceManager mngr = null; if (nodeNsTable != null) { // 准备名字空间环境 nRet = PrepareNs( nodeNsTable, out mngr, out strError); if (nRet == -1) { goto ERROR1; } } // 构造数据库定义和库名的对照表 XmlNodeList nodes = this.LibraryCfgDom.DocumentElement.SelectNodes("//zhongcihao/group[@name='" + strZhongcihaoGroupName + "']/database"); if (nodes.Count == 0) { strError = "library.xml中尚未配置有关 '" + strZhongcihaoGroupName + "'的<zhongcihao>/<group>/<database>相关参数"; goto ERROR1; } Hashtable db_prop_table = new Hashtable(); for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; DbZhongcihaoProperty prop = new DbZhongcihaoProperty(); prop.DbName = DomUtil.GetAttr(node, "name"); prop.NumberXPath = DomUtil.GetAttr(node, "rightxpath"); prop.TitleXPath = DomUtil.GetAttr(node, "titlexpath"); prop.AuthorXPath = DomUtil.GetAttr(node, "authorxpath"); db_prop_table[prop.DbName] = prop; } if (String.IsNullOrEmpty(strResultSetName) == true) { strResultSetName = "default"; } Record[] origin_searchresults = null; // lRet = channel.DoGetSearchResult( strResultSetName, lStart, lCount, "id", strLang, null, out origin_searchresults, out strError); if (lRet == -1) { goto ERROR1; } long lResultCount = lRet; searchresults = new ZhongcihaoSearchResult[origin_searchresults.Length]; for (int i = 0; i < origin_searchresults.Length; i++) { ZhongcihaoSearchResult item = new ZhongcihaoSearchResult(); item.Path = origin_searchresults[i].Path; searchresults[i] = item; // 继续填充其余成员 string strXml = ""; string strMetaData = ""; byte[] timestamp = null; string strOutputPath = ""; lRet = channel.GetRes(item.Path, out strXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) { item.Zhongcihao = "获取记录 '" + item.Path + "' 出错: " + strError; continue; } string strDbName = ResPath.GetDbName(item.Path); DbZhongcihaoProperty prop = (DbZhongcihaoProperty)db_prop_table[strDbName]; if (prop == null) { item.Zhongcihao = "数据库名 '" + strDbName + "' 不在定义的种次号特性(<zhongcihao>/<group>/<database>)中"; continue; } string strNumber = ""; string strTitle = ""; string strAuthor = ""; nRet = GetRecordProperties( strXml, prop, mngr, out strNumber, out strTitle, out strAuthor, out strError); if (nRet == -1) { item.Zhongcihao = strError; continue; } item.Zhongcihao = strNumber; item.Cols = new string[2]; item.Cols[0] = strTitle; item.Cols[1] = strAuthor; } result.Value = lResultCount; return(result); ERROR1: result.Value = -1; result.ErrorCode = ErrorCode.SystemError; result.ErrorInfo = strError; return(result); }
// 进行查重 // parameters: // sessioninfo 仅仅用来存放DupResultSet,不应该用来sessioninfo.GetChannel(),而要用channel来进行检索操作 // channel // strOriginBiblioRecPath 发起的书目记录路径 // strOriginBiblioRecXml 发起的书目记录XML // strProjectName 查重方案名 // strStyle includeoriginrecord输出结果中包含发起记录(缺省为不包含) // return: // -1 error // 0 not found // 其他 命中记录条数 public LibraryServerResult SearchDup( SessionInfo sessioninfo1, RmsChannel channel, string strOriginBiblioRecPath, string strOriginBiblioRecXml, string strProjectName, string strStyle, out string strUsedProjectName) { string strError = ""; int nRet = 0; strUsedProjectName = ""; string strDebugInfo = ""; strStyle = strStyle.ToLower(); bool bIncludeOriginRecord = StringUtil.IsInList("includeoriginrecord", strStyle); LibraryServerResult result = new LibraryServerResult(); // 如果没有给出方案名,则需要在<default>元素中找到一个书目库的缺省查重方案 if (String.IsNullOrEmpty(strProjectName) == true) { if (String.IsNullOrEmpty(strOriginBiblioRecPath) == true) { strError = "既没有给出查重方案名,也没有给出记录路径,无法进行查重"; goto ERROR1; } string strOriginBiblioDbName = ResPath.GetDbName(strOriginBiblioRecPath); XmlNode nodeDefault = this.LibraryCfgDom.DocumentElement.SelectSingleNode("//dup/default[@origin='" + strOriginBiblioDbName + "']"); if (nodeDefault == null) { strError = "在没有明确指定查重方案名的情况下,本希望通过相关书目库的缺省查重方案名进行查重。但目前系统没有为书目库 '" + strOriginBiblioDbName + "' 定义缺省查重方案名,无法进行查重"; goto ERROR1; } string strDefaultProjectName = DomUtil.GetAttr(nodeDefault, "project"); if (String.IsNullOrEmpty(strDefaultProjectName) == true) { strError = "书目库 '" + strOriginBiblioDbName + "' 的<default>元素中未定义project属性值"; goto ERROR1; } strProjectName = strDefaultProjectName; } strUsedProjectName = strProjectName; // 获得查重方案定义节点 // return: // -1 出错 // 0 not found // 1 found nRet = GetDupProjectNode(strProjectName, out XmlNode nodeProject, out strError); if (nRet == 0 || nRet == -1) { goto ERROR1; } Debug.Assert(nodeProject != null, ""); DupResultSet alldatabase_set = null; // 所有库的结果集 XmlNodeList nodeDatabases = nodeProject.SelectNodes("database"); // 循环,针对每个数据库进行检索 for (int i = 0; i < nodeDatabases.Count; i++) { XmlNode nodeDatabase = nodeDatabases[i]; string strDatabaseName = DomUtil.GetAttr(nodeDatabase, "name"); string strThreshold = DomUtil.GetAttr(nodeDatabase, "threshold"); int nThreshold = 0; try { nThreshold = Convert.ToInt32(strThreshold); } catch { } List <AccessKeyInfo> aKeyLine = null; // 模拟创建检索点,以获得检索点列表 // return: // -1 error // 0 succeed nRet = GetKeys( // sessioninfo.Channels, channel, strOriginBiblioRecPath, strOriginBiblioRecXml, out aKeyLine, out strError); if (nRet == -1) { goto ERROR1; } DupResultSet onedatabase_set = null; // 一个库的结果集 try { XmlNodeList accesspoints = nodeDatabase.SelectNodes("accessPoint"); // <accessPoint>循环 for (int j = 0; j < accesspoints.Count; j++) { XmlNode accesspoint = accesspoints[j]; string strFrom = DomUtil.GetAttr(accesspoint, "name"); // 获得from所对应的key List <string> keys = GetKeyByFrom(aKeyLine, strFrom); if (keys.Count == 0) { continue; } string strWeight = DomUtil.GetAttr(accesspoint, "weight"); string strSearchStyle = DomUtil.GetAttr(accesspoint, "searchStyle"); int nWeight = 0; try { nWeight = Convert.ToInt32(strWeight); } catch { // 警告定义问题? } for (int k = 0; k < keys.Count; k++) { string strKey = (string)keys[k]; if (strKey == "") { continue; } DupResultSet dupset = null; try { // 针对一个from进行检索 // return: // -1 error // 0 not found // 1 found nRet = SearchOneFrom( // sessioninfo.Channels, channel, strDatabaseName, strFrom, strKey, strSearchStyle, nWeight, nThreshold, 5000, // ??? (bIncludeOriginRecord == false) ? strOriginBiblioRecPath : null, out dupset, out strError); if (nRet == -1) { // ??? 警告检索错误? continue; } if (onedatabase_set == null) { onedatabase_set = dupset; dupset = null; // 避免出 try 范围时被释放。因为内容已经转移给 onedatabase_set 了 continue; } if (nRet == 0) { continue; } Debug.Assert(dupset != null, ""); if (onedatabase_set.Sorted == true) { onedatabase_set.EnsureCreateIndex(getTempFileName); } else { onedatabase_set.Sort(getTempFileName); } // dupset.EnsureCreateIndex(getTempFileName); // 2017/4/14 dupset.Sort(getTempFileName); // Sort() 里面自动确保了创建 Index // 将dupset和前一个set归并 // 归并可以参考ResultSet中的Merge算法 DupResultSet tempset = new DupResultSet(); tempset.Open(false, getTempFileName); // 功能: 合并两个数组 // parameters: // strStyle 运算风格 OR , AND , SUB // sourceLeft 源左边结果集 // sourceRight 源右边结果集 // targetLeft 目标左边结果集 // targetMiddle 目标中间结果集 // targetRight 目标右边结果集 // bOutputDebugInfo 是否输出处理信息 // strDebugInfo 处理信息 // return // -1 出错 // 0 成功 nRet = DupResultSet.Merge("OR", onedatabase_set, dupset, null, // targetLeft, tempset, null, // targetRight, false, out strDebugInfo, out strError); if (nRet == -1) { goto ERROR1; } { if (onedatabase_set != null) { onedatabase_set.Dispose(); } onedatabase_set = tempset; onedatabase_set.Sorted = true; // 归并后产生的结果集自然是符合顺序的 } } finally { if (dupset != null) { dupset.Dispose(); } } } // end of k loop } // end of j loop if (alldatabase_set == null) { alldatabase_set = onedatabase_set; onedatabase_set = null; // 避免出 try 范围时被释放。因为内容已经转移给 alldatabase_set 了 continue; } // 合并 if (onedatabase_set != null) { DupResultSet tempset0 = new DupResultSet(); tempset0.Open(false, getTempFileName); if (alldatabase_set.Sorted == true) { alldatabase_set.EnsureCreateIndex(getTempFileName); } else { alldatabase_set.Sort(getTempFileName); } // onedatabase_set.EnsureCreateIndex(getTempFileName); // 2017/4/14 onedatabase_set.Sort(getTempFileName); // Sort() 里面自动确保了创建 Index nRet = DupResultSet.Merge("OR", alldatabase_set, onedatabase_set, null, // targetLeft, tempset0, null, // targetRight, false, out strDebugInfo, out strError); if (nRet == -1) { goto ERROR1; } { if (alldatabase_set != null) { alldatabase_set.Dispose(); } alldatabase_set = tempset0; alldatabase_set.Sorted = true; } } } finally { if (onedatabase_set != null) { onedatabase_set.Dispose(); } } } // 最后要按照 Weight和Threshold的差额 对结果集进行排序,便于输出 if (alldatabase_set != null) { alldatabase_set.SortStyle = DupResultSetSortStyle.OverThreshold; alldatabase_set.Sort(getTempFileName); } { if (sessioninfo1.DupResultSet != null) { sessioninfo1.DupResultSet.Dispose(); } sessioninfo1.DupResultSet = alldatabase_set; } if (alldatabase_set != null) { result.Value = alldatabase_set.Count; } else { result.Value = 0; } return(result); ERROR1: result.Value = -1; result.ErrorCode = ErrorCode.SystemError; result.ErrorInfo = strError; return(result); }
protected override void Render(HtmlTextWriter output) { int nRet = 0; long lRet = 0; string strError = ""; string strOutputPath = ""; string strItemXml = ""; LibraryApplication app = (LibraryApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; string strItemRecPath = ""; RmsChannel channel = sessioninfo.Channels.GetChannel(app.WsUrl); if (channel == null) { strError = "channel == null"; goto ERROR1; } if (String.IsNullOrEmpty(this.Barcode) == false) { // 获得册记录 // return: // -1 error // 0 not found // 1 命中1条 // >1 命中多于1条 nRet = app.GetItemRecXml( channel, this.Barcode, out strItemXml, out strOutputPath, out strError); if (nRet == 0) { strError = "册条码号为 '" + this.Barcode + "' 的册记录没有找到"; goto ERROR1; } if (nRet == -1) { goto ERROR1; } strItemRecPath = strOutputPath; } string strItemDbName = ""; string strBiblioRecID = ""; string strBiblioDbName = ""; // 若需要同时取得种记录 if ((this.DispStyle & DispStyle.Biblio) == DispStyle.Biblio) { string strBiblioRecPath = ""; if (String.IsNullOrEmpty(this.BiblioRecPath) == true) { /* * // 准备工作: 映射数据库名 * nRet = app.GetGlobalCfg(sessioninfo.Channels, * out strError); * if (nRet == -1) * goto ERROR1; * */ strItemDbName = ResPath.GetDbName(strOutputPath); // string strBiblioDbName = ""; // 根据实体库名, 找到对应的书目库名 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = app.GetBiblioDbNameByItemDbName(strItemDbName, out strBiblioDbName, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { strError = "实体库名 '" + strItemDbName + "' 没有找到对应的书目库名"; goto ERROR1; } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strItemXml); } catch (Exception ex) { strError = "册记录XML装载到DOM出错:" + ex.Message; goto ERROR1; } strBiblioRecID = DomUtil.GetElementText(dom.DocumentElement, "parent"); // if (String.IsNullOrEmpty(strBiblioRecID) == true) { strError = "册记录XML中<parent>元素缺乏或者值为空, 因此无法定位种记录"; goto ERROR1; } strBiblioRecPath = strBiblioDbName + "/" + strBiblioRecID; } else { strBiblioRecPath = this.BiblioRecPath; strBiblioDbName = ResPath.GetDbName(this.BiblioRecPath); if (String.IsNullOrEmpty(strItemDbName) == true) { // 根据书目库名, 找到对应的实体库名 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = app.GetItemDbName(strBiblioDbName, out strItemDbName, out strError); if (nRet == -1) { goto ERROR1; } } strBiblioRecID = ResPath.GetRecordId(this.BiblioRecPath); } string strBiblioXml = ""; string strMetaData = ""; byte[] timestamp = null; lRet = channel.GetRes(strBiblioRecPath, out strBiblioXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) { strError = "获得种记录 '" + strBiblioRecPath + "' 时出错: " + strError; goto ERROR1; } // 需要从内核映射过来文件 string strLocalPath = ""; nRet = app.MapKernelScriptFile( sessioninfo, strBiblioDbName, "./cfgs/loan_biblio.fltx", out strLocalPath, out strError); if (nRet == -1) { goto ERROR1; } // 将种记录数据从XML格式转换为HTML格式 string strBiblio = ""; // 2006/11/28 changed string strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx"; if (string.IsNullOrEmpty(strBiblioXml) == false) { nRet = app.ConvertBiblioXmlToHtml( strFilterFileName, strBiblioXml, strBiblioRecPath, out strBiblio, out strError); if (nRet == -1) { goto ERROR1; } } else { strBiblio = ""; } // output.Write(strBiblio); LiteralControl literal = (LiteralControl)FindControl("biblio"); literal.Text = strBiblio; } if ((this.DispStyle & DispStyle.Items) == DispStyle.Items) { this.ItemConverter = app.NewItemConverter( app.CfgDir + "\\itemopac.cs", app.CfgDir + "\\itemopac.cs.ref", out strError); if (this.ItemConverter == null) { goto ERROR1; } this.ItemConverter.App = app; // 检索出该种的所有册 sessioninfo.ItemLoad += new ItemLoadEventHandler(SessionInfo_ItemLoad); tempOutput = ""; // tempOutput = output; try { nRet = sessioninfo.SearchItems( app, strItemDbName, strBiblioRecID, out strError); if (nRet == -1) { goto ERROR1; } } finally { sessioninfo.ItemLoad -= new ItemLoadEventHandler(SessionInfo_ItemLoad); //tempOutput = null; this.ItemConverter = null; } LiteralControl literal = (LiteralControl)FindControl("items"); literal.Text = tempOutput; tempOutput = ""; } else if ((this.DispStyle & DispStyle.Item) == DispStyle.Item) { string strResult = ""; // 取得册信息 // 将册记录数据从XML格式转换为HTML格式 nRet = app.ConvertItemXmlToHtml( app.CfgDir + "\\itemxml2html.cs", app.CfgDir + "\\itemxml2html.cs.ref", strItemXml, strItemRecPath, // 2009/10/18 out strResult, out strError); if (nRet == -1) { goto ERROR1; } // output.Write(strResult); LiteralControl literal = (LiteralControl)FindControl("items"); literal.Text = strResult; } base.Render(output); return; ERROR1: output.Write(strError); }
protected override void Render(HtmlTextWriter output) { if (this.RecPath == "") { output.Write("尚未指定记录路径"); return; } int nRet = 0; long lRet = 0; string strError = ""; // string strOutputPath = ""; OpacApplication app = (OpacApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; bool bManager = false; if (string.IsNullOrEmpty(sessioninfo.UserID) == true || StringUtil.IsInList("managecomment", sessioninfo.RightsOrigin) == false) { bManager = false; } else { bManager = true; } PlaceHolder inputline = (PlaceHolder)this.FindControl("inputline"); PlaceHolder cmdline = (PlaceHolder)this.FindControl("cmdline"); if (bManager == false) { cmdline.Visible = false; } string strBiblioState = ""; #if NO string strBiblioXml = ""; // 获得书目XML { byte[] timestamp = null; string[] formats = new string[1]; formats[0] = "xml"; string[] results = null; lRet = sessioninfo.Channel.GetBiblioInfos( null, this.RecPath, formats, out results, out timestamp, out strError); if (lRet == -1) { strError = "获得种记录 '" + this.RecPath + "' 时出错: " + strError; goto ERROR1; } if (results == null || results.Length < 1) { strError = "results error "; goto ERROR1; } strBiblioXml = results[0]; this.Timestamp = ByteArray.GetHexTimeStampString(timestamp); this.BiblioRecPath = this.RecPath; } string strMarc = ""; // 转换为MARC { string strOutMarcSyntax = ""; // 将MARCXML格式的xml记录转换为marc机内格式字符串 // parameters: // bWarning ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换 // strMarcSyntax 指示marc语法,如果=="",则自动识别 // strOutMarcSyntax out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值 nRet = MarcUtil.Xml2Marc(strBiblioXml, true, "", // this.CurMarcSyntax, out strOutMarcSyntax, out strMarc, out strError); if (nRet == -1) { goto ERROR1; } } #endif bool bAjax = true; if (this.DisableAjax == true) { bAjax = false; } else { if (app != null && app.WebUiDom != null && app.WebUiDom.DocumentElement != null) { XmlNode nodeBiblioControl = app.WebUiDom.DocumentElement.SelectSingleNode( "biblioControl"); if (nodeBiblioControl != null) { DomUtil.GetBooleanParam(nodeBiblioControl, "ajax", true, out bAjax, out strError); } } } string strMarc = ""; if (string.IsNullOrEmpty(this.m_strMARC) == true) { nRet = PrepareBiblioRecord(out strError); if (nRet == -1) { goto ERROR1; } strMarc = this.m_strMARC; } strBiblioState = MarcDocument.GetFirstSubfield(strMarc, "998", "s"); // 状态 string strOriginCreator = MarcDocument.GetFirstSubfield(strMarc, "998", "z"); bool bReaderCreate = false; if (StringUtil.IsInList("读者创建", strBiblioState) == true) { bReaderCreate = true; } // 不是读者创建的记录,就不让在这里修改状态 if (bReaderCreate == false) { cmdline.Visible = false; } bool bDisplayOriginContent = false; if (StringUtil.IsInList("审查", strBiblioState) == false && StringUtil.IsInList("屏蔽", strBiblioState) == false) { bDisplayOriginContent = true; } // 管理员和作者本人都能看到被屏蔽的内容 if (bManager == true || strOriginCreator == sessioninfo.UserID) { bDisplayOriginContent = true; } string strBiblio = ""; if (bDisplayOriginContent == true) { if (bAjax == true) { strBiblio = "<div class='pending'>biblio_html:" + HttpUtility.HtmlEncode(this.RecPath) + "</div>"; } else { strBiblio = this.m_strOpacBiblio; #if NO string strBiblioDbName = ResPath.GetDbName(this.RecPath); // 需要从内核映射过来文件 string strLocalPath = ""; nRet = app.MapKernelScriptFile( null, // sessioninfo, strBiblioDbName, "./cfgs/opac_biblio.fltx", // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件 out strLocalPath, out strError); if (nRet == -1) { goto ERROR1; } // 将种记录数据从XML格式转换为HTML格式 Hashtable result_params = null; // 2006/11/28 changed string strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx"; nRet = app.ConvertBiblioXmlToHtml( strFilterFileName, strBiblioXml, this.RecPath, out strBiblio, out result_params, out strError); if (nRet == -1) { goto ERROR1; } // TODO: Render的时候设置,已经晚了半拍 // 要想办法在全部Render前得到题名和进行设置 if (this.AutoSetPageTitle == true && result_params != null) { string strTitle = (string)result_params["title"]; if (string.IsNullOrEmpty(strTitle) == false) { this.Page.Title = strTitle; } } /* * string strPrefix = ""; * if (this.Wrapper == true) * strPrefix = this.GetPrefixString("书目信息", "content_wrapper") + "<div class='biblio_wrapper'>"; + + string strPostfix = ""; + if (this.Wrapper == true) + strPostfix = "</div>" + this.GetPostfixString(); * */ /* * LiteralControl literal = (LiteralControl)FindControl("biblio"); * literal.Text = strPrefix + strBiblio + strPostfix; * */ // strBiblio = strPrefix + strBiblio + strPostfix; #endif } } // 屏蔽等状态显示 string strResult = ""; string strImage = ""; if (StringUtil.IsInList("精品", strBiblioState) == true) { strImage = "<img src='" + MyWebPage.GetStylePath(app, "valuable.gif") + "'/>"; strResult += "<div class='valuable' title='精品'>" + strImage + this.GetString("精品") + "</div>"; } if (StringUtil.IsInList("锁定", strBiblioState) == true) { strImage = "<img src='" + MyWebPage.GetStylePath(app, "locked.gif") + "'/>"; strResult += "<div class='locked' title='锁定'>" + strImage + this.GetString("锁定") + "</div>"; } string strDisplayState = ""; if (StringUtil.IsInList("审查", strBiblioState) == true) { strImage = "<img src='" + MyWebPage.GetStylePath(app, "censor.gif") + "'/>"; strDisplayState = this.GetString("审查"); } if (StringUtil.IsInList("屏蔽", strBiblioState) == true) { strImage = "<img src='" + MyWebPage.GetStylePath(app, "disable.gif") + "'/>"; if (String.IsNullOrEmpty(strDisplayState) == false) { strDisplayState += ","; } strDisplayState += this.GetString("屏蔽"); } if (String.IsNullOrEmpty(strDisplayState) == false) { strResult += "<div class='forbidden' title='" + this.GetString("屏蔽原因") + "'>" + strImage + string.Format(this.GetString("本书目记录目前为X状态"), strDisplayState) + (strOriginCreator == sessioninfo.UserID ? "," + this.GetString("其他人(非管理员)看不到下列内容") : "") + "</div>"; } if (String.IsNullOrEmpty(strResult) == false) { strResult = "<div class='biblio_state'>" + strResult + "</div>"; } if (this.EditAction == "changestate") { inputline.Visible = true; SetStateValueToControls(strBiblioState); cmdline.Visible = false; // 在编辑态,命令条就不要出现了 } else { inputline.Visible = false; } if (this.Active == false) { cmdline.Visible = false; inputline.Visible = false; // 即便在编辑态也要加以压抑 } string strClass = "biblio"; if ((String.IsNullOrEmpty(strResult) == false || inputline.Visible == true) && this.Wrapper == false) { strClass += " frame-border"; } LiteralControl outer_class = (LiteralControl)this.FindControl("outer_class"); outer_class.Text = strClass; // output.Write(strBiblio); LiteralControl literal = (LiteralControl)FindControl("biblio"); // literal.Text = "<div class='"+strClass+"'>" + strResult + strBiblio + "</biblio>"; literal.Text = strResult + strBiblio; base.Render(output); return; ERROR1: output.Write(strError); }