欢迎来到福编程网,本站提供各种互联网专业知识!

asp简单的ajax留言板

发布时间:2006-09-14 作者: 来源:转载
复制代码代码如下:客户留言BLL_Guest.aspDAL_Guest.aspMOD_Guest.asp1Thenparms=Array(Pageurl,1)lFirstpage=Format(C_FIRSTPAGE1,parms)parms=Array(Pageurl,CInt(CurrentPage)-1)lPrevpage=Format(C_PREVPAGE1,parms)ElselFirstpage=C_FIRSTPAGE2lPrevpage=
复制代码 代码如下:
<%@codepage=65001%>
<%
optionexplicit
%>
<%Response.Charset="utf-8"%>
<%Session.CodePage=65001%>





<%
Dimmybll
DimmyList
Setmybll=newBLL_Guest
SelectCaseRequest("tCMD")
Case"SAVE"
mybll.Insert()
Case"DEL"
mybll.Delete()
EndSelect
myList=mybll.FindByPage()
%>

客户留言








<%=myList%>

BLL_Guest.asp
<%
'///


'///摘要说明。
'///

ClassBLL_Guest

Privatemycom,mymod,mydal

PrivateLI,UL

PrivateDEL

'获取信息
PublicSubGetGuest()

mydal.GetGuest(Id)

EndSub

'新增信息
PublicSubInsert()

mymod.Content=Request("content")
mymod.re=Request("Re")
mymod.Addtime=Now()
mymod.Ip=request.servervariables("HTTP_X_FORWARDED_FOR")
Iflen(mymod.Ip)<=0Thenmymod.Ip=request.servervariables("REMOTE_ADDR")

Callmydal.Insert(mymod)

EndSub

'更新信息
PublicSubUpdate()

Callmydal.Update(mymod)

EndSub

'删除信息
PublicSubDelete()

mydal.Delete(Request("Id"))

EndSub

'查找信息
PublicFunctionFindByPage()

DimPageSize,CurrentPage,WhereValue,OrderValue,RecordCount
DimobjRS
Dimtmp1,tmp2,tmp3,parms,i
DimtCMD
tCMD=Request("tCMD")
PageSize="8"
CurrentPage=Request("PageNo")
IfLen(CurrentPage)<=0Then
CurrentPage=1
EndIf
WhereValue=""
OrderValue="Id"
SetobjRS=mydal.FindByPage(PageSize,CurrentPage-1,WhereValue,OrderValue)
i=1
RecordCount=mydal.Count(WhereValue)
DoWhileNotobjRS.EOF
IftCMD="DEL"Then
DEL="删除"
Else
DEL=""
EndIf
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

EndFunction

PrivateSubClass_Initialize()

