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

📄 dbboards.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.laoer.bbscs.bbs.business;

import com.laoer.bbscs.db.*;
import java.util.List;
import java.util.Hashtable;
import com.laoer.bbscs.exception.ObjectException;
import com.laoer.bbscs.exception.ObjectNoExistException;
import java.sql.*;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import org.apache.log4j.*;
import java.io.*;
import com.laoer.bbscs.servlet.*;

/**
 * <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 DBBoards
    extends Boards
    implements DBInf {

  ResultSet rs = null;
  String SQL = "";
  static Logger logger = Logger.getLogger(DBBoards.class.getName());

  static final String LOAD_BOARDS = "select * from boards where ID = ?";
  static final String LOAD_ALLBOARDS = "select * from boards";
  static final String LOAD_BOARDS_BYBID =
      "select * from boards where BoardID = ? order by Orders";
  static final String LOAD_BOARDS_ELITE =
      "select * from boards where BoardID = ? and UseStat = 1 and Attrib3 = 0 order by Orders";
  static final String LOAD_BOARDS_BYNAME =
      "select * from boards where BoardsName = ?";
  static final String LOAD_BOARDS_TOTAL =
      "select count(*) from boards where Attrib3 = 0";
  static final String LOAD_BOARS_ORDERBYNUM =
      "select * from boards where Attrib3 = 0 order by MainPostNum,PostNum";
  static final String INSERT_BOARDS = "insert into boards (ID,BoardID,BoardsName,BoardsEName,MainMaster,AssiMaster,HideMaster,Explains,Bulletin,UseStat,Orders,MainPostNum,PostNum,Pic,Attrib1,Attrib2,Attrib3,Attrib4,Attrib5,Attrib6,Attrib7,Attrib8,Attrib9,Attrib10,UserCanIn) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  static final String UPDATE_BOARDS = "update boards set BoardsName=?,BoardsEName=?,MainMaster=?,AssiMaster=?,HideMaster=?,"
      +
      "Explains=?,Bulletin=?,UseStat=?,Orders=?,Pic=?,Attrib1=?,Attrib2=?,Attrib3=?,"
      + "Attrib4=?,Attrib5=?,Attrib6=?,Attrib7=?,Attrib8=?,Attrib9=?,Attrib10=? where ID = ?";
  static final String UPDATE_BOARDS_LASTPOST = "update boards set LastPostTitle=?,LastPostID=?,LastPostUser=?,LastPostUserID=?,"
      + "LastPostTime=? where ID = ?";
  static final String UPDATE_BOARDS_POSTNUM =
      "update boards set MainPostNum=?,PostNum=? where ID = ? ";
  static final String DELETE_BOARDS = "delete from boards where ID = ?";
  static final String LOAD_ORDERS =
      "select max(Orders)+5 as orders from boards where BoardID = ?";
  static final String UPDATE_BOARDS_POSTMNUM =
      "update boards set MainPostNum=MainPostNum+1,PostNum=PostNum+1 where ID = ? ";
  static final String UPDATE_BOARDS_POSTNUMS =
      "update boards set PostNum=PostNum+1 where ID = ? ";
  static final String UPDATE_BOARDS_DECPOSTMNUM =
      "update boards set MainPostNum = MainPostNum - 1,PostNum = PostNum - 1 where ID = ? ";
  static final String UPDATE_BOARDS_DECPOSTNUMS =
      "update boards set PostNum = PostNum - 1 where ID = ? ";
  static final String UPDATE_BOARDS_POSTNUM_ALL =
      "update boards set MainPostNum = ?,PostNum = ? where ID = ?";
  static final String UPDATE_BOARDS_USERCANIN =
      "update boards set UserCanIn = ? where ID = ?";

  public DBBoards() {
  }

  public void checkBoardsMaster() {
    this.myBoardsMaster.checkMaster();
  }

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

  public synchronized void setBoardsList(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      logger.info("整理二级版区信息静态列表");
      List alist = null;
      alist = this.loadDBs(myDBTrans, "All");
      Hashtable aht = new Hashtable();
      BoardsInfo aBoardsInfo = null;
      for (int i = 0; i < alist.size(); i++) {
        aBoardsInfo = (BoardsInfo) alist.get(i);
        aht.put(String.valueOf(aBoardsInfo.getID()), aBoardsInfo);
        logger.info("加入二级版区静态列表:" + aBoardsInfo.getID() + " " +
                    aBoardsInfo.getBoardsName());
      }
      BoardList.boardslist = aht;
    }
    catch (ObjectException e) {
      logger.error(e);
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public int createBoards(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.insertDB(myDBTrans);
      this.setBoardsList(myDBTrans);
      UpMsg aUpMsg = new UpMsg(3);
      ServerSession.upMsg(aUpMsg);
      return Sys.RESULT_RIGHT;
    }
    catch (ObjectException e) {
      logger.error(e);
      //Util.log(e.toString());
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public List getBoardsList(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);
      //Util.log(e.toString());
      return (List) Sys.RESULT_NULL;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }

  }

  public int getBoardsOrders() {
    int orders = 1;
    TranContext DBSQL = new TranContext();
    try {
      if (DBSQL == null) {
        return 1;
      }
      DBSQL.prepareStatement(LOAD_ORDERS);
      DBSQL.setLong(1, this.myBoardsInfo.getBoardID());
      rs = DBSQL.executeQuery();
      if (rs.next()) {
        orders = rs.getInt("orders");
      }
      if (orders == 0) {
        orders = 5;
      }
      return orders;
    }
    catch (Exception e) {
      //Util.log(e.toString());
      logger.error(e);
      return 1;
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException e) {
      }
      try {
        DBSQL.close();
      }
      catch (SQLException e) {
      }
      DBSQL.freeCon();
    }

  }

  public int getBoards(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);
      //Util.log(e.toString());
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    catch (ObjectNoExistException e) {
      return Sys.RESULT_OBJECTNOEXISTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

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

  public void createBoardsFile() {
    TranContext myDBTrans = new TranContext();
    try {
      List myList = null;
      this.pages = PagesFactory.getInstance();
      this.pages.setPages(1);
      this.pages.setPerPageNum(10);
      BoardsInfo abi = new BoardsInfo();
      ForumInfo fi = new ForumInfo();
      Forum f = ForumFactory.getInstance();
      int mnum = 0;
      int pnum = 0;
      myList = this.loadDBs(myDBTrans, "All");
      int len = myList.size();
      for (int i = 0; i < len; i++) {
        abi = (BoardsInfo) myList.get(i);
        fi.setBoardID(abi.getID());
        f.setForumInfo(fi);
        mnum = f.getPostNum(myDBTrans, "PostMainList");
        pnum = f.getPostNum(myDBTrans, "PostAllNum");
        abi.setMainPostNum(mnum);
        abi.setPostNum(pnum);
        this.myBoardsInfo = abi;
        this.updateBoards(myDBTrans, "PostNum");
      }
      myList = this.loadDBs(myDBTrans, "bynum");
      len = myList.size();
      StringBuffer sb = new StringBuffer();

      for (int i = 0; i < len; i++) {
        abi = (BoardsInfo) myList.get(i);
        sb.append("<tr>\n");
        sb.append("<li><a href='rightAction.do?sid=###&bid=" + abi.getID() +
                  "&pages=1'>" + abi.getBoardsName() +
                  "</a> <font face='Tahoma' size='1' color='#C23862'><b>[Main:" +
                  abi.getMainPostNum() + " Total :" + abi.getPostNum() +
                  "]</b></font></li>");
        sb.append("</td></tr>");
      }
      String filepath = Util.getPubFilePath();
      File file = new File(filepath + "boardslist.htm");
      if (file.exists()) {
        file.delete();
      }
      FileOutputStream wf = new FileOutputStream(filepath + "boardslist.htm");
      if (Sys.isLocale()) {
        wf.write(sb.toString().getBytes());
      }
      else {
        wf.write(sb.toString().getBytes("UTF8"));
      }
      wf.close();
      logger.info("版区排行文件写入");
    }
    catch (ObjectException e) {
      logger.error(e);
    }
    catch (IOException e) {
      logger.error(e);
    }
    finally {
      myDBTrans.freeCon();
    }
  }

  public int setUserCanIn(TranContext aTranContext, UserInfo aUserInfo,
                          int inorout) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      if (inorout == 1) {
        String us = this.myBoardsInfo.getUserCanIn();
        if ( ("," + us).indexOf(aUserInfo.getUserName()) != -1) {
          return Sys.RESULT_OBJECTEXIST;
        }
        us = us + aUserInfo.getUserName() + ",";
        this.myBoardsInfo.setUserCanIn(us);
        this.updateDB(myDBTrans, "UserCanIn");
        User u = UserFactory.getInstance();
        u.setUserInfo(aUserInfo);
        u.setUserCanInBoards(null, String.valueOf(this.myBoardsInfo.getID()), 1);
      }
      if (inorout == 2) {
        String us = this.myBoardsInfo.getUserCanIn();
        if ( ("," + us).indexOf(aUserInfo.getUserName()) != -1) {
          us = Util.replace(us, aUserInfo.getUserName() + ",", "");
          this.myBoardsInfo.setUserCanIn(us);
          this.updateDB(myDBTrans, "UserCanIn");
          User u = UserFactory.getInstance();
          u.setUserInfo(aUserInfo);
          u.setUserCanInBoards(null, String.valueOf(this.myBoardsInfo.getID()),
                               2);
        }
      }

⌨️ 快捷键说明

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