📄 purchase.java
字号:
package check;
import java.sql.*;
import java.util.Vector;
import check.*;
import javax.servlet.http.*;
import check.books;
import check.indentlist;
import check.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循环结束
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循环结束
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循环结束
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 + -