飞度网
转到手机版您现在的位置: 飞度网电脑/网络正文
扫码穿越到手机

[ 字号:    来源:互联网 2007-9-12 11:14:00 ]
好久没有写过asp了,这回写个留言板还真觉得有点难度,竞然写了整整一天,哈哈.
就只有留言其它的都什么也没写,采用三层结构(不知道算不算,本来对三层的概念很糊涂)
演示的留言板,希望各位大哥大姐如果发现有漏洞的话请在这里告诉我,千万不要黑我的网站,在这里小弟先谢过了.
index.asp
<%@ codepage=65001%>
<%
option explicit
%>
<% Response.Charset="utf-8"%>
<% Session.CodePage=65001 %>
<!-- #include file="AccHelper.asp" -->
<!-- #include file="Common.asp"-->
<!-- #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()
%>
<h2>客户留言</h2>
<p>
<form name="subForm" id="subForm">
<textarea id="con" name="con" cols="56" rows="6" wrap="VIRTUAL"></textarea>
<input type="button" name="submit" value="提交留言" onclick="$('guest/index.asp?tCMD=SAVE&content='+escape(this.form.con.value))" />
</form>
</p>
<%=myList%>
BLL_Guest.asp
<%
'/// <summary>
'/// 摘要说明。
'/// </summary>
Class BLL_Guest
Private mycom,mymod,mydal
Private LI,UL
Private DEL

