Esempio n. 1
0
        void m_genDataViewer_TriggerAction(object sender, TriggerActionArgs e)
        {
            if (this.m_detailHostObj != null)
            {
                if (this._myForm != null && this._myForm.IsDisposed == true)
                {
                    if (this.m_genDataViewer != null)
                    {
                        this.m_genDataViewer.Clear();
#if NO
                        this.m_genDataViewer.Close();
                        this.m_genDataViewer = null;
#endif
                        CloseGenDataViewer();
                        return;
                    }
                }
                if (String.IsNullOrEmpty(e.EntryName) == false)
                {
                    this.SynchronizeMarc();

                    this.m_detailHostObj.Invoke(e.EntryName,
                                                e.sender,
                                                e.e);

                    // if (this.tabControl_biblioInfo.SelectedTab == this.tabPage_template) TODO: 这里是不是没有必要优化了
                    this.SynchronizeMarc();
                }

                if (this.m_genDataViewer != null)
                {
                    this.m_genDataViewer.RefreshState();
                }
            }
        }
Esempio n. 2
0
        int _inCloseGenDataViewer = 0;  // 防止重入

        void CloseGenDataViewer()
        {
            if (_inCloseGenDataViewer > 0)
            {
                return;
            }

            _inCloseGenDataViewer++;
            try
            {
                if (this.m_genDataViewer != null)
                {
                    // 2015/11/7
                    // 注意解除 dock 时建立的关系。便于后面 Dispose()
                    if (Program.MainForm.CurrentGenerateDataControl == m_genDataViewer.Table)
                    {
                        Program.MainForm.CurrentGenerateDataControl = null;
                    }

                    this.m_genDataViewer.Close();
                    m_genDataViewer.DoDockEvent   -= new DoDockEventHandler(m_genDataViewer_DoDockEvent);
                    m_genDataViewer.SetMenu       -= new RefreshMenuEventHandler(m_genDataViewer_SetMenu);
                    m_genDataViewer.TriggerAction -= new TriggerActionEventHandler(m_genDataViewer_TriggerAction);
                    m_genDataViewer.MyFormClosed  -= new EventHandler(m_genDataViewer_MyFormClosed);
                    m_genDataViewer.FormClosed    -= new FormClosedEventHandler(m_genDataViewer_FormClosed);
                    this.m_genDataViewer           = null;
                }
            }
            finally
            {
                _inCloseGenDataViewer--;
            }
        }
Esempio n. 3
0
        void m_genDataViewer_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (m_genDataViewer != null)
            {
                Program.MainForm.AppInfo.SetBoolean("detailform", "gen_auto_run", m_genDataViewer.AutoRun);

                {       // 保存列宽度
                    string strWidths = DpTable.GetColumnWidthListString(m_genDataViewer.ActionTable);
                    Program.MainForm.AppInfo.SetString(
                        "gen_data_dlg",
                        "column_width",
                        strWidths);
                }

                Program.MainForm.AppInfo.UnlinkFormState(m_genDataViewer);
#if NO
                this.m_genDataViewer = null;
#endif
                CloseGenDataViewer();
            }
        }
Esempio n. 4
0
        void DisplayAutoGenMenuWindow(bool bOpenWindow)
        {
            // string strError = "";


            // 优化,避免无谓地进行服务器调用
            if (bOpenWindow == false)
            {
                if (Program.MainForm.PanelFixedVisible == false &&
                    (m_genDataViewer == null || m_genDataViewer.Visible == false))
                {
                    return;
                }
            }


            if (this.m_genDataViewer == null ||
                (bOpenWindow == true && this.m_genDataViewer.Visible == false))
            {
                m_genDataViewer = new GenerateDataForm();

                m_genDataViewer.AutoRun = Program.MainForm.AppInfo.GetBoolean("detailform", "gen_auto_run", false);
                // MainForm.SetControlFont(m_genDataViewer, this.Font, false);

                {       // 恢复列宽度
                    string strWidths = Program.MainForm.AppInfo.GetString(
                        "gen_data_dlg",
                        "column_width",
                        "");
                    if (String.IsNullOrEmpty(strWidths) == false)
                    {
                        DpTable.SetColumnHeaderWidth(m_genDataViewer.ActionTable,
                                                     strWidths,
                                                     false);
                    }
                }

                // m_genDataViewer.MainForm = Program.MainForm;  // 必须是第一句
                m_genDataViewer.Text = "创建数据";

                m_genDataViewer.DoDockEvent -= new DoDockEventHandler(m_genDataViewer_DoDockEvent);
                m_genDataViewer.DoDockEvent += new DoDockEventHandler(m_genDataViewer_DoDockEvent);

                m_genDataViewer.SetMenu -= new RefreshMenuEventHandler(m_genDataViewer_SetMenu);
                m_genDataViewer.SetMenu += new RefreshMenuEventHandler(m_genDataViewer_SetMenu);

                m_genDataViewer.TriggerAction -= new TriggerActionEventHandler(m_genDataViewer_TriggerAction);
                m_genDataViewer.TriggerAction += new TriggerActionEventHandler(m_genDataViewer_TriggerAction);

                m_genDataViewer.MyFormClosed -= new EventHandler(m_genDataViewer_MyFormClosed);
                m_genDataViewer.MyFormClosed += new EventHandler(m_genDataViewer_MyFormClosed);

                m_genDataViewer.FormClosed -= new FormClosedEventHandler(m_genDataViewer_FormClosed);
                m_genDataViewer.FormClosed += new FormClosedEventHandler(m_genDataViewer_FormClosed);
            }

            if (bOpenWindow == true)
            {
                if (m_genDataViewer.Visible == false)
                {
                    Program.MainForm.AppInfo.LinkFormState(m_genDataViewer, "autogen_viewer_state");
                    m_genDataViewer.Show(this._myForm);
                    m_genDataViewer.Activate();

                    Program.MainForm.CurrentGenerateDataControl = null;
                }
                else
                {
                    if (m_genDataViewer.WindowState == FormWindowState.Minimized)
                    {
                        m_genDataViewer.WindowState = FormWindowState.Normal;
                    }
                    m_genDataViewer.Activate();
                }
            }
            else
            {
                if (m_genDataViewer.Visible == true)
                {
                }
                else
                {
                    if (Program.MainForm.CurrentGenerateDataControl != m_genDataViewer.Table)
                    {
                        m_genDataViewer.DoDock(false); // 不会自动显示FixedPanel
                    }
                }
            }

            if (this.m_genDataViewer != null)
            {
                this.m_genDataViewer.CloseWhenComplete = bOpenWindow;
            }

            return;

            /*
             * ERROR1:
             * MessageBox.Show(this, "DisplayAutoGenMenu() 出错: " + strError);
             * */
        }
Esempio n. 5
0
        // 自动加工数据
        // 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 = Program.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 (Program.MainForm.PanelFixedVisible == true &&
                            e.Parameter == null)    // 2015/6/5
                        {
                            Program.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: 这里要研究一下如何实现
                        )
                    {
                        Program.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 (Program.MainForm.PanelFixedVisible == true &&
                                bOnlyFillMenu == false &&
                                Program.MainForm.CurrentGenerateDataControl != null)
                            {
                                TableLayoutPanel table = (TableLayoutPanel)Program.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--;
            }
        }