ASP.NET2.0+SQL Server2005构建多层应用(4)[1]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

  创建逻辑层

  接下来,我们创建逻辑层,在这个例子中,逻辑层是十分简单的,只是起到说明作用。首先,我们新建一个类AuthroBiz类,并将其放在App_code文件夹中,并将类的代码修改如下:

public class AuthorsBiz
{
 public AuthorsBiz()
 {}

 public DataTable GetAuthors()
 {
  AuthorsTableAdapters.AuthorsTableAdapter authorDB = new AuthorsTableAdapters.AuthorsTableAdapter();
  return authorDB.GetAuthors();
 }
 public DataTable GetAuthorTitles(string authorID)
 {
  AuthorsTableAdapters.AuthorTitlesTableAdapter authorDB = new AuthorsTableAdapters.AuthorTitlesTableAdapter();
  return authorDB.GetTitlesByAuthor(authorID);
 }
}

  从上面的代码中,可以看到,我们刚才通过向导创建的"Authors.xsd"类型化dataset类,现在在代码中,可以通过使用AuthorsTableAdapters类来调用,其中authorDB是AuthorsTableAdapters类的实例。

  创建表示层

  在ASP.NET 2.0中,在创建表示层时,可以使用master-page技术,使得可以很方便地构建页面。Mater-page的意思是,可以首先构建出一个页面的主框架模版结构,然后在其中放置一个ContentPlaceHolder控件,在该控件中,将展现其他子页面的内容。在其他子页面中,只需要首先引用该master页面,然后再修改ContentPlaceHolder控件的内容就可以了。

  首先,在工程中新增加一个"master"类型的文件,将其命名为CommonMaster,然后输入以下代码:

<%@ master language="C#" %>
<html>
 <head id="Head1" runat="server">
  <title>Master Page</title>
 </head>
<body>
<form id="Form1" runat="server">
 <table id="header" style="WIDTH: 100%; HEIGHT: 80px" cellspacing="1" cellpadding="1" border="1">
 <tr>
  <td style="TEXT-ALIGN: center; width: 100%; height: 74px;" bgcolor="teal">
   <asp:label runat="server" id="Header" Font-Size="12pt" Font-Bold="True">
     Authors Information
   </asp:label>
  </td>
 </tr>
 </table>
 <b/>
 <table id="leftNav" style="WIDTH: 108px; HEIGHT: 100%" cellspacing="1" cellpadding="1" border="1">
 <tr>
  <td style="WIDTH: 100px">
   <table>
    <tr>
     <td>
      <a href="Home.aspx">Home</a>
     </td>
    </tr>
    <tr>
     <td>
      <a href="Authors.aspx">Authors List</a>
     </td>
    </tr>
   </table>
  </td>
 </tr>
 </table>
 <table id="mainBody" style="LEFT: 120px; VERTICAL-ALIGN: top; WIDTH: 848px; POSITION: absolute; TOP: 94px; HEIGHT: 100%" border="1">
  <tr>
   <td width="100%" style="VERTICAL-ALIGN: top">
    <asp:contentplaceholder id="middleContent" runat="Server"></asp:contentplaceholder>
   </td>
  </tr>
 </table>

本文关键:ASP.NET2.0+SQL Server2005构建多层应用(4)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top