// 有在借册的 --> 读者查询窗 void menu_exportBorrowingToReaderSearchForm_Click(object sender, EventArgs e) { string strError = ""; List<string> barcodes = new List<string>(); foreach (ListViewItem item in this.listView_records.SelectedItems) { // TODO: 用 style 来识别列 barcodes.Add(item.SubItems[1].Text); } int nCount = 0; ReaderSearchForm form = new ReaderSearchForm(); form.MdiParent = this.MainForm; form.Show(); form.EnableControls(false); try { // return: // -1 出错。包括用户中断的情况 // >=0 实际处理的读者记录数 int nRet = this.ProcessPatrons(barcodes, (strRecPath, dom, timestamp) => { this.ShowMessage("正在处理读者记录 " + strRecPath); form.ShowMessage("正在处理读者记录 " + strRecPath); string barcode = DomUtil.GetElementText(dom.DocumentElement, "barcode"); XmlNodeList nodes = dom.DocumentElement.SelectNodes("borrows/borrow"); if (nodes.Count > 0) { form.AddBarcodeToBrowseList(barcode); nCount++; } return true; }, out strError); if (nRet == -1) goto ERROR1; form.RrefreshAllItems(); form.ShowMessage("共装入读者记录 " + nCount + " 个", "green", true); } finally { form.EnableControls(true); } this.ShowMessage("完成", "green", true); return; ERROR1: MessageBox.Show(this, strError); }
// 装入读者查询窗口 void menu_exportToReaderSearchForm_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; int nWarningLineCount = 0; int nDupCount = 0; string strText = ""; if (this.listView_records.SelectedItems.Count == 0) { strError = "尚未选定要装入读者查询窗的行"; goto ERROR1; } stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在装入记录到读者查询窗 ..."); stop.BeginLoop(); try { List<string> reader_barcodes = new List<string>(); nRet = GetSelectedReaderBarcodes(out reader_barcodes, ref nWarningLineCount, ref nDupCount, out strError); if (nRet == -1) goto ERROR1; if (nWarningLineCount > 0) strText = "有 " + nWarningLineCount.ToString() + " 行因为相关库浏览格式没有定义 type 为 borrower 的栏而被忽略"; if (nDupCount > 0) { if (string.IsNullOrEmpty(strText) == false) strText += "\r\n\r\n"; strText += "读者记录有 " + nDupCount.ToString() + " 项重复被忽略"; } if (reader_barcodes.Count == 0) { strError = "没有找到相关的读者记录"; goto ERROR1; } ReaderSearchForm form = new ReaderSearchForm(); form.MdiParent = this.MainForm; form.Show(); form.EnableControls(false); foreach (string barcode in reader_barcodes) { form.AddBarcodeToBrowseList(barcode); } form.EnableControls(true); form.RrefreshAllItems(); } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; } if (string.IsNullOrEmpty(strText) == false) MessageBox.Show(this, strText); return; ERROR1: if (string.IsNullOrEmpty(strText) == false) MessageBox.Show(this, strText); MessageBox.Show(this, strError); }
// 筛选 --> 读者查询窗 void menu_filterToAnotherReaderSearchForm_Click(object sender, EventArgs e) { string strError = ""; FilterPatronDialog dlg = new FilterPatronDialog(); MainForm.SetControlFont(dlg, this.Font, false); this.MainForm.AppInfo.LinkFormState(dlg, "readersearchform_FilterPatronDialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) return; ReaderSearchForm form = new ReaderSearchForm(); form.MdiParent = this.MainForm; form.Show(); form.EnableControls(false); try { int nCount = 0; // return: // -1 出错。包括用户中断的情况 // >=0 实际处理的读者记录数 int nRet = this.ProcessSelectedPatrons( (strRecPath, dom, timestamp) => { this.ShowMessage("正在处理读者记录 " + strRecPath); form.ShowMessage("正在处理读者记录 " + strRecPath); string barcode = DomUtil.GetElementText(dom.DocumentElement, "barcode"); XmlNodeList borrows = dom.DocumentElement.SelectNodes("borrows/borrow"); XmlNodeList overdues = dom.DocumentElement.SelectNodes("overdues/overdue"); bool bOn = false; // “无在借册和违约金的” if (dlg.NoBorrowAndOverdueItem == true) { if (borrows.Count == 0 || overdues.Count == 0) bOn = true; } // “有在借册的 / 已超期” if (dlg.OutofPeriodItem == true) { if (borrows.Count > 0) { foreach (XmlElement borrow in borrows) { // 2016/6/12 { string strBorrowDate = borrow.GetAttribute("borrowDate"); string strPeriod = borrow.GetAttribute("borrowPeriod"); if (string.IsNullOrEmpty(strBorrowDate) == true || string.IsNullOrEmpty(strPeriod) == true) { // 记入错误日志 continue; } nRet = Global.IsOverdue(strBorrowDate, strPeriod, out strError); if (nRet == -1) { // 记入错误日志 continue; } if (nRet == 1) { bOn = true; break; } continue; } #if NO string strReturningDate = borrow.GetAttribute("returningDate"); // 注: returningDate 为空,这是不正常状态,或者早期的数据。但依然可以通过 borrowDate 和 period 来测算 if (string.IsNullOrEmpty(strReturningDate) == true) continue; try { // TODO: 处理抛出异常 DateTime time = DateTimeUtil.FromRfc1123DateTimeString(strReturningDate); // TODO: 时间要正规化以后再比较 if (time.ToLocalTime() < DateTime.Now) { bOn = true; break; } } catch (Exception ex) { // TODO: 记入错误日志 } #endif } } } // “有在借册的 / 未超期”是否被勾选 if (dlg.InPeriodItem == true) { if (borrows.Count > 0) { int nOverdueCount = 0; foreach (XmlElement borrow in borrows) { #if NO string strReturningDate = borrow.GetAttribute("returningDate"); // TODO: 处理抛出异常 DateTime time = DateTimeUtil.FromRfc1123DateTimeString(strReturningDate); // TODO: 时间要正规化以后再比较 if (time.ToLocalTime() < DateTime.Now) nOverdueCount++; #endif string strBorrowDate = borrow.GetAttribute("borrowDate"); string strPeriod = borrow.GetAttribute("borrowPeriod"); if (string.IsNullOrEmpty(strBorrowDate) == true || string.IsNullOrEmpty(strPeriod) == true) { // 记入错误日志 continue; } nRet = Global.IsOverdue(strBorrowDate, strPeriod, out strError); if (nRet == -1) { // 记入错误日志 continue; } if (nRet == 1) nOverdueCount++; } if (nOverdueCount == 0) bOn = true; } } // “有违约金的”是否被勾选 if (dlg.HasOverdueItem == true) { if (overdues.Count > 0) bOn = true; } if (bOn == true) { form.AddBarcodeToBrowseList(barcode); nCount++; } return true; }, out strError); if (nRet == -1) goto ERROR1; form.RrefreshAllItems(); form.ShowMessage("共装入读者记录 " + nCount + " 个", "green", true); } finally { form.EnableControls(true); } this.ShowMessage("完成", "green", true); return; ERROR1: MessageBox.Show(this, strError); }