⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 op_buy.java~131~

📁 基于JSP的网上书店.功能较为全面 开发环境:sql server2000+tomcat+jdk
💻 JAVA~131~
📖 第 1 页 / 共 2 页
字号:
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
{

    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 = 10;              //每页显示的订单数
    private int pageCount = 0;              //页面总数
    private long recordCount = 0;           //查询的记录总数

    private ResultSet rs;
    public String sqlStr = "";

    Calendar date = Calendar.getInstance();
    long time=date.getTimeInMillis();



    public op_buy()
    {
        super();
    }

    public void finalize()
    {
        //super.finalize();
    }

    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");
        String szSoldPrice = request.getParameter("soldprice");
        long bookid = 0;
        int amount = 0;
        float fSoldPrice = 0;
        try
        {
            bookid = Long.parseLong(ID);
            amount = Integer.parseInt(Amount);
            fSoldPrice = Float.parseFloat(szSoldPrice);
        }
        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 = db.stmt.executeQuery(sqlStr);
            if (rs.next())
            {
                if (amount > rs.getInt(1))
                {
                    leaveBook = rs.getInt(1);
                    isEmpty = true;
                    return false;
                }
            }
            rs.close();
            db.finalize();
        }
        catch (SQLException e)
        {
            return false;
        }

        allorder iList = new allorder();
        iList.setBookNo(bookid);
        iList.setAmount(amount);
        iList.setSoldPrice(fSoldPrice);
        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 = db.stmt.executeQuery(sqlStr);
            if (rs.next())
            {
                if (amount > rs.getInt(1))
                {
                    leaveBook = rs.getInt(1);
                    isEmpty = true;
                    db.finalize();
                    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
    {
        //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)
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -