📄 orderpro.jsp
字号:
<%-- 这个JSP脚本是用来处理用户定书的 --%>
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page errorPage="errorpage.jsp" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="DBexecuteBean" scope="page" class="bookSearchOrderBean.DBexecuteBean"/> <%-- 调用JavaBean --%>
<html>
<head>
<title>网上图书信息检索和订购</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.TableLine { border: #6666FF; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-->
</style>
</head>
<%
String islogin = null;
Cookie[] bookcookie = request.getCookies();
/* 首先验证访问者是否已经登录 */
if(bookcookie != null)
{
for(int j = 0;j < bookcookie.length;j++)
{
if(bookcookie[j].getName().equals("hadlogin"))
{
islogin = bookcookie[j].getValue();
}
}
}
if((islogin == null) || (!(islogin.equals("1"))))
{
throw new Exception("你还没有登录,请先登录!");
}
%>
<body bgcolor="#FFFFFF" link="#6666FF" vlink="#6666FF" alink="#6666FF">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="TableLine">
<tr>
<td height="158">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="2">
<%
String bookID = null;
String UserID = null;
int BuyNumber = 1;
int isOK = -1;
double prePrice = 0;
double NowPrice = 0;
double Oldprice = 0;
int Oldbuynumber = 0;
boolean flag = false;
String sSQLCmd = null;
ResultSet rset = null;
bookID = request.getParameter("hiddenfield_id"); // 获取图书的编号
UserID = (String)session.getValue("UserID"); // 获得用户编号
if(UserID == null || UserID.length() < 7)
{
throw new Exception("用户的ID号出错!");
}
else
{
UserID = UserID.trim();
bookID = bookID.trim();
try
{BuyNumber = Integer.parseInt(request.getParameter("textfield_count").trim());}
catch(Exception e)
{throw new Exception("请正确填写订购数量!");}
try
{prePrice = (Double.valueOf(request.getParameter("hiddenfield_price").trim())).doubleValue();}
catch(Exception e)
{throw new Exception("单价不正确!");}
sSQLCmd = "select Buynumber,Totalprice from orderlist where UserID='" + UserID + "' and BookID = '" + bookID + "'";
rset = DBexecuteBean.getTableRecords(sSQLCmd);
while(rset.next())
{
/* 首先检查此用户是否已经定了这本书 */
Oldbuynumber = rset.getInt(1);
Oldprice = rset.getDouble(2);
flag = true;
}
if(flag == true)
{
/* 如果已经定过此书,那么将总价和订购数量进行累加 */
BuyNumber = Oldbuynumber + BuyNumber;
NowPrice = BuyNumber * prePrice;
sSQLCmd = " update orderlist set UserID = '" + UserID + "',BookID ='" + bookID + "',BuyNumber = " + BuyNumber + ",TotalPrice = " + NowPrice + " where UserID='" + UserID + "' and BookID = '" + bookID + "'";
isOK = DBexecuteBean.doTSQL(sSQLCmd);
}
else
{
NowPrice = BuyNumber * prePrice;
sSQLCmd = " insert into OrderList(UserID,BookID,BuyNumber,TotalPrice) values('" + UserID + "','" + bookID + "',"+ BuyNumber + "," + NowPrice + ")";
isOK = DBexecuteBean.doTSQL(sSQLCmd);
}
if(isOK == 1)
{
out.println("<div align=\"center\"><font color=\"#6666FF\" size=\"5\" face=\"华文新魏\"><font size=\"+3\"><b><font size=\"6\">订购成功!</font></b></font></font></div>");
out.println("<br>您已经成功订购此书,请按“后退”按钮继续选择,或等待10秒钟,系统将显示您的临时购物篮...");
%>
<meta http-equiv="refresh" content="10;URL=http://127.0.0.1/chapter5/book/OrderList.jsp">
<%
}
else
{
throw new Exception("系统出现错误!");
}
}
%>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -