第二部分:实例
项目结构:
该项目主要由几个ASP文件和一个数据库组成:
book.mdb:存放数据库的内容
index.asp:网站主要的文件,大部分的内容均由它来显示
buy.asp:购物蓝的内容
in.asp:供登录使用
registry.asp:使您成为我们的会员
数据库(book.mdb):
第一个表是Book,用于存储关于书目的一些相关的信息,结构如下:
ID
整型
书的序号
Name
字符
书的名字
Author
字符
作者
Brief
字符
简介
Ifcover
整型
是否首页显示
Price
双精度
价格
Publisher
字符
出版社
Cover
字符
封面的图片的路径
Flag
整型
标志
第二个表是info,用于存储会员的信息,结构如下:
Id
字符
会员登录号
Name
字符
会员姓名
Pwd
字符
登录密码
Email
字符
Address
字符
地址
Phone
字符
电话
Post
字符
邮编
Sfz
字符
身份证号码
第三个表是class,用于存储书目的类别,其结构如下:
ID
字符
编号
Name
字符
类别
几个ASP文件的内容:
Index.asp
<!--
分三个TD,最主要的中间的一个,大多数操作都是对中间的一个。
-->
<%@ Language=VBScript %>
<script language=javascript>
function openwindow(num){
window.open ("info.asp?key=" + num,"yu",0,0)
}
</script>
<script language=javascript>
function buy(name){
window.open ("buy.asp?name=" + name ,"yu",0,0)
}
</script>
<script language=javascript>
function viewPage(ipage){
document.Page.txtPage.value=ipage
document.Page.submit()
}
</script>
<HTML>
<HEAD>
<title>网上书店</title>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY bgColor=lightcyan>
<P align=center><IMG alt="网上书店"
src="http://edu.cnzz.cn/NewsInfo/file://C:/InetPub/wwwroot/images/title.jpg"><br>
<TABLE align=center border=0 cellPadding=0 cellSpacing=10
width="100%" style="BORDER-BOTTOM-COLOR: red; BORDER-LEFT-COLOR: red;
BORDER-RIGHT-COLOR: red; BORDER-TOP-COLOR: red">
<tr>
<td colspan=3>
<table border=1 width=100% bgcolor=Khaki cellpadding=0 cellspacing=0>
<tr>
<td bgcolor=MediumSeaGreen ><% =year(date()) & "年" & month(date)
& "月" & day(date) & "日" %></td>
<td bgcolor=MediumSeaGreen ><a href="about.htm">关于我们</a></td>
<td bgcolor=MediumSeaGreen ><a href=buy.asp?name=view>查询购物蓝
</a></td>
<%
if session("UserID")<>"" then
Response.Write "<td bgcolor=MediumSeaGreen> 会员:" & session
("UserName") & "</td>"
else
Response.Write "<td bgcolor=MediumSeaGreen>会员:未登录</td>"
end if
if session("sum")="" then session("sum")=0
Response.Write "<td bgcolor=MediumSeaGreen>购货总金额:" & session
("sum") & "</td>"
%>
</tr>
</table>
</td>
</tr>
<TR>
<TD width="15%" valign=top bordercolor=deeppink bgcolor=beige>
<A href=index.asp?ifcover=1><P align=center>
最新书目</a><br>
畅销书目<br>
<hr color=deeppink>
<P></P>
<p align=center>
图书分类<br>
<table border=1 cellspacing=0 cellpadding=0 width=100%>
<% set rs=server.CreateObject("ADODB.recordset")
rs.open "select * from class order by ID","DSN=sqlsales;UID=sa;",3,3
rs.movefirst
do while not rs.eof
Response.Write "<tr><td align=center>"
Response.Write "<A href=index.asp?flag=" & rs("ID") & ">" & rs
("Name") & "</a><br>"
Response.Write "</td><tr>"
rs.movenext
loop
%>
</table>
</p>
</TD>
<TD width = "65%" bordercolor=orangered valign=top>
<% if Request.QueryString("flag")="" and session("flag")="" or
request.querystring("ifcover")=1 then %>
<%
set rs=server.CreateObject("ADODB.Recordset")
rs.Open "select * from book where
ifcover=1","DSN=sqlsales;UID=sa;",3,3
%>
<P align=center style="FONT-SIZE: x-large"><FONT
color=mediumslateblue style="FONT-FAMILY: serif" >最新书目</FONT></P>
<% for i=1 to rs.RecordCount %>
<table border=0 cellpadding=5 cellspacing=5 width="100%">
<tr>
<td colspan=2><font color=red size=5 ><p align=center><% =rs.Fields
("Name") %></p></font></td>
</tr>
<tr>
<td width="30%"><a href="javascript:openwindow(<% =rs.Fields("ID") %
>)"><img src=<% =rs.Fields("Cover") %>>
</td>
<td><FONT color=mediumslateblue>书号:</FONT><% =rs.Fields("ID") %><br>
<FONT color=mediumslateblue>作者:</FONT><% =rs.Fields("Author") %
><br><FONT
color=mediumslateblue>原价:</FONT><% =rs.Fields("Price") %><br><FONT
color=mediumslateblue>现价:</FONT><% =rs.Fields("Price") %><br><FONT
color=mediumslateblue>出版社</FONT><% =rs.Fields("Publisher") %></td>
</tr>
<tr>
<td colspan=5> <FONT
color=#660066><% =rs.Fields("Brief") %>
</FONT>
</td>
</tr>
<tr>
<td colspan=6><p align=right><a href=buy.asp?name=<% =rs.Fields("ID")
& "`" & rs.fields("Name") & "`" & rs.fields("Price") %>>购买
</A></p></td>
</tr>
</table>
<hr>
<% rs.MoveNext
next
rs.Close
%>
<% elseif Request.QueryString("flag")=9999 then
Response.Write "购物蓝"
else
set rs=server.CreateObject("ADODB.recordset")
if Request.QueryString("flag")<>"" then session("flag")
=Request.QueryString("flag")
rs.open "select* from book where flag=" & session
("flag"),"DSN=sqlsales;UID=sa;",3,3
session("PageNum")=rs.PageCount
if rs.RecordCount <>0 then
%>
<table border=1 width="100%">
<tr>
<td width=40% align=center>书名</td>
<td width=15% align=center>作者</td>
<td width=29% align=center>出版社</td>
<td width=8% align=center>价格</td>
<td width=8% align=center>订购</td>
</tr>
<%
rs.MoveFirst
session("pagecur")=session("pagecur" & Request.QueryString("flag"))
if session("pagecur") ="" then
session("pagecur")=1
rs.AbsolutePage=1
else
if (Request.Form("txtPage"))="" then
'response.write session("pagecur") & "<BR>"
rs.AbsolutePage =session("pagecur")
session("page")=session("pagecur")
else
rs.AbsolutePage =clng(Request.Form("txtPage"))
session("page")=clng(Request.Form("txtPage"))
'session("Page")=clng(Request.Form("txtPage"))
end if
end if
%>
<form action="index.asp" method=post name=Page>
<% ="<a href=" & chr(34) & "javascript:viewPage(1)" & chr(34) & ">首页
</a>" %>
<%
if session("Page")="" then
session("Page")=1
end if
if clng(session("Page"))>1 then
session("pagecur")=clng(session("page"))-1
Response.Write "<a href=" & chr(34) & "javascript:viewPage(" & session
("Pagecur") & ")" & chr(34) & "> 前页</a>"
else
Response.Write " 前页"
end if
if clng(session("Page"))<clng(session("PageNum")) then
session("pagecur")=clng(session("Page"))+1
Response.Write "<A href=" & chr(34) & "javascript:viewPage(" & session
("Pagecur") & ")" & chr(34) & "> 后页 </a>"
else
Response.Write " 后页 "
end if
Response.Write "<a href=" & chr(34) & "javascript:viewPage(" & session
("PageNum") & ")" & chr(34) & ">末页</a>"
%>
<INPUT id=txtPage name=txtPage style="HEIGHT: 22px; WIDTH: 103px"
value=1>
<INPUT id=submit1 name=cmdPage type=submit value=GO style="BACKGROUND-
COLOR: peru; COLOR: greenyellow">
</form>
<%
i=0
do while not rs.EOF and i<rs.PageSize
i=i+1
Response.Write "<tr>"
'Response.Write "<td>" & rs.Fields("ID") & "</td>" %>
<td><a href="javascript:openwindow(<% =rs.Fields("ID") %>)"><%
=rs.Fields("Name") %></a></td>
<% Response.Write "<td>" & rs.Fields("Author") & "</td>"
Response.Write "<td>" & rs.Fields("Publisher") & "</td>"
Response.Write "<td>" & rs.Fields("Price") & "</td>"
Response.Write "<td>订购</td>"
Response.Write "</tr>"
rs.MoveNext
loop
Response.Write "</table>"
end if
rs.Close
end if %>
<TD width="20%" valign=top bordercolor=orangered bgcolor=beige>
<form method=post action="in.asp" id=login name=login>
<p align=center>
会员登录</p><p align=center>用户<INPUT
id=text1 name=txtUser size=12>
<br>
密码<INPUT id=text2 name=txtPWD size=12 type=password></p>
<P align=center><INPUT id=cmdLogon name=cmdLogon type=submit value=进
入><INPUT id=cmdReg name=cmdReg type=button value=申请
onclick=window.location.href="registry.asp"></form></P>
<%
' session("num_book")=session("num")
' if session("num_book")<>"" then
' num_book=clng(session("num_book"))
' response.write "<table border=1 width=100%\><tr><td>书号</td><td>单
价</td><td>数量</td></tr>"
' for i=0 to num_book
' response.write "<tr><td>" & session("ID_" & cstr(num_book))
& "</td><td>" & session("price_" & cstr(num_book)) & "</td><td>" &
session("num_" & cstr(num_book)) & "</td></tr>"
' next
' response.write "</table>"
' end if
%>
<P>为了您获得更优惠的价格,请您申请成为我们的会员,并在此进行登录。</P>
<p>付账方式:采用邮局付款或送货上门方式。
</p></TD></TR></TBODY></TABLE></P>
<p align=center><font size=2 color=blue>本站所包括文字和图片版权归于爱武
所有,未经许可,不得抄录<br>于爱武</font></p>
</BODY>
</HTML>