面向接口开发的一个架构(四)
讲述一个基于接口开发的架构模式,Web展现层
Web展现层
1、PageBase.cs
1

/**//// <summary>2
/// Summary description for PageBase3
/// </summary>4
public class PageBase : System.Web.UI.Page5


{6
public IBusinessBase business = new BaseBusiness();7
public PageBase()8

{9
10
}11
}
2、Log.aspx
1

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Log.aspx.cs" Inherits="Log" %>2

3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">4
<html xmlns="http://www.w3.org/1999/xhtml">5
<head runat="server">6
<title>Log Test</title>7
</head>8
<body>9
<form id="form1" runat="server">10
<div>11
<asp:GridView runat="server" ID="gvLogList" AutoGenerateColumns="True" CellPadding="4"12
ForeColor="#333333" GridLines="None" ondatabound="gvLogList_DataBound">13
<RowStyle BackColor="#EFF3FB" />14
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />15
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />16
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />17
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />18
<EditRowStyle BackColor="#2461BF" />19
<AlternatingRowStyle BackColor="White" />20
</asp:GridView>21
</div>22
</form>23
</body>24
</html>
3、Log.aspx.cs
1
public partial class Log : PageBase2


{3
LogBusiness logBusiness = new LogBusiness();4

5
protected void Page_Load(object sender, EventArgs e)6

{7
business.Init("Log");8
AddLog();9
GetLog();10
}11

12
private void AddLog()13

{14
Random rand = new Random();15
int number = rand.Next();16
DataSet ds = business.Get(0);17
if (ds.Tables.Count > 0)18

{19
ds.Tables[0].Rows.Add(null, "Name" + number, "Content" + number, DateTime.Now);20
business.Add(ds);21
}22
else23

{24
Response.Write("Failed get table scheme,maybe database connect failed");25
}26
}27

28
private void GetLog()29

{30
DataSet ds = business.Get();31
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)32

{33
gvLogList.DataSource = ds; 34
gvLogList.DataBind();35
}36
else37

{38
Response.Write("No data in database");39
}40
}41
protected void gvLogList_DataBound(object sender, EventArgs e)42

{43
gvLogList.HeaderRow.Cells[0].Text = "序号";44
gvLogList.HeaderRow.Cells[1].Text = "名称";45
gvLogList.HeaderRow.Cells[2].Text = "内容";46
gvLogList.HeaderRow.Cells[3].Text = "时间";47
}48
}

浙公网安备 33010602011771号