LI="

  • {0}{1}

    作者:{2}{3}{4}

  • "&vbCrLf
    UL="
      {0}
    • {1}
    "
    DEL=""

    Setmycom=newCommon
    setmymod=newMOD_Guest
    setmydal=newDAL_Guest

    EndSub

    PrivateSubClass_Terminate()

    Setmycom=Nothing
    Setmymod=Nothing
    setmydal=Nothing

    EndSub

    EndClass
    %>

    DAL_Guest.asp
    <%
    '///


    '///摘要说明。
    '///

    ClassDAL_Guest

    PrivateSQL_01
    PrivateSQL_02
    PrivateSQL_03
    PrivateSQL_04
    PrivateSQL_05
    PrivateSQL_06
    PrivateSQL_07

    Privatemycom,myacc,mymod

    '///


    '///获得信息
    '///

    '///判断字段
    '///信息体
    PublicFunctionGetGuest(Id)

    Dimparms,SQL,objRS
    parms=Array(Id)
    SQL=mycom.Format(SQL_01,parms)
    SetobjRS=myacc.ExecuteReader(myacc.CONN_STRING,SQL)
    IfNotobjRS.EOFthen
    Callmymod.SetVar(objRs("Id"),objRs("Content"),objRs("Re"),objRs("Addtime"),objRs("Ip"))
    SetGetGuest=mymod
    Else
    GetGuest=Null
    EndIf

    EndFunction

    '///


    '///插入信息
    '///

    '///信息体
    PublicSubInsert(vmod)

    Dimparms,SQL
    parms=Array(vmod.Content,vmod.Re,vmod.Addtime,vmod.Ip)
    SQL=mycom.Format(SQL_02,parms)
    Callmyacc.ExecuteReader(myacc.CONN_STRING,SQL)

    EndSub

    '///


    '///更新信息
    '///

    '///信息体
    PublicSubUpdate(vmod)

    Dimparms,SQL
    parms=Array(vmod.Id,vmod.Content,vmod.Re,vmod.Addtime,vmod.Ip)
    SQL=mycom.Format(SQL_03,parms)
    Callmyacc.ExecuteReader(myacc.CONN_STRING,SQL)

    EndSub

    '///


    '///删除信息
    '///

    '///信息体
    PublicSubDelete(Id)

    Dimparms,SQL
    parms=Array(Id)
    SQL=mycom.Format(SQL_04,parms)
    Callmyacc.ExecuteNonQuery(myacc.CONN_STRING,SQL)

    EndSub

    '///


    '///统计信息
    '///

    '///信息体
    PublicFunctionCount(WhereValue)

    Dimparms,SQL,objRS
    parms=Array(WhereValue)
    SQL=mycom.Format(SQL_07,parms)
    SetobjRS=myacc.Recordset(myacc.CONN_STRING,SQL)
    Count=objRS.RecordCount

    EndFunction

    '///


    '///根据条件列出所有信息(带有分页)
    '///

    '///每页记录数
    '///页码
    '///判断值
    '///排序
    '///返回objRS
    PublicFunctionFindByPage(PageSize,CurrentPage,WhereValue,OrderValue)

    Dimparms,SQL,objRS
    Dims1
    IfCurrentPage="0"Then
    s1=PageSize&"|"+OrderValue&"|"&WhereValue
    parms=Split(s1,"|")
    SQL=mycom.Format(SQL_05,parms)
    Else
    s1=PageSize&"|"&OrderValue&"|"+WhereValue&"|"&CurrentPage*PageSize
    parms=Split(s1,"|")
    SQL=mycom.Format(SQL_06,parms)
    EndIf

    SetobjRS=myacc.ExecuteReader(myacc.CONN_STRING,SQL)
    SetFindByPage=objRS

    EndFunction


    PrivateSubClass_Initialize()

    SQL_01="Select*From[Guest]WhereId={0}"
    SQL_02="Insertinto[Guest]([Content],[Re],[Addtime],[Ip])values('{0}','{1}','{2}','{3}')"
    SQL_03="Update[Guest]Set[Content]='{1}',[Re]='{2}',[Addtime]='{3}',[Ip]='{4}'WhereId={0}"
    SQL_04="DeleteFrom[Guest]WhereIdIn({0})"
    SQL_05="SelectTop{0}*From[Guest]WhereContentLike'%{2}%'OrderBy{1}Desc,IdDesc"
    SQL_06="SelectTop{0}*From[Guest]WhereContentLike'%{2}%'AndIdNotIN(SelectTop{3}IdFrom[Guest]WhereContentLike'%{2}%'OrderBy{1}Desc,IdDesc)OrderBy{1}Desc,IdDesc"
    SQL_07="Select*From[Guest]WhereContentLike'%{0}%'"

    Setmycom=newCommon
    Setmyacc=newAccHelper
    Setmymod=newMOD_Guest

    EndSub

    PrivateSubClass_Terminate()

    Setmycom=Nothing
    Setmyacc=Nothing
    Setmymod=Nothing

    EndSub

    EndClass
    %>

    MOD_Guest.asp
    <%
    '///


    '///摘要说明。
    '///

    ClassMOD_Guest

    PublicId
    PublicContent
    PublicRe
    PublicAddtime
    PublicIp

    PublicSubSetVar(vId,vContent,vRe,vAddtime,vIp)
    Id=vId
    Content=vContent
    Re=vContent
    Addtime=vAddtime
    Ip=vIp
    EndSub

    EndClass
    %>

    Common.asp
    <%
    '///


    '///摘要说明
    '///

    ClassCommon

    '///


    '///获得信息
    '///

    '///需要内容
    '///替换关键字
    '///格式化后内容
    PublicFunctionFormat(str,arr)

    Dimr,i
    r=str
    Fori=0ToUBound(arr)
    r=Replace(r,"{"&i&"}",arr(i))
    Next
    Format=r

    EndFunction

    PublicFunctionPage(PageSize,CurrentPage,RecordCount,PageUrl)

    constC_RECORDCOUNT="合计{0}篇|"
    constC_FIRSTPAGE1="首页"
    constC_FIRSTPAGE2="首页"
    constC_PREVPAGE1="上一页"
    constC_PREVPAGE2="上一页"
    constC_NEXTPAGE1="下一页"
    constC_NEXTPAGE2="下一页"
    constC_LASTPAGE1="尾页"
    constC_LASTPAGE2="尾页"
    constC_CURRENTPAGE="页次:{0}/{1}页"
    constC_PAGESIZE="{0}篇/页"
    constC_GOTOPAGE="跳转:"

    DimPageCount,pages
    DimlRecordCount,lFirstpage,lPrevpage,lNextpage,lLastpage,lCurrentpage,lPagesize,lGotopage
    Dimp,parms

    IfRecordCountModPageSize<>0Then
    pages=1
    else
    pages=0
    EndIf
    PageCount=CInt(RecordCount/PageSize+pages)

    parms=Array(RecordCount)
    lRecordCount=Format(C_RECORDCOUNT,parms)

    ifCInt(CurrentPage)>1Then
    parms=Array(Pageurl,1)
    lFirstpage=Format(C_FIRSTPAGE1,parms)
    parms=Array(Pageurl,CInt(CurrentPage)-1)
    lPrevpage=Format(C_PREVPAGE1,parms)
    Else
    lFirstpage=C_FIRSTPAGE2
    lPrevpage=C_PREVPAGE2
    EndIf

    ifCInt(CurrentPage)parms=Array(Pageurl,CInt(CurrentPage)+1)
    lNextpage=Format(C_NEXTPAGE1,parms)
    parms=Array(Pageurl,CInt(CurrentPage)+1)
    lLastpage=Format(C_LASTPAGE1,parms)
    Else
    lNextpage=C_NEXTPAGE2
    lLastpage=C_LASTPAGE2
    EndIf

    parms=Array(CurrentPage,PageCount)
    lCurrentpage=Format(C_CURRENTPAGE,parms)
    parms=Array(PageSize)
    lPagesize=Format(C_PAGESIZE,parms)
    parms=Array(Pageurl,CurrentPage)
    lGotopage=Format(C_GOTOPAGE,parms)

    p=lRecordCount&lFirstpage&lPrevpage&lNextpage&lLastpage&lCurrentpage&lPagesize&lGotopage
    Page=p

    EndFunction

    EndClass
    %>

    AccHelper.asp
    <%
    '///


    '///AccHelper的摘要说明。
    '///

    ClassAccHelper

    PublicCONN_STRING

    '///


    '///执行ExecuteNonQuery
    '///

    '///连接字符
    '///sql命令
    PublicFunctionExecuteNonQuery(connString,cmdText)

    DimobjConn
    SetobjConn=Server.CreateObject("ADODB.Connection")
    objConn.OpenconnString
    objConn.Execute(cmdText)

    EndFunction

    '///


    '///执行ExecuteReader
    '///

    '///连接字符
    '///sql命令
    '///RS
    PublicFunctionExecuteReader(connString,cmdText)

    DimobjConn,objRS
    SetobjConn=Server.CreateObject("ADODB.Connection")
    objConn.OpenconnString
    SetobjRS=objConn.Execute(cmdText)
    SetExecuteReader=objRS

    EndFunction

    '///


    '///执行Recordset
    '///

    '///连接字符
    '///sql命令
    '///RS
    PublicFunctionRecordset(connString,cmdText)

    DimobjConn,objRS
    SetobjConn=Server.CreateObject("ADODB.Connection")
    objConn.OpenconnString
    SetobjRS=Server.CreateObject("ADODB.RecordSet")
    objRS.OpencmdText,objConn,1,3
    SetRecordset=objRS

    EndFunction

    PrivateSubClass_Initialize()
    CONN_STRING="provider=microsoft.jet.oledb.4.0;datasource="&Server.Mappath("db.mdb")
    EndSub

    EndClass
    %>

    相关推荐