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

📄 dbadminuser.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 JAVA
字号:
package com.laoer.bbscs.bbs.business;

import java.util.List;
import java.sql.*;
import com.laoer.bbscs.db.*;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import com.laoer.bbscs.exception.ObjectException;
import com.laoer.bbscs.exception.ObjectNoExistException;
import org.apache.log4j.*;
/**
 * <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 DBAdminUser
    extends AdminUser
    implements DBInf {

  ResultSet rs = null;
  static Logger logger = Logger.getLogger(DBAdminUser.class.getName());

  static final String INSERT_ADMINUSER =
      "insert into adminuser (UserID,Uname) values (?,?)";
  static final String LOAD_ADMINUSER =
      "select * from adminuser where Uname = ?";
  static final String LOAD_ADMINUSER_BYID =
      "select * from adminuser where UserID = ?";
  static final String LOAD_ADMINUSERS = "select * from adminuser ";
  static final String UPDATE_ADMINUSER = "update adminuser set SuperAdmin = ?,Manager = ?,Board = ?,Bulletin = ?,UserAdmin = ? where UserID = ?";
  static final String DELETE_ADMINUSER =
      "delete from adminuser where UserID = ?";

  public DBAdminUser() {
  }

  public int getAdminUser(TranContext aTranContext, String key) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.loadDB(myDBTrans, key, true);
      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 int createAdminUser(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      UserInfo aUserInfo = new UserInfo();
      aUserInfo.setUserName(this.myAdminUserInfo.getUname());
      User aUser = UserFactory.getInstance();
      aUser.setUserInfo(aUserInfo);
      int result = aUser.getUser(myDBTrans, "UserName", true);
      if (result != Sys.RESULT_RIGHT) {
        return Sys.RESULT_OBJECTNOEXISTEXCEPTION;
      }
      this.myAdminUserInfo.setUserID(aUser.getUserInfo().getID());
      result = this.getAdminUser(myDBTrans, "Name");
      if (result == Sys.RESULT_OBJECTNOEXISTEXCEPTION) {
        this.insertDB(myDBTrans);
        return Sys.RESULT_RIGHT;
      }
      else {
        return Sys.RESULT_OBJECTEXIST;
      }
    }
    catch (ObjectException e) {
      logger.error(e);
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public int updateAdminUser(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.updateDB(myDBTrans, "ID");
      return Sys.RESULT_RIGHT;
    }
    catch (ObjectException e) {
      logger.error(e);
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public List getAdminUserList(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    List alist = null;
    try {
      alist = this.loadDBs(myDBTrans, "All");
      return alist;
    }
    catch (ObjectException e) {
      logger.error(e);
      return (List) Sys.RESULT_NULL;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public void loadDB(TranContext myDB, String key, boolean isLoad) throws
      ObjectException, ObjectNoExistException {
    try {
      if (key.equals("ID")) {
        myDB.prepareStatement(LOAD_ADMINUSER_BYID);
        myDB.setLong(1, this.myAdminUserInfo.getUserID());
      }
      if (key.equals("Name")) {
        myDB.prepareStatement(LOAD_ADMINUSER);
        myDB.setString(1, this.myAdminUserInfo.getUname());
      }
      rs = myDB.executeQuery();
      if (rs.next()) {
        if (isLoad) {
          this.myAdminUserInfo.setUserID(rs.getLong("UserID"));
          this.myAdminUserInfo.setUname(rs.getString("Uname"));
          this.myAdminUserInfo.setSuperAdmin(rs.getInt("SuperAdmin"));
          this.myAdminUserInfo.setManager(rs.getInt("Manager"));
          this.myAdminUserInfo.setBoard(rs.getInt("Board"));
          this.myAdminUserInfo.setBulletin(rs.getInt("Bulletin"));
          this.myAdminUserInfo.setUserAdmin(rs.getInt("UserAdmin"));
        }
      }
      else {
        throw new ObjectNoExistException();
      }
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
          rs = null;
        }
      }
      catch (SQLException e) {
      }
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public List loadDBs(TranContext myDB, String key) throws ObjectException {
    List avct = ListFactory.getInstance(2);
    AdminUserInfo aAdminUserInfo = null;
    try {
      if (key.equals("All")) {
        myDB.prepareStatement(LOAD_ADMINUSERS);
        rs = myDB.executeQuery();
      }
      while (rs.next()) {
        aAdminUserInfo = new AdminUserInfo();
        aAdminUserInfo.setUserID(rs.getLong("UserID"));
        aAdminUserInfo.setUname(rs.getString("Uname"));
        aAdminUserInfo.setSuperAdmin(rs.getInt("SuperAdmin"));
        aAdminUserInfo.setManager(rs.getInt("Manager"));
        aAdminUserInfo.setBoard(rs.getInt("Board"));
        aAdminUserInfo.setBulletin(rs.getInt("Bulletin"));
        aAdminUserInfo.setUserAdmin(rs.getInt("UserAdmin"));
        avct.add(aAdminUserInfo);
      }
      return avct;
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
          rs = null;
        }
      }
      catch (SQLException e) {
      }
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public void insertDB(TranContext myDB) throws ObjectException {
    try {
      myDB.prepareStatement(INSERT_ADMINUSER);
      myDB.setLong(1, this.myAdminUserInfo.getUserID());
      myDB.setString(2, this.myAdminUserInfo.getUname());
      myDB.executeUpdate();
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public void updateDB(TranContext myDB, String key) throws ObjectException {
    try {
      if (key.equals("ID")) {
        myDB.prepareStatement(UPDATE_ADMINUSER);
        myDB.setInt(1, this.myAdminUserInfo.getSuperAdmin());
        myDB.setInt(2, this.myAdminUserInfo.getManager());
        myDB.setInt(3, this.myAdminUserInfo.getBoard());
        myDB.setInt(4, this.myAdminUserInfo.getBulletin());
        myDB.setInt(5, this.myAdminUserInfo.getUserAdmin());
        myDB.setLong(6, this.myAdminUserInfo.getUserID());
        myDB.executeUpdate();
      }
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public void delDB(TranContext myDB, String key) throws ObjectException {
    try {
      if (key.equals("ID")) {
        myDB.prepareStatement(DELETE_ADMINUSER);
        myDB.setLong(1, this.myAdminUserInfo.getUserID());
        myDB.executeUpdate();
      }
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

}

⌨️ 快捷键说明

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