asp.net implementation of the three-tier architecture example _ Practical Tips

Source: Internet
Author: User

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

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.