Sponsored Links
This presentation is the property of its rightful owner.
1 / 1378

 浅谈“三层结构”原理与用意 PowerPoint PPT Presentation


  • 110 Views
  • Uploaded on
  • Presentation posted in: General

 浅谈“三层结构”原理与用意. 浅谈“三层结构”原理与用意. 2005 年 02 月 28 日, AfritXia 撰写. 2006 年 12 月 28 日, AfritXia 第一次修改. 序. 在刚刚步入“多层结构” Web 应用程序开发的时候,我阅读过几篇关于“ asp.net 三层结构开发”的文章。但其多半都是对 PetShop3.0 和 Duwamish7 的局部剖析或者是学习笔记。对“三层结构”通体分析的学术文章几乎没有。.

Download Presentation

 浅谈“三层结构”原理与用意

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript




20050228AfritXia


20061228AfritXia



Webasp.netPetShop3.0Duwamish7


2005211Bincess BBS7TraceLWord1~TraceLWord7CodePackage


Webasp.net


asp.netWeb




n


n


nXML




Web



ListLWord.aspxListLWord.aspx.cs


PostLWord.aspxPostLWord.aspx.cs


CodePackage/TraceLWord1



[LWordID] INT NOT NULLIDENTITY(1, 1)


[TextContent] NText N


[PostTime] DateTime GetDate()


ListLWord.aspx


#001 <%@ Page language="c#" Codebehind="ListLWord.aspx.cs" AutoEventWireup="false"


Inherits="TraceLWord1.ListLWord" %>


#002 <!DOCTYPEHTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


#003


#004 <html>


#005 <head>


#006 <title>ListLWord</title>


#007 <metaname="GENERATOR"Content="Microsoft Visual Studio .NET 7.1">


#008 <metaname="CODE_LANGUAGE"Content="C#">


#009 <metaname=vs_defaultClientScriptcontent="JavaScript">


#010 <metaname=vs_targetSchemacontent="http://schemas.microsoft.com/intellisense/ie5">


#011</head>


#012 <bodyMS_POSITIONING="GridLayout">


#013


#014 <formid="__aspNetForm"method="post"runat="server">


#015


#016 <ahref="PostLWord.aspx"></a>


#017


#018 <asp:DataListID="m_lwordListCtrl"Runat="Server">


#019 <ItemTemplate>


#020 <div>


#021 <%# DataBinder.Eval(Container.DataItem, "PostTime") %>


#022 <%# DataBinder.Eval(Container.DataItem, "TextContent") %>


#023 </div>


#024 </ItemTemplate>


#025 </asp:DataList>


#026


#027 </form>


#028


#029 </body>


#030 </html>



Visual Studio.NET 2003ListLWord.aspx ListLWord.aspx.cs


#001 usingSystem;


#002 usingSystem.Collections;


#003 usingSystem.ComponentModel;


#004 usingSystem.Data;


#005 usingSystem.Data.OleDb;// Access


#006 usingSystem.Drawing;


#007 usingSystem.Web;


#008 usingSystem.Web.SessionState;


#009 usingSystem.Web.UI;


#010 usingSystem.Web.UI.WebControls;


#011 usingSystem.Web.UI.HtmlControls;


#012


#013 namespaceTraceLWord1


#014 {


#015 ///<summary>


#016 ///ListLWord


#017 ///</summary>


#018 publicclassListLWord : System.Web.UI.Page


#019 {


#020 //


#021 protectedSystem.Web.UI.WebControls.DataList m_lwordListCtrl;


#022


#023 ///<summary>


#024 ///ListLWord.aspx


#025 ///</summary>


#026 privatevoidPage_Load(objectsender, System.EventArgs e)


#027 {


#028 LWord_DataBind();


#029 }


#030


#031 #regionWeb


#032 overrideprotectedvoidOnInit(EventArgs e)


#033 {


#034 InitializeComponent();


#035 base.OnInit(e);


#036 }


#037


#038 privatevoidInitializeComponent()


