// 快速修改记录 void menu_quickChangeItemRecords_Click(object sender, EventArgs e) { string strError = ""; int nRet = 0; // bool bSkipUpdateBrowse = false; // 是否要跳过更新浏览行 if (this.listView_records.SelectedItems.Count == 0) { strError = "尚未选择要快速修改的"+this.DbTypeCaption+"记录事项"; goto ERROR1; } List<OneAction> actions = null; XmlDocument cfg_dom = null; if (this.DbType == "item" || this.DbType == "order" || this.DbType == "issue" || this.DbType == "comment") { ChangeItemActionDialog dlg = new ChangeItemActionDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.DbType = this.DbType; dlg.Text = "快速修改" + this.DbTypeCaption + "记录 -- 请指定动作参数"; dlg.MainForm = this.MainForm; dlg.GetValueTable -= new GetValueTableEventHandler(dlg_GetValueTable); dlg.GetValueTable += new GetValueTableEventHandler(dlg_GetValueTable); this.MainForm.AppInfo.LinkFormState(dlg, "itemsearchform_quickchange"+this.DbType+"dialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) return; actions = dlg.Actions; cfg_dom = dlg.CfgDom; } DateTime now = DateTime.Now; // TODO: 检查一下,看看是否一项修改动作都没有 this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始执行快速修改" + this.DbTypeCaption + "记录</div>"); stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("快速修改" + this.DbTypeCaption + "记录 ..."); stop.BeginLoop(); EnableControls(false); this.listView_records.Enabled = false; int nProcessCount = 0; int nChangedCount = 0; try { stop.SetProgressRange(0, this.listView_records.SelectedItems.Count); List<ListViewItem> items = new List<ListViewItem>(); foreach (ListViewItem item in this.listView_records.SelectedItems) { if (string.IsNullOrEmpty(item.Text) == true) continue; items.Add(item); } ListViewPatronLoader loader = new ListViewPatronLoader(this.Channel, stop, items, this.m_biblioTable); int i = 0; foreach (LoaderItem item in loader) { Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; goto ERROR1; } stop.SetProgressValue(i); BiblioInfo info = item.BiblioInfo; this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode(info.RecPath) + "</div>"); XmlDocument dom = new XmlDocument(); try { dom.LoadXml(info.OldXml); } catch (Exception ex) { strError = "装载XML到DOM时发生错误: " + ex.Message; goto ERROR1; } string strDebugInfo = ""; if (this.DbType == "item" || this.DbType == "order" || this.DbType == "issue" || this.DbType == "comment") { // 修改一个订购记录 XmlDocument // return: // -1 出错 // 0 没有实质性修改 // 1 发生了修改 nRet = ModifyOrderRecord( cfg_dom, actions, ref dom, now, out strDebugInfo, out strError); if (nRet == -1) goto ERROR1; } this.MainForm.OperHistory.AppendHtml("<div class='debug normal'>" + HttpUtility.HtmlEncode(strDebugInfo).Replace("\r\n", "<br/>") + "</div>"); nProcessCount++; if (nRet == 1) { string strXml = dom.OuterXml; if (info != null) { if (string.IsNullOrEmpty(info.NewXml) == true) this.m_nChangedCount++; info.NewXml = strXml; } item.ListViewItem.BackColor = SystemColors.Info; item.ListViewItem.ForeColor = SystemColors.InfoText; } i++; nChangedCount++; } } finally { EnableControls(true); this.listView_records.Enabled = true; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束快速修改" + this.DbTypeCaption + "记录</div>"); } DoViewComment(false); MessageBox.Show(this, "修改" + this.DbTypeCaption + "记录 " + nChangedCount.ToString() + " 条 (共处理 " + nProcessCount.ToString() + " 条)\r\n\r\n(注意修改并未自动保存。请在观察确认后,使用保存命令将修改保存回" + this.DbTypeCaption + "库)"); return; ERROR1: MessageBox.Show(this, strError); }
// 快速修改记录 // return: // -1 呼错 // 0 放弃 // 1 成功 internal int QuickChangeItemRecords(out string strError) { strError = ""; int nRet = 0; if (this._listviewRecords.SelectedItems.Count == 0) { strError = "尚未选择要快速修改的" + this.DbTypeCaption + "记录事项"; return -1; } List<OneAction> actions = null; XmlDocument cfg_dom = null; if (this.DbType == "item" || this.DbType == "order" || this.DbType == "issue" || this.DbType == "comment" || this.DbType == "patron") { ChangeItemActionDialog dlg = new ChangeItemActionDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.DbType = this.DbType; dlg.Text = "快速修改" + this.DbTypeCaption + "记录 -- 请指定动作参数"; dlg.MainForm = this.MainForm; dlg.GetValueTable -= new GetValueTableEventHandler(dlg_GetValueTable); dlg.GetValueTable += new GetValueTableEventHandler(dlg_GetValueTable); this.MainForm.AppInfo.LinkFormState(dlg, this.DbType + "searchform_quickchangedialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) return 0; // 放弃 actions = dlg.Actions; cfg_dom = dlg.CfgDom; } DateTime now = DateTime.Now; // TODO: 检查一下,看看是否一项修改动作都没有 this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始执行快速修改" + this.DbTypeCaption + "记录</div>"); stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("快速修改" + this.DbTypeCaption + "记录 ..."); stop.BeginLoop(); EnableControls(false); this._listviewRecords.Enabled = false; int nProcessCount = 0; int nChangedCount = 0; try { stop.SetProgressRange(0, this._listviewRecords.SelectedItems.Count); List<ListViewItem> items = new List<ListViewItem>(); foreach (ListViewItem item in this._listviewRecords.SelectedItems) { if (string.IsNullOrEmpty(item.Text) == true) continue; items.Add(item); } bool bOldSource = true; // 是否要从 OldXml 开始做起 int nChangeCount = this.GetItemsChangeCount(items); if (nChangeCount > 0) { bool bHideMessageBox = true; DialogResult result = MessageDialog.Show(this, "当前选定的 " + items.Count.ToString() + " 个事项中有 " + nChangeCount + " 项修改尚未保存。\r\n\r\n请问如何进行修改? \r\n\r\n(重新修改) 重新进行修改,忽略以前内存中的修改; \r\n(继续修改) 以上次的修改为基础继续修改; \r\n(放弃) 放弃整个操作", MessageBoxButtons.YesNoCancel, MessageBoxDefaultButton.Button1, null, ref bHideMessageBox, new string [] {"重新修改","继续修改","放弃"}); if (result == DialogResult.Cancel) { strError = "放弃"; return 0; } if (result == DialogResult.No) { bOldSource = false; } } ListViewPatronLoader loader = new ListViewPatronLoader(this.Channel, stop, items, this.m_biblioTable); loader.DbTypeCaption = this.DbTypeCaption; int i = 0; foreach (LoaderItem item in loader) { Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } stop.SetProgressValue(i); BiblioInfo info = item.BiblioInfo; Debug.Assert(info != null, ""); this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode(info.RecPath) + "</div>"); XmlDocument dom = new XmlDocument(); try { if (bOldSource == true) { dom.LoadXml(info.OldXml); // 放弃上一次的修改 if (string.IsNullOrEmpty(info.NewXml) == false) { info.NewXml = ""; this.m_nChangedCount--; } } else { if (string.IsNullOrEmpty(info.NewXml) == false) dom.LoadXml(info.NewXml); else dom.LoadXml(info.OldXml); } } catch (Exception ex) { strError = "装载XML到DOM时发生错误: " + ex.Message; return -1; } string strDebugInfo = ""; // 修改一个订购记录 XmlDocument // return: // -1 出错 // 0 没有实质性修改 // 1 发生了修改 nRet = ModifyItemRecord( cfg_dom, actions, ref dom, now, out strDebugInfo, out strError); if (nRet == -1) return -1; this.MainForm.OperHistory.AppendHtml("<div class='debug normal'>" + HttpUtility.HtmlEncode(strDebugInfo).Replace("\r\n", "<br/>") + "</div>"); nProcessCount++; if (nRet == 1) { string strXml = dom.OuterXml; Debug.Assert(info != null, ""); if (info != null) { if (string.IsNullOrEmpty(info.NewXml) == true) this.m_nChangedCount++; info.NewXml = strXml; } item.ListViewItem.BackColor = SystemColors.Info; item.ListViewItem.ForeColor = SystemColors.InfoText; } i++; nChangedCount++; } } finally { EnableControls(true); this._listviewRecords.Enabled = true; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束快速修改" + this.DbTypeCaption + "记录</div>"); } DoViewComment(false); strError = "修改" + this.DbTypeCaption + "记录 " + nChangedCount.ToString() + " 条 (共处理 " + nProcessCount.ToString() + " 条)\r\n\r\n(注意修改并未自动保存。请在观察确认后,使用保存命令将修改保存回" + this.DbTypeCaption + "库)"; return 1; }
// 快速修改记录 // return: // -1 出错 // 0 放弃 // 1 成功 internal int QuickChangeItemRecords(out string strError) { strError = ""; int nRet = 0; if (this.listView_records.SelectedItems.Count == 0) { strError = "尚未选择要快速修改的 856 字段事项"; return -1; } List<OneAction> actions = null; XmlDocument cfg_dom = null; { ChangeItemActionDialog dlg = new ChangeItemActionDialog(); MainForm.SetControlFont(dlg, this.Font, false); dlg.ElementCaption = "子字段"; dlg.DbType = "856"; dlg.Text = "快速修改 856 字段 -- 请指定动作参数"; dlg.MainForm = this.MainForm; //dlg.GetValueTable -= new GetValueTableEventHandler(dlg_GetValueTable); //dlg.GetValueTable += new GetValueTableEventHandler(dlg_GetValueTable); dlg.UiState = this.MainForm.AppInfo.GetString( "marc856search_form", "ChangeItemActionDialog_uiState", ""); this.MainForm.AppInfo.LinkFormState(dlg, "marc856searchform_quickchangedialog_state"); dlg.ShowDialog(this); this.MainForm.AppInfo.UnlinkFormState(dlg); this.MainForm.AppInfo.SetString( "marc856search_form", "ChangeItemActionDialog_uiState", dlg.UiState); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) return 0; // 放弃 actions = dlg.Actions; cfg_dom = dlg.CfgDom; } DateTime now = DateTime.Now; // TODO: 检查一下,看看是否一项修改动作都没有 this.MainForm.OperHistory.AppendHtml("<div class='debug begin'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 开始执行快速修改 856 字段</div>"); stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("快速修改 856 字段 ..."); stop.BeginLoop(); EnableControls(false); this.listView_records.Enabled = false; int nProcessCount = 0; int nChangedCount = 0; try { stop.SetProgressRange(0, this.listView_records.SelectedItems.Count); List<ListViewItem> items = new List<ListViewItem>(); foreach (ListViewItem item in this.listView_records.SelectedItems) { if (string.IsNullOrEmpty(item.Text) == true) continue; items.Add(item); } bool bOldSource = true; // 是否要从 OldXml 开始做起 int nChangeCount = this.GetItemsChangeCount(items); if (nChangeCount > 0) { bool bHideMessageBox = true; DialogResult result = MessageDialog.Show(this, "当前选定的 " + items.Count.ToString() + " 个事项中有 " + nChangeCount + " 项修改尚未保存。\r\n\r\n请问如何进行修改? \r\n\r\n(重新修改) 重新进行修改,忽略以前内存中的修改; \r\n(继续修改) 以上次的修改为基础继续修改; \r\n(放弃) 放弃整个操作", MessageBoxButtons.YesNoCancel, MessageBoxDefaultButton.Button1, null, ref bHideMessageBox, new string[] { "重新修改", "继续修改", "放弃" }); if (result == DialogResult.Cancel) { strError = "放弃"; return 0; } if (result == DialogResult.No) { bOldSource = false; } } int i = 0; foreach (ListViewItem item in items) { Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; return -1; } stop.SetProgressValue(i); LineInfo info = (LineInfo)item.Tag; if (info == null) { strError = "item.Tag == null"; return -1; } Debug.Assert(info != null, ""); string strField = ""; if (bOldSource == true) { strField = info.OldField; // 放弃上一次的修改 if (string.IsNullOrEmpty(info.State) == false) { info.State = ""; this.m_nChangedCount--; if (string.IsNullOrEmpty(info.NewField) == false) strField = info.NewField; else strField = info.OldField; } else { if (string.IsNullOrEmpty(info.NewField) == false) { info.NewField = ""; this.m_nChangedCount--; } } } else { if (string.IsNullOrEmpty(info.State) == false) { // 在删除的基础上继续修改 --- 等于承认删除状态,并无法修改,只好跳过 i++; continue; } if (string.IsNullOrEmpty(info.NewField) == false) strField = info.NewField; else strField = info.OldField; } string strBiblioRecPath = ListViewUtil.GetItemText(item, COLUMN_RECPATH); this.MainForm.OperHistory.AppendHtml("<div class='debug recpath'>" + HttpUtility.HtmlEncode(strBiblioRecPath + ":" + info.Index) + "</div>"); string strDebugInfo = ""; // 修改一个订购记录 XmlDocument // return: // -1 出错 // 0 没有实质性修改 // 1 发生了修改 nRet = Modify856Field( cfg_dom, actions, ref strField, now, out strDebugInfo, out strError); if (nRet == -1) return -1; this.MainForm.OperHistory.AppendHtml("<div class='debug normal'>" + HttpUtility.HtmlEncode(strDebugInfo).Replace("\r\n", "<br/>") + "</div>"); nProcessCount++; if (nRet == 1) { Debug.Assert(info != null, ""); if (info != null) { if (string.IsNullOrEmpty(info.NewField) == true) this.m_nChangedCount++; info.NewField = strField; } // 刷新除了记录路径和书目摘要的其余列的显示 MarcField field = new MarcField(info.NewField); SetItemColumns(item, null, field, info.Index); item.BackColor = SystemColors.Info; item.ForeColor = SystemColors.InfoText; } i++; nChangedCount++; } } finally { EnableControls(true); this.listView_records.Enabled = true; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; this.MainForm.OperHistory.AppendHtml("<div class='debug end'>" + HttpUtility.HtmlEncode(DateTime.Now.ToLongTimeString()) + " 结束快速修改 856 字段</div>"); } DoViewComment(false); strError = "修改 856 字段 " + nChangedCount.ToString() + " 个 (共处理 " + nProcessCount.ToString() + " 个)\r\n\r\n(注意修改并未自动保存。请在观察确认后,使用保存命令将修改保存回书目库)"; return 1; }