コード例 #1
0
            /// <summary>
            /// 获取实现 IHtmlContext 接口的 GetContext 方法的内容。
            /// </summary>
            /// <param name="typeName">类型名称</param>
            /// <param name="parameter">参数</param>
            /// <param name="callback">HTML 页面中回调方法的名称</param>
            public void GetHtmlContext(string typeName, string parameter, string callback)
            {
                Type typ = Function.GetType(typeName);

                if (typ != null)
                {
                    try
                    {
                        System.Reflection.ConstructorInfo ciObject = typ.GetConstructor(new System.Type[] { });
                        object obj = ciObject.Invoke(new object[] { });

                        IHtmlContext _IHtmlContext = obj as IHtmlContext;
                        if (_IHtmlContext is IUseAccount)
                        {
                            IUseAccount _IUseAccount = _IHtmlContext as IUseAccount;
                            _IUseAccount.SetAccount(this.PluginView.Application.CurrentAccount);
                        }
                        this.PluginView.SetHtmlContext(callback, true, _IHtmlContext.GetContext(this.PluginView.Application, parameter));
                    }
                    catch (Exception ex)
                    {
                        this.PluginView.SetHtmlContext(callback, false, ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("无法加载名称为“" + typeName + "”的类型", "获取内容", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
コード例 #2
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);
        }
コード例 #3
0
ファイル: DeviceFilterBasic.cs プロジェクト: xibeilang524/AC
        private void AddFilter(IDeviceFilter filter, bool isReadonly)
        {
            this.RowCount++;
            this.RowStyles.Add(new RowStyle());

            Type typControl = this.m_Application.GetControlType(filter.GetType(), typeof(System.Windows.Forms.Control));

            if (typControl == null)
            {
                Label lab = new Label();
                lab.Text         = "未发现 " + filter.GetType().FullName + " 的筛选器控件";
                lab.AutoEllipsis = true;
                lab.Padding      = new System.Windows.Forms.Padding(3);
                lab.Dock         = DockStyle.Bottom;
                this.Controls.Add(lab);

                if (this.EnabledRemove)
                {
                    System.Windows.Forms.Button btnFilterRemove = new Button();
                    btnFilterRemove.Image     = Properties.Resources.DeleteBlack;
                    btnFilterRemove.Width     = 24;
                    btnFilterRemove.FlatStyle = FlatStyle.Flat;
                    btnFilterRemove.FlatAppearance.BorderSize = 0;
                    btnFilterRemove.Dock   = DockStyle.Right;
                    btnFilterRemove.Click += new EventHandler(btnFilterRemove_Click);
                    this.Controls.Add(btnFilterRemove);
                }
            }
            else
            {
                System.Reflection.ConstructorInfo ciFilter = typControl.GetConstructor(new System.Type[] { });
                object objFilterInstance = ciFilter.Invoke(new object[] { });

                IDeviceFilterControl _FilterControl = objFilterInstance as IDeviceFilterControl;
                _FilterControl.SetApplication(this.m_Application);

                if (objFilterInstance is IUseAccount)
                {
                    IUseAccount useAccount = objFilterInstance as IUseAccount;
                    useAccount.SetAccount(this.m_Account);
                }

                _FilterControl.SetFilter(filter);

                Control ctl = objFilterInstance as Control;
                ctl.Dock = DockStyle.Bottom;
                if (isReadonly)
                {
                    ctl.Enabled = false;
                }
                this.Controls.Add(ctl);

                if (this.EnabledRemove)
                {
                    if (isReadonly)
                    {
                        Control ctlButton = new Control();
                        this.Controls.Add(ctlButton);
                    }
                    else
                    {
                        System.Windows.Forms.Button btnFilterRemove = new Button();
                        btnFilterRemove.Image     = Properties.Resources.DeleteBlack;
                        btnFilterRemove.Width     = 24;
                        btnFilterRemove.FlatStyle = FlatStyle.Flat;
                        btnFilterRemove.FlatAppearance.BorderSize = 0;
                        btnFilterRemove.Dock   = DockStyle.Right;
                        btnFilterRemove.Click += new EventHandler(btnFilterRemove_Click);
                        this.Controls.Add(btnFilterRemove);
                    }
                }
            }
        }
コード例 #4
0
        //如果返回 true 则表示该次调用有菜单项被输出
        private bool GetDeviceMenu(PluginTypeCollection pluginTypes, ToolStripItemCollection menuItems)
        {
            bool bolIsOutput = false;

            for (int intIndex = 0; intIndex < pluginTypes.Count; intIndex++)
            {
                DevicePluginType _PluginType = pluginTypes[intIndex] as DevicePluginType;

                if ((_PluginType.Type.GetInterface(typeof(IDeviceHtmlPlugin).FullName, true) != null) || (Function.IsInheritableBaseType(_PluginType.Type, typeof(System.Windows.Forms.Control))))
                {
                    //HTML、控件
                    ToolStripMenuItem mnuDevicePlugin = new ToolStripMenuItem();
                    mnuDevicePlugin.Text  = _PluginType.Name;
                    mnuDevicePlugin.Image = _PluginType.Icon16;
                    mnuDevicePlugin.Tag   = _PluginType;
                    if (_PluginType.Description != null && _PluginType.Description.Length > 0)
                    {
                        mnuDevicePlugin.ToolTipText = _PluginType.Description;
                    }
                    if (_PluginType.Icon16 != null)
                    {
                        mnuDevicePlugin.Image = _PluginType.Icon16;
                    }
                    mnuDevicePlugin.Click += new EventHandler(mnuDevicePlugin_Click);

                    if (_PluginType.Children.Count > 0)
                    {
                        this.GetDeviceMenu(_PluginType.Children, mnuDevicePlugin.DropDownItems);
                    }
                    //mnuDevicePlugin.MouseEnter += new EventHandler(mnuDevicePlugin_MouseEnter);
                    menuItems.Add(mnuDevicePlugin);
                    bolIsOutput = true;
                }
                else if (Function.IsInheritableBaseType(_PluginType.Type, typeof(System.Windows.Forms.ToolStripItem)))
                {
                    //自定义的菜单项
                    System.Reflection.ConstructorInfo ci = _PluginType.Type.GetConstructor(new System.Type[] { });
                    object objInstance = ci.Invoke(new object[] { });

                    IDevicePlugin plugin          = objInstance as IDevicePlugin;
                    ToolStripItem mnuDevicePlugin = plugin as ToolStripItem;
                    if (_PluginType.Icon16 != null)
                    {
                        mnuDevicePlugin.Image = _PluginType.Icon16;
                    }
                    menuItems.Add(mnuDevicePlugin);

                    plugin.SetDevices((Device[])mnuDevicePlugin.Owner.Tag);
                    if (plugin is IUseAccount)
                    {
                        IUseAccount useAccount = plugin as IUseAccount;
                        useAccount.SetAccount(this.CurrentAccount);
                    }
                    plugin.SetApplication(this);

                    if (mnuDevicePlugin.Text.Length == 0)
                    {
                        mnuDevicePlugin.Text = _PluginType.Name;
                    }
                    if (_PluginType.Description != null && _PluginType.Description.Length > 0 && (mnuDevicePlugin.ToolTipText == null || mnuDevicePlugin.ToolTipText.Length == 0))
                    {
                        mnuDevicePlugin.ToolTipText = _PluginType.Description;
                    }
                    //tsi.MouseEnter += new EventHandler(mnuDevicePlugin_MouseEnter);
                    bolIsOutput = true;
                }
                else if (_PluginType.Name == null)
                {
                    //分隔线
                    if (bolIsOutput && _PluginType.Children.Count > 0)
                    {
                        menuItems.Add(new ToolStripSeparator());
                    }

                    //分隔线的子插件
                    if (this.GetDeviceMenu(_PluginType.Children, menuItems))
                    {
                        bolIsOutput = true;
                    }
                }
                else
                {
                    //作为分类处理
                    if (_PluginType.Children.Count > 0)
                    {
                        ToolStripMenuItem mnuDevicePlugin = new ToolStripMenuItem();
                        mnuDevicePlugin.Text = _PluginType.Name;
                        if (_PluginType.Description != null && _PluginType.Description.Length > 0)
                        {
                            mnuDevicePlugin.ToolTipText = _PluginType.Description;
                        }
                        if (_PluginType.Icon16 != null)
                        {
                            mnuDevicePlugin.Image = _PluginType.Icon16;
                        }
                        //mnuDevicePlugin.MouseEnter += new EventHandler(mnuDevicePlugin_MouseEnter);

                        this.GetDeviceMenu(_PluginType.Children, mnuDevicePlugin.DropDownItems);
                        menuItems.Add(mnuDevicePlugin);
                        bolIsOutput = true;
                    }
                }
            }
            return(bolIsOutput);
        }