package com.mss.user.javabeans;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import com.mss.common.DBClasses;
public class UserManage {
private String username = null;
private String password = null;
private String email = null;
private String qq = null;
private String grade = null;
public UserManage() {
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getPassword() {
return password;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getQq() {
return qq;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
/**
* @功能 只根据用户名检查用户是否存在
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
public static ResultSet checkUserName(String userName) throws SQLException {
String strSql="select username, password, grade from user where username='"+userName+"'";
ResultSet rs = DBClasses.getRs(strSql);
return rs;
}
/**
* @功能 检查用户是否存在,成功返回true,失败返回false
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
public static boolean checkUser(String username, String password)
throws Exception {
String strSql;
ResultSet rs;
strSql = "select * from user where username='" + username
+ "' and password='" + password + "'";
rs = DBClasses.getRs(strSql);
if (rs.next()) {
return true;
} else {
return false;
}
}
/**
* @功能 向数据库中插入新的用户信息 成功返回true,失败返回false
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
public boolean insert() throws Exception {
String sql = "insert into user(username, password, email,qq) values('"
+ username + "','" + password + "','" + email + "','" + qq
+ "'" + ")";
if (DBClasses.sqlExcute(sql) == true) {
return true;
} else {
return false;
}
}
/**
* @功能 根据用户名得到此用户的权限,如果这个用户存在,
* 就返回他的权限
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
public static String getUserGrade(String username) throws Exception {
String strSql;
ResultSet rs;
strSql = "select * from user where username='" + username + "'";
rs = DBClasses.getRs(strSql);
if (rs.next()) {
return rs.getString("grade");
} else {
return null;
}
}
/**
* @功能 检查用户名进行模糊查找,打到用户后返回用户信息
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
@SuppressWarnings("unchecked")
public static Vector search(String username) throws Exception {
Vector Users = new Vector();
ResultSet rs;
String strSql = null;
strSql = "select * from user where username like '%" + username + "%'";
rs = DBClasses.getRs(strSql);
while (rs.next()) {
UserManage user = new UserManage();
user.setUsername(rs.getString("username"));
user.setGrade(rs.getString("grade"));
Users.add(user);
}
return Users;
}
/**
* @功能根据用户名进行精确查找,关保存在Vector对象中,并返回
* @param strSql 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
@SuppressWarnings("unchecked")
public static Vector searchUsers() throws Exception {
Vector userVector = new Vector();
ResultSet rs;
String strSql = null;
strSql = "select * from user";
rs = DBClasses.getRs(strSql);
while (rs.next()) {
UserManage user = new UserManage();
user.setUsername(rs.getString("username"));
user.setGrade(rs.getString("grade"));
userVector.add(user);
}
return userVector;
}
/**
* @功能 根据用户名删除用户 成功返回true,失败返回false
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.17
* @班级:软件工程四班
*/
public static boolean delete(String username) throws Exception {
String strSql;
strSql = "delete from user where username='" + username + "'";
if (DBClasses.sqlExcute(strSql) == true) {
return true;
} else {
return false;
}
}
/**
* @功能 根据用户名修改密码 成功返回true,失败返回false
* @param strSql
* 查询语句
* @author 魏兴强
* @时间 2010.4.19
* @班级:软件工程四班
*/
public static boolean changePwd(String username,String newPwd) throws Exception {
String strSql;
strSql = "update user set password='" +newPwd+"' where username='" +username+ "'" ;
if(DBClasses.sqlExcute(strSql)) {
return true;
} else {
return false;
}
}
}