Пример #1
0
        /// <summary>
        /// 获取该视图所呈现的包含参数设置、插件控件、翻页控件的界面。
        /// </summary>
        /// <returns></returns>
        public override Control CreateViewControl()
        {
            Control         ctlView       = new Control();
            FlowLayoutPanel flpParameters = null;

            //初始化插件
            System.Reflection.ConstructorInfo ci = this.PluginType.Type.GetConstructor(new System.Type[] { });
            object objInstance = ci.Invoke(new object[] { });

            this.m_Plugin = objInstance as IPlugin;

            if (this.m_IsHtmlPlugin)
            {
                this.m_PluginControl = new System.Windows.Forms.WebBrowser();
                ((System.Windows.Forms.WebBrowser) this.m_PluginControl).ObjectForScripting = new ScriptManager(this);
                ((System.Windows.Forms.WebBrowser) this.m_PluginControl).NewWindow         += new System.ComponentModel.CancelEventHandler(PluginViewBase_NewWindow);
            }
            else
            {
                this.m_PluginControl = objInstance as Control;
            }

            //设置应用程序框架
            this.m_Plugin.SetApplication(base.Application);

            //设置账号
            if (this.m_Plugin is IUseAccount)
            {
                if (this.Application.CurrentAccount == null)
                {
                    throw new Exception("“" + this.PluginType.Name + "”需要使用操作员账号,但应用程序框架无账号信息。");
                }

                IUseAccount useAccount = this.m_Plugin as IUseAccount;
                useAccount.SetAccount(this.Application.CurrentAccount);
            }

            //由继承的类设置对象
            this.SetPlugin(this.m_Plugin);

            //设置参数
            foreach (Type typParameter in this.PluginType.ParameterTypes)
            {
                if (flpParameters == null)
                {
                    flpParameters = new FlowLayoutPanel();
                }
                if (this.m_lsParameterControls == null)
                {
                    this.m_lsParameterControls = new List <IParameterControl>();
                }

                Type typControlType = this.Application.GetParameterControlType(typParameter);
                if (typControlType != null)
                {
                    System.Reflection.ConstructorInfo ciParameter = typControlType.GetConstructor(new System.Type[] { });
                    object objParameterInstance = ciParameter.Invoke(new object[] { });

                    IParameterControl parameterControl = objParameterInstance as IParameterControl;
                    parameterControl.SetApplication(base.Application);

                    if (objParameterInstance is IUseAccount)
                    {
                        IUseAccount useAccount = objParameterInstance as IUseAccount;
                        useAccount.SetAccount(this.Application.CurrentAccount);
                    }

                    parameterControl.SetOrientation(true);

                    if (this.m_ParameterValues != null)
                    {
                        foreach (ParameterValue _ParameterValue in this.m_ParameterValues)
                        {
                            if (_ParameterValue.Type.Equals(typParameter))
                            {
                                parameterControl.SetParameterValue(_ParameterValue.Value);
                                break;
                            }
                        }
                    }
                    m_lsParameterControls.Add(parameterControl);
                    parameterControl.SetParameterPlugin(this.m_Plugin as IParameter);
                    flpParameters.Controls.Add(objParameterInstance as Control);
                }
                else
                {
                    Label labError = new Label();
                    labError.Text      = "未发现“" + typParameter.FullName + "”的查询参数界面控件。";
                    labError.ForeColor = System.Drawing.Color.Red;
                    labError.AutoSize  = true;
                    flpParameters.Controls.Add(labError);
                }
            }
            //edit by xch 3.23
            if (Function.IsInheritableBaseType(this.PluginType.Type, typeof(System.Windows.Forms.UserControl)))
            {
                ctlView.Size = new System.Drawing.Size((this.m_PluginControl as UserControl).Width + 10, (this.m_PluginControl as UserControl).Height + 40);
            }
            else
            {
                ctlView.Size = new System.Drawing.Size(800, 600);
            }

            this.m_PluginControl.Dock = DockStyle.Fill;
            ctlView.Controls.Add(this.m_PluginControl);

            if (flpParameters != null)
            {
                Button btnParameter = new Button();
                btnParameter.Text   = "确定";
                btnParameter.Click += new EventHandler(btnParameter_Click);
                flpParameters.Controls.Add(btnParameter);

                flpParameters.Dock     = DockStyle.Top;
                flpParameters.AutoSize = true;
                ctlView.Controls.Add(flpParameters);
            }

            if (this.PluginType.IsPagination)
            {
                IPagination pluginPagination = this.m_Plugin as IPagination;
                pluginPagination.Pagination += new PaginationEventHandler(plugin_Pagination);
                this.m_Pagination            = new Pagination();
                this.m_Pagination.Dock       = DockStyle.Bottom;
                this.m_Pagination.Paging    += new PagingEventHandler(m_Pagination_Paging);
                ctlView.Controls.Add(this.m_Pagination);
                pluginPagination.SetPageNumber(1);
            }

            if (this.m_IsHtmlPlugin)
            {
                this.WriterHtmlPlugin(this.m_Plugin);
            }



            this.m_IsCreateViewControl = true;
            return(ctlView);
        }