前面大家应该对应用框架的代码已经有所了解了。现在我们再看看UI层的配置和使用。
首先看配置文件,详见 http://www.cnblogs.com/starstarfire/archive/2006/10/06/522329.html
aspx页面代码:
插入和更新数据代码如下:
1
/**/
/// <summary>
2 /// 功能:保存
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 private void btnSave_ServerClick( object sender, System.EventArgs e)
7 {
8 if (m_ID == 0)
9 {
10 // 插入一条数据
11 entity = new BsiTestEntity();
12 entity.TestName = this.txtName.Value;
13 BsiTestBLL.GetInstance().Insert(entity);
14 }
15 else
16 {
17 // 更新一条数据
18 entity = BsiTestBLL.GetInstance().Get(new BsiTestEntity().Key(m_ID));
19 entity.TestName = this.txtName.Value;
20 BsiTestBLL.GetInstance().Update(entity);
21 }
22 }
查询代码如下:
2 /// 功能:保存
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 private void btnSave_ServerClick( object sender, System.EventArgs e)
7 {
8 if (m_ID == 0)
9 {
10 // 插入一条数据
11 entity = new BsiTestEntity();
12 entity.TestName = this.txtName.Value;
13 BsiTestBLL.GetInstance().Insert(entity);
14 }
15 else
16 {
17 // 更新一条数据
18 entity = BsiTestBLL.GetInstance().Get(new BsiTestEntity().Key(m_ID));
19 entity.TestName = this.txtName.Value;
20 BsiTestBLL.GetInstance().Update(entity);
21 }
22 }
1
/**/
/// <summary>
2 /// 根据条件获得数据
3 /// </summary>
4 /// <returns></returns>
5 private DataTable GetDataTable()
6 {
7 HybridDictionary ht = new HybridDictionary();
8 if (this.txtName.Value.Length > 0)
9 {
10 ht.Add("test_name", this.txtName.Value);
11 }
12
13 return BsiTestBLL.GetInstance().DAO.ExcuteDataTable("selecttest", ht);;
14 }
删除代码如下(此处代码示范在DataGrid中删除一条记录):
2 /// 根据条件获得数据
3 /// </summary>
4 /// <returns></returns>
5 private DataTable GetDataTable()
6 {
7 HybridDictionary ht = new HybridDictionary();
8 if (this.txtName.Value.Length > 0)
9 {
10 ht.Add("test_name", this.txtName.Value);
11 }
12
13 return BsiTestBLL.GetInstance().DAO.ExcuteDataTable("selecttest", ht);;
14 }
1
/**/
/// <summary>
2 /// 执行删除
3 /// </summary>
4 /// <param name="source"></param>
5 /// <param name="e"></param>
6 private void dtgDataList_ItemCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
7 {
8 if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
9 {
10 LinkButton linkButton = (System.Web.UI.WebControls.LinkButton)e.CommandSource;
11
12 // 删除
13 decimal m_ID = Convert.ToInt32(dtgDataList.DataKeys[e.Item.ItemIndex]);;
14 BsiTestBLL.GetInstance().Delete(new BsiTestEntity().Key(m_ID));
15
16 //刷新
17 btnQuery_ServerClick(null,null);
18 }
19 }
2 /// 执行删除
3 /// </summary>
4 /// <param name="source"></param>
5 /// <param name="e"></param>
6 private void dtgDataList_ItemCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
7 {
8 if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
9 {
10 LinkButton linkButton = (System.Web.UI.WebControls.LinkButton)e.CommandSource;
11
12 // 删除
13 decimal m_ID = Convert.ToInt32(dtgDataList.DataKeys[e.Item.ItemIndex]);;
14 BsiTestBLL.GetInstance().Delete(new BsiTestEntity().Key(m_ID));
15
16 //刷新
17 btnQuery_ServerClick(null,null);
18 }
19 }