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

📄 bsuserinfo.java

📁 一个网上购书系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.bookstore.user;

import com.bookstore.db.DBSource;
import com.bookstore.BookStoreConst;
import com.bookstore.movie.BsMovieInfo;
import com.bookstore.music.BsMusicInfo;
import com.bookstore.util.StringUtil;
import com.bookstore.book.BsBookInfo;

import java.io.*;
import java.sql.SQLException;
import java.util.Vector;
import java.util.Map;

/**
 * Created on 2006-5-15
 * 
 * @author zhangh
 * 
 * Preferences - Java - Code Style - Code Templates
 */
public class BsUserInfo {
	DBSource dbconn = null;

	BsBookInfo bookinfo = null;

	BsMusicInfo musicinfo = null;

	BsMovieInfo movieinfo = null;

	public BsUserInfo(String pool) throws SQLException, IOException {
		dbconn = new DBSource();
		dbconn.Init(pool);
		if (pool == null)
			pool = BookStoreConst.BOOKSTORESPOOL;
		bookinfo = new BsBookInfo(pool);
		musicinfo = new BsMusicInfo(pool);
		movieinfo = new BsMovieInfo(pool);
	}

	// 添加后台用户
	public void insertAdminUser(String userName, String password, String popedom)
			throws SQLException, IOException {
		String sql = "";
		sql = "insert into admin_user_info(userName,password,popedom,registerDate) "
				+ "VALUES('"
				+ userName
				+ "','"
				+ password
				+ "','"
				+ popedom
				+ "','" + StringUtil.genDateString() + "')";

		dbconn.execute(sql);
	}

	/**
	 * 列出所有的后台用户
	 * 
	 * @return Vector
	 */
	public Vector getAdminUserInfo() throws SQLException, IOException {
		Vector v = null;
		String sql = "";
		sql = "select * from admin_user_info order by registerDate desc";

		v = dbconn.ListOfMapData(sql);

		return v;
	}

	/**
	 * 验证用户登录信息是否正确
	 * 
	 * @return
	 */
	public String loadAdminUser(String username, String password)
			throws SQLException, IOException {
		Vector v = null;
		String userId = "";
		String sql = "";
		sql = "select * from admin_user_info where userName ='" + username
				+ "' " + "and password='" + password + "' ";
		v = dbconn.ListOfMapData(sql);
		if (v.size() > 0) {
			Map map = (Map) v.get(0);
			userId = (String) map.get("userId");
		}
		return userId;
	}

	/*
	 * 修改后台用户信息
	 */
	public void modifyAdminUser(String userId, String userName,
			String password, String popedom) throws SQLException, IOException {
		String sql = "";
		sql = "update admin_user_info set userName = '" + userName + "', ";
		if (password.length() != 0) {
			sql = sql + "password='" + password + "',";
		}
		sql = sql + " popedom='" + popedom + "' where userId = '" + userId
				+ "' ";

		dbconn.execute(sql);
	}

	/**
	 * 删除后台用户
	 */
	public void deleteAdminUser(String userId) throws SQLException, IOException {
		String sql = "";
		sql = "delete from admin_user_info where userId = '" + userId + "' ";

		dbconn.execute(sql);
	}

	/**
	 * 检查管理员用户名是否已存在
	 * 
	 * @param username
	 *            String
	 * @return boolean
	 */
	public boolean loadAdminUserName(String username) throws SQLException,
			IOException {
		Vector v = null;
		boolean flag = false;
		String sql = "";
		sql = "select * from admin_user_info where userName ='" + username
				+ "' ";
		v = dbconn.ListOfMapData(sql);
		if (v.size() == 0) {
			flag = true;
		}
		return flag;
	}

