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

📄 user.java

📁 BBS虚拟社区
💻 JAVA
字号:
package com.laoer.bbscs.user;import java.sql.*;import java.io.*;import java.util.*;import com.laoer.bbscs.db.*;import com.laoer.bbscs.txthtml.*;import com.laoer.bbscs.tool.MD5;/** * Title:        BBS-CS * Description:  BBS-CS(BBS式虚拟社区系统) * Copyright:    Copyright (c) 2002 * Company:      loveroom.com.cn * @author laoer * @version 3.0 */public class User {  String SQL = "";  DbTrans myDbTrans;  DoText myDoText;  ResultSet rs = null;  MD5 myMD5;  public User() {      this.myDbTrans = new DbTrans();      this.myDoText = new DoText();      this.myMD5 = new MD5();  }  public boolean isUser(String userName) {      boolean isUser = false;      int numIsUser = 0;      SQL = "select count(*) as numIsUser from user where name='"+ userName +"'";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              numIsUser = rs.getInt("numIsUser");          }          rs.close();      }      catch (SQLException e){      }      if (numIsUser != 0) {          isUser = true;      }      else {          isUser = false;      }      return isUser;  }  public boolean isUser(String userName, String userPassWD) {      boolean isUser = false;      int numIsUser = 0;      SQL = "select count(*) as numIsUser from user where name='"+ userName +"' and passwd1='"+ myMD5.getMD5ofStr(userPassWD) +"'";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              numIsUser = rs.getInt("numIsUser");          }          rs.close();      }      catch (SQLException e){      }      if (numIsUser != 0) {          isUser = true;      }      else {          isUser = false;      }      return isUser;  }  public String getUserID(String userName) {      String userID = "";      SQL = "select ID from user where name ='"+ userName +"'";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              userID = rs.getString("ID");          }          rs.close();      }      catch (SQLException e){      }      return userID;  }  public boolean isHaveEmail(String strEmailAdd) {      boolean isHaveEmail = false;      int numIsHaveEmail = 0;      SQL = "select count(*) as numIsHaveEmail from user where email='" + strEmailAdd + "'";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              numIsHaveEmail = rs.getInt("numIsHaveEmail");          }          rs.close();      }      catch (SQLException e){      }      if (numIsHaveEmail != 0) {          isHaveEmail = true;      }      else {          isHaveEmail = false;      }      return isHaveEmail;  }  public boolean addUser(String strName,String strNick,String strEmailAdd,String strPasswd,String strQuestion,String strAnswer) {      boolean addUser = false;      String strPasswd1 = "";      strPasswd1 = myMD5.getMD5ofStr(strPasswd);      SQL = "insert into user (name,nick,email,passwd,passwd1,question,answer,logintime) values ('"+ strName +"','"+ strNick +"','"+ strEmailAdd +"','"+ strPasswd +"','"+ strPasswd1 +"','"+ strQuestion +"','"+ strAnswer +"',now())";      try {          myDbTrans.executeUpdate(SQL);          addUser = true;      }      catch (SQLException e){          return false;      }      int intUID = 0;      SQL = "select ID from user where name = '"+ strName +"'";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              intUID = rs.getInt("ID");          }          else {              return false;          }          rs.close();      }      catch (SQLException e){      }      SQL = "insert into userdata (UID,power,hpower) values ('"+ intUID +"',10,10)";      try {          myDbTrans.executeUpdate(SQL);          addUser = true;      }      catch (SQLException e){          return false;      }      SQL = "insert into mydata (UID) values ('"+ intUID +"')";      try {          myDbTrans.executeUpdate(SQL);          addUser = true;      }      catch (SQLException e){          return false;      }      return addUser;  }  public boolean userLogin(String userName) {      String strUserID = getUserID(userName);      SQL = "select (UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(likai)) as nstaytime from user where ID="+ strUserID;      int nstaytime = 0;      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              nstaytime = rs.getInt("nstaytime");              nstaytime=nstaytime/3600;          }          rs.close();      }      catch (SQLException e){      }      SQL = "select power,hpower from userdata where UID="+ strUserID;      int power = 0;      int hpower = 0;      int hfpower = 0;      try {         rs = myDbTrans.executeQuery(SQL);         if (rs.next()) {            power=rs.getInt("power");	    hpower=rs.getInt("hpower");         }         rs.close();      }      catch (SQLException e){      }      hfpower = hpower*nstaytime/12;      int zpower = hfpower + power;      if (zpower >= hpower) {          hfpower = hpower - power;      }      SQL = "update userdata set nstaytime="+ nstaytime +",power=power+"+ hfpower +" where UID="+ strUserID;      try {          myDbTrans.executeUpdate(SQL);      }      catch (SQLException e){          return false;      }      SQL = "update user set logintime=now(),cishu=cishu+1 where ID="+ strUserID;      try {          myDbTrans.executeUpdate(SQL);      }      catch (SQLException e){          return false;      }      return true;  }  public int guestLogin() {      int guestID = getGuestMaxID();      while (!addGuest(guestID)) {          guestID = getGuestMaxID();      }      return guestID;  }  public int getGuestMaxID() {      int numMaxID = 1;      SQL = "select max(ID)+1 as numMaxID from guestuser";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              numMaxID = rs.getInt("numMaxID");          }          rs.close();          if (numMaxID == 0) {              numMaxID = 1;          }      }      catch (SQLException e) {      }      return numMaxID;  }  public boolean addGuest(int guestID) {      SQL = "insert into guestuser (ID,guestname,glogintime) values ('"+ guestID +"','Guest"+ guestID +"',now())";      try {          myDbTrans.executeQuery(SQL);          return true;      }      catch (SQLException e) {          return false;      }  }  public int getOlineUser() {      int numOlineUser = 0;      SQL = "select count(*) as numOlineUser from user WHERE (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(logintime))<=180";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              numOlineUser = rs.getInt("numOlineUser");          }          rs.close();      }      catch (SQLException e) {      }      return numOlineUser;  }  public void userRef(String strUserID) {      int staytime = 0;      SQL = "select (UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(logintime)) as tltime from user where ID="+ strUserID;      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              staytime = rs.getInt("tltime");          }          rs.close();      }      catch (SQLException e) {      }      SQL = "update userdata set staytime=staytime+"+ staytime +",nstaytime=0 where UID="+ strUserID;      try {          myDbTrans.executeUpdate(SQL);      }      catch (SQLException e) {      }      SQL = "update user set logintime=now(),likai=now() where ID="+ strUserID;      try {          myDbTrans.executeUpdate(SQL);      }      catch (SQLException e) {      }  }  public void guestRef(String strGuestID) {      SQL = "update guestuser set glogintime = now() where ID = "+strGuestID;      try {          myDbTrans.executeUpdate(SQL);      }      catch (SQLException e) {      }  }  public int getOlineGuest() {      int numOlineGuest = 0;      SQL = "select count(*) as numOlineGuest from guestuser WHERE (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(glogintime))<=180";      try {         rs = myDbTrans.executeQuery(SQL);         if (rs.next()) {             numOlineGuest = rs.getInt("numOlineGuest");         }         rs.close();      }      catch (SQLException e) {      }      return numOlineGuest;  }  public boolean isUnPost(String strUserName) {      int numIsUnPost = 0;      SQL = "select count(*) as numIsUnPost from unpost where (UNIX_TIMESTAMP(unposttime)-UNIX_TIMESTAMP(NOW()))>0 and Uname='"+strUserName+"'";      try {          rs = myDbTrans.executeQuery(SQL);          if (rs.next()) {              numIsUnPost = rs.getInt("numIsUnPost");          }          rs.close();      }      catch (SQLException e) {      }      if (numIsUnPost != 0) {          return true;      }      else {          return false;      }  }  public boolean setUserUnPost(String strUserID) {      SQL = "update user set post = 1 where ID="+strUserID;      try {          myDbTrans.executeUpdate(SQL);          return true;      }      catch (SQLException e) {          return false;      }  }  public boolean setUserPost(String strUserName) {      SQL = "update user set post = 0 where name='"+strUserName+"'";      try {          myDbTrans.executeUpdate(SQL);          return true;      }      catch (SQLException e) {          return false;      }  }  public void close() {      try {          myDbTrans.close();      }      catch (SQLException e){      }  }}

⌨️ 快捷键说明

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