An example of using a three-tier architecture for data access
I have read the three-tier architecture over the past two days. I have read this architecture before. I can only know the three-tier architecture because I have never used it, yesterday, I checked some of his internal architectures. The three layers are BLL, WEB, and DAL. on the web, I accept user requests, bll handles services, and dal processes database transactions, the following is a simple example! This is a page for adding new employees:
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) {} protectedvoidButt OnOK_Click (objectsender, EventArgse) {stringERRM = ""; if (! PageValidate. IsNumber (Temployeeid. Text. Trim () {ERRM + = "the input id is not a number and is invalid! ";} If (this. Temployeeid. Text. Trim (). Length = 0) {ERRM + =" User ID cannot be blank! ";} 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 model object in the dal layer for data processing model of the database Employees table. employeeID = EmployeeID; // transmits the id data entered by the user in text to the model. employeesName = EmployeesName; // transmits the name data entered by the user in text to model Maticsoft. BLL. employe Esbll = newBLL. employees (); // create an employees object on the bll layer to call the model object bll of the dal layer. add (model ); // call the add method on the bll layer to add a data record ///////////////////////////// /////// add method of The bll layer ////////////////////////// //////////////////////////////////////// ///// // Add a data entry publicboolAdd (Maticsoft. model. employeesmodel) {returndal. add (model ); // call the add method of the dal layer to add a piece of data }//////////////////////////// //////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /// // Add method of the dal layer ///////// //////////////////////////////////////// //// // Add a data publicboolAdd (Maticsoft. model. employeesmodel) {StringBuilderstrSql = newStringBuilder (); strSql. append ("insert into Employees ("); strSql. append ("EmployeeID, EmployeesName)"); strSql. append ("value S ("); 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, "saved successfully |! "," MYAdd. aspx "); // after successful creation, a dialog box is displayed, and you are redirected to the current page!} ProtectedvoidButtonNo_Click (objectsender, EventArgse) {Response. Redirect ("list. aspx ");}}}