	public void insertCommonUser(String userName, String password,
			String email, String request, String answer, String trueName,
			String sex, String address, String postcode, String birthday,
			String city, String area, String phone, String mobile)
			throws SQLException, IOException {
		String sql = "";
		sql = "insert into common_user_info(userName,password,email,request,answer,trueName,sex,"
				+ "address,postcode,birthday,city,area,phone,mobile,registerDate,ifAttestation,ifAction) "
				+ "VALUES('"
				+ userName
				+ "','"
				+ password
				+ "','"
				+ email
				+ "','"
				+ request
				+ "','"
				+ answer
				+ "','"
				+ trueName
				+ "'"
				+ ",'"
				+ sex
				+ "','"
				+ address
				+ "','"
				+ postcode
				+ "','"
				+ birthday
				+ "','"
				+ city
				+ "','"
				+ area
				+ "'"
				+ ",'"
				+ phone
				+ "','"
				+ mobile
				+ "','"
				+ StringUtil.genDateTimeString()
				+ "','02','02')";

		dbconn.execute(sql);
	}

	/**
	 * 检查用户名是否已存在
	 * 
	 * @param username
	 *            String
	 * @return boolean
	 */
	public boolean loadCommonUserName(String username) throws SQLException,
			IOException {
		Vector v = null;
		boolean flag = false;
		String sql = "";
		sql = "select * from common_user_info where userName ='" + username
				+ "' ";
		v = dbconn.ListOfMapData(sql);
		if (v.size() == 0) {
			flag = true;
		}
		return flag;
	}

	/**
	 * 根据用户名找到相应的用户ID
	 * 
	 * @param username
	 * @return String
	 * @throws SQLException
	 * @throws IOException
	 */
	public String getUserIdByName(String username) throws SQLException,
			IOException {
		Vector v = null;
		String userid = "";
		String sql = "";
		sql = "select * from common_user_info where userName ='" + username
				+ "' ";
		v = dbconn.ListOfMapData(sql);
		if (v != null && v.size() > 0) {
			Map map = (Map) v.get(0);
			userid = (String) map.get("userId");
		}
		return userid;
	}

	/**
	 * 根据用户ID找到用户邮箱
	 * 
	 * @param userid
	 * @return String
	 * @throws SQLException
	 * @throws IOException
	 */
	public String getEmailByUserid(String userid) throws SQLException,
			IOException {
		Vector v = null;
		String email = "";
		String sql = "";
		sql = "select * from common_user_info where userId ='" + userid + "' ";
		v = dbconn.ListOfMapData(sql);
		if (v != null && v.size() > 0) {
			Map map = (Map) v.get(0);
			email = (String) map.get("email");
		}
		return email;
	}

	/**
	 * 激活前台会员的账号
	 * 
	 * @param userId
	 * @throws SQLException
	 * @throws IOException
	 */
	public void modifyIfAction(String userId) throws SQLException, IOException {
		String sql = "";
		sql = "update common_user_info set ifAction = '01'  where userId = '"
				+ userId + "' ";
		dbconn.execute(sql);
	}

	/**
	 * 根据用户ID找到用户注册时间
	 * 
	 * @param userid
	 * @return String
	 * @throws SQLException
	 * @throws IOException
	 */
	public String getRegisterDateByUserid(String userid) throws SQLException,
			IOException {
		Vector v = null;
		String registerDate = "";
		String sql = "";
		sql = "select * from common_user_info where userId ='" + userid + "' ";
		v = dbconn.ListOfMapData(sql);
		if (v != null && v.size() > 0) {
			Map map = (Map) v.get(0);
			registerDate = (String) map.get("registerDate");
		}
		return registerDate;
	}

	/**
	 * 删除前台会员名
	 * 
	 * @param userId
	 * @throws SQLException
	 * @throws IOException
	 */
	public void deleteCommonUser(String userId) throws SQLException,
			IOException {
		String sql = "";
		sql = "delete from common_user_info where userId = '" + userId + "' ";
		dbconn.execute(sql);
	}

	/**
	 * 验证前台用户登录是否成功
	 * 
	 * @param username
	 * @param password
	 * @return
	 * @throws SQLException
	 * @throws IOException
	 */
	public boolean loadCommonUser(String username, String password)
			throws SQLException, IOException {
		Vector v = null;
		boolean flag = false;
		String sql = "";
		sql = "select * from common_user_info where userName ='" + username

⌨️ 快捷键说明

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