int GetBarcodeColumnIndex(string strItemDbName) { int nCol = -1; object o = m_tableBarcodeColIndex[strItemDbName]; if (o == null) { ColumnPropertyCollection temp = this.MainForm.GetBrowseColumnProperties(strItemDbName); nCol = temp.FindColumnByType("item_barcode"); if (nCol == -1) { #if NO // 这个实体库没有在 browse 文件中 册条码号 列 strError = "警告:实体库 '" + strItemDbName + "' 的 browse 配置文件中没有定义 type 为 item_barcode 的列。请注意刷新或修改此配置文件"; if (bWarning == true) { MessageBox.Show(this, strError); } #endif nCol = 0; // 这个大部分情况能奏效 } if (m_bBiblioSummaryColumn == false) { nCol += 1; } else { nCol += 2; } if (this.m_bFirstColumnIsKey == true) { nCol++; // 2013/11/12 } m_tableBarcodeColIndex[strItemDbName] = nCol; // 储存起来 } else { nCol = (int)o; } Debug.Assert(nCol > 0, ""); return(nCol); }
// 获得一个列 type 对应的列 index,针对特定的数据库 // return: // -1 该数据库 browse 配置文件中没有找到这个列 type 定义 // 其他 返回列 index int GetColumnIndex(string strItemDbName, string strColumnType) { int nCol = -1; // 根据数据库名和列 type 去获得 列号 string strCacheKey = strItemDbName + ":" + strColumnType; object o = _columnIndexTable[strCacheKey]; if (o == null) { ColumnPropertyCollection temp = this.MainForm.GetBrowseColumnProperties(strItemDbName); nCol = temp.FindColumnByType(strColumnType); if (nCol == -1) { return(-1); } if (m_bBiblioSummaryColumn == false) { nCol += 1; } else { nCol += 2; } if (this.m_bFirstColumnIsKey == true) { nCol++; // 2013/11/12 } _columnIndexTable[strCacheKey] = nCol; // 储存起来 } else { nCol = (int)o; } Debug.Assert(nCol > 0, ""); return(nCol); }
// TODO: 如果册条码号为空,则根据参考 ID 返回 @refID:xxxxxxx 这样形式的内容 // 根据 ListViewItem 对象,获得册条码号列的内容 // parameters: // bWarning 是否出现警告对话框 /// <summary> /// 根据浏览行 ListViewItem 对象,获得册条码号列的内容 /// </summary> /// <param name="item">浏览行 ListViewItem 对象</param> /// <param name="bWarning">当需要时,是否出现警告对话框</param> /// <param name="strBarcode">返回册条码号</param> /// <param name="strError">返回出错信息</param> /// <returns>01: 出错; 0: 成功</returns> public int GetItemBarcode( ListViewItem item, bool bWarning, out string strBarcode, out string strError) { strError = ""; strBarcode = ""; string strRecPath = ListViewUtil.GetItemText(item, 0); // 根据记录路径获得数据库名 string strItemDbName = Global.GetDbName(strRecPath); if (string.IsNullOrEmpty(strItemDbName) == true) { strError = "从(来自事项第一列的)记录路径 '" + strRecPath + "' 获得库名时出错"; return(-1); } // 根据数据库名获得 册条码号 列号 // return: // -1 该数据库 browse 配置文件中没有找到这个列 type 定义 // 其他 返回列 index int nCol = GetColumnIndex(strItemDbName, "item_barcode"); if (nCol == -1) { // 这个实体库没有在 browse 文件中 册条码号 列 strError = "警告:实体库 '" + strItemDbName + "' 的 browse 配置文件中没有定义 type 为 item_barcode 的列。请注意刷新或修改此配置文件"; if (bWarning == true) { MessageBox.Show(this, strError); } nCol = 0; // 这个大部分情况能奏效 if (m_bBiblioSummaryColumn == false) { nCol += 1; } else { nCol += 2; } if (this.m_bFirstColumnIsKey == true) { nCol++; // 2013/11/12 } } strBarcode = ListViewUtil.GetItemText(item, nCol); return(0); #if NO int nCol = -1; object o = m_tableBarcodeColIndex[strItemDbName]; if (o == null) { ColumnPropertyCollection temp = this.MainForm.GetBrowseColumnProperties(strItemDbName); nCol = temp.FindColumnByType("item_barcode"); if (nCol == -1) { // 这个实体库没有在 browse 文件中 册条码号 列 strError = "警告:实体库 '" + strItemDbName + "' 的 browse 配置文件中没有定义 type 为 item_barcode 的列。请注意刷新或修改此配置文件"; if (bWarning == true) { MessageBox.Show(this, strError); } nCol = 0; // 这个大部分情况能奏效 } if (m_bBiblioSummaryColumn == false) { nCol += 1; } else { nCol += 2; } if (this.m_bFirstColumnIsKey == true) { nCol++; // 2013/11/12 } m_tableBarcodeColIndex[strItemDbName] = nCol; // 储存起来 } else { nCol = (int)o; } Debug.Assert(nCol > 0, ""); strBarcode = ListViewUtil.GetItemText(item, nCol); return(0); #endif }
// parameters: // lStartIndex 调用前已经做过的事项数。为了准确显示 Progress // return: // -2 获得书目摘要的权限不够 // -1 出错 // 0 用户中断 // 1 完成 internal int _fillBiblioSummaryColumn(List <ListViewItem> items, long lStartIndex, bool bDisplayMessage, bool bAutoSearch, out string strError) { strError = ""; int nRet = 0; if (m_bBiblioSummaryColumn == false) { return(0); } Debug.Assert(this.DbType == "item" || this.DbType == "order" || this.DbType == "issue" || this.DbType == "comment" || this.DbType == "arrive", ""); List <string> biblio_recpaths = new List <string>(); // 尺寸可能比 items 数组小,没有包含里面不具有 parent id 列的事项 List <int> colindex_list = new List <int>(); // 存储每个 item 对应的 parent id colindex。数组大小等于 items 数组大小 foreach (ListViewItem item in items) { #if NO string strRecPath = ListViewUtil.GetItemText(item, 0); // 根据记录路径获得数据库名 string strItemDbName = Global.GetDbName(strRecPath); // 根据数据库名获得 parent id 列号 int nCol = -1; object o = m_tableSummaryColIndex[strItemDbName]; if (o == null) { ColumnPropertyCollection temp = this.MainForm.GetBrowseColumnProperties(strItemDbName); nCol = temp.FindColumnByType("parent_id"); if (nCol == -1) { colindex_list.Add(-1); continue; // 这个实体库没有 parent id 列 } nCol += 2; if (this.m_bFirstColumnIsKey == true) { nCol++; // 2013/11/12 } m_tableSummaryColIndex[strItemDbName] = nCol; // 储存起来 } else { nCol = (int)o; } Debug.Assert(nCol > 0, ""); colindex_list.Add(nCol); // 获得 parent id string strText = ListViewUtil.GetItemText(item, nCol); string strBiblioRecPath = ""; // 看看是否已经是路径 ? if (strText.IndexOf("/") == -1) { // 获得对应的书目库名 strBiblioRecPath = this.MainForm.GetBiblioDbNameFromItemDbName(this.DbType, strItemDbName); if (string.IsNullOrEmpty(strBiblioRecPath) == true) { strError = "数据库名 '" + strItemDbName + "' 没有找到对应的书目库名"; return(-1); } strBiblioRecPath = strBiblioRecPath + "/" + strText; ListViewUtil.ChangeItemText(item, nCol, strBiblioRecPath); } else { strBiblioRecPath = strText; } #endif int nCol = -1; string strBiblioRecPath = ""; // 获得事项所从属的书目记录的路径 // return: // -1 出错 // 0 相关数据库没有配置 parent id 浏览列 // 1 找到 nRet = GetBiblioRecPath(item, bAutoSearch, // true 如果遇到没有 parent id 列的时候速度较慢 out nCol, out strBiblioRecPath, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { colindex_list.Add(-1); continue; } if (string.IsNullOrEmpty(strBiblioRecPath) == false && nCol == -1) { colindex_list.Add(0); } else { colindex_list.Add(nCol); } biblio_recpaths.Add(strBiblioRecPath); } CacheableBiblioLoader loader = new CacheableBiblioLoader(); loader.Channel = this.Channel; loader.Stop = this.stop; loader.Format = "summary"; loader.GetBiblioInfoStyle = GetBiblioInfoStyle.None; loader.RecPaths = biblio_recpaths; var enumerator = loader.GetEnumerator(); int i = 0; foreach (ListViewItem item in items) { Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; return(0); } string strRecPath = ListViewUtil.GetItemText(item, 0); if (stop != null && bDisplayMessage == true) { stop.SetMessage("正在刷新浏览行 " + strRecPath + " 的书目摘要 ..."); stop.SetProgressValue(lStartIndex + i); } int nCol = colindex_list[i]; if (nCol == -1) { ListViewUtil.ChangeItemText(item, this.m_bFirstColumnIsKey == false ? 1 : 2, ""); ClearOneChange(item, true); // 清除内存中的修改 i++; continue; } try { bool bRet = enumerator.MoveNext(); if (bRet == false) { Debug.Assert(false, "还没有到结尾, MoveNext() 不应该返回 false"); // TODO: 这时候也可以采用返回一个带没有找到的错误码的元素 strError = "error 1"; return(-1); } } catch (ChannelException ex) { strError = ex.Message; if (ex.ErrorCode == ErrorCode.AccessDenied) { return(-2); } return(-1); } BiblioItem biblio = (BiblioItem)enumerator.Current; // Debug.Assert(biblio.RecPath == strRecPath, "m_loader 和 items 的元素之间 记录路径存在严格的锁定对应关系"); ListViewUtil.ChangeItemText(item, this.m_bFirstColumnIsKey == false ? 1 : 2, biblio.Content); ClearOneChange(item, true); // 清除内存中的修改 i++; } return(1); }