else { // 不是第一次购买
for (int i = 0; i < purchaselist.size(); i++) {
allorder itList = (allorder) purchaselist.elementAt(i);
if (iList.getcdNo() == itList.getcdNo()) {
itList.setAmount(itList.getAmount() + iList.getAmount());
purchaselist.setElementAt(itList, i);
match = true;
break;
} //if name matches结束
} // for循环结束
if (!match)
purchaselist.addElement(iList);
}
session.setAttribute("shopcar", purchaselist);
return true;
}
/**
* 修改已经放进购物车的数据
* @param newrequest
* @return
*/
public boolean modiShoper(HttpServletRequest newrequest) {
request = newrequest;
String ID = request.getParameter("cdid");
String Amount = request.getParameter("amount");
long cdid = 0;
int amount = 0;
try {
cdid = Long.parseLong(ID);
amount = Integer.parseInt(Amount);
}
catch (Exception e) {
return false;
}
if (amount < 1)
return false;
session = request.getSession(false);
if (session == null) {
return false;
}
purchaselist = (Vector) session.getAttribute("shopcar");
if (purchaselist == null) {
return false;
}
sqlStr = "select leav_number from cd where id=" + cdid;
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
if (rs.next()) {
if (amount > rs.getInt(1)) {
leavecd = rs.getInt(1);
isEmpty = true;
return false;
}
}
close();
}
catch (SQLException e) {
return false;
}
for (int i = 0; i < purchaselist.size(); i++) {
allorder itList = (allorder) purchaselist.elementAt(i);
if (cdid == itList.getcdNo()) {
itList.setAmount(amount);
purchaselist.setElementAt(itList, i);
break;
} //if name matches结束
} // for循环结束
return true;
}
/**
*删除购物车中数据
* @param newrequest
* @return
*/
public boolean delShoper(HttpServletRequest newrequest) {
request = newrequest;
String ID = request.getParameter("cdid");
long cdid = 0;
try {
cdid = Long.parseLong(ID);
}
catch (Exception e) {
return false;
}
session = request.getSession(false);
if (session == null) {
return false;
}
purchaselist = (Vector) session.getAttribute("shopcar");
if (purchaselist == null) {
return false;
}
for (int i = 0; i < purchaselist.size(); i++) {
allorder itList = (allorder) purchaselist.elementAt(i);
if (cdid == itList.getcdNo()) {
purchaselist.removeElementAt(i);
break;
} //if name matches结束
} // for循环结束
return true;
}
/**
* 提交购物车
* @param newrequest
* @return
* @throws java.lang.Exception
*/
public boolean payout(HttpServletRequest newrequest) throws Exception {
op_user opUser=new op_user();
request = newrequest;
session = request.getSession(false);
// System.out.print("f1");
if (session == null) {
return false;
}
String Userid = (String) session.getAttribute("userid"); //取得用户ID号
long userid = 0;
if (Userid == null || Userid.equals("")) {
isLogin = false;
return false;
}
else {
try {
userid = Long.parseLong(Userid);
}
catch (NumberFormatException e) {
// System.out.print(e.getMessage());
return false;
}
}
751com.cn
String TotalPrice = request.getParameter("totalprice");
float payPrice=(Float.parseFloat(TotalPrice))*opUser.getUserRate(Userid);
long timeInMillis = System.currentTimeMillis();
//System.out.println("f4");
sqlStr = "insert into orders (orderId,UserId,SubmitTime,ConsignmentTime,TotalPrice,content,IPAddress,IsPayoff,IsSales) values (";
orderId=""+timeInMillis;//以系统时间产生位移的订单编号
sqlStr = sqlStr + orderId + ",'";
sqlStr = sqlStr + userid + "',GETDATE(),GETDATE()+7,'";
sqlStr = sqlStr + payPrice + "','";
sqlStr = sqlStr + dataFormat.toSql(Content) + "','";
sqlStr = sqlStr + IP + "',1,1)";
// System.out.print(sqlStr);
//String setIdSql="udate orders set orderid=orderid+id where UserId = " + userid;
try {
stmt.execute(sqlStr);
//stmt.execute(setIdSql);
// sqlStr = "select max(id) from orders where UserId = " + userid;
// rs = stmt.executeQuery(sqlStr);
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>