#039 {


#040 this.Load+=newSystem.EventHandler(this.Page_Load);


#041 }


#042 #endregion


#043


#044 ///<summary>


#045 ///


#046 ///</summary>


#047 privatevoidLWord_DataBind()


#048 {


#049 stringmdbConn=@"PROVIDER=Microsoft.Jet.OLEDB.4.0;


DATA Source=C:\DbFs\TraceLWordDb.mdb";


#050 stringcmdText=@"SELECT * FROM [LWord] ORDER BY [LWordID] DESC";


#051


#052OleDbConnectiondbConn=newOleDbConnection(mdbConn);


#053 OleDbDataAdapterdbAdp=newOleDbDataAdapter(cmdText, dbConn);


#054


#055 DataSet ds=newDataSet();


#056 dbAdp.Fill(ds, @"LWordTable");


#057


#058 m_lwordListCtrl.DataSource=ds.Tables[@"LWordTable"].DefaultView;


#059 m_lwordListCtrl.DataBind();


#060 }


#061 }


#062 }


PostLWord.aspx


#001 <%@ Page language="c#" Codebehind="PostLWord.aspx.cs" AutoEventWireup="false"


Inherits="TraceLWord1.PostLWord" %>


#002 <!DOCTYPEHTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">


#003


#004 <html>


#005 <head>


#006 <title>PostLWord</title>


#007 <metaname="GENERATOR"Content="Microsoft Visual Studio .NET 7.1">


#008 <metaname="CODE_LANGUAGE"Content="C#">


#009 <metaname=vs_defaultClientScriptcontent="JavaScript">


#010 <metaname=vs_targetSchemacontent="http://schemas.microsoft.com/intellisense/ie5">


#011 </head>


#012 <bodyMS_POSITIONING="GridLayout">


#013


#014 <formid="__aspNetForm"method="post"runat="server">


#015


#016 <textareaid="m_txtContent"runat="Server"rows=8cols=48></textarea>


#017 <inputtype="Button"id="m_btnPost"runat="Server"value=""/>


#018


#019 </form>


#020


#021 </body>


#022 </html>


PostLWord.aspxPostLWord.aspx.cs


#001 usingSystem;


#002 usingSystem.Collections;


#003 usingSystem.ComponentModel;


#004 usingSystem.Data;


#005 usingSystem.Data.OleDb;// Access


#006 usingSystem.Drawing;


#007 usingSystem.Web;


#008 usingSystem.Web.SessionState;


#009 usingSystem.Web.UI;


#010 usingSystem.Web.UI.WebControls;


#011 usingSystem.Web.UI.HtmlControls;


#012


#013 namespaceTraceLWord1


#014 {


#015 ///<summary>


#016 ///PostLWord


#017 ///</summary>


#018 publicclassPostLWord : System.Web.UI.Page


#019 {


#020 //


#021 protectedSystem.Web.UI.HtmlControls.HtmlTextArea m_txtContent;


#022 //


#023 protectedSystem.Web.UI.HtmlControls.HtmlInputButton m_btnPost;


#024


#025 ///<summary>


#026 ///PostLWord.aspx


#027 ///</summary>


#028 privatevoidPage_Load(objectsender, System.EventArgs e)


#029 {


#030 }


#031


#032 #regionWeb


#033 overrideprotectedvoidOnInit(EventArgs e)


#034 {


#035 InitializeComponent();


#036 base.OnInit(e);


#037 }


#038


#039 privatevoidInitializeComponent()


#040 {


#041 this.Load+=newSystem.EventHandler(this.Page_Load);


#042 this.m_btnPost.ServerClick+=newEventHandler(Post_ServerClick);


#043 }


#044 #endregion


#046 ///<summary>


#047 ///


#048 ///</summary>


#049 privatevoidPost_ServerClick(objectsender, EventArgs e)


#050 {


#051 //


#052 stringtextContent=this.m_txtContent.Value;


#053


#054 //


#055 if(textContent=="")


#056 thrownewException("");


