objConn.Execute(strSQL)
End If
objRS.MoveNext
Next
objRS.Close
'跳转回主页
Response.Redirect "index.asp"
End If
%>
5.2.3 影片浏览界面及代码
用户在浏览此页面的时候,可以执行的功能主要有影片的浏览,查找,查看影片的状态,可以查看影片被点击的次数,因此,在代码设计的时候主要是围绕这几个功能进行的。
用户浏览,查找,查看影片状态的代码:
<!--#include file="CONN.ASP"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<link href="style.css" rel="stylesheet" type="text/css">
<title>影片租赁系统</title>
<script language="java script" src="JS\inc.js"></script>
</head>
<body>
<!--插入通用的Html头模板-->
<!--#include file="head.asp"-->
<%
FindMovie=Request("FindMovie")
FindMovie=Replace(FindMovie,"'","")
'判断用户是否查找电影
If FindMovie<>"" Then
'如果返回的查找电影名称的字符串非空,则根据用户的输入查找电影名称
'如果返回的是数字,则根据电影ID查找
If IsNumeric(FindMovie) Then
strSQL="SELECT * FROM [VideoInfo] WHERE VI_ID_N="&FindMovie
Else
Select Case Request("FindType")
Case "Title"
strSQL="SELECT * FROM [VideoInfo] WHERE VI_Title_S LIKE”&_
“ '%"&FindMovie&"%'"
Case "Director"
strSQL="SELECT * FROM [VideoInfo] WHERE VI_Director_S LIKE “&_
”'%"&FindMovie&"%'"
Case "Playactor"
strSQL="SELECT * FROM [VideoInfo] WHERE VI_Playactor_S LIKE “&_
”'%"&FindMovie&"%'"
Case "Issuer"
strSQL="SELECT * FROM [VideoInfo] WHERE VI_Issuer_S LIKE “&_
”'%"&FindMovie&"%'"
Case Else
strSQL="SELECT * FROM [VideoInfo] WHERE VI_Title_S LIKE “&_
”'%"&FindMovie&"%'"
End Select
End If
'判断用户是否在特定的区域浏览电影
If IsNumeric(Request("ViewArea")) AND Request("ViewArea")<>0 Then
strSQL=strSQL&" AND VI_VS_ID_FN="&Request("ViewArea")
End If
Else
strSQL="SELECT * FROM [VideoInfo] ORDER BY VI_AddTime_D DESC"
If IsNumeric(Request("ViewArea")) AND Request("ViewArea")<>0 Then
strSQL="SELECT * FROM [VideoInfo] WHERE”&_
” VI_VS_ID_FN="&Request("ViewArea")&" ORDER BY VI_AddTime_D DESC"
End If
End If
Set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.PageSize=3
objRS.Open strSQL,objConn,1,3
'如果从数据库中没有读取到任何电影的信息,则返回信息
If objRS.BOF Or objRS.EOF Then
Response.Write "<table width=97% ><tr><td align=center>没有找到要查找的影片!”&_
”[<a href=java script:history.go(-1)>返回</a>]</td></tr></table>"
Response.Write strSQL&"<br>"
Response.End
End If
Response.Write "<form method=Get name=MyForm>"
Response.Write "<table class=tableborder1 align=center cellspacing=1 cellpadding=3”&_
” width=97% height=25% >"
Response.Write "<tr><th colspan=2 id=tabletitlelink height=25 style=font-weight:normal”&_
” align=left>浏览电影:</th></tr>"
Response.Write "<tr><td class=TableBody2 colspan=2 align=right>"
%>
<!--#include file="ChangePage.asp"-->
<%
Call ChangePage("index.asp")
Response.Write " 查找影片:<input type=text maxlength=20”&_
” name=FindMovie class=inputarea> "
Response.Write "<select case name=FindType>"
Response.Write "<option value=Title>名称</option><option value=Director>导演</option>”&_
”<option value=Playactor>演员</option><option value=Issuer>发行商</option>"
Response.Write "</select>"
Response.Write " <input class=inputarea type=submit value=查找>"
Response.Write " 共<b>"&ObjRS.RecordCount&"</b>部电影<br>"
Response.Write "</td></tr>"
'读取指定页面容量的内容
For i=1 to objRS.PageSize
Response.Write "<tr><td class=TableBody1 width=120 rowspan=3 align=center>”&_
”<a href=dispmovie.asp?id="&objRS("VI_ID_N")&"><img src=”&_
objRS("VI_Img_S")&" height=160 width=120 border=0></a></td>"
Response.Write "<td class=tablebody2 width=650 height=17 align=center>”&_
”<a href=dispmovie.asp?id="&objRS("VI_ID_N")&_
">"&objRS("VI_Title_S")&"(ID:"&objRS("VI_ID_N")&")</td></tr>"
Response.Write "<tr><td class=TableBody1 height=71><b>内容:</b>"&_
Left(objRS("VI_Content_S"),100)&"……"&_
"<br><br><b>导演:</b>"&objRS("VI_Director_S")&_
" <b>演员:</b>"&objRS("VI_PlayActor_S")&_
"<br><b>发行商:</b>"&objRS("VI_Issuer_S")&_
" <b>评价:</b>"&objRS("VI_Rank_N")&"</td></tr>"
Response.Write "<tr><td class=TableBody1 height=17 align=right>状态:浏览" &_
objRS("VI_Count_N")&"次/出租"&objRS("VI_RentCount_N")&”次”
'利用Select Case判断影片的状态
Select Case objRS("VI_Status_N")
Case 1
Response.Write "待租"
Case 2
Response.Write "<i>未发行</i>"
Case 3
Response.Write "<b>已出租</b>"
Case 4
Response.Write "<font color=red>被预定</font>"
End Select
Response.Write "</td></tr>"
objRS.MoveNext
'如果记录已到末尾则退出循环
If objRS.EOF Then Exit For
Next
Response.Write "</table>"
Response.Write "</form>"
objRS.Close
%>
<!--插入通用的Html末尾-->
<!--#include file="bottom.asp"-->
</body>
</html>
用户查看影片被点的次数的代码分析
<!--#include file="CONN.ASP"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<link href="style.css" rel="stylesheet" type="text/css">
<title>影片租赁系统</title>
<script language="java script" src="JS\inc.js"></script>
</head>
<body>
<!--插入通用的Html头模板-->
<!--#include file="head.asp"-->
<%
If IsNumeric(Request("id"))=False Then
Response.Write GetErr(11)
Response.End
End If
strSQL="SELECT * FROM [VideoInfo],[Payment] WHERE VI_ID_N="&Request("id")&_
" AND VI_PMT_ID_FN=PMT_ID_N"
Set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL,objConn,1,3
'更新影片点击数
strSQL="UPDATE [VideoInfo] SET VI_Count_N="&objRS("VI_Count_N")+1&_
" WHERE VI_ID_N="&objRS("VI_ID_N")
objConn.Execute(strSQL)
objRS.Close
Response.Write "</table>"
%>
<!--插入通用的Html末尾-->
<!--#include file="bottom.asp"-->
</body>
</html>
5.2.4用户信息界面及代码分析
用户信息界面
用户可以在此界面进行用户信息的查看,已租影片,要到期的影片的查看,用户的管理的功能,因此,代码的设计如下:
用户要进行以上功能的时候,首先应该判断用户是否为注册用户,次判断的代码如下:
If IsEmpty(Session("UserID"))=True Then
'若没有登录则显示登陆框
Response.Write "<table class=tableborder1 align=center cellspacing=1”&_
” cellpadding=3 width=97% >"
Response.Write "<form action=login.asp>"
Response.Write "<tr><th colspan=2 id=tabletitlelink height=25”&_
” style=font-weight:normal align=left>用户信息:访客,"&_
"您的IP是"&Request.ServerVariables("REMOTE_ADDR")&" </th></tr>"
Response.Write "</table>"
Response.Write "<table border=0 width=97% align=center><tr><td colspan=2 “&_
”id=tabletitlelink height=25 style=font-weight:normal align=left>"
Response.Write "用户名:<input type=text class=inputarea name=UserName> "
Response.Write "密码:<input type=password class=inputarea name=UserPassword> "
Response.Write "<input type=submit value=登录 class=inputarea> ”&_
”[<a href=java script:openWindow('Reg.asp',420,240)><font color=black>”&_
”没有注册?</font></a>]"
Response.Write "</form>"
Response.Write "</td></tr></table>"
Else
'
若果登录,则读取用户信息
'通过SQL多表查询读取用户已预订或者已租的影片代码如下:
strSQL="SELECT * FROM [Tenancy],[VideoInfo] WHERE TAC_UI_ID_FN="&_
Session("UserID")&" AND VI_ID_N=TAC_VI_ID_FN AND (TAC_Status_N=4 OR “&_
”TAC_Status_N=3)"
Set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL,objConn,1,3
'读取已预订影片及已租影片的信息
Dim Rent,Prearrange,MsgRent,OvertimeRent
If objRS.BOF Or objRS.EOF Then
Rent="您还没有租影片"
MsgRent="您还没有租影片"
OvertimeRent="您还没有租影片"
Prearrange="您还没有预订影片"
Else
For i=1 To objRS.RecordCount
'通过Select Case语句将已预订与已租影片分类
Select Case objRS("TAC_Status_N")
Case "3"
If DateDiff("h",Now(),DateAdd("h",&_
objRS("TAC_Lease_N")*24,&_
objRS("TAC_StartTime_D")))>24 Then
'如果租出的影片在返还时间24小时以外,则显示为“已租影片”
Rent=Rent&"<a href=java script:openWindow”&_
”('disprent.asp?ID="&objRS("TAC_ID_N") & _
"',320,370) title='起租时间:"&_
objRS("TAC_StartTime_D")&_
" 租期:"&_
objRS("TAC_Lease_N")&"天 到期时间:"&DateAdd("d",objRS("TAC_Lease_N"),
&_objRS("TAC_StartTime_D"))&_
" ' >《"&objRS("VI_Title_S")&"》还剩"&_
DateDiff("h",Now(),DateAdd("h",&_
objRS("TAC_Lease_N")*24,&_
objRS("TAC_StartTime_D")))&"小时</a>"
ElseIf DateDiff("h",Now(),DateAdd("h",&_
objRS("TAC_Lease_N")*24,&_
objRS("TAC_StartTime_D")))>=0 Then
'如果租出的影片离返还时间不到24小时,则显示为“要到期影片”
MsgRent=MsgRent&"<a href=java script:openWindow”&_
”('disprent.asp?ID="&objRS("TAC_ID_N") & _
"',320,370) title='起租时间:"&_
objRS("TAC_StartTime_D")&" 租期:"&_
objRS("TAC_Lease_N")&"天 到期时”&_
”间:"&DateAdd("d",objRS("TAC_Lease_N"),&_
objRS("TAC_StartTime_D"))&_
" >《"&objRS("VI_Title_S")&"》还剩<font”&_
” color=red>"&DateDiff("h",Now(),&_
DateAdd("h",objRS("TAC_Lease_N")*24,&_
objRS("TAC_StartTime_D")))&"</font>小时</a>"
Else
'如果租出的影片已经超过归还期限,则显示为“超期影片”
OvertimeRent=OvertimeRent&"<a href=”&_
”java script:openWindow('disprent.asp?ID="&_
objRS("TAC_ID_N") & _
"',320,370) title='起租时间:"&_
objRS("TAC_StartTime_D")&" 租期:"&_
objRS("TAC_Lease_N")&"天 到期时”&_
”间:"&DateAdd("d",objRS("TAC_Lease_N"),&_
objRS("TAC_StartTime_D"))&_
"' >《"&objRS("VI_Title_S")&"》已过期"&_
DateDiff("h",DateAdd("h",&_
objRS("TAC_Lease_N")*24,&_
objRS("TAC_StartTime_D")),Now())&"小时!</a>"
End If
Case "4"
'显示预订时间
If DateDiff("h",objRS("TAC_ReserveTime_D"),Now())<=12 Then
Prearrange=Prearrange&"<a href=java script:openWindow”&_
”('disprent.asp?ID="&objRS("TAC_ID_N")&"',320,370)" &_
" title='预订时间:"&objRS("TAC_ReserveTime_D")&_
" 还可保留预订"& 12-DateDiff("h",&_
objRS("TAC_ReserveTime_D"),Now())&_
"小时'>《"&objRS("VI_Title_S")&"》</a>"
End If
End Select
objRS.MoveNext
Next
End If
objRS.Close
显示用户IP,及页面代码如下:
Response.Write "<th colspan=2 id=tabletitlelink height=25”&_
” style=font-weight:normal align=left>欢迎您的来访!"&_
"您的IP是"&Request.ServerVariables("REMOTE_ADDR")&_
5.2.5 用户资料界面及代码
用户资料管理界面
用户在此界面可以进行对用户个人信息的修改,实现功能,其代码大致如下:
If IsEmpty(Session("UserID"))=True Then
Response.Write GetErr(7)
Response.End
End If
‘根据IsModify判断是执行程序还是显示页面
If Request("IsModify")<>"" Then
'判断要更改的用户是否存在
Set objRS=Server.CreateObject("ADODB.RecordSet")
strSQL="SELECT UI_ID_N FROM [UserInfo] WHERE UI_ID_N="&Request("uid")
objRS.Open strSQL,objConn,1,3
If objRS.BOF Or objRS.EOF Then
Response.Write "<br><br><br>"
ResultMsg("要修改的用户没有找到!")
objRS.Close
Set objRS=Nothing
CloseDatabase
Response.End
End If
objRS.Close
'检查输入的合法性
'密码
If Request("ChangePassword")<>"" Then
If Request("Password")="" Then
ResultMsg("如果选择了更改密码,则必须输入密码!")
Response.End
End If
If Len(Request("Password"))>20 Then
ResultMsg("密码请不要超过20个字符!")
Response.End
End If
If InStr(Request("Password"),"'")>0 Then
ResultMsg("字符“'”为非法输入,请去掉此字符!")
Response.End
End If
End If
'Email
If IsValidEmail(Request("Email"))=False Then
ResultMsg("Email输入不符合规范,请返回重新输入!")
Response.End
End If
'QQ
If Request("QQ")<>"" Then
If IsNumeric(Request("QQ"))=False Then
ResultMsg("QQ号码必须为数字,请返回重新输入!")
Response.End
End If
End If
'当管理员修改时判断
If Request("ChangeBy")="admin" Then
'判断用户是否为管理员
strSQL="SELECT UI_IsAdmin_B FROM [UserInfo] WHERE UI_ID_N="&_
Session("UserID")
objRS.Open strSQL,objConn,1,3
If objRS("UI_IsAdmin_B")=False Then
objRS.Close
Response.Write GetErr(8)
CloseDatabase
Response.End
End If
objRS.Close
'供应商
If IsNumeric(Request("Provider"))=False Or Request("Provider")="" Then
Response.Write GetErr(1)
Response.End
End If
'管理员
If Request("IsAdmin")<>"true" AND Request("IsAdmin")<>"false" Then
Response.Write GetErr(1)
Response.End
End If
'锁定
If Request("IsLocked")<>"true" AND Request("IsLocked")<>"false" Then
Response.Write GetErr(1)
Response.End
End If
'信用等级
If IsNumeric(Request("CerRank"))=False Or Request("CerRank")="" Then
ResultMsg("信用等级不能留空!")
Response.End
End If
End If
'取得用户信息
‘如果用户填了新密码,则加密此密码以便更新
If Request("ChangePassword")<>"" Then
UserPassword=(Request("Password")
End If
Email=Request("Email")
QQ=Request("QQ")
ProviderID=Request("Provider")
‘如果ProviderID>0则说明用户是供应商
If ProviderID<>0 Then
IsProvider=True
Else
IsProvider=False
End If
IsAdmin=Request("IsAdmin")
IsLocked=Request("IsLocked")
CerRank=Request("CerRank")
'根据情况建立SQL语句更新数据库
If Request("ChangeBy")="admin" Then
If Request("ChangePassword")<>"" Then
strSQL="UPDATE [UserInfo] SET UI_PI_ID_FN="&ProviderID&_
",UI_Password_S='"&UserPassword&"',UI_IsLocked_B="&IsLocked&_
",UI_CerRank_N="&CerRank&",UI_IsProvider_B="&IsProvider&_
",UI_Email_S='"&Email&"',UI_QQ_S='"&QQ&"',UI_IsAdmin_B="&IsAdmin&_
" WHERE UI_ID_N="&Request("uid")
Else
strSQL="UPDATE [UserInfo] SET UI_PI_ID_FN="&ProviderID&_
",UI_IsLocked_B="&IsLocked&",UI_CerRank_N="&CerRank&_
",UI_IsProvider_B="&IsProvider&",UI_Email_S='"&Email&"',UI_QQ_S='"&_
QQ&"',UI_IsAdmin_B="&IsAdmin&" WHERE UI_ID_N="&Request("uid")
End If
Else
If Request("ChangePassword")<>"" Then
strSQL="UPDATE [UserInfo] SET UI_Password_S='"&UserPassword&_
"',UI_Email_S='"&Email&"',UI_QQ_S='"&QQ&"' WHERE UI_ID_N="&_
Request("uid")
Else
strSQL="UPDATE [UserInfo] SET UI_Email_S='"&Email&"',UI_QQ_S='"&_
QQ&"' WHERE UI_ID_N="&Request("uid")
End If
End If
objConn.Execute(strSQL)
'输出结果
Response.Write "<br><br><br>"
ResultMsg("用户信息更新完毕!")
CloseDatabase
Response.End
Else
'判断输入是否合法
If IsNumeric(Request("uid"))=False Or Request("uid")="" Then
Response.Write GetErr(1)
Response.End
End If
'判断用户是否为管理员
Dim strSQL,objRS
Dim IsAdmin
strSQL="SELECT UI_ID_N,UI_IsAdmin_B FROM [UserInfo] WHERE UI_ID_N="&_
Session("UserID")
Set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL,objConn,1,3
IsAdmin=objRS("UI_IsAdmin_B")
objRS.Close
'若用户不是管理员则判断其修改的是否为自己的信息
If IsAdmin=False Then
If Cint(Request("uid"))<>Cint(Session("UserID")) Then
Response.Write GetErr(8)
CloseDatabase
Response.End
End If
End If
'取得用户信息
Dim UserName,Email,QQ
Dim Provider,IsProvider,ProviderID
Dim IsLocked,IsAdmin2
Dim RentCount,CerRank
&n