package StudyBbs;
import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;
public class User {
private String username = null;
private String password = null;
private String nickname = null;
private String sex = null;
private String birthyear = null;
private String birthmonth = null;
private String birthday = null;
private String email = null;
private String mobile = null;
private String signiture = null;
private String grade = null;
private int score = 0;
public User(){}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getNickname() {
return nickname;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return sex;
}
public void setBirthyear(String birthyear) {
this.birthyear = birthyear;
}
public String getBirthyear() {
return birthyear;
}
public void setBirthmonth(String birthmonth) {
this.birthmonth = birthmonth;
}
public String getBirthmonth() {
return birthmonth;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getBirthday() {
return birthday;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMobile() {
return mobile;
}
public void setSigniture(String signiture) {
this.signiture = signiture;
}
public String getSigniture() {
return signiture;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getGrade() {
return grade;
}
public void setScore(int score) {
this.score = score;
}
public int getScore() {
return score;
}
public static boolean checkUser(DB db,String name,String psw) throws Exception{
String strSql;
ResultSet rs;
strSql = "select * from bbsuser where username='"
+ name + "' and password='" + psw + "'";
rs = db.OpenSql(strSql);
if ( rs.next()) {
return true;
}
else{
return false;
}
}
public boolean Insert(DB db) throws Exception{
String strSql;
strSql = "insert into bbsuser values('"
+ username +"','"
+ password +"','"
+ nickname +"','"
+ sex +"','"
+ birthyear +"','"
+ birthmonth+"','"
+ birthday +"','"
+ email +"','"
+ mobile +"','"
+ signiture +"','普通用户',10)";
if ( db.ExecSql(strSql)==0) {
return false;
}
else{
return true;
}
}
public static String getUserGrade(DB db,String name) throws Exception{
String strSql;
ResultSet rs;
strSql = "select * from bbsuser where username='"
+ name + "'";
rs = db.OpenSql(strSql);
if ( rs.next()) {
return rs.getString("usergrade");
}
else{
return null;
}
}
public static Vector Search(DB db ,String username) throws Exception{
Vector Users = new Vector();
ResultSet rs,rsNest;
String strSql=null;
strSql = "select * from bbsuser where username like '%" + username + "%'";
rs = db.OpenSql(strSql);
while (rs.next()){
User user = new User();
user.setUsername(rs.getString("username")) ;
user.setGrade(rs.getString("usergrade")) ;
Users.add(user);
}
return Users;
}
public static Vector SearchMaster(DB db) throws Exception{
Vector Users = new Vector();
ResultSet rs,rsNest;
String strSql=null;
strSql = "select * from bbsuser where usergrade = '斑竹'";
rs = db.OpenSql(strSql);
while (rs.next()){
User user = new User();
user.setUsername(rs.getString("username")) ;
user.setGrade(rs.getString("usergrade")) ;
Users.add(user);
}
return Users;
}
public static boolean Delete(DB db,String username) throws Exception{
String strSql;
strSql = "delete from bbsuser where username='"+username+"'";
if ( db.ExecSql(strSql)==0) {
return false;
}
else{
return true;
}
}
public static boolean Edit(DB db,String username,String grade,String sort) throws Exception{
String strSql;
strSql = "update bbsuser set usergrade='"+grade+"' where username='"+username+"'";
if ( db.ExecSql(strSql)==0) {
return false;
}
else{
if (!grade.equals("斑竹")){
strSql = "update sort set master='' where master='"+username+"'";
db.ExecSql(strSql);
}
return true;
}
}
}