?? bsuserinfo.java
字號:
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 + -