'获取信息
Public Sub GetGuest()
mydal.GetGuest(Id)
End Sub
'新增信息
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
'更新信息
Public Sub Update()
Call mydal.Update(mymod)
End Sub
'删除信息
Public Sub Delete()
mydal.Delete(Request("Id"))
End Sub
'查找信息
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 While Not objRS.EOF
If tCMD="DEL" Then
DEL = "<a href=""?tCMD=DEL&Id="&objRS("Id")&""">删除</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>作者:{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>
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>
'/// 获得信息
'/// </summary>
'/// <param name="Id">判断字段</param>
'/// <returns>信息体</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
End If

End Function
'/// <summary>
'/// 插入信息
'/// </summary>
'/// <param name="">信息体</param>
Public Sub Insert(vmod)
Dim parms,SQL
parms = Array(vmod.Content,vmod.Re,vmod.Addtime,vmod.Ip)
SQL = mycom.Format(SQL_02,parms)
Call myacc.ExecuteReader(myacc.CONN_STRING,SQL)
End Sub
'/// <summary>
'/// 更新信息
'/// </summary>
'/// <param name="">信息体</param>
Public Sub Update(vmod)

Dim parms,SQL
parms = Array(vmod.Id,vmod.Content,vmod.Re,vmod.Addtime,vmod.Ip)
SQL = mycom.Format(SQL_03,parms)
Call myacc.ExecuteReader(myacc.CONN_STRING,SQL)
End Sub
'/// <summary>
'/// 删除信息
'/// </summary>
'/// <param name="">信息体</param>
Public Sub Delete(Id)
Dim parms,SQL
parms = Array(Id)
SQL = mycom.Format(SQL_04,parms)
Call myacc.ExecuteNonQuery(myacc.CONN_STRING,SQL)
End Sub
'/// <summary>
'/// 统计信息
'/// </summary>
'/// <param name="">信息体</param>
Public Function Count(WhereValue)
Dim parms,SQL,objRS
parms = Array(WhereValue)
SQL = mycom.Format(SQL_07,parms)
Set objRS = myacc.Recordset(myacc.CONN_STRING,SQL)
Count = objRS.RecordCount
End Function
'/// <summary>
'/// 根据条件列出所有信息(带有分页)
'/// </summary>
'/// <param name="PageSize">每页记录数</param>
'/// <param name="CurrentPage">页码</param>
'/// <param name="WhereValue">判断值</param>
'/// <param name="OrderValue">排序</param>
'/// <returns>返回objRS</returns>
Public Function FindByPage(PageSize,CurrentPage,WhereValue,OrderValue)
Dim parms,SQL,objRS
Dim s1
If CurrentPage="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)
End If
Set objRS = myacc.ExecuteReader(myacc.CONN_STRING,SQL)
Set FindByPage = objRS

End Function
Private Sub Class_Initialize()
SQL_01 = "Select * From [Guest] Where Id = {0}"
SQL_02 = "Insert into [Guest] ([Content],[Re],[Addtime],[Ip]) values('{0}','{1}','{2}','{3}')"
SQL_03 = "Update [Guest] Set [Content]='{1}',[Re]='{2}',[Addtime]='{3}',[Ip]='{4}' Where Id = {0}"
SQL_04 = "Delete From [Guest] Where Id In ({0})"
SQL_05 = "Select Top {0} * From [Guest] Where Content Like '%{2}%' Order By {1} Desc,Id Desc"
SQL_06 = "Select Top {0} * From [Guest] Where Content Like '%{2}%' And Id Not IN(Select Top {3} Id From [Guest] Where Content Like '%{2}%' Order By {1} Desc,Id Desc) Order By {1} Desc,Id Desc"
SQL_07 = "Select * From [Guest] Where Content Like '%{0}%' "
Set mycom = new Common
Set myacc = new AccHelper
Set mymod = new MOD_Guest
End Sub
Private Sub Class_Terminate()
Set mycom = Nothing
Set myacc = Nothing
Set mymod = Nothing
End Sub
End Class
%>
MOD_Guest.asp
<%
'/// <summary>
'/// 摘要说明。
'/// </summary>
Class MOD_Guest
Public Id
Public Content
Public Re
Public Addtime
Public Ip
Public Sub SetVar(vId,vContent,vRe,vAddtime,vIp)
Id=vId
Content=vContent
Re=vContent
Addtime=vAddtime
Ip=vIp
End Sub
End Class
%>
Common.asp
<%
'/// <summary>
'/// 摘要说明
'/// </summary>
Class Common
'/// <summary>
'/// 获得信息
'/// </summary>
'/// <param name="Id">需要内容</param>
'/// <param name="Id">替换关键字</param>
'/// <returns>格式化后内容</returns>
Public Function Format(str,arr)
Dim r,i
r = str
For i = 0 To UBound(arr)
r = Replace(r,"{"&i&"}",arr(i))
Next
Format = r
End Function
Public Function Page(PageSize,CurrentPage,RecordCount,PageUrl)

const C_RECORDCOUNT = "合计<STRONG><FONT color=""red"">{0}</FONT></STRONG>篇 |"
const C_FIRSTPAGE1 = "&n
·分享到:
·看完后,您有任何想法或观点,请立即参与评论
·或者:向飞度网提问 留言 举报 纠错
·更多关于  ajax 留言板 asp 三层 模式 网页技术 的内容
 
站内搜索:
·相关评论
  还没有人评论!赶快第一个发表评论吧!
·我来评论
评论内容(必填)

注:评论内容限200字,不支持图片和链接。
您的姓名(选填): 
注:姓名所有人可见,可以填写昵称。
联系方式(选填): 
注:联系方式仅管理员可见,推荐填写电子邮箱。
评价(选填): 
不好
验证码(必填): 
验证码,看不清楚?请点击刷新验证码
版权与免责声明:
1. 凡注明来源为“飞度网”(faydo.com 以下简称为"本站")的所有作品(文章、资料),包括文字与图片,除特殊注明外均可转载,但必须保留版权信息并回链。违反上述声明者,本站将依法追究法律责任。
2. 凡未注明来源的作品(文章、资料),均转载自互联网,本站转载的目的在于传播更多信息,此类作品(文章、资料)并不代表本站观点,本网不承担此类作品侵权行为的直接责任及连带责任。
3. 如因作品内容、版权等需要同本站联系的,请使用页面底部的联系方式。
4. 本站竭力确保所刊载的作品(文章、资料)准确可靠,但不保证该等资料绝对正确可靠;对于任何因资料不确或遗漏又或因根据或依赖本站资料所作决定、行动或不行动而引致的损失或损害,本站概不负责(不论是民事侵权行为责任或合约责任或其他)。
5. 网友评论不代表本站观点。
设为首页 收藏本页 留言与建议 网站地图
©2016 飞度网 版权所有 联系方式:请邮件联系或msn联系。