在業務系統的開發過程中
實際使用時
class FormBase
class BizFormBase
class ViewFormBase : BizFormBase
class EditFormBase : BizFormBase
class QueryFormBase : FormBase
FormBase
BizFormBase
ViewFormBase
QueryFormBase
從面向對象的角度看
為了幫助大家理解
一個最簡單的查詢頁面會包括三部分
QueryPeopleForm
OnQueryButtonClick()
{
string peopleName = txtPeopleName
string peopleAge = txtPeopleAge
string sql;
sql = string
PeopleManager manager = new PeopleManager();
this
this
}
當點擊查詢按鈕時
這兒的提交查詢和綁定在不同的查詢頁面都是一樣的
使用基類頁後的代碼
QueryPeopleForm : QueryFormBase
OnQueryButtonClick()
{
string peopleName = txtPeopleName
string peopleAge = txtPeopleAge
sql = string
QueryAndBind(new PeopleManager()
}
這兒的代碼少了
public enum QueryOperator
{
//等於比較
Equal =
// 不等於
NotEqual =
// Like比較
Like =
}
class Query
{
void Add(string fieldName
string GetSql();
}
QueryPeopleForm : QueryFormBase
OnQueryButtonClick()
{
Query query = new Query();
query
query
QueryAndBind(new PeopleManager()
}
把拼Sql的工作放在Query類中做
到這一步
修改後的代碼
QueryPeopleForm : QueryFormBase
OnQueryButtonClick()
{
InitControls(gridMain);
Query query = new Query();
query
query
QueryAndBind(new PeopleManager()
}
至此
QueryPeopleForm : QueryFormBase
void Initialize()
{
// 指定頁面對應的Manager
Manager = new PeopleManager();
// 綁定控件
InitControls(gridMain
}
void GetQueryInfo(Query query)
{
//獲得查詢條件
query
query
}
QueryFormBase:
private IManager manager = null;
public IManager Manager
{
get { return manager; }
set { manager = value; }
}
void InitControls(GridView grid
{
this
this
queryButton
}
void QueryButton_Click(object sender
{
Query query = new Query();
GetQueryInfo(Query);
QueryAndBind(manager
}
總的代碼可以從附件中下載
應該說基類的設計相對復雜
而基類頁的設計其實是有技巧的
從設計上來講
From:http://tw.wingwit.com/Article/program/net/201311/12754.html