?? op_buy.java
字號(hào):
package bookshop.run;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.sql.*;
import java.util.Vector;
import bookshop.util.*;
import bookshop.book.*;
import javax.servlet.http.*;
import java.util.*;
public class op_buy extends DataBase {
private javax.servlet.http.HttpServletRequest request; //建立頁(yè)面請(qǐng)求
private HttpSession session; //頁(yè)面的session;
private boolean sqlflag = true; //對(duì)接收到的數(shù)據(jù)是否正確
private Vector purchaselist; //顯示圖書(shū)列表向量數(shù)組
private Vector allorder; //訂購(gòu)單列表
private Vector order_list; //訂單清單列表
private int booknumber = 0; //購(gòu)書(shū)總數(shù)量
private float all_price = 0; //購(gòu)書(shū)總價(jià)錢(qián)
private boolean isEmpty = false; //庫(kù)中的書(shū)數(shù)量是否夠購(gòu)買(mǎi)的數(shù)
private int leaveBook = 0; //庫(kù)存數(shù)量
private String orderId = ""; //用戶(hù)訂單號(hào)
private boolean isLogin = true; //用戶(hù)是否登錄!
private int page = 1; //顯示的頁(yè)碼
private int pageSize = 15; //每頁(yè)顯示的訂單數(shù)
private int pageCount = 0; //頁(yè)面總數(shù)
private long recordCount = 0; //查詢(xún)的記錄總數(shù)
Calendar date = Calendar.getInstance();
long time=date.getTimeInMillis();
public op_buy() {
super();
}
public Vector getPurchaselist() {
return purchaselist;
}
public Vector getOrder_list() {
return order_list;
}
public Vector getAllorder() {
return allorder;
}
public boolean getSqlflag() {
return sqlflag;
}
public void setIsEmpty(boolean flag) {
isEmpty = flag;
}
public boolean getIsEmpty() {
return isEmpty;
}
public void setLeaveBook(int bknum) {
leaveBook = bknum;
}
public int getLeaveBook() {
return leaveBook;
}
public void setOrderId(String newId) {
orderId = newId;
}
public String getOrderId() {
return orderId;
}
public void setIsLogin(boolean flag) {
isLogin = flag;
}
public boolean getIsLogin() {
return isLogin;
}
public int getPage() { //顯示的頁(yè)碼
return page;
}
public void setPage(int newpage) {
page = newpage;
}
public int getPageSize() { //每頁(yè)顯示的圖書(shū)數(shù)
return pageSize;
}
public void setPageSize(int newpsize) {
pageSize = newpsize;
}
public int getPageCount() { //頁(yè)面總數(shù)
return pageCount;
}
public void setPageCount(int newpcount) {
pageCount = newpcount;
}
public long getRecordCount() {
return recordCount;
}
public void setRecordCount(long newrcount) {
recordCount = newrcount;
}
public String getGbk(String str) {
try {
return new String(str.getBytes("ISO8859-1"));
}
catch (Exception e) {
return str;
}
}
public String getSql() {
sqlStr = "select id,classname from book order by id";
return sqlStr;
}
/**
* 往購(gòu)物車(chē)中添加選購(gòu)的圖書(shū)
* @param newrequest
* @return
*/
public boolean addnew(HttpServletRequest newrequest) {
request = newrequest;
String ID = request.getParameter("bookid");
String Amount = request.getParameter("amount");
long bookid = 0;
int amount = 0;
try {
bookid = 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");
sqlStr = "select leav_number from book where id=" + bookid;
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
if (rs.next()) {
if (amount > rs.getInt(1)) {
leaveBook = rs.getInt(1);
isEmpty = true;
return false;
}
}
rs.close();
}
catch (SQLException e) {
return false;
}
allorder iList = new allorder();
iList.setBookNo(bookid);
iList.setAmount(amount);
boolean match = false; //是否購(gòu)買(mǎi)過(guò)該圖書(shū)
if (purchaselist == null) { //第一次購(gòu)買(mǎi)
purchaselist = new Vector();
purchaselist.addElement(iList);
}
else { // 不是第一次購(gòu)買(mǎi)
for (int i = 0; i < purchaselist.size(); i++) {
allorder itList = (allorder) purchaselist.elementAt(i);
if (iList.getBookNo() == itList.getBookNo()) {
itList.setAmount(itList.getAmount() + iList.getAmount());
purchaselist.setElementAt(itList, i);
match = true;
break;
} //if name matches結(jié)束
} // for循環(huán)結(jié)束
if (!match)
purchaselist.addElement(iList);
}
session.setAttribute("shopcar", purchaselist);
return true;
}
/**
* 修改已經(jīng)放進(jìn)購(gòu)物車(chē)的數(shù)據(jù)
* @param newrequest
* @return
*/
public boolean modiShoper(HttpServletRequest newrequest) {
request = newrequest;
String ID = request.getParameter("bookid");
String Amount = request.getParameter("amount");
long bookid = 0;
int amount = 0;
try {
bookid = 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 book where id=" + bookid;
try {
DataBase db = new DataBase();
db.connect();
stmt = db.conn.createStatement ();
rs = stmt.executeQuery(sqlStr);
if (rs.next()) {
if (amount > rs.getInt(1)) {
leaveBook = rs.getInt(1);
isEmpty = true;
return false;
}
}
rs.close();
}
catch (SQLException e) {
return false;
}
for (int i = 0; i < purchaselist.size(); i++) {
allorder itList = (allorder) purchaselist.elementAt(i);
if (bookid == itList.getBookNo()) {
itList.setAmount(amount);
purchaselist.setElementAt(itList, i);
break;
} //if name matches結(jié)束
} // for循環(huán)結(jié)束
return true;
}
/**
*刪除購(gòu)物車(chē)中數(shù)據(jù)
* @param newrequest
* @return
*/
public boolean delShoper(HttpServletRequest newrequest) {
request = newrequest;
String ID = request.getParameter("bookid");
long bookid = 0;
try {
bookid = 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 (bookid == itList.getBookNo()) {
purchaselist.removeElementAt(i);
break;
} //if name matches結(jié)束
} // for循環(huán)結(jié)束
return true;
}
/**
* 提交購(gòu)物車(chē)
* @param newrequest
* @return
* @throws java.lang.Exception
*/
public boolean payout(HttpServletRequest newrequest) throws Exception {
request = newrequest;
session = request.getSession(false);
// System.out.print("f1");
if (session == null) {
return false;
}
String Userid = (String) session.getAttribute("userid"); //取得用戶(hù)ID號(hào)
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;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -