private void button_load_loadFromBarcodeFile_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; bool bClearBefore = true; if (Control.ModifierKeys == Keys.Control) bClearBefore = false; if (bClearBefore == true) ClearBefore(); OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "请指定要打开的条码号文件名"; // dlg.FileName = this.BarcodeFilePath; // dlg.InitialDirectory = dlg.Filter = "条码号文件 (*.txt)|*.txt|All files (*.*)|*.*"; dlg.RestoreDirectory = true; if (dlg.ShowDialog() != DialogResult.OK) return; EnableControls(false); // MainForm.ShowProgress(true); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在将册条码号转换为记录路径 ..."); stop.BeginLoop(); try { Hashtable barcode_table = new Hashtable(); int nDupCount = 0; List<string> lines = new List<string>(); using (StreamReader sr = new StreamReader(dlg.FileName)) { for (; ; ) { Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; goto ERROR1; } string strLine = ""; strLine = sr.ReadLine(); if (strLine == null) break; strLine = strLine.Trim(); if (String.IsNullOrEmpty(strLine) == true) continue; if (strLine[0] == '#') continue; // 注释行 if (barcode_table[strLine] != null) { nDupCount++; continue; } barcode_table[strLine] = true; lines.Add(strLine); } } if (lines.Count == 0) { strError = "条码号文件为空"; goto ERROR1; } stop.SetProgressRange(0, lines.Count); ItemBarcodeLoader loader = new ItemBarcodeLoader(); loader.Channel = this.Channel; loader.Stop = this.stop; loader.Barcodes = lines; int i = 0; foreach (EntityItem item in loader) { Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; goto ERROR1; } DpRow row = new DpRow(); // icon1 DpCell cell = new DpCell(); row.Add(cell); // icon2 cell = new DpCell(); row.Add(cell); // barcode cell = new DpCell(); cell.Text = item.Barcode; row.Add(cell); // summary cell = new DpCell(); // 如果出错 if (string.IsNullOrEmpty(item.ErrorInfo) == false) cell.Text = item.ErrorInfo; row.Add(cell); // recpath cell = new DpCell(); cell.Text = item.RecPath; row.Add(cell); this.dpTable1.Rows.Add(row); i++; stop.SetProgressValue(i); } // BrowseLoader } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); EnableControls(true); // MainForm.ShowProgress(false); } return; ERROR1: MessageBox.Show(this, strError); }
// return: // -1 出错 // 0 用户中断 // 1 成功 public int ExportChargingHistoryToItemSearchForm(List<string> reader_barcodes, out string strError) { strError = ""; //int nRet = 0; ItemSearchForm form = this.MainForm.OpenItemSearchForm("item"); form.Enabled = false; stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("导出读者借阅历史 ..."); stop.BeginLoop(); EnableControls(false); this.listView_records.Enabled = false; try { if (stop != null) stop.SetProgressRange(0, reader_barcodes.Count); int nReaderIndex = 0; foreach (string strBarcode in reader_barcodes) { Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; return 0; } if (string.IsNullOrEmpty(strBarcode) == true) continue; // 获得读者记录 byte[] baTimestamp = null; string strOutputRecPath = ""; stop.SetMessage("正在处理读者记录 " + strBarcode + " ..."); string[] results = null; long lRet = Channel.GetReaderInfo( stop, strBarcode, "advancexml", out results, out strOutputRecPath, out baTimestamp, out strError); if (lRet == -1) return -1; if (lRet == 0) return -1; if (lRet > 1) // 不可能发生吧? { strError = "读者证条码号 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,放弃装入读者记录。\r\n\r\n注意这是一个严重错误,请系统管理员尽快排除。"; return -1; } if (results == null || results.Length < 1) { strError = "返回的results不正常。"; return -1; } string strXml = results[0]; XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strXml); } catch (Exception ex) { strError = "装载读者记录 XML 到 DOM 时发生错误: " + ex.Message; return -1; } try { ChargingHistoryLoader history_loader = new ChargingHistoryLoader(); history_loader.Channel = this.Channel; history_loader.Stop = this.stop; history_loader.PatronBarcode = strBarcode; history_loader.TimeRange = "~"; // strTimeRange; history_loader.Actions = "return,lost"; history_loader.Order = "descending"; ItemBarcodeLoader barcode_loader = new ItemBarcodeLoader(); barcode_loader.Channel = this.Channel; barcode_loader.Stop = this.stop; // 输出借阅历史表格 int nRet = OutputBorrowHistory(form, dom, history_loader, barcode_loader, out strError); if (nRet == -1) return -1; } catch (Exception ex) { strError = "输出借阅历史时出现异常: " + ex.Message; return -1; } nReaderIndex++; if (stop != null) stop.SetProgressValue(nReaderIndex); } } finally { EnableControls(true); this.listView_records.Enabled = true; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; form.Enabled = true; } return 1; }
// 将一个读者的操作历史输出到实体查询窗 // parameters: static int OutputBorrowHistory( ItemSearchForm form, XmlDocument reader_dom, ChargingHistoryLoader history_loader, ItemBarcodeLoader barcode_loader, out string strError) { strError = ""; if (StringUtil.CompareVersion(Program.MainForm.ServerVersion, "2.67") < 0) { strError = "输出操作历史到实体查询窗要求 dp2library 为 2.67 或以上版本"; return -1; } List<string> barcodes = new List<string>(); foreach (ChargingItemWrapper wrapper in history_loader) { ChargingItem item = wrapper.Item; string strItemBarcode = item.ItemBarcode; #if NO ChargingItem rel = wrapper.RelatedItem; string strBorrowDate = rel == null ? "" : rel.OperTime; string strBorrowPeriod = GetDisplayTimePeriodString(rel == null ? "" : rel.Period); string strReturnDate = item.OperTime; #endif barcodes.Add(strItemBarcode); } string strTempFileName = Program.MainForm.GetTempFileName("exphis"); try { int nCount = 0; using (StreamWriter sw = new StreamWriter(strTempFileName, false, Encoding.UTF8)) { barcode_loader.Barcodes = barcodes; foreach (EntityItem info in barcode_loader) { string strRecPath = info.RecPath; if (string.IsNullOrEmpty(strRecPath) == true) continue; // TODO: 是否要警告? sw.WriteLine(strRecPath); nCount++; } } if (nCount > 0) { int nRet = form.ImportFromRecPathFile(strTempFileName, "", out strError); if (nRet == -1) return -1; } return 0; } finally { File.Delete(strTempFileName); } }
private void button_load_loadFromBarcodeFile_Click(object sender, EventArgs e) { string strError = ""; //int nRet = 0; bool bClearBefore = true; if (Control.ModifierKeys == Keys.Control) { bClearBefore = false; } if (bClearBefore == true) { ClearBefore(); } OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "请指定要打开的条码号文件名"; // dlg.FileName = this.BarcodeFilePath; // dlg.InitialDirectory = dlg.Filter = "条码号文件 (*.txt)|*.txt|All files (*.*)|*.*"; dlg.RestoreDirectory = true; if (dlg.ShowDialog() != DialogResult.OK) { return; } EnableControls(false); // MainForm.ShowProgress(true); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在将册条码号转换为记录路径 ..."); stop.BeginLoop(); try { Hashtable barcode_table = new Hashtable(); int nDupCount = 0; List <string> lines = new List <string>(); using (StreamReader sr = new StreamReader(dlg.FileName)) { for (; ;) { Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; goto ERROR1; } string strLine = ""; strLine = sr.ReadLine(); if (strLine == null) { break; } strLine = strLine.Trim(); if (String.IsNullOrEmpty(strLine) == true) { continue; } if (strLine[0] == '#') { continue; // 注释行 } if (barcode_table[strLine] != null) { nDupCount++; continue; } barcode_table[strLine] = true; lines.Add(strLine); } } if (lines.Count == 0) { strError = "条码号文件为空"; goto ERROR1; } stop.SetProgressRange(0, lines.Count); ItemBarcodeLoader loader = new ItemBarcodeLoader(); loader.Channel = this.Channel; loader.Stop = this.stop; loader.Barcodes = lines; int i = 0; foreach (EntityItem item in loader) { Application.DoEvents(); if (stop != null && stop.State != 0) { strError = "用户中断"; goto ERROR1; } DpRow row = new DpRow(); // icon1 DpCell cell = new DpCell(); row.Add(cell); // icon2 cell = new DpCell(); row.Add(cell); // barcode cell = new DpCell(); cell.Text = item.Barcode; row.Add(cell); // summary cell = new DpCell(); // 如果出错 if (string.IsNullOrEmpty(item.ErrorInfo) == false) { cell.Text = item.ErrorInfo; } row.Add(cell); // recpath cell = new DpCell(); cell.Text = item.RecPath; row.Add(cell); this.dpTable1.Rows.Add(row); i++; stop.SetProgressValue(i); } // BrowseLoader } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); EnableControls(true); // MainForm.ShowProgress(false); } return; ERROR1: MessageBox.Show(this, strError); }