技术篇(3)--QPG界面分解方法介绍

在实际开发中,我发现很多程序员花很多时间在界面处理上.并且界面之间的关系和控制逻辑可能工作量并不小.所以好些老手到后面就跑去做后台服务,做通讯去了.
    界面布局和交互设计本身有很多的学问,或者有很多艺术,但是本文这里先不讨论这个问题.
    在QPG团队实践中,我们把界面划分成很多的UI_PART,这和ASP.NET2.0的WebPart可能有相同的地方.我们用这些简单的PART进行接受输入或者展示结果.这样就可以比较方便的测试了.通常这些PART就是一些用户控件,我们提供了IMainForm接口,使得UI的容器可以动态调入这些部件,哪怕程序已经运行,您也可以编写一个PART,您只要把它放到bin\plugins目录即可.
    有时部件可能要和容器通讯,看看下面的代码您可能就会明白:
ContractedBlock.gifExpandedBlockStart.gifIMainForm 成员#region IMainForm 成员
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public string CurUserID dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{
InBlock.gif                
// TODO:  添加 Form1.CurUserID getter 实现
InBlock.gif
                return "admin";
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public object getCookie(string name) dot.gif{
InBlock.gif            
// TODO:  添加 Form1.getCookie 实现
InBlock.gif
            return name;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void addCookie(string name, object obj) dot.gif{
InBlock.gif            
// TODO:  添加 Form1.addCookie 实现
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public QPG.UIP.Privilege getPrivilegeByUser(string uid, string cmdName) dot.gif{
InBlock.gif            
// TODO:  添加 Form1.getPrivilegeByUser 实现
InBlock.gif
            return  QPG.UIP.Privilege.Full;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void showStatus(string msg) dot.gif{
InBlock.gif            MessageBox.Show(msg);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void showHelp(string help) dot.gif{
InBlock.gif            
// TODO:  添加 Form1.showHelp 实现
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public void showNotify(string title, string msg) dot.gif{
InBlock.gif            MessageBox.Show(msg);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif        
#endregion
要使用插件服务.您的代码Form容器大致如下:
None.gifpublic class Form1 : System.Windows.Forms.Form,IMainForm
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
private System.ComponentModel.IContainer components;
InBlock.gif        
private System.Windows.Forms.Panel panel1;
InBlock.gif        
public static PluginService Plugins=new PluginService();
InBlock.gif        
private QPG.UIP.Actions.ActionList actionList1;
InBlock.gif        
private QPG.UIP.Actions.Action action1;
InBlock.gif        
private QPG.UIP.Actions.Action action2;
InBlock.gif    
//dot.gifdot.gif
InBlock.gif
    protected IPlugin selectedPlugin;
InBlock.gif
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// Windows 窗体设计器支持所必需的
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            Plugins.MainForm
=this;
InBlock.gif        
InBlock.gif            action1.Tag
="Demo.UIC.Plugin1";
InBlock.gif            action2.Tag
="Demo.UIC.Plugin2";
InBlock.gif            action1.Execute
+=new EventHandler(runAction);
InBlock.gif            action2.Execute
+=new EventHandler(runAction);
InBlock.gif
InBlock.gif        
//    Tester t=new Tester();
InBlock.gif        
//    t.testParametersConfig();
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
private void runAction(object sender, System.EventArgs e) dot.gif{
InBlock.gif            QPG.UIP.Actions.Action a
=sender as QPG.UIP.Actions.Action;
InBlock.gif        
InBlock.gif            
if(getPrivilegeByUser("admin", a.Tag.ToString())==Privilege.None) return;
InBlock.gif        
InBlock.gif            selectedPlugin
=Plugins.FindPlugin(a.Tag.ToString() );
InBlock.gif            panel1.Controls.Clear();
InBlock.gif            panel1.Controls.Add(selectedPlugin.MainInterface);
InBlock.gif            selectedPlugin.MainInterface.Dock
=DockStyle.Fill;
InBlock.gif
ExpandedSubBlockEnd.gif        }

插件的编写就很简单了,大致如下:
None.gifusing System;
None.gif
using QPG.UIP;
None.gif
None.gif
namespace Demo.UIC
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Plugin2
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class Plugin1 :  BasePlugin  
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
public Plugin1():base()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void init()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.init();
InBlock.gif    
InBlock.gif
InBlock.gif            
this.myRequimentNo = "uca01";
InBlock.gif            
InBlock.gif            
this.myDescription="统计图";
InBlock.gif            
this.myAuthor="alex";
InBlock.gif                    
InBlock.gif                
InBlock.gif        
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif            
InBlock.gif        
InBlock.gif        
public override void Initialize()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.MainInterface=new PlugUI1();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
public override void Dispose()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Put any cleanup code in here for when the program is stopped
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Drawing;
None.gif
using System.Data;
None.gif
using System.Windows.Forms;
None.gif
using QPG.UIP;
None.gif
None.gif
None.gif
namespace Demo.UIC
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for ctlMain.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class PlugUI1 : PluginBaseUI
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif    
InBlock.gif        
private System.Windows.Forms.Label label1;
InBlock.gif        
private System.Windows.Forms.GroupBox groupBox1;
InBlock.gif        
private System.Windows.Forms.TextBox txtFeedback;
InBlock.gif        
private System.Windows.Forms.Button button1;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// Required designer variable.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private System.ComponentModel.Container components = null;
InBlock.gif
InBlock.gif        
public PlugUI1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// This call is required by the Windows.Forms Form Designer.
InBlock.gif
            InitializeComponent();
InBlock.gif
InBlock.gif            
// TODO: Add any initialization after the InitializeComponent call
InBlock.gif

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// Clean up any resources being used.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected override void Dispose( bool disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if( disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(components != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    components.Dispose();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.Dispose( disposing );
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
//dot.gifdot.gif
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif        
private void button1_Click(object sender, System.EventArgs e) dot.gif{
InBlock.gif            
this.PluginHost.showStatus(txtFeedback.Text);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif
InBlock.gif        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

 具体代码可以参阅:下载开发演示文件

转载于:https://www.cnblogs.com/QPG2006/archive/2005/10/07/249662.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/264986.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux编程MQTT实现主题发布订阅

【物联网阿里云平台开发项目实战|附课件资料】智能硬件开发-数据上云&#xff0c;零基础入门 4G模块连接阿里云教程 MQTT通信协议(mosquitto)在Linux上的环境构建与测试 MQTT通信协议(mosquitto)发布订阅例子C语言实现 MQTT客户端软件(MQTT.fx)的使用详解 各类MQTT代理服务器特…

用memcached实现session共享

用memcached实现session共享一、简介1&#xff09;Memcached简介&#xff1a;是一种高性能的分布式缓存服务器&#xff1b;一般的使用目的是&#xff0c;通过“缓存数据” 查询结果&#xff0c;减少数据访问次数&#xff0c;以提高动态web应用的速度&#xff1b;开源且垮平台的…

事物传递机制、应用、加载时机

try() catch(){ } 后事物会回滚吗 事物机制 事物的底层实现 spring 事物 a调用 b调用a的时候对bean进行加载后&#xff0c;对原生类生成代理类(jdk代理或者cglibdialing)代理类 在调用的时候 注意是调用的时候 对有trasaction或者拦截切面切点的方式方法 增加事物管理。默认的事…

Linux串口应用编程

目录Demo串口应用编程介绍终端Terminal串口应用编程(配置、读取、写入)struct termios 结构体配置输入模式: c_iflag输出模式: c_oflag控制模式: c_cflag(波特率、数据位、校验位、停止位)本地模式: c_lflag特殊控制字符: c_cc注意事项三种工作模式(原始模式read是否阻塞)什么时…

一篇有关教育的文章

http://learning.sohu.com/s2005/jiatingjiaoyu.shtml转载于:https://www.cnblogs.com/froster/archive/2005/11/04/268642.html

Codeforces - 65D - Harry Potter and the Sorting Hat - 简单搜索

https://codeforces.com/problemset/problem/65/D 哈利波特&#xff01;一种新思路的状压记忆化dfs&#xff0c;记得每次dfs用完要减回去。而且一定是要在dfs外部进行加减&#xff01;防止在中间return的时候忘记弄回来。用哈希记录状态实现真正的记忆化。 #include<bits/st…

Linux MQTT 物联网通信

更多干货推荐可以去牛客网看看&#xff0c;他们现在的IT题库内容很丰富&#xff0c;属于国内做的很好的了&#xff0c;而且是课程刷题面经求职讨论区分享&#xff0c;一站式求职学习网站&#xff0c;最最最重要的里面的资源全部免费&#xff01;&#xff01;&#xff01;点击进…

.NET平台下Web树形结构程序设计

.NET平台下Web树形结构程序设计 我的上篇文章《树形结构在开发中的应用》主要是在Windows Form下的实现&#xff0c;下面是Web Form下的实现。数据库设计 首先&#xff0c;我们在SQL SERVER 2000里建立一个表tbTree&#xff0c;表的结构设计如下&#xff1a;列名数据类型描述长…

Advanced Installer 9.8打包实录

原文 Advanced Installer 9.8打包实录 主要介绍&#xff1a;&#xff08;1&#xff09;创建工程&#xff0c;&#xff08;2&#xff09;创建快捷方式及其图标&#xff08;3&#xff09;卸载设置 创建工程&#xff08;.net为例&#xff09;&#xff1a; 工程创建完成。。。。接下…

Java多线程_阻塞队列

1.什么是阻塞队列 我们知道&#xff0c;PriorityQueue、LinkedList这些都是非阻塞队列。在我们使用非阻塞队列的时候有一个很大问题&#xff0c;它不会对当前线程产生阻塞&#xff0c;那么在面对类似消费者-生产者的模型时&#xff0c;就必须额外地实现同步策略以及线程间…

CMake 入门与进阶

目录cmake简介cmake的下载cmake 的使用方法示例一&#xff1a;单个源文件(cmake生成的中间文件以及可执行文件都放在build目录下)示例二&#xff1a;多个源文件示例三&#xff1a;生成库文件(动态库和静态库、修改库文件名字、最低版本要求)示例四&#xff1a;将源文件放到不同…

nunit 2.2.3 released, 支持vs2005 和.net 2.0了.

主要是提供对vs 2005 及.net 2.0的支持&#xff0c;同时修正了一些bug&#xff0e;对于没有使用vs team suite的人而言&#xff0c;可以将nunit集成到vs 2005 professional了&#xff0e;http://sourceforge.net/projects/nunit转载于:https://www.cnblogs.com/margiex/archive…

【UOJ#246】套路(动态规划)

【UOJ#246】套路&#xff08;动态规划&#xff09; 题面 UOJ 题解 假如答案的选择的区间长度很小&#xff0c;我们可以做一个暴力\(dp\)计算\(s(l,r)\)&#xff0c;即\(s(l,r)min(s(l1,r),s(l,r-1),abs(a_r-a_l))\)。 我们发现\(s(l,r)\le \frac{m}{r-l1}\)&#xff0c;那么当长…

将对象集合包装成JSON格式

import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import com.jssh.bean.system.SysMenu; import com.jssh.bean.system.SysMenuId; public class JsonUtil<T> {/*** 将对象集合包装成JSON格式* p…

.Net应用之数据连接(少儿助学网MisDataSet.dll)原代码

原代码文件下载 :MisDataSet数据连接字符串放置在web.config文件中如下:<?xml version"1.0" encoding"utf-8" ?><configuration> <appSettings> <add key "SQLCONNECTIONSTRING" value "data source . ; uid…

Linux开发板网线直连电脑配置方法/vmware虚拟机与本机的网络ping通

目录Linux开发板网线直连电脑配置方法vmware虚拟机与本机的网络ping通Linux开发板网线直连电脑配置方法 参考&#xff1a;https://www.bilibili.com/video/BV1n541197rk?spm_id_from333.999.0.0 一般情况&#xff0c;开发板连路由器&#xff0c;电脑也连路由器&#xff0c;路由…

ubuntu网站做图像外链

http://paste.ubuntu.org.cn 转载于:https://www.cnblogs.com/yuliyang/p/3658964.html

Markdown 基础学习

Markdown是什么&#xff1f; Markdwon是一种轻量级标记语言&#xff0c;它以纯文本形式&#xff08;易读、易写、易更改&#xff09;编写文档&#xff0c;并最终以HTLM格式发布。Markdown也可以理解为将以 MARKDOWN语法编写的语言转换成HTML内容的工具。 为什么要使用Markdown?…

黑暗精灵崔斯特系列小说

[资料]黑暗精灵崔斯特系列小说 转自群星论坛&#xff1a; The complete Drizzts saga 崔斯特传奇完全列表 1、Realms of Magic《魔法国度》 作者&#xff1a;Brian Thomsen, Fred Fields 1995年12月出版 三星半 相关内容&#xff1a;短篇“Guenhwyvar"&#xff0c;关…

状态机模型

参考&#xff1a;什么是状态机&#xff1f;用C语言实现进程5状态模型 参考&#xff1a;设计模式&#xff1a;一目了然的状态机图 案例&#xff1a;状态模式(C语言实现)——MP3播放、暂停案例 STM32按键消抖——入门状态机思维&#xff08;常用的switch-case形式&#xff0c;实现…