An example of using a three-tier architecture for data access

Source: Internet
Author: User

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 ");}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.