// 自动加工数据 // parameters: // sender 从何处启动? MarcEditor EntityEditForm BindingForm public void AutoGenerate(object sender, GenerateDataEventArgs e, string strBiblioRecPath, bool bOnlyFillMenu = false) { int nRet = 0; string strError = ""; bool bAssemblyReloaded = false; // 防止重入 if (bOnlyFillMenu == true && this.m_nInFillMenu > 0) { return; } this.m_nInFillMenu++; try { // 初始化 dp2circulation_marc_autogen.cs 的 Assembly,并new DetailHost对象 // return: // -1 error // 0 没有重新初始化Assembly,而是直接用以前Cache的Assembly // 1 重新(或者首次)初始化了Assembly nRet = InitialAutogenAssembly(strBiblioRecPath, // null, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { if (this.m_detailHostObj == null) { return; // 库名不具备,无法初始化 } } if (nRet == 1) { bAssemblyReloaded = true; } Debug.Assert(this.m_detailHostObj != null, ""); if (this.AutoGenNewStyle == true) { bool bDisplayWindow = this.MainForm.PanelFixedVisible == false ? true : false; if (bDisplayWindow == true) { if (String.IsNullOrEmpty(e.ScriptEntry) != true && e.ScriptEntry != "Main") { bDisplayWindow = false; } } if (sender is EntityEditForm && (String.IsNullOrEmpty(e.ScriptEntry) == true || e.ScriptEntry == "Main")) { bDisplayWindow = true; } else if (sender is BindingForm && (String.IsNullOrEmpty(e.ScriptEntry) == true || e.ScriptEntry == "Main")) { bDisplayWindow = true; } DisplayAutoGenMenuWindow(bDisplayWindow); // 可能会改变 .ActionTable以及 .Count if (bOnlyFillMenu == false) { if (this.MainForm.PanelFixedVisible == true && e.Parameter == null) // 2015/6/5 { MainForm.ActivateGenerateDataPage(); } } if (this.m_genDataViewer != null) { this.m_genDataViewer.sender = sender; this.m_genDataViewer.e = e; } // 清除残留菜单事项 if (m_autogenSender != sender || bAssemblyReloaded == true) { if (this.m_genDataViewer != null && this.m_genDataViewer.Count > 0) { this.m_genDataViewer.Clear(); } } } else // 旧的风格 { #if NO if (this.m_genDataViewer != null) { this.m_genDataViewer.Close(); this.m_genDataViewer = null; } #endif CloseGenDataViewer(); if (this._myForm.Focused == true // || this.m_marcEditor.Focused TODO: 这里要研究一下如何实现 ) { this.MainForm.CurrentGenerateDataControl = null; } // 如果意图仅仅为填充菜单 if (bOnlyFillMenu == true) { return; } } try { // 旧的风格 if (this.AutoGenNewStyle == false) { this.m_detailHostObj.Invoke(String.IsNullOrEmpty(e.ScriptEntry) == true ? "Main" : e.ScriptEntry, sender, e); // this.SetSaveAllButtonState(true); TODO: 应该没有必要。MARC 编辑器内容修改自然会引起保存按钮状态变化 return; } // 初始化菜单 try { if (this.m_genDataViewer != null) { // 出现菜单界面 if (this.m_genDataViewer.Count == 0) { dynamic o = this.m_detailHostObj; o.CreateMenu(sender, e); this.m_genDataViewer.Actions = this.m_detailHostObj.ScriptActions; } // 根据当前插入符位置刷新加亮事项 this.m_genDataViewer.RefreshState(); } if (String.IsNullOrEmpty(e.ScriptEntry) == false) { this.m_detailHostObj.Invoke(e.ScriptEntry, sender, e); } else { if (this.MainForm.PanelFixedVisible == true && bOnlyFillMenu == false && this.MainForm.CurrentGenerateDataControl != null) { TableLayoutPanel table = (TableLayoutPanel)this.MainForm.CurrentGenerateDataControl; for (int i = 0; i < table.Controls.Count; i++) { Control control = table.Controls[i]; if (control is DpTable) { control.Focus(); break; } } } } } catch (Exception /*ex*/) { /* * // 被迫改用旧的风格 * this.m_detailHostObj.Invoke(String.IsNullOrEmpty(e.ScriptEntry) == true ? "Main" : e.ScriptEntry, * sender, * e); * this.SetSaveAllButtonState(true); * return; * */ throw; } } catch (Exception ex) { strError = "执行脚本文件 '" + m_strAutogenDataCfgFilename + "' 过程中发生异常: \r\n" + ExceptionUtil.GetDebugText(ex); goto ERROR1; } this.m_autogenSender = sender; // 记忆最近一次的调用发起者 if (bOnlyFillMenu == false && this.m_genDataViewer != null) { this.m_genDataViewer.TryAutoRun(); } return; ERROR1: // TODO: 报错是否要直接显示在 dpTable 中? // MessageBox.Show(this._myForm, strError); DisplayAutoGenMenuWindow(false); if (this.m_genDataViewer != null) { this.m_genDataViewer.DisplayError(strError); } } finally { this.m_nInFillMenu--; } }