⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cartinfo.jsp

📁 JSP软件工程案例精解 书中的webStore例子源码
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.sql.*,java.lang.Double.*"%>
<%@include file="comm.jsp"%>

<html>
<body >
<div>
  <table>
     <tr>
	<td width="236" align=center valign=top><br> 
		<p ><a href=CustomerInfo.jsp?action=view>我的资料 </a></p>
		<p>商品信息
		<br>&nbsp;<a href="GoodsList.jsp?type=1">可用商品</a>
		</p>
		<p>我的购物车
		<br>&nbsp; <a href="CartInfo.jsp?action=view&type=1">未提交订单</a>
		<br>&nbsp; <a href="CartInfo.jsp?action=view&type=2">已提交订单</a>
		<br>&nbsp; <a href="CartInfo.jsp?action=view&type=3">已发货订单</a>
		</p>
		<p>帐单管理
		<br>&nbsp; <a href="CustomerBill.jsp?action=view&type=1">已汇款帐单</a>
		<br>&nbsp; <a href="CustomerBill.jsp?action=view&type=2">已确认帐单</a>
		</p>
		
	</td>

<%
String CustomerID=(String)session.getValue("user");
action=request.getParameter("action");
String Type=request.getParameter("type");
int iType=Integer.parseInt(Type);

if(CustomerID==null)
{%>
	<jsp:forward page="CustomerLogin.htm"/>
<%}

if(action.equals("insert"))
{
String GoodsID=request.getParameter("GoodsID");
String Price=request.getParameter("Price");

strSql="{call dbo.sp_InsertTransaction(?,?,?,?,?)}";
cstmt=conn.prepareCall(strSql);
cstmt.setString(1,"buy");
cstmt.setString(2,CustomerID);
cstmt.setInt(3,Integer.parseInt(GoodsID));
cstmt.setDouble(4,Double.parseDouble(Price));
cstmt.setInt(5,1);

cstmt.executeUpdate();
}

if(action.equals("checkout"))
{
//获得客户购物篮中商品的总价
strSql="{call dbo.sp_GetTransaction(?,?)}";
cstmt=conn.prepareCall(strSql);
cstmt.setString(1,CustomerID);
cstmt.setInt(2,4);
rs=cstmt.executeQuery();
rs.next();

//更新客户余额
strSql="{call dbo.sp_UpdateRemains(?,?,?,?)}";
cstmt=conn.prepareCall(strSql);
cstmt.registerOutParameter(4, java.sql.Types.INTEGER);
cstmt.setString(1,CustomerID);
cstmt.setDouble(2,rs.getDouble(1));
cstmt.setInt(3,2);

cstmt.executeUpdate();

int iR=cstmt.getInt(4);	
	if(iR==0){
		strSql="{call dbo.sp_UpdateTransactionByCus(?,?)}";
		cstmt=conn.prepareCall(strSql);
		cstmt.setString(1,CustomerID);
		cstmt.setInt(2,2);

		cstmt.executeUpdate();
	}
	else{
		out.print("<p align=center>余额不足,结帐失败</p>");
	}	

}

if(action.equals("del"))
{
String TransID=request.getParameter("TransID");

strSql="{call dbo.sp_DelTransaction(?)}";
cstmt=conn.prepareCall(strSql);
cstmt.setInt(1,Integer.parseInt(TransID));

cstmt.executeUpdate();
}

%>
	<td align=center valign=top>
	<p align=center>欢迎您:<%=CustomerID%></p>
<%
if(iType==1)
{
%>
	<form method="POST" action="CartInfo.jsp?action=checkout&type=2">
	<p align=left>未提交订单
<%
}
else if(iType==2)
{%>
	<p align=left>已提交订单
<%}
else if(iType==3)
{%>
	<p align=left>已发货订单
<%}
%>
	<table>
	  <tr bgcolor=#E9E9D1>
		<td width=50>交易ID</td>
		<td width=80>交易类型</td>
		<td width=70>商品ID</td>
		<td width=170>商品名</td>
		<td width=70>单价</td>
		<td width=60>数量</td>
		<td width=70>小计</td>
		<td width=70>操作时间</td>
	  </tr>
<%

//根据类型值获取订单信息
strSql="{call dbo.sp_GetTransaction(?,?)}";
cstmt=conn.prepareCall(strSql);
cstmt.setString(1,CustomerID);
cstmt.setInt(2,iType);

rs=cstmt.executeQuery();

while(rs.next())
{ 
%>
	  <tr bgcolor="#EAFfFff">
		<td><%=rs.getInt(1)%></td>
		<td><%=new String(rs.getString(2).getBytes("8859_1"),"gb2312")%></td>
		<td><%=rs.getInt(3)%></td>
		<td><%=new String(rs.getString(4).getBytes("8859_1"),"gb2312")%></td>
		<td><%=rs.getDouble(5)%></td>
		<td><%=rs.getInt(6)%></td>
		<td><%=rs.getDouble(7)%></td>
		<td><%=rs.getDate(8)%></td>
	     <% if(iType==1) {%>
		<td><a href="CartInfo.jsp?action=del&TransID=<%=rs.getInt(1)%>&type=1">删除</a></td>
	     <%}%>
	  </tr>
	<%}%>

	</table>
<%
if(iType==1)
{%>
	<table>
        	<p align=left><input type="submit" value=" 结帐 " name="B1"></p>
	</table>
	</form>
<%}%>	
	</td> 

<%	
rs.close();
cstmt.close();
conn.close();
%>
   </tr>
  </table>
 </div>
</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -