ASP uses three layer mode to realize simple AJAX message Board

Source: Internet
Author: User
Tags array insert servervariables

For a long time did not write ASP, this time to write a message board really feel a little difficult, the competition has written a whole day, haha.
There is nothing else to write, the use of three-layer structure (do not know, the original three-layer concept is very confused)

Demo www.zj55.com Message board, I hope you Big Brother elder sister if found that there is a loophole please tell me here, do not black my website, here Brother first thanked.

Index.asp
<%@ codepage=65001%>
<%
Option Explicit
%>
<% response.charset= "Utf-8" %>
<% session.codepage=65001%>
<!--#include file= "acchelper.asp"
<!--#include file= "Common.asp" The
<!--#include file= "dal_guest.asp";
<!--#include file= "mod_guest.asp"-->
<!--#include file= "bll_guest.asp"
<%
Dim mybll
Dim MyList
Set Mybll = new Bll_guest
Select case Request ("Tcmd")
Case "SAVE"
Mybll. Insert ()
Case "DEL"
Mybll. Delete ()
End Select
myList = mybll. Findbypage ()
%>
<p>
<form name= "Subform" id= "Subform"
<textarea id= "con" name= "con" cols= "rows=" "6" wrap= "VIRTUAL" ></TEXTAREA>
<input type= "button" Name= "Submit" value= "submitted Message" onclick= "$ (' guest/index.asp?tcmd=save&content= ' +escape (this.form.con.value))"
</form>
</p>
<%=mylist%>

Bll_guest.asp
<%
'///<summary>
'///Summary description.
'///</summary>
Class Bll_guest

Private Mycom,mymod,mydal

Private Li,ul

Private DEL

' Get information
Public Sub getguest ()

Mydal. Getguest (ID)

End Sub

' New information
Public Sub Insert ()

Mymod. Content = Request ("content")
Mymod.re = Request ("Re")
Mymod. Addtime = Now ()
Mymod. Ip = Request.ServerVariables ("Http_x_forwarded_for")
If Len (mymod. Ip) <=0 Then mymod. Ip = Request.ServerVariables ("REMOTE_ADDR")

Call Mydal. Insert (Mymod)

End Sub

' Update information
Public Sub Update ()

Call Mydal. Update (Mymod)

End Sub

' Delete Information
Public Sub Delete ()

Mydal. Delete (Request ("Id")

End Sub

' Find information
Public Function Findbypage ()

Dim Pagesize,currentpage,wherevalue,ordervalue,recordcount
Dim objRS
Dim Tmp1,tmp2,tmp3,parms,i
Dim Tcmd
Tcmd = Request ("Tcmd")
PageSize = "8"
CurrentPage = Request ("PageNo")
If Len (currentpage) <=0 Then
Currentpage=1
End If
Wherevalue = ""
OrderValue = "Id"
Set objRS = Mydal. Findbypage (Pagesize,currentpage-1,wherevalue,ordervalue)
i = 1
RecordCount = Mydal. Count (Wherevalue)
Do as Not objrs.eof
If tcmd= "DEL" Then
DEL = "<a tcmd=del&id=" &objrs ("Id") & "" > Delete </a>
Else
DEL = ""
End If
Parms=array (I,objrs ("content"), objRS ("IP"), objRS ("Addtime"), DEL)
TMP1 = TMP1 & mycom. Format (li,parms)
Objrs.movenext
i = i + 1
Loop
Tmp3 = mycom. Page (Pagesize,currentpage,recordcount, "guest/index.asp?tcmd=list")
Parms=array (Tmp1,tmp3)
TMP2 = TMP2 & mycom. Format (ul,parms)

Findbypage = TMP2

End Function

Private Sub Class_Initialize ()

LI = "<li><span>{0}</span> <span>{1}</span><br/><span> Author: {2}</span > <span>{3}</span> <span>{4}</span></li> "& vbCrLf
UL = "<UL>{0}<li>{1}</li></UL>"
DEL = ""

Set mycom = new Common
Set mymod = new Mod_guest
Set mydal = new Dal_guest

End Sub

Private Sub Class_Terminate ()

Set mycom = Nothing
Set Mymod = Nothing
Set mydal = Nothing

End Sub

End Class
%>

Dal_guest.asp
<%
'///<summary>
'///Summary description.
'///</summary>
Class Dal_guest

Private sql_01
Private sql_02
Private sql_03
Private sql_04
Private sql_05
Private sql_06
Private sql_07

Private Mycom,myacc,mymod

'///<summary>
'///Get information
'///</summary>
'///<param name= ' Id > Judgment field </param>
'///<returns> information body </returns>
Public Function getguest (Id)

Dim Parms,sql,objrs
Parms = Array (Id)
SQL = mycom. Format (sql_01,parms)
Set objRS = Myacc. ExecuteReader (MYACC. Conn_string,sql)
If Not objRS.EOF Then
Call Mymod. SetVar (objRS ("Id"), objRS ("Content"), objRS ("Re"), objRS ("Addtime"), objRS ("Ip")
Set getguest = Mymod
Else
Getguest = Null

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.