?? op_buy.java~1~
字號:
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.*;
public class op_buy extends DataBase {
private javax.servlet.http.HttpServletRequest request; //建立頁面請求
private HttpSession session; //頁面的session;
private boolean sqlflag = true; //對接收到的數據是否正確
private Vector purchaselist; //顯示圖書列表向量數組
private Vector allorder; //訂購單列表
private Vector order_list; //訂單清單列表
private int booknumber = 0; //購書總數量
private float all_price = 0; //購書總價錢
private boolean isEmpty = false; //庫中的書數量是否夠購買的數
private int leaveBook = 0; //庫存數量
private String orderId = ""; //用戶訂單號
private boolean isLogin = true; //用戶是否登錄!
private int page = 1; //顯示的頁碼
private int pageSize = 15; //每頁顯示的訂單數
private int pageCount = 0; //頁面總數
private long recordCount = 0; //查詢的記錄總數
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() { //顯示的頁碼
return page;
}
public void setPage(int newpage) {
page = newpage;
}
public int getPageSize() { //每頁顯示的圖書數
return pageSize;
}
public void setPageSize(int newpsize) {
pageSize = newpsize;
}
public int getPageCount() { //頁面總數
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;
}
/**
* 往購物車中添加選購的圖書
* @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; //是否購買過該圖書
if (purchaselist == null) { //第一次購買
purchaselist = new Vector();
purchaselist.addElement(iList);
}
else { // 不是第一次購買
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結束
} // 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("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結束
} // for循環結束
return true;
}
/**
*刪除購物車中數據
* @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結束
} // for循環結束
return true;
}
/**
* 提交購物車
* @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"); //取得用戶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());
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -