ASP also play three layer architecture (active code)

Source: Internet
Author: User

Entity class

<%class UserInfo    Private mintid Public Property Let    UserId (intuserid)        Mintid = Intuserid    End Property Public Property     Get UserId ()        userid=mintid    End Property    Private mstrname    Public Property Let UserName (strName)            mstrname = StrName End Property Public Property    Get UserName ()            UserName = Mstrname    End Property        Private mintage Public Property Let    userage (intAge)            mintage= IntAge End Property Public Property    Get userage ()        userage = mintage    End propertyend class%>

Data Access Layer Classes

<!--#include file= "model.asp"--><!--#include file= "dbhelper.asp"--><%class userdal public Sub Insertuser (objuserinfo) strinsertsql= "INSERT into Users (username,userage) VALUES ('" &objuserinfo.username &am P;_ "'," & Objuserinfo.userage & ")" DB. ExecuteNonQuery (strinsertsql) End Sub public Sub deleteuser (intuserid) strdeletesql= "Delete from Users wh Ere userid= "& Intuserid DB. ExecuteNonQuery (strdeletesql) End Sub public Sub UpdateUser (objuserinfo) strupdatesql= "Update Users set U Sername= ' "& Objuserinfo.username &" ', userage= "& Objuserinfo.userage &_" where userid= "& O Bjuserinfo.userid DB.        ExecuteNonQuery (strupdatesql) End Sub public Function getalluser () strselectsql= ' select * from Users ' Set rs=db. ExecuteQuery (Strselectsql) Set dic=server.createobject ("Scripting.Dictionary") while not rs.eof S ET User=creaTeuser (RS) dic. ADD user. Userid,user Rs. MoveNext Wend Rs. Close set rs=nothing set getalluser=dic End function Public Function Getuserbyid (intuserid) str Selectsql= "SELECT * from Users where userid=" &intuserid Set rs=db. ExecuteQuery (Strselectsql) Set User=createuser (RS) Rs.        Close set rs=nothing set getuserbyid=user End function Private Function CreateUser (RS) Set user=new UserInfo user. Userid=rs ("UserId") user. Username=rs ("UserName") user. Userage=rs ("Userage") Set Createuser=user end Function End Classset Userdao=new userdal%>

The DBHelper class used

<%class dbhelper    Private conn    private Sub class_initialize        strconn= "provider= Microsoft.jet.oledb.4.0;data source= "& Server.MapPath (" Db.mdb ")         Set conn=server.createobject (" ADODB. Connection ")        Conn. Open (strconn)    End Sub    Private Sub class_terminate        Conn. The Close ()        set conn=nothing    End Sub public    Function ExecuteQuery (strSQL)        set Rs=server.createobject ( "ADODB. RecordSet ")        Rs. Open strsql,conn,1,1        Set executequery=rs    End Function public    Sub ExecuteNonQuery (strSQL)        Conn. Execute (strSQL)    end Sub End Classset Db=new dbhelper%>

Business Layer Classes

<!--#include file= "dal.asp"--><%class userbll public Function insertuser (objuserinfo) If not IsNumeric (        Objuserinfo.userage) then insertuser= "Age must be number!" Else Userdao.insertuser (Objuserinfo) insertuser= "Add user success! "End If End Function Public function deleteuser (intuserid) If isnumeric (Intuserid) then Us Erdao.deleteuser (Intuserid) deleteuser= "Delete User success! "End If End Function Public function UpdateUser (objuserinfo) If not IsNumeric (objuserinfo.userage) Th        En updateuser= "age must be a number!"        Else Userdao.updateuser (objuserinfo) updateuser= "Update user success!" End If End Function Public Function getalluser () Set getalluser=userdao.getalluser () End function publi C Function Getuserbyid (Intuserid) Set Getuserbyid=userdao.getuserbyid (intuserid) End functionend classset UserMa Nager=new userbll%>

The following is the presentation layer code
showing all user

<!--#include file= "bll.asp"--><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

  

ASP also play three layer architecture (active code)

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.