#057


#058 stringmdbConn=@"PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=C:\DbFs\TraceLWordDb.mdb";


#059 stringcmdText="INSERT INTO [LWord]([TextContent]) VALUES(@TextContent)";


#060


#061 OleDbConnectiondbConn=newOleDbConnection(mdbConn);


#062 OleDbCommanddbCmd=newOleDbCommand(cmdText, dbConn);


#063


#064 //


#065 dbCmd.Parameters.Add(newOleDbParameter("@TextContent",


OleDbType.LongVarWChar));


#066 dbCmd.Parameters["@TextContent"].Value=textContent;


#067


#068 try


#069 {


#070 dbConn.Open();


#071 dbCmd.ExecuteNonQuery();


#072 }


#073 catch


#074 {


#075 throw;


#076 }


#077 finally


#078 {


#079 dbConn.Close();


#080 }


#081


#082 //


#083 Response.Redirect("ListLWord.aspx", true);


#084 }


#085 }


#086 }


Access




Microsoft SQL Server 2000SQL Server 2000.aspx.csOleDbConnectionSqlConnectionOleDbAdapterSqlAdapter


  • n09111317

  • n40


PostLWord.aspx.csPostLWord.aspx.cs


WindowsWeb




ListLWord.aspx.csLWordTask.cs


DataSet


PostLWord.aspx.cs



TraceLWord2CodePackage/TraceLWord2


LWordTask.csLWordTask.cs


#001 usingSystem;


#002 usingSystem.Data;


#003 usingSystem.Data.OleDb;// Access


#004 usingSystem.Web;


#005


#006 namespaceTraceLWord2


#007 {


#008 ///<summary>


#009 ///LWordTask


#010 ///</summary>


#011 publicclassLWordTask


#012 {


#013 //


#014 privateconststringDB_CONN=@"PROVIDER=Microsoft.Jet.OLEDB.4.0;


DATA Source=C:\DbFs\TraceLWordDb.mdb";


#015


#016///<summary>


#017 ///LWordDataSet


#018 ///</summary>


#019 ///<param name="ds"></param>


#020 ///<param name="tableName"></param>


#021 ///<returns></returns>


#022 publicintListLWord(DataSet ds, stringtableName)


#023 {


#024 stringcmdText="SELECT * FROM [LWord] ORDER BY [LWordID] DESC";


#025


#026 OleDbConnectiondbConn=newOleDbConnection(DB_CONN);


#027 OleDbDataAdapterdbAdp=newOleDbDataAdapter(cmdText, dbConn);


#028


#029 intcount=dbAdp.Fill(ds, tableName);


#030


#031 returncount;


#032 }


#033


#034 ///<summary>


#035 ///


#036 ///</summary>


#037 ///<param name="textContent"></param>


#038 publicvoidPostLWord(stringtextContent)


#039 {


#040 //


#041 if(textContent==null|| textContent=="")


#042 thrownewException("");


#043


#044 stringcmdText="INSERT INTO [LWord]([TextContent]) VALUES(@TextContent)";


#045


#046 OleDbConnectiondbConn=newOleDbConnection(DB_CONN);


#047 OleDbCommanddbCmd=newOleDbCommand(cmdText, dbConn);


#048


#049 //


#050 dbCmd.Parameters.Add(newOleDbParameter("@TextContent", OleDbType.LongVarWChar));


#051 dbCmd.Parameters["@TextContent"].Value=textContent;


#052


#053 try


#054 {


#055 dbConn.Open();


#056 dbCmd.ExecuteNonQuery();


#057 }


#058 catch


#059 {


#060 throw;


#061 }


#062 finally


#063 {


#064 dbConn.Close();


#065 }


#066 }


#067 }


#068 }


Access 2000SQL Server 2000LWordTask.csLWordTask.csListLWord.aspx.csLWord_DataBind


...


#046 privatevoidLWord_DataBind()


#047 {


#048 DataSet ds=newDataSet();


