图 3-2 显示资料信息
2. 页面中需要用户填写的HTML表单元素。
此页无需填写HTML表单元素。
3. 页面所涉及的数据库表信息。
此页面用来显示资料信息,使用了系统中的资料信息表main和教师信息表teacher。
4. 页面代码分析
‘引用创建数据库连接对象函数文件
<!--#include file="conn.asp"-->
‘引用网站设置文件
<!--#include file="fenlei.asp"-->
<%’取得网站设置信息
sql = "select * from config"
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,3
schoolname = rs("schoolname")
gonggao = rs("gonggao")
todaytimes = rs("todaytimes")
times = rs("times")
‘今日访问统计
if rs("todaydate") <> date() then
rs("todaydate") = date()
rs.update
todaytimes = 0
end if
‘总访问统计
if request.cookies("counted") <> "yes" then
response.cookies("counted") = "yes"
‘设置cookies失效时间
response.cookies("counted").expires = now() + 1/72
‘统计数加1
times = times + 1
todaytimes = todaytimes + 1
rs("times") = times
rs("todaytimes") = todaytimes
rs.update
end if
‘关闭记录集对象
rs.close
dim num1
dim rndnum
Randomize
%>
‘Html页面显示部分
……
<%’取最近更新的10条资料记录
sql = "select * from main,teacher where main.idofteacher=teacher.teacherid order by main.times desc"
rs.open sql,conn,1,1
‘显示最近更新的10条资料记录
for i = 1 to 10
if rs.eof then
response.write "<tr><td> </td><td> </td><td> </td><td> </td></tr>"
else
if len(rs("title")) > 10 then
filetitle = left(rs("title"),10)&"..."
else
filetitle = rs("title")
end if
%>
<tr><td align=left> <img src=images/arrow.gif>
<a href=# title="<%=rs("title")%>" onclick=java script:showdetail(<%=rs("mainid")%>);><%=filetitle%></a>
</td><td align=center><a href=teacherinfo.asp?id=<%=rs("teacherid")%> title="查看<%=rs("teacher")%>的个人专集"><%=rs("teacher")%></a></td>
<td align=center><%=rs("times")%></td>
<td align=left> <%=rs("fenlei2")%></td></tr>
<%‘取下一条资料记录
rs.movenext
end if
next
‘关闭记录集对象
rs.close
%>
3.1.2 资料详细信息页
1. etail.asp页面示例
图3-3为显示资料详细信息的页面。
图3-3 资料详细信息
2. 页面中需要用户填写的Html表单元素。
此页无需填写Html表单元素。
3. 面所涉及的数据库表信息。
此页使用了系统中的资料信息表main和教师信息表teacher。
4. 页面代码分析
‘引用创建数据库连接对象函数文件
<!--#include file="conn.asp"-->
‘引用网站设置文件
<!--#include file="fenlei.asp"-->
<%’取得要显示资料信息的id号
id = request("id")
if id = "" then
conn.close
set conn = nothing
response.write "<script>alert('没有找到您要查看的记录');window.close();</script>"
response.end
end if
‘打开记录集对象
set rs = server.createobject("adodb.recordset")
sql = "select * from main,teacher,type where main.idofteacher=teacher.teacherid and main.idoftype=type.typeid and main.mainid="&id
‘取得资料详细信息
rs.open sql,conn,1,1
‘如果资料详细信息不存在则提示错误
if rs.bof and rs.eof then
rs.close
set rs = nothing
conn.close
set conn = nothing
response.write "<script>alert('没有找到您要查看的记录');window.close();</script>"
response.end
else
%>
‘Html页面显示部分,显示资料的详细信息
……
<%’关闭记录集对象
rs.close
set rs = nothing
‘关闭数据库连接对象
conn.close
set conn = nothing
end if
3.1.3 资料信息下载页
1. download.asp页面示例
图3-4 为阅读资料信息所看到的页面。
图3-4 阅读资料信息
2. 页面中需要用户填写的Html表单元素
此页无需填写Html表单元素。
3. 页面所涉及的数据库表信息
此页使用了系统中的资料信息表main。
4. 页面代码分析
<%’取得要显示资料信息的id号
id = trim(request("id"))
if id = "" then
conn.close
set conn = nothing
response.write "<script>alert('没有找到您要阅读的资料');window.close();</script>"
response.end
end if
sql = "select * from main where mainid="&id
set rs = server.createobject("adodb.recordset")
‘取得资料详细信息
rs.open sql,conn,1,3
‘如果资料详细信息不存在则提示错误
if rs.bof and rs.eof then
rs.close
set rs = nothing
conn.close
set conn = nothing
response.write "<script>alert('没有找到您要阅读的资料');window.close();</script>"
response.end
‘如果资料详细信息存在
Else
‘该资料阅读数加1
rs("times") = rs("times") + 1
rs.update
‘页面下载或者打开资料信息
response.redirect rs("fileurl")
‘关闭记录集对象
rs.close
set rs = nothing
‘关闭数据库连接对象
conn.close
set conn = nothing
end if
%>
3.1.4 提交回复作业页
1. redetail.asp页面示例
图3-5为提交回复作业信息所看到的页面。
图3-5 提交回复作业信息
2. 页面中需要用户填写的Html表单元素
此页中有3个表单元素,如表1所示。
表1 redetail.asp页的表单元素
名称 表单元素类型 含义 最大长度
Name Text 学生姓名 20
Title Text 作业标题 20
Message Textarea 作业答案 100
3. 页面所涉及的数据库表信息
此页面用来显示提交回复作业信息,并没有涉及到数据库表的操作。
4. 页面代码分析
‘Html页面表单提交到redetailok.asp提交作业答案
<form action="redetailok.asp" method="post" >
‘Html页面显示部分
……
</form>
3.1.5 提交回复作业成功页
1. 页面中需要用户填写的Html表单元素
此页无需填写Html表单元素。
2. 页面所涉及的数据库表信息
此页使用了系统中的回复作业信息记录表work。
3. 页面代码分析
‘引用创建数据库连接对象函数文件
<!--#include file="conn.asp"-->
<%’学生姓名必须要输入
name = trim(request("name"))
if name = "" then
response.write "<script>alert('请输入学生姓名');history.go(-1);</script>"
conn.close
set conn = nothing
response.end
end if
if len(name) > 5 then
response.write "<script>alert('学生姓名不得超过5个汉字');history.go(-1);</script>"
conn.close
set conn = nothing
response.end
end if
‘作业标题必须要输入
title = trim(request("title"))
if title = "" then
response.write "<script>alert('请输入作业标题');history.go(-1);</script>"
conn.close
set conn = nothing
response.end
end if
‘作业答案必须要输入
message = trim(request("message"))
if message = "" then
response.write "<script>alert('请输入作业答案');history.go(-1);</script>"
conn.close
set conn = nothing
response.end
end if
‘作业的id号必须存在
reid = trim(request("reid"))
if reid = "" then
response.write "<script>alert('非法操作');history.go(-1);</script>"
conn.close
set conn = nothing
response.end
end if
sql = "select * from work where name='"&name&"' and reid="&reid
set rs = server.createobject("adodb.recordset")
‘查找作业表中是否存在学生姓名和回复作业的id号相同的记录存在
rs.open sql,conn,1,3
‘如果存在则说明学生已经提交过作业不能再提交了
if not (rs.bof and rs.eof) then
rs.close
set rs = nothing
conn.close
set conn = nothing
response.write "<script>alert('你已经提交过作业了');history.go(-1);</script>"
response.end
else
‘如果不存在则添加作业答案记录
rs.addnew
rs("reid")=reid
rs("name")=name
rs("title")=title
rs("message")=message
‘添加作业答案记录成功
rs.update
‘关闭记录集对象
rs.close
set rs = nothing
‘关闭数据库连接对象
conn.close
set conn = nothing
end if
response.write "<script>alert('添加成功');window.location.href='index.asp';</script>"
%>
3.1.6 教师基本信息页
1. teacherinfo.asp页面示例
图3-6为显示教师基本信息所看到的页面。
图3-6 显示教师基本信息
2. 页面中需要用户填写的Html表单元素
此页无需填写Html表单元素。
3. 页面所涉及的数据库表信息
此页面用来显示教师基本信息,此页使用了系统中的资料信息表main和教师信息表teacher。
4. 页面代码分析
<%’取得要显示教师信息的id号
id = trim(request("id"))
if id = "" then
conn.close
set conn = nothing
response.write "<script>alert('请不要捣乱');top.window.location.href='index.asp';</script>"
response.end
end if
‘判断用户是否是管理员
if session("admin") = "admin" then
isadmin = true
else
isadmin = false
end if
‘判断用户是否是教师
if session("teacherid") <> "" then
isteacher = true
else
isteacher = false
end if
‘取得教师详细信息
sql = "select * from teacher where teacherid="&id
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,1
%>
‘Html页面显示部分,显示教师信息
……
<%’关闭记录集对象
rs.close
end if
‘取得栏目信息
sql = "select * from type"
rs.open sql,conn,1,1
set rs1 = server.createobject("adodb.recordset")
‘所有栏目信息
do while not rs.eof
sql1 = "select count(mainid) from main where idofteacher="&id&" and idoftype="&rs("typeid")
‘取得教师在该栏目发表的资料总数
rs1.open sql1,conn,1,1
counter = rs1(0)
rs1.close
‘发表的资料总数如果是3的倍数
if counter mod 3 = 0 then
‘定义显示资料记录的框架的高度
iframeheight = 20*(int(counter/3)+1)
else
iframeheight = 20*(int(counter/3)+2)
end if
‘框架的高度最大值为220
if iframeheight > 220 then iframeheight = 220
%>
<tr><td align="center" class="header" colspan=3>已在本站发布的<%=rs("type")%>(共<%=counter%>件)</td></tr>
<tr><td align="center" colspan=3>
‘显示资料记录的框架页
<iframe name="titleof<%=rs("typeid")%>" frameborder=0 width=100% height=<%=iframeheight%> scrolling=no src=titlelist.asp?type=<%=rs("typeid")%>&id=<%=id%>></iframe>
</td></tr>
<%’取下一个栏目
rs.movenext
loop
‘关闭记录集对象
set rs1 = nothing
‘关闭记录集对象
rs.close
set rs = nothing
%>
</table>
<%’如果用户既不是管理员也不是教师
if not isadmin and not isteacher then
%>
<!--#include file="foot.asp"-->
<%
end if
%>
</body>
</html>
<%’关闭数据库连接对象
conn.close
set conn = nothing
%>
3.1.7 资料信息搜索页
1. search.asp页面示例
图3-7为搜索资料信息所看到的页面。
图3-7搜索资料信息
2. 页面中需要用户填写的Html表单元素
此页共有5个表单元素,如表2所示。
表2 search.asp页的表单元素
名称 表单元素类型 含义 最大长度
fenlei1 Text 所属学院 20
feilei2 Text 所属系 20
Teacher Text 教师姓名 10
Course Text