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

📄 bsuserinfo.java

📁 一个网上购书系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				+ "' " + "and password='" + password + "' ";
		v = dbconn.ListOfMapData(sql);
		if (v.size() > 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 将商品(图书)加入购物车
	 * 
	 * @param userId
	 * @param bookId
	 * @throws SQLException
	 * @throws IOException
	 */
	public void addBookToCart(String userId, String bookId)
			throws SQLException, IOException {
		String sql = "";
		String sumPrice = "0";
		String seaPrice = "0";
		String isbn  = null;
		String name = null;
		// String saleNumber = "0";
		int number = 0;
		Vector bookVec = bookinfo.getBookById(bookId);
		if (bookVec.size() > 0) {
			Map map = (Map) bookVec.get(0);
			seaPrice = (String) map.get("seaPrice");
			isbn = (String)map.get("bookNumber");
			number = number + 1;
			sumPrice = String.valueOf(Integer.parseInt(seaPrice) * number);
			name = (String)map.get("bookName");
		}
		// 检测userid,bookid相对应的购物记录是否已存在
		if (loadCartByUseridBookid(userId, bookId, "01")) {
			double dd = Double.parseDouble(sumPrice);
			sql = "update cart_manager set number=number+1,sumPrice=sumPrice+"
					+ dd + ",cartDate='" + StringUtil.genDateTimeString()
					+ "' where userId='" + userId + "' " + "and bookId='"
					+ bookId + "' ";
		} else {
			sql = "insert into cart_manager(userId,bookId,productType,number,sumPrice,cartDate,isbn,name) "
					+ "VALUES('"
					+ userId
					+ "','"
					+ bookId
					+ "','01','"
					+ number
					+ "','"
					+ sumPrice
					+ "',"
					+ "'"
					+ StringUtil.genDateTimeString() + "','"+isbn+"','"+name+"')";
		}
		// sql1 = "update book_info set
		// saleNumber='"+saleNumber+"',stockNumber=stockNumber-1 " +
		// " where id='"+bookId+"' ";
		dbconn.execute(sql);
		// dbconn.execute(sql1);
	}

	/**
	 * 将商品(图书)加入购物车
	 * 
	 * @param userId
	 * @param bookId
	 * @param bookNumber
	 * @throws SQLException
	 * @throws IOException
	 */
	public void addBookTOCart(String userId, String bookId, String bookNumber)
			throws SQLException, IOException {
		String sql = "";
		String sumPrice = "0";
		String seaPrice = "0";
		String isbn  = null;
		String name = null;
		int number = Integer.parseInt(bookNumber);
		Vector bookVec = bookinfo.getBookById(bookId);
		if (bookVec.size() > 0) {
			Map map = (Map) bookVec.get(0);
			seaPrice = (String) map.get("seaPrice");
			isbn = (String)map.get("bookNumber");
			name = (String)map.get("bookName");
			sumPrice = String.valueOf(Integer.parseInt(seaPrice) * number);
		}
		// 检测userid,bookid相对应的购物记录是否已存在
		if (loadCartByUseridBookid(userId, bookId, "01")) {
			double dd = Double.parseDouble(sumPrice);
			sql = "update cart_manager set number=" + number + ",sumPrice="
					+ dd + ",cartDate='" + StringUtil.genDateTimeString()
					+ "' where userId='" + userId + "' " + "and bookId='"
					+ bookId + "' and productType='01'";
		} else {
			sql = "insert into cart_manager(userId,bookId,productType,number,sumPrice,cartDate,isbn,name) "
					+ "VALUES('"
					+ userId
					+ "','"
					+ bookId
					+ "','01','"
					+ number
					+ "','"
					+ sumPrice
					+ "',"
					+ "'"
					+ StringUtil.genDateTimeString() + "','"+isbn+"','"+name+"')";
		}
		dbconn.execute(sql);
	}

	public void cleanCart(String userId) {
		String sql = "delete from cart_manager where userId = " + userId;
		try {
			dbconn.execute(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void cleanCartByCartId(String cartId) {
		String sql = "delete from cart_manager where cartId = " + cartId;
		try {
			dbconn.execute(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据ID找到相应的前台用户对象
	 * 
	 * @param userid
	 * @return Vector
	 * @throws SQLException
	 * @throws IOException
	 */
	public Vector getUserInfoByUserid(String userid) throws SQLException,
			IOException {
		Vector v = null;
		String sql = "";
		sql = "select * from common_user_info where userId ='" + userid + "' ";
		v = dbconn.ListOfMapData(sql);
		return v;
	}

	/**
	 * 列出某用户的购物列表
	 * 
	 * @param userid
	 * @return Vector
	 * @throws SQLException
	 * @throws IOException
	 */
	public Vector getCartInfoByUserid(String userid) throws SQLException,
			IOException {
		Vector v = null;
		String sql = "";
		sql = "select * from cart_manager where userId ='" + userid + "' ";
		v = dbconn.ListOfMapData(sql);
		return v;
	}

	/**
	 * 删除购物记录
	 * 
	 * @param id
	 * @throws SQLException
	 * @throws IOException
	 */
	public void deleteCartInfo(String id,String typeId) throws SQLException, IOException {
		String sql = "";
		sql = "delete from cart_manager where cartId = '" + id + "' and productType='"+typeId+"'";
		dbconn.execute(sql);
	}

	/**
	 * 检测userid,bookid相对应的购物记录是否已存在
	 * 
	 * @param userid
	 * @param bookid
	 * @return boolean
	 * @throws SQLException
	 * @throws IOException
	 */
	public boolean loadCartByUseridBookid(String userid, String bookid,
			String typeId) throws SQLException, IOException {
		Vector v = null;
		boolean flag = false;
		String sql = "";
		sql = "select * from cart_manager where userId ='" + userid + "' "
				+ "and bookId='" + bookid + "' and productType='" + typeId
				+ "'";
		v = dbconn.ListOfMapData(sql);
		if (v.size() > 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 列出所有的前台用户
	 * 
	 * @return Vector
	 * @throws SQLException
	 * @throws IOException
	 */
	public Vector getAllCommonUser() throws SQLException, IOException {
		Vector v = null;
		String sql = "";
		sql = "select * from common_user_info order by  registerDate desc ";
		v = dbconn.ListOfMapData(sql);
		return v;
	}

	public void addMusicTOCart(String userId, String bookId, String bookNumber)
			throws SQLException, IOException {
		String sql = "";
		String sumPrice = "0";
		String seaPrice = "0";
		String isbn = null;
		String name = null;
		int number = Integer.parseInt(bookNumber);
		Vector bookVec = musicinfo.getMusicById(bookId);
		if (bookVec.size() > 0) {
			Map map = (Map) bookVec.get(0);
			seaPrice = (String) map.get("price");
			isbn = (String) map.get("isbn");
			name = (String) map.get("tradeName");
			sumPrice = String.valueOf(Integer.parseInt(seaPrice) * number);
		}
		// 检测userid,bookid相对应的购物记录是否已存在
		if (loadCartByUseridBookid(userId, bookId, "02")) {
			double dd = Double.parseDouble(sumPrice);
			sql = "update cart_manager set number=" + number + ",sumPrice="
					+ dd + "," + "cartDate='" + StringUtil.genDateTimeString()
					+ "' where userId='" + userId + "' " + "and bookId='"
					+ bookId + "' and productType='02'";
		} else {
			sql = "insert into cart_manager(userId,bookId,productType,number,sumPrice,cartDate,isbn,name) "
					+ "VALUES('"
					+ userId
					+ "','"
					+ bookId
					+ "','02','"
					+ number
					+ "','"
					+ sumPrice
					+ "',"
					+ "'"
					+ StringUtil.genDateTimeString() + "','"+isbn+"','"+name+"')";
		}
		dbconn.execute(sql);
	}

	public void addMovieTOCart(String userId, String bookId, String bookNumber)
			throws SQLException, IOException
	{
		String sql = "";
		String sumPrice = "0";
		String seaPrice = "0";
		String isbn = null;
		String name = null;
		int number = Integer.parseInt(bookNumber);
		Vector bookVec = movieinfo.getMovieById(bookId);
		if (bookVec.size() > 0) {
			Map map = (Map) bookVec.get(0);
			seaPrice = (String) map.get("price");
			isbn = (String) map.get("isbn");
			name = (String) map.get("tradeName");
			sumPrice = String.valueOf(Integer.parseInt(seaPrice) * number);
		}
		// 检测userid,bookid相对应的购物记录是否已存在
		if (loadCartByUseridBookid(userId, bookId, "03")) {
			double dd = Double.parseDouble(sumPrice);
			sql = "update cart_manager set number=" + number + ",sumPrice="
					+ dd + "," + "cartDate='" + StringUtil.genDateTimeString()
					+ "' where userId='" + userId + "' " + "and bookId='"
					+ bookId + "' and productType='03'";
		} else {
			sql = "insert into cart_manager(userId,bookId,productType,number,sumPrice,cartDate,isbn,name) "
					+ "VALUES('"
					+ userId
					+ "','"
					+ bookId
					+ "','03','"
					+ number
					+ "','"
					+ sumPrice
					+ "',"
					+ "'"
					+ StringUtil.genDateTimeString() + "','"+isbn+"','"+name+"')";
		}
		dbconn.execute(sql);
	}
	
	public Vector getCartById(String cartId) throws SQLException
	{
		String sql = "select * from cart_manager where cartId ='" + cartId + "' ";
		Vector v = dbconn.ListOfMapData(sql);
		return v;
	}
	
	public Vector getCommodityByUserId(String userId) throws SQLException
	{
		Vector v = null;
		String sql = "";
		sql = "select * from cart_manager where userId="+userId+"  order by  cartDate desc ";
		v = dbconn.ListOfMapData(sql);
		return v;
	}
	
}

⌨️ 快捷键说明

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