📄 dbuser.java
字号:
package com.laoer.bbscs.bbs.business;
import com.laoer.bbscs.db.*;
import com.laoer.bbscs.exception.ObjectException;
import com.laoer.bbscs.exception.ObjectNoExistException;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import java.util.List;
import java.sql.*;
import org.apache.log4j.*;
import java.io.*;
/**
* <p>Title: ��������V5.0</p>
* <p>Description: BBS-CS��������V5.0</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: laoer.com</p>
* @author ������
* @version 5.0
*/
public class DBUser
extends User
implements DBInf {
ResultSet rs = null;
String SQL = "";
static Logger logger = Logger.getLogger(DBUser.class.getName());
private static final String ISUSERNAME =
"select * from userinfo where UserName = ?";
private static final String ISUSERID = "select * from userinfo where ID = ?";
private static final String ISUSERPASSWD =
"select * from userinfo where UserName = ? and RePasswd = ?";
private static final String ISUSERPASSWD1 =
"select * from userinfo where UserName = ? and Passwd = ?";
private static final String ISUSEREMAIL =
"select * from userinfo where Email = ?";
private static final String LOAD_TOTAL =
"select count(ID) as total from userinfo";
private static final String ADDUSER = "insert into userinfo (ID,UserName,NickName,Passwd,RePasswd,Email,Question,Answer,LoginTime,LogoutTime,LoginTimes,Post,Exp,Expression,ArticleNum,StayTime,Nstaytime,Power,Hpower) values (?,?,?,?,?,?,?,?,?,?,0,0,0,0,0,0,0,10,10)";
private static final String UPDATEUSER = "update userinfo set NickName=?,Passwd=?,RePasswd=?,LoginTime=?,LogoutTime=?,LoginTimes=? where ID=?";
private static final String UPDATE_NICKNAME =
"update userinfo set NickName = ? where ID = ?";
private static final String UPDATE_PASSWD =
"update userinfo set Passwd=?,RePasswd=? where ID = ?";
private static final String UPDATE_USERDATA =
"update userinfo set Exp = ?,Power = ?,Hpower = ? where ID = ?";
private static final String UPDATE_USERSTAYTIME = "update userinfo set StayTime = StayTime + ?,LoginTime = ?,LogoutTime = ? where ID = ? ";
private static final String UPDATE_USERLOGIN = "update userinfo set Power = ?,LoginTime = ?,LoginTimes = LoginTimes + 1 where ID = ?";
private static final String UPDATE_USERLOGIN1 =
"update userinfo set Power = ?,LoginTime = ? where ID = ?";
private static final String UPDATE_USERSIGN = "update userinfo set Sign_Name1 = ?,Sign_Detail1 = ?,Sign_Name2 = ?,Sign_Detail2 = ?,Sign_Name3 = ?,Sign_Detail3 = ? where ID = ?";
private static final String UPDATE_USERFRIEND =
"update userinfo set Friend = ? where ID = ?";
private static final String UPDATE_BOARDSAVE =
"update userinfo set BoardSave = ? where ID = ?";
private static final String UPDATE_USERDATAPOST =
"update userinfo set Expression = ?,ArticleNum = ?,Power = ? where ID = ?";
private static final String UPDATE_USERPIC =
"update userinfo set HavePic = ?,PicFileName = ? where ID = ?";
private static final String UPDATE_CANINBOARDS =
"update userinfo set CanInBoards = ? where ID = ?";
public DBUser() {
}
public int createUser(TranContext aTranContext) {
TranContext myDB = null;
if (aTranContext == null) {
myDB = new TranContext();
}
else {
myDB = aTranContext;
}
try {
myDB.beginTrans();
UserDetail myUserDetail = UserDetailFactory.getInstance();
myUserDetail.setUserInfo(this.myUserInfo);
this.insertDB(myDB);
int result = myUserDetail.createUserDetail(myDB);
myDB.commit();
if (result != Sys.RESULT_RIGHT) {
myDB.roolback();
return Sys.RESULT_OBJECTEXCEPTION;
}
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
myDB.roolback();
return Sys.RESULT_OBJECTEXCEPTION;
}
catch (SQLException e) {
logger.error(e);
myDB.roolback();
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDB != null) {
myDB.freeCon();
}
}
}
public int getUser(TranContext aTranContext, String key, boolean isLoad) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.loadDB(myDBTrans, key, isLoad);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
catch (ObjectNoExistException e) {
return Sys.RESULT_OBJECTNOEXISTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public List getUserList(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
List alist = null;
alist = this.loadDBs(myDBTrans, key);
return alist;
}
catch (ObjectException e) {
logger.error(e);
return (List) Sys.RESULT_NULL;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int getUserNum(TranContext aTranContext, String key) {
String sSQL = "";
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
int total = 0;
if (key.equals("All")) {
myDBTrans.prepareStatement(LOAD_TOTAL);
rs = myDBTrans.executeQuery();
if (rs.next()) {
total = rs.getInt("total");
}
rs.close();
}
return total;
}
catch (SQLException e) {
logger.error(e);
return Sys.RESULT_ZERO;
}
finally {
try {
if (rs != null) {
rs.close();
}
}
catch (SQLException e) {
}
try {
if (myDBTrans != null) {
myDBTrans.close();
}
}
catch (SQLException e) {
}
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public String[] getUserLevel() {
String level = "";
int hpower = 0;
int exp = this.myUserInfo.getExp();
if (exp >= 0 && exp <= 10) {
hpower = 10;
level = "新手上路";
}
if (exp >= 11 && exp <= 50) {
hpower = 15;
level = "初出江湖";
}
if (exp >= 51 && exp <= 130) {
hpower = 20;
level = "一般站友";
}
if (exp >= 131 && exp <= 260) {
hpower = 30;
level = "中级站友";
}
if (exp >= 261 && exp <= 450) {
hpower = 40;
level = "高级站友";
}
if (exp >= 451 && exp <= 700) {
hpower = 50;
level = "老 站 友";
}
if (exp >= 701 && exp <= 1100) {
hpower = 60;
level = "青铜长老";
}
if (exp >= 1101 && exp <= 1900) {
hpower = 80;
level = "白银长老";
}
if (exp >= 1901 && exp <= 3000) {
hpower = 100;
level = "黄金长老";
}
if (exp >= 3001 && exp <= 4500) {
hpower = 120;
level = "白金长老";
}
if (exp >= 4501 && exp <= 6500) {
hpower = 140;
level = "钻石长老";
}
if (exp >= 6501 && exp <= 9000) {
hpower = 170;
level = "本站元老";
}
if (exp >= 9001) {
hpower = 200;
level = "开国大老";
}
this.myUserInfo.setHpower(hpower);
String[] olevel = {
level, String.valueOf(hpower)};
return olevel;
}
public int updateUser(TranContext aTranContext, String key) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
this.updateDB(myDBTrans, key);
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int setUserCanInBoards(TranContext aTranContext, String boardsID,
int inorout) {
TranContext myDBTrans = null;
if (aTranContext == null) {
myDBTrans = new TranContext();
}
else {
myDBTrans = aTranContext;
}
try {
if (inorout == 1) {
String uci = this.myUserInfo.getCanInBoards();
if ( ("," + uci).indexOf(boardsID) != -1) {
return Sys.RESULT_OBJECTEXIST;
}
uci = uci + boardsID + ",";
this.myUserInfo.setCanInBoards(uci);
this.updateDB(myDBTrans, "caninboards");
}
if (inorout == 2) {
String uci = this.myUserInfo.getCanInBoards();
if ( ("," + uci).indexOf(boardsID) != -1) {
uci = Util.replace(uci, boardsID + ",", "");
this.updateDB(myDBTrans, "caninboards");
}
}
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error(e);
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
if (aTranContext == null && myDBTrans != null) {
myDBTrans.freeCon();
}
}
}
public int userAtLongin() {
TranContext myDBTrans = new TranContext();
long nstaytime = Util.getaLongTime() - this.myUserInfo.getLogoutTime();
int hfpower = 0;
hfpower = (int) (this.myUserInfo.getHpower() * (nstaytime / 3600000) / 12);
int zpower = hfpower + this.myUserInfo.getPower();
if (zpower >= this.myUserInfo.getHpower()) {
hfpower = this.myUserInfo.getHpower() - this.myUserInfo.getPower(); // hpower - power;
}
this.myUserInfo.setPower(this.myUserInfo.getPower() + hfpower);
try {
if ( (Util.getaLongTime() - this.myUserInfo.getLogintime()) < 900000) {
this.updateDB(myDBTrans, "userLogin1");
}
else {
this.updateDB(myDBTrans, "userLogin");
}
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error("userAtLongin() Method Error:" + e.toString());
return Sys.RESULT_OBJECTEXCEPTION;
}
finally {
myDBTrans.freeCon();
}
}
public int userLongin() {
this.myUserInfo.setExp( (int) ( (this.myUserInfo.getLoginTimes() / 4) +
this.myUserInfo.getArticleNum() +
(this.myUserInfo.getStayTime() / 3600000) +
this.myUserInfo.getExpression()));
String[] olevel = getUserLevel();
this.myUserInfo.setHpower(Integer.parseInt(olevel[1]));
TranContext DBSQL = new TranContext();
try {
if (!this.myUserInfo.getIsGuest()) {
this.updateDB(DBSQL, "updateUserData");
}
return Sys.RESULT_RIGHT;
}
catch (ObjectException e) {
logger.error("userLongin() Method Error:" + e.toString());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -