一个BBS的源代码(一)
建立数据库结构:
' bbs
' 序号 INT NOT NULL IDENTITY
' 作者 VARCHAR(80)
' 题目 VARCHAR(255)
' 回复 INT NOT NULL DEFAULT 0
' 点击 INT NOT NULL DEFAULT 0
' 时间 DATETIME DEFAULT GETDATE()
' 内容 TEXT
' 邮件通知 BIT DEFAULT 0
'
' bbsreply
' 序号 INT NOT NULL IDENTITY
' 原文 INT
' 作者 VARCHAR(80)
' 题目 VARCHAR(255)
' 时间 DATETIME DEFAULT GETDATE()
' 内容 TEXT
'
' bbsmember
' 序号 INT NOT NULL IDENTITY
' 账号 VARCHAR(80)
' 密码 VARCHAR(80)
' 邮件 VARCHAR(80)
' 文章数 INT DEFAULT 0
一个BBS的源代码(二)
' 打开数据库
Set Con = Server.CreateObject("ADODB.Connection")
Con.Open "asp" , Application("ConASP_RuntimeUserName") , Application("ConASP_RuntimePassword")
Set RecBBS = Server.CreateObject("ADODB.RecordSet")
Set RecReply = Server.CreateObject("ADODB.RecordSet")
Set RecMember = Server.CreateObject("ADODB.RecordSet")
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312">
<TITLE>经验交流</TITLE>
<STYLE TYPE="TEXT/CSS">
td {
color: #ffffff;
font-size: 9pt;
}
color: #000000;
background-color: #f0f0d0;
font-size: 12pt;
}
input {
color: #000000;
font-size: 9pt;
border-top: 1px solid;
border-left: 1px solid;
border-right: 1px solid;
border-bottom: 1px solid;
}
select {
color: #000000;
font-size: 9pt;
border-top: 1px solid;
border-left: 1px solid;
border-right: 1px solid;
border-bottom: 1px solid;
}
textarea {
color: #000000;
font-size: 9pt;
border-top: 1px solid;
border-left: 1px solid;
border-right: 1px solid;
border-bottom: 1px solid;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</STYLE>
</HEAD>
<BODY bgcolor=#c0c0c0>
<P>
<TABLE align=center valign=top bgColor=#d0d0d0 border=1 borderColorDark=#f0f0f0 borderColorLight=#505050 cellPadding=5 cellSpacing=0 width=600 height=400>
<TR>
<TD valign=top>
<%
Job = Request("Job")
If Job = "" Then Job = "List"
'==============================
Select Case Job
'==============================
'=============================
Case "List"
'==============================
' 显示文章
%>
<TABLE align=center border=0 cellPadding=1 cellSpacing=0 width=650>
<TR>
<TD>
<TABLE WIDTH="100%" ALIGN=center BORDER=0 CELLSPACING=0 CELLPADDING=2 BGCOLOR=#f0f0d0>
<TR>
<TD class=menu valign=top>
<A href="/">飞林庄</A>-><A href="<%= ASP_FILE_NAME %>">经验交流</A>
</TD>
<TD class=menu></TD>
<TD align=right class=menu>
<FORM action="<%= ASP_FILE_NAME %>" method=get>
<INPUT type=hidden name=Job value=List>
[<A href="<%= ASP_FILE_NAME %>?Job=Write">发表文章</A>][<A href="<%= ASP_FILE_NAME %>?Job=Apply">申请账号</A>]
<INPUT id=
Keyword maxLength=20 name=Keyword size=18>
<INPUT type=Submit value=主题搜索>
</FORM>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<TABLE align=center bgColor=#000000 border=0 cellPadding=1 cellSpacing=1 width=650>
<%
If Request("Keyword") <> "" Then KeyWord = Request("Keyword") Else KeyWord = ""
If Request("Page") = "" Then
If IsNumeric( Session("BBS_Page") ) Then
Page = Int(Session("BBS_Page"))
Else
Page = 1
End If
Else
Page = Int(Request("Page"))
End If
If Page < 1 Then Page = 1
RecBBS.PageSize = ListSize
SQL = "SELECT * FROM bbs "
If KeyWord <> "" Then
SQL = SQL + "WHERE [题目] LIKE '%" & KeyWord & "%' "
End If
SQL = SQL + "ORDER BY [序号] DESC"
RecBBS.Open SQL , Con , 3
PageCount = RecBBS.PageCount
RecordCount = RecBBS.RecordCount
If Page > PageCount Then Page = PageCount
Session("BBS_Page") = Page
If Not RecBBS.EOF Then
%>
<TR>
<TD>作者</TD> 有没有什么网站分享源码
<TD>题目</TD>
<TD>回复</TD>
<TD>点击</TD>
<TD>时间</TD></TR>
<%
RecBBS.AbsolutePage = Page
For iRec = 1 To ListSize
If Not RecBBS.EOF Then
%>
<TR>
<TD><%= Server.HTMLEncode( RecBBS.Fields("作者") ) %></TD>
<TD>
<A href="<%= ASP_FILE_NAME %>?Job=Content&Which=<%= RecBBS.Fields("序号") %><% If KeyWord <> "" Then Response.Write "&Keyword=" & KeyWord %>">
<%= Server.HTMLEncode( RecBBS.Fields("题目") ) %>
</A>
</TD>
<TD><%= Server.HTMLEncode( RecBBS.Fields("回复") ) %></TD>
<TD><%= Server.HTMLEncode( RecBBS.Fields("点击") ) %></TD>
<TD><%= Server.HTMLEncode( RecBBS.Fields("时间") ) %></TD></TR>
</TR>
<%
RecBBS.MoveNext
Else
Response.Write " <TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>" & Chr(13)
End If
Next
Else
%>
No Record
<%
End If
RecBBS.Close
%>
</TABLE>
<TABLE align=center border=0 cellPadding=1 cellSpacing=0 width=650>
<TR>
<TD class="menu">
共有 <%= PageCount %> 页 <%= RecordCount %> 篇文章
<%
If Page > 1 Then
Response.Write "<A href=""" & ASP_FILE_NAME & "?Job=List&Page=" & Page-1
If KeyWord <> "" Then Response.Write "&Keyword=" & KeyWord
Response.Write """>"
End If
%>
上一页
<% If Page > 1 Then Response.Write "</A>" %>
<%
If Page < PageCount Then
Response.Write "<A href=""" & ASP_FILE_NAME & "?Job=List&Page=" & Page+1
If KeyWord <> "" Then Response.Write "&Keyword=" & KeyWord
Response.Write """>"
End If
%>
下一页
<% If Page < PageCount Then Response.Write "</A>" %>
<A href="javascript:window.open('<%= ASP_FILE_NAME %>?Job=List&Page=' + Page.value , '_self')">
转到</A>第<INPUT id=Page name=Page size=4 maxlength=4 >页
<% Response.Write Page & "/" & PageCount %>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<%
一个BBS的源代码(三)
'=============================
Case "Content"
'=============================
' 显示内容
If Request("Keyword") <> "" Then KeyWord = Request("Keyword
") Else KeyWord = ""
%>
<TABLE align=center border=0 cellPadding=1 cellSpacing=0 width=650>
<TR>
<TD class="menu">
<A href="/">飞林庄</A>-><A href="<%= ASP_FILE_NAME %><% If KeyWord <> "" Then Response.Write "?Keyword=" & KeyWord %>">经验交流</A>->;怎样输出图像</TD>
</TR>
</TABLE>
<TABLE align=center border=0 cellPadding=8 cellSpacing=0 width=650>
<TR>
<TD bgColor=#000000>
<%
Which = Request("Which")
If IsNumeric( Which ) Then
Session("BBS_Which") = Which
' 点击数加一
Con.Execute( "UPDATE bbs SET [点击]=[点击]+1 WHERE [序号]=" & Which )
SQL = "SELECT * FROM bbs WHERE [序号]=" & Which
RecBBS.Open SQL , Con , 1
If Not RecBBS.EOF Then
Title = RecBBS.Fields("题目")
Session("BBS_WhichTitle") = Title
%>
<P><FONT color=#66ff99>序号</FONT>:<FONT color=#6699ff>E<%= Which %></FONT><BR>
<FONT color=#66ff99>作者</FONT>:<%= Server.HTMLEncode( RecBBS.Fields("作者") ) %><BR>
<FONT color=#66ff99>题目</FONT>:<%= Server.HTMLEncode( Title ) %><BR>
<FONT color=#66ff99>时间</FONT>:<%= RecBBS.Fields("时间") %><BR>
<BR>
<PRE>
<%= Server.HTMLEncode( RecBBS.Fields("内容") ) %>
</PRE>
</P>
<%
End If
RecBBS.Close
SQL = "SELECT * FROM bbsreply WHERE [原文]=" & Which
RecReply.Open SQL , Con , 3
AllID = "E" & Which
Do While Not RecReply.EOF
ID = RecReply.Fields("序号")
AllID = AllID & ":" & ID
%>
<P><FONT color=#66ff99>序号</FONT>:<FONT color=#6699ff><%= ID %></FONT><BR>
<FONT color=#66ff99>作者</FONT>:<%= Server.HTMLEncode( RecReply.Fields("作者") ) %><BR>
<FONT color=#66ff99>题目</FONT>:<%= Server.HTMLEncode( RecReply.Fields("题目") ) %><BR>
<FONT color=#66ff99>时间</FONT>:<%= RecReply.Fields("时间") %><BR>
<BR>
<PRE>
<%= Server.HTMLEncode( RecReply.Fields("内容") ) %>
</PRE>
</P>
<%
RecReply.MoveNext
If RecReply.EOF Then Exit Do
Loop
RecReply.Close
End If
%>
</TD>
</TR>
</TABLE>
<TABLE align=center border=0 cellPadding=7 cellSpacing=0 width=650>
<TR>
<TD class=menu>
<FORM action="<%= ASP_FILE_NAME %>" method=post>
<INPUT type=hidden id=Job name=Job value=Reply>
账号:<INPUT id=Userid name=Userid maxLength=30 size=30>
密码:<INPUT id=Password maxLength=30 name=Password size=30 type=password><BR>
题目:<INPUT id=Title maxLength=80 name=Title size=72 value="回复:<%= Title %>"><BR>
<TEXTAREA cols=80 id=Content name=Content rows=10></TEXTAREA><BR>
<INPUT type=submit value=" 回 复 ">
</FORM>
<P>
选中文章:
<SELECT id=Which name=Which size=1>
<%
WhichID = Split( AllID , ":" )
For Each ID In WhichID
Response.Write "<OPTION value="
Response.Write ID & ">" & ID
Response.Write "</OPTION>"
Next
%>
</SELECT><BR>
<INPUT id=Email maxLength=80 name=Email size=40>
<INPUT type=button id=MailBack name=MailBack value="寄回信箱" OnClick="window.open('<%= ASP_FILE_NAME %>?Job=Send&Which=' + Wh
ich.value + '&Email=' + Email.value , '_self')">
<INPUT type=button id=Modify name=Modify value="修改" OnClick="window.open('<%= ASP_FILE_NAME %>?Job=Modify&Which=' + Which.value , '_self')">
<INPUT type=button id=Delete name=Dalete value="删除" OnClick="window.open('<%= ASP_FILE_NAME %>?Job=Delete&Which=' + Which.value , '_self')">
</P>
</TD>
</TR>
</TABLE>
一个BBS的源代码(四)
'==============================
Case "Write"
'==============================
' 发表文章
%>
<TABLE align=center border=0 cellPadding=7 cellSpacing=0 width=650>
<TR>
<TD class=menu>
<P><A href="/">飞林庄</A>-><A href="<%= ASP_FILE_NAME %>">经验交流</A></P>
<FORM action="<%= ASP_FILE_NAME %>" id=FORM1 method=post name=FORM1>
<INPUT type=hidden name=Job value=Add>
账号:<INPUT id=Userid maxLength=30 name=Userid size=30>
密码:<INPUT id=Password name=Password type=password><BR>
题目:<INPUT id=Title maxLength=80 name=Title size=72><BR>
<TEXTAREA cols=80 id=Content name=Content rows=20></TEXTAREA><BR>
<INPUT id=Mailme name=Mailme value=Yes type=checkbox >有回复时发邮件通知我
<INPUT type=submit value=" 发 表 ">
<INPUT type=reset value=" 重 写 ">
</FORM>
</TD>
</TR>
</TABLE>
<%
'================================
Case "Add","Reply"
'================================
' 把文章加进数据库
' 检查数据
Userid = Trim(Request("Userid"))
Password = Trim(Request("Password"))
Title = Trim(Request("Title"))
Content = Rtrim(Request("Content"))
If Request("Mailme") = "Yes" Then Mailme = 1 Else Mailme = 0
WrongMsg = ""
If Userid = "" Then WrongMsg = WrongMsg + "<DD><LI>请输入你的账号。"
If Password = "" Then WrongMsg = WrongMsg + "<DD><LI>请输入你的密码。"
If Title = "" Then WrongMsg = WrongMsg + "<DD><LI>请输入文章题目。"
If Content = "" Then WrongMsg = WrongMsg + "<DD><LI>请输入内容。"
If WrongMsg = "" Then
Userid = SqlStr( Userid )
Password = SqlStr( Password )
Title = SqlStr( Title )
Content = SqlStr( Content )
' 检察账号与密码
SQL = "SELECT COUNT(*) FROM bbsmember WHERE [账号]='" & Userid & "' AND [密码]='" & Password & "'"
RecMember.Open SQL , Con , 1
If RecMember.Fields(0).Value = 0 Then MemberExist = True Else MemberExist = False
RecMember.Close
If MemberExist Then
WrongMsg = WrongMsg + "<DD><LI>用户名不存在或者密码不对。"
Else ' 加进数据库
If Job = "Add" Then
SQL = "INSERT INTO bbs ([作者],[题目],[内容],[邮件通知]) VALUES('" &_
SqlStr( Userid ) & "','" &_
SqlStr( Title ) & "','" &_
SqlStr( Content ) & "'," &_
Mailme & ")"
Else
' 回复文章数加一
Con.Execute( "UPDATE bbs SET [回复]=[回复]+1 WHERE [序号]=" & Session("BBS_Which") )
'
' 邮件通知原作者
'
SQL = "SELECT [题目],[时
间],[邮件通知] FROM bbs WHERE [序号]=" & Session("BBS_Which")
RecBBS.Open SQL , Con , 1
If RecBBS.Fields("邮件通知") Then
FirstTitle = RecBBS.Fields("题目")
WriteTime = RecBBS.Fields("时间")
一个BBS的源代码(五)
'=================================
Case "Modify"
'================================
' 修改文章
Which = Request("Which")
WhichID = GetID( Which )
If Left( Which , 1 ) = "E" Then Table = "bbs" Else Table = "bbsreply"
WrongMsg = ""
If Request("Modify") = "Yes" Then
Userid = Request("Userid")
Password = Request("Password")
Title = Trim(Request("Title"))
Content = Rtrim(Request("Content"))
If Title = "" Then WrongMsg = WrongMsg + "<DD><LI>题目不能为空。</LI>"
If Content = "" Then WrongMsg = WrongMsg + "<DD><LI>内容不能为空。</LI>"
If WrongMsg = "" Then
RecBBS.Open "SELECT [作者] FROM " & Table & " WHERE [序号]=" & WhichID , Con , 1
If RecBBS.Fields("作者") = Userid Then
SQL = "SELECT COUNT(*) FROM bbsmember WHERE [账号]='" & SqlStr(Userid) & "' AND [密码]='" & SqlStr(Password) & "'"
RecMember.Open SQL , Con , 1
If RecMember.Fields(0) > 0 Then
SQL = "UPDATE " & Table & " SET [题目]='" & SqlStr(Title) & "',[内容]='" & SqlStr(Content) & "' WHERE [序号]=" & WhichID
Con.Execute( SQL )
Else
WrongMsg = "<DD><LI>密码不正确。</LI>"
End If
RecMember.Close
Else
WrongMsg = "<DD><LI>用户名不正确。</LI>"
End If
RecBBS.Close
End If
End If
Title = ""
Content = ""
SQL = "SELECT [题目],[内容] FROM " & Table & " WHERE [序号]=" & WhichID
RecBBS.Open SQL , Con , 1
If Not RecBBS.EOF Then
Title = RecBBS.Fields("题目")
Content = RecBBS.Fields("内容")
End If
RecBBS.Close
%>
<TABLE align=center border=0 cellPadding=1 cellSpacing=0 width=650>
<TR>
<TD class="menu">
<A href="/">飞林庄</A>-><A href="<%= ASP_FILE_NAME %>">经验交流</A>-><A href="<%= ASP_FILE_NAME %>?Job=Content&Which=<%= Session("BBS_Which") %>"><%= Session("BBS_WhichTitle") %></A>
<% If WrongMsg <> "" Then %>
<BR><BR>修改失败!<BR><BR>
<%= WrongMsg %><BR>
<% Else %>
<BR><BR>修改成功!<BR><BR>
<% End If %>
<FORM action="<%= ASP_FILE_NAME %>" method=post>
<INPUT type=hidden name=Job value=Modify>
<INPUT type=hidden name=Modify value=Yes>
<INPUT type=hidden name=Which value="<%= Which %>">
账号:<INPUT type=text id=Userid name=Userid size=30 maxlength=80><BR>
密码:<INPUT type=password id=Password name=Password size=30 maxlength=80><BR><BR>
题目:<INPUT type=text id=Title name=Title value="<%= Title %>">
<TEXTAREA id=Content name=Content cols=80 rows=16><%= Content %></TEXTAREA><BR>
<INPUT type=submit value="确认修改">
</FORM>
</TD>
</TR>
</TABLE>
<%
'===============================
Case "Apply"
'===============================
' 申请账号
%>
<TABLE align=center border=0 cellPadding=7 cellSpacing=0 width=650>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论