After looking at the three-tier architecture for 2 days, in fact, I have seen this before, you can not use, so for the three-tier architecture is just know, yesterday looked at some of his internal specific structure, three layers are BLL, web, DAL, in the Web to accept user requests, BLL processing business, The DAL handles database transactions, the following is a simple example! This is a page to add a new employee:
The background code is as follows:
Usingsystem.collections;
Usingsystem.web;
usingSystem.Web.Security;
UsingSystem.Web.UI;
UsingSystem.Web.UI.WebControls;
UsingSystem.Web.UI.WebControls.WebParts;
UsingSystem.Web.UI.HtmlControls;
Usingsystem.text;
Usingmaticsoft.common;
UsingLTP.Accounts.Bus;
Usingsystem;
NamespaceMaticsoft.Web.Employees {publicpartialclassmyadd:page {protectedvoidpage_load (OBJECTSENDER,EVENTARGSE)
{} protectedvoidbuttonok_click (Objectsender,eventargse) {stringerrm = ""; if (! Pagevalidate.isnumber (Temployeeid.Text.Trim ()) {ERRM = "The ID entered is not a number, not legal!"
"; } if (this. Temployeeid.Text.Trim (). Length ==0) {errm + = "User ID cannot be empty!"
";
} if (Errm!= "") {MessageBox.Show (this, ERRM);
ERRM = "";
Return } Intemployeeid =int. Parse (this. Temployeeid.text); /Stringemployeesname =this.
Temployeename.text; Maticsoft.Model.Employeesmodel =newmodel.employees (); Create a new one at the DAL layerThe model object of employees is used for data processing model of database Employees table. EmployeeID = EmployeeID; The text inside the user input ID data to model model. Employeesname = Employeesname; The text inside the user entered the name data to model MATICSOFT.BLL.EMPLOYEESBLL =newbll.employees (); Creates a new employees object at the BLL layer that invokes the model object BLL of the DAL layer. ADD (model); Call the Add method at the BLL layer to add a data//////////////////////////////////////the BLL layer's Add method//////////// Add a piece of data Publicbooladd (M Aticsoft. Model.employeesmodel) {Returndal. ADD (model); Call the Add method of the DAL layer to add a data}///////////////////////////////////////////////////////////////////////////////// Add to the DAL layer Method//////////////////////////////////////////////////////////////////////////////Add a data publicbool
ADD (Maticsoft.Model.Employeesmodel) {stringbuilderstrsql=newstringbuilder ();
Strsql.append ("INSERT INTO Employees (");
Strsql.append ("employeeid,employeesname)");
Strsql.append ("Values (");
Strsql.append ("@EmployeeID, @EmployeesName)");
sqlparameter[] Parameters = {Newsqlparameter ("@EmployeeID", sqldbtype.int,4),
Newsqlparameter ("@EmployeesName", sqldbtype.varchar,90)}; Parameters[0]. Value = model.
EmployeeID; PARAMETERS[1]. Value = model.
Employeesname;
Introws=dbhelpersql.executesql (Strsql.tostring (), parameters);
if (Rows >0) {returntrue;
else {returnfalse; }
}
/////////////////////////////////////////////////////////////////////////////////////////////// Maticsoft.Common.MessageBox.ShowAndRedirect (This, "Save success |! "," myadd.aspx ");
After the successful creation of the pop-up dialog box, and jump to the current page!
} protectedvoidbuttonno_click (Objectsender,eventargse) {Response.Redirect ("list.aspx"); }
}
}