#049 (newLWordTask()).ListLWord(ds, @"LWordTable");


#050


#051 m_lwordListCtrl.DataSource=ds.Tables[@"LWordTable"].DefaultView;


#052 m_lwordListCtrl.DataBind();


#053 }


...


PostLWord.aspx.csPost_ServerClick


...


#048 privatevoidPost_ServerClick(objectsender, EventArgs e)


#049 {


#050 //


#051 stringtextContent=this.m_txtContent.Value;


#052


#053 (newLWordTask()).PostLWord(textContent);


#054


#055 //


#056 Response.Redirect("ListLWord.aspx", true);


#057 }


...


ListLWord.aspx.csPostLWord.aspx.csLWordTaskTraceLWord1ListLWord.aspx.csOleDbConnectionOleDbDataAdapterLWordTask


ListLWord.aspx.csPostLWord.aspx.csLWordTask


public classListLWord


{


private voidLWord_DataBind()


{


(newLWordTask()).ListLWord( ... );


}


}


public classPostLWord


{


private voidPost_ServerClick(objectsender, EventArgs e)


{


(newLWordTask()).PostLWord( ... );


}


}


public classLWordTask


{


publicDataSet ListLWord(DataSet ds)...


public voidPostLWord(stringtextContent)...


}






TraceLWord3LWordTask.csAccessTaskInterServiceLWordService.csTraceLWord3WebUICodePackage/TraceLWord3



LWordService.cs


#001 usingSystem;


#002 usingSystem.Data;


#003


#004 usingTraceLWord3.AccessTask;//


#005


#006 namespaceTraceLWord3.InterService


#007 {


#008 ///<summary>


#009 ///LWordService


#010 ///</summary>


#011 publicclassLWordService


#012 {


#013 ///<summary>


#014 ///LWordDataSet


#015 ///</summary>


#016 ///<param name="ds"></param>


#017 ///<param name="tableName"></param>


#018 ///<returns></returns>


#019 publicintListLWord(DataSet ds, stringtableName)


#020 {


#021 return(newLWordTask()).ListLWord(ds, tableName);


#022 }


#023


#024 ///<summary>


#025 ///


#026 ///</summary>


#027 ///<param name="textContent"></param>


#028 publicvoidPostLWord(stringcontent)


#029 {


#030 (newLWordTask()).PostLWord(content);


#031 }


#032 }


#033 }


LWordService.cs#021#030ListLWord.aspx.cs


...


#012 usingTraceLWord3.InterService;//


...


#045 ///<summary>


#046 ///


#047 ///</summary>


#048 privatevoidLWord_DataBind()


#049 {


#050 DataSet ds=newDataSet();


#051 (newLWordService()).ListLWord(ds, @"LWordTable");


#052


#053 m_lwordListCtrl.DataSource=ds.Tables[@"LWordTable"].DefaultView;


#054 m_lwordListCtrl.DataBind();


#055 }


...


PostLWord.aspx.cs


...


#012 usingTraceLWord3.InterService;//


...


#047 ///<summary>


#048 ///


#049 ///</summary>


#050 privatevoidPost_ServerClick(objectsender, EventArgs e)


#051 {


#052 //


#053 stringtextContent=this.m_txtContent.Value;


#054


#055 (newLWordService()).PostLWord(textContent);


#056


#057 //


#058 Response.Redirect("ListLWord.aspx", true);


#059 }


...


TraceLWord3


namespaceTraceLWord3.WebLWord


{


public classListLWord


{


private voidLWord_DataBind()


{


(newLWordService()).ListLWord( ... );


}


}


public classPostLWord


{


private voidPost_ServerClick(objectsender, EventArgs e)


{


(newLWordService()).PostLWord( ... );


}


}


}


namespaceTraceLWord3.InterService


{


public classLWordTask


{


publicDataSet ListLWord(DataSet ds, stringtableName)


{


return(newLWordTask()).ListLWord(ds, tableName);


}


public voidPostLWord(stringcontent)


{


(newLWordTask()).PostLWord(content);


}


}


}


