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

📄 op_buy.java

📁 java+javabean开发的一套网上购物系统.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package cdshop.run;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @Singer not attributable
 * @version 1.0
 */

import java.sql.*;
import java.util.Vector;
import cdshop.util.*;
import cdshop.cd.*;
import javax.servlet.http.*;
import java.util.*;
public class op_buy extends DataBase {

    private javax.servlet.http.HttpServletRequest request; //建立页面请求
    private HttpSession session; //页面的session;
    private boolean sqlflag = true; //对接收到的数据是否正确
    private Vector purchaselist; //显示CD列表向量数组
    private Vector allorder; //订购单列表
    private Vector order_list; //订单清单列表
    private int cdnumber = 0; //购买CD总数量
    private float all_price = 0; //购买CD总价钱
    private boolean isEmpty = false; //库中的CD数量是否够购买的数
    private int leavecd = 0; //库存数量
    private String orderId = ""; //用户订单号
    private boolean isLogin = true; //用户是否登录!
    private int page = 1; //显示的页码
    private int pageSize = 15; //每页显示的订单数
    private int pageCount = 0; //页面总数
    private long recordCount = 0; //查询的记录总数

    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 setLeavecd(int bknum) {
      leavecd = bknum;
    }
    public int getLeavecd() {
      return leavecd;
    }
    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 cd order by id";
      return sqlStr;
    }
    /**
     * 往购物车中添加选购的图书
     * @param newrequest
     * @return
     */
    public boolean addnew(HttpServletRequest newrequest) {
      request = newrequest;
      String ID = request.getParameter("cdid");
      String Amount = request.getParameter("amount");
      long cdid = 0;
      int amount = 0;
      try {
        cdid = 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 cd where id=" + cdid;
      try {
        DataBase db = new DataBase();
                  db.connect();
                  stmt = db.conn.createStatement ();

        rs = stmt.executeQuery(sqlStr);
        if (rs.next()) {
          if (amount > rs.getInt(1)) {
            leavecd = rs.getInt(1);
            isEmpty = true;
            return false;
          }
        }
        close();
      }
      catch (SQLException e) {
        return false;
      }

      allorder iList = new allorder();
      iList.setcdNo(cdid);
      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.getcdNo() == itList.getcdNo()) {
            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("cdid");
      String Amount = request.getParameter("amount");
      long cdid = 0;
      int amount = 0;
      try {
        cdid = 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 cd where id=" + cdid;
      try {
        DataBase db = new DataBase();
                  db.connect();
                  stmt = db.conn.createStatement ();

        rs = stmt.executeQuery(sqlStr);
        if (rs.next()) {
          if (amount > rs.getInt(1)) {
            leavecd = rs.getInt(1);
            isEmpty = true;
            return false;
          }
        }
        close();
      }
      catch (SQLException e) {
        return false;
      }
      for (int i = 0; i < purchaselist.size(); i++) {
        allorder itList = (allorder) purchaselist.elementAt(i);
        if (cdid == itList.getcdNo()) {
          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("cdid");
      long cdid = 0;
      try {
        cdid = 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 (cdid == itList.getcdNo()) {
          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) {
        //  System.out.print(e.getMessage());
          return false;
        }
      }
  System.out.println("f2");

⌨️ 快捷键说明

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