?? purchase.java~1~
字號:
package org.pan.web;
import java.sql.*;
import java.util.Vector;
import org.pan.util.*;
import javax.servlet.http.*;
import org.pan.web.book.books;
import org.pan.web.book.indentlist;
import org.pan.web.book.indent;
public class purchase extends DataBase {
private javax.servlet.http.HttpServletRequest request; //建立頁面請求
private HttpSession session; //頁面的session;
private boolean sqlflag = true ; //對接收到的數據是否正確
private Vector purchaselist; //顯示圖書列表向量數組
private Vector my_indent; //訂購單列表
private Vector indent_list; //訂單清單列表
private int booknumber=0; //購書總數量
private float all_price=0; //購書總價錢
private boolean isEmpty=false; //庫中的書數量是否夠購買的數
private int leaveBook=0; //庫存數量
private String IndentNo = ""; //用戶訂單號
private boolean isLogin = true; //用戶是否登錄!
private int page = 1; //顯示的頁碼
private int pageSize=15; //每頁顯示的訂單數
private int pageCount =0; //頁面總數
private long recordCount =0; //查詢的記錄總數
public purchase() throws Exception{
super();
}
public Vector getPurchaselist() {
return purchaselist;
}
public Vector getIndent_list() {
return indent_list;
}
public Vector getMy_indent() {
return my_indent;
}
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 setIndentNo(String newIndentNo) {
IndentNo = newIndentNo;
}
public String getIndentNo() {
return IndentNo;
}
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 my_Book order by id";
return sqlStr;
}
public boolean addnew(HttpServletRequest newrequest){
request = newrequest;
String ID = request.getParameter("bookid");//獲取bookid參數
String Amount = request.getParameter("amount");//獲取amount參數
long bookid = 0;
int amount = 0;
try
{
bookid = Long.parseLong(ID);//轉化ID格式
amount = Integer.parseInt(Amount);//轉化Amount格式
}
catch (Exception e)
{
return false;
}
if (amount<1) return false;//如果amount參數小于1,則出錯
session = request.getSession(false);
if (session == null)
{
return false;
}
purchaselist = (Vector)session.getAttribute("shopcar");
sqlStr = "select leav_number from My_book where id=" + bookid;//查看數據庫中圖書剩余數量leav_number
try
{
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;
}
indentlist iList = new indentlist();
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++) {
indentlist itList= (indentlist) purchaselist.elementAt(i);
if ( iList.getBookNo() == itList.getBookNo() ) {
itList.setAmount(itList.getAmount() + iList.getAmount());
purchaselist.setElementAt(itList,i);
match = true;
break;
}
} // for循環(huán)結束
if (!match)
purchaselist.addElement(iList);
}
session.setAttribute("shopcar", purchaselist);
return true;
}
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 My_book where id=" + bookid;
try
{
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++) {
indentlist itList= (indentlist) purchaselist.elementAt(i);
if ( bookid == itList.getBookNo() ) {
itList.setAmount(amount);
purchaselist.setElementAt(itList,i);
break;
} //if name matches結束
} // for循環(huán)結束
return true;
}
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++) {
indentlist itList= (indentlist) purchaselist.elementAt(i);
if ( bookid == itList.getBookNo() ) {
purchaselist.removeElementAt(i);
break;
} //if name matches結束
} // for循環(huán)結束
return true;
}
public boolean payout(HttpServletRequest newrequest) throws Exception {
request = newrequest;
session = request.getSession(false);
if (session == null)
{
return false;
}
String Userid = (String) session.getAttribute("userid"); //取得用戶ID號
long userid=0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -