// 有在借册的 --> 读者查询窗 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_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); }