第二部分:实例
项目结构:
该项目主要由几个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="file://C:InetPubwwwrootimages itle.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">
<
项目结构:
该项目主要由几个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
字符
登录密码
字符
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="file://C:InetPubwwwrootimages itle.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">
<