至此,基类页的功能已经完整了,但仍然不够,如果我们以后想改变查询按钮点击的行为,比如查询结果为空时,要弹出对话框提示,这时仍然要到处修改页面代码,这不是我们所希望的,于是我们将QueryButton的OnClick操作也放在基类页了中执行,继承页只要初始化数据访问组件和设置查询条件即可。
QueryPeopleForm : QueryFormBase void Initialize() { // 指定页面对应的Manager Manager = new PeopleManager(); // 绑定控件 InitControls(gridMain, btnQuery); }
void GetQueryInfo(Query query) { //获得查询条件 query.Add(“Name”, txtPeopleName.Text, QueryOperator.Like); query.Add(“Age”, txtPeopleAge.Text, QueryOperator.Equal); }
QueryFormBase:
private IManager manager = null; public IManager Manager { get { return manager; } set { manager = value; } }
void InitControls(GridView grid, Button queryButton) { this.defaultGrid = grid; this.queryButton = queryButton; queryButton.Click += new EventHandler(QueryButton_Click); }
void QueryButton_Click(object sender, EventArgs e) { Query query = new Query(); GetQueryInfo(Query); QueryAndBind(manager, query.GetSql()); }
(编辑:aniston)
|