购物车的源程序

2019-05-27 09:53:11于丽



 



//动作
if (request.getParameter("action")==null){
action="view";
}else{
action=request.getParameter("action");
}



 



//商品编号
if (request.getParameter("product_id")==null){
product_id=0;
}
else{
product_id=java.lang.Integer.parseInt(
 request.getParameter("product_id"));
}



int bbb;
bbb=1;



Integer num = new Integer(bbb);



//商店编号
session.putValue("shop_id",num);
//顾客username
session.putValue("guest_name","asp2001");
String guest_name=(String)session.getValue("guest_name");
Integer shop_id=(Integer)session.getValue("shop_id");
java.lang.String sql; 
java.sql.ResultSet rs;
if (action.compareTo("add")==0) {
sql="select cart_quantity from shop_cart where " 
+ "cart_shop_id=" + shop_id + " and cart_guest_id="" 
+ guest_name + "" and cart_product_id=" + product_id ;
rs = bka.executeQuery(sql);
if (rs.next()){
int cart_quantity;
cart_quantity=java.lang.Integer.parseInt(
 rs.getString("cart_quantity"))+1;
sql="update shop_cart set cart_quantity=" 
+ cart_quantity + " where cart_shop_id=" 
+ shop_id + " and cart_guest_id="" + guest_name 
+ "" and cart_product_id=" + product_id ;
rs = bka.executeQuery(sql);}
else
{
sql="insert into shop_cart (cart_shop_id,cart_guest_id,"
+"cart_product_id,cart_quantity) values ("" + shop_id 
+ "","" + guest_name + "","" + product_id + "",1)";
rs = bka.executeQuery(sql);
}
}
if (action.compareTo("clear")==0) {
sql="delete from shop_cart where cart_shop_id=" + shop_id 
+ " and cart_guest_id="" + guest_name + """;
rs = bka.executeQuery(sql);
}



 



if (action.compareTo("delete")==0) { 
sql="delete from shop_cart where cart_shop_id=" + shop_id 
+ " and cart_guest_id="" + guest_name + "" and cart_product_id=" 
+ product_id ;
rs = bka.executeQuery(sql);
}
%>
<div align="center"><center>
<table border="0" cellpadding="0" cellspacing="0" width="610" height="2">
<tr>
<td>
<form method="POST" action="shop_cart.jsp?action=update&
product_type=<%=product_type%>&curpage=<%=curpage%>">
<table border="0" cellpadding="0" cellspacing="0" width="610" height="2">