namespaceTraceLWord3.AccessTask


{


public classLWordTask


{


publicDataSet ListLWord(DataSet ds)...


public voidPostLWord(stringcontent)...


}


}


TraceLWord3ListLWord.aspx


TraceLWord5ListLWord.aspxPage_LoadLWord_DataBindLWord_DataBindLWordServiceListLWordLWordService.ListLWordLWordTaskListLWordPostLWord.aspx



Web


ASP.NET WebaspxdllWebASP.NETDuwamish7WebBusinessFacadeDataAccessASP.NETPetShop3.0WebBLLSQLServerDALOracleDALBincess.CNWebForumInterServiceSqlServerTask


Duwamish7PetShop3.0PetShop3.0PetShop3.0Duwamish7PetShop3.0ModelIDALDALFactoryDuwamish7CommonBincess.CNClassesDbTask



Web


n.aspx


n


n


n



asp.netaspxaspxTraceLWord3ListLWord.aspxListLWord.aspx.csLWordServiceListLWord(DataSet ds)AccessTaskListLWord(DataSet ds)




asp.netaspx



































TraceLWord3TraceLWord3


ListLWord.aspx.cs


...


#048 privatevoidLWord_DataBind()


#049 {


#050 DataSet ds=newDataSet();


#051 (newLWordService()).ListLWord(ds, @"LWordTable");


#052


#053 m_lwordListCtrl.DataSource=ds.Tables[@"LWordTable"].DefaultView;


#054 m_lwordListCtrl.DataBind();


#055 }


...


ListLWord.aspx.csDataSetDataSet#051LWordServiceDataSetDataTableDataTableLWordServiceListLWord


...


#006 namespaceTraceLWord3.InterService


#007 {


...


#011 publicclassLWordService


#012 {


...


#019 publicintListLWord(DataSet ds, stringtableName)


#020 {


#021ds.Tables.Clear();


#022ds.Tables.Add(newDataTable(tableName));


#023


#024 return1;


#025 }


...


ListLWord.aspx


...


#018 <asp:DataListID="m_lwordListCtrl"Runat="Server">


#019 <ItemTemplate>


#020 <div><!--// //-->


#021 <%# DataBinder.Eval(Container.DataItem, "PostTime") %>


#022 <%# DataBinder.Eval(Container.DataItem, "TextContent") %>


#023 </div>


#024 </ItemTemplate>


#025 </asp:DataList>


...



LWordService.cs


...


#019 publicintListLWord(DataSet ds, stringtableName)


#020 {


#021 return(newLWordTask()).ListLWord(ds, tableName);


#022 }


...


LWordService.csDataSetDataSet#021LWordTaskDataSet#019DataSet#021LWordTaskListLWord


...


#006 namespaceTraceLWord2


#007 {


...


#011 publicclassLWordTask


#012 {


...


#022 publicintListLWord(DataSet ds, stringtableName)


#023 {


#024 ds.Tables.Clear();


#025


#026 // SQL[RegUser] [LWord]


#027 stringcmdText="SELECT * FROM [RegUser]ORDER BY [RegUserID] DESC";


#028


#029 OleDbConnectiondbConn=newOleDbConnection(DB_CONN);


#030 OleDbDataAdapterdbAdp=newOleDbDataAdapter(cmdText, dbConn);


#031


#032 intcount=dbAdp.Fill(ds, tableName);


#033


#034 returncount;


#035 }


...


[RegUser]DataSetLWordService.cs#019DataSet


LWordTask.cs


...


#022 publicintListLWord(DataSet ds, stringtableName)


#023 {


#024 stringcmdText="SELECT * FROM [LWord]ORDER BY [LWordID] DESC";


#025


#026 OleDbConnectiondbConn=newOleDbConnection(DB_CONN);


#027 OleDbDataAdapterdbAdp=newOleDbDataAdapter(cmdText, dbConn);


#028


#029 intcount=dbAdp.Fill(ds, tableName);


#030