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

📄 dbforum.java

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

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

/**
 * <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 DBForum
    extends Forum
    implements DBInf {

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

  public DBForum() {
  }

  public int updatePost(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 getPostNum(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("PostMainList")) {
        sSQL = "select count(id) as total from " +
            this.myForumInfo.getTablename() +
            " where BoardID = ? and IsNew = 1 and DelSign = 0";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
      }
      if (key.equals("PostAllNum")) {
        sSQL = "select count(id) as total from " +
            this.myForumInfo.getTablename() +
            " where BoardID = ? and DelSign = 0";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
      }
      if (key.equals("AllNum")) {
        sSQL = "select count(id) as total from " +
            this.myForumInfo.getTablename() + " where BoardID = ? ";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
      }
      if (key.equals("PostTopicList")) {
        sSQL = "select count(id) as total from " +
            this.myForumInfo.getTablename() +
            " where BoardID = ? and  ID2 = ? and DelSign = 0";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
        myDBTrans.setLong(2, this.myForumInfo.getID2());
      }
      if (key.equals("PostManagerList")) {
        sSQL = "select count(ID) as total from " +
            this.myForumInfo.getTablename() +
            " where BoardID = ? and DelSign = 0";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
      }
      if (key.equals("wastebox")) {
        sSQL = "select count(ID) as total from " +
            this.myForumInfo.getTablename() +
            " where BoardID = ? and DelSign = 1";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
      }
      if (key.equals("search")) {
        sSQL = "select count(ID) as total from " +
            this.myForumInfo.getTablename() +
            " where BoardID = ? and  DelSign = 0 and " + this.getSearchCon() +
            " like '%" + this.getSearchText() + "%' ";
        myDBTrans.prepareStatement(sSQL);
        myDBTrans.setLong(1, this.myForumInfo.getBoardID());
      }
      rs = myDBTrans.executeQuery();
      if (rs.next()) {
        total = rs.getInt("total");
      }
      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 List getPostList(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 getPost(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 int createPost(TranContext aTranContext, String key) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      //保存帖子文件
      String filename = "post_" + this.myForumInfo.getID2() + "_" +
          this.myForumInfo.getBoardID() + "_" + this.myForumInfo.getID() + "_" +
          this.myForumInfo.getPostTime() +
          ".html";
      String filepath = Util.getForumPath(String.valueOf(this.myForumInfo.
          getBoardID()), this.myForumInfo.getPostTime());
      File file = new File(filepath + filename);
      if (file.exists()) {
        file.delete();
      }
      file = null;
      StringBuffer sb = new StringBuffer();
      sb.append("<html><head><title>");
      sb.append(this.myForumInfo.getTitle());
      sb.append("</title><body>");
      sb.append(this.myForumInfo.getDetail());
      sb.append("</body></html>");

      FileOutputStream wf = new FileOutputStream(filepath + filename);
      //wf.write(sb.toString().getBytes("UTF8"));
      if (Sys.isLocale()) {
        wf.write(sb.toString().getBytes());
      }
      else {
        wf.write(sb.toString().getBytes("UTF8"));
      }
      wf.close();
      wf = null;

      this.myForumInfo.setDetail(filename);
      //存入数据库
      this.insertDB(myDBTrans);
      if (key.equals("new")) {
        //处理版面信息
        /*暂不处理版面信息
                 Boards myBoards = BoardsFactory.getInstance();
                 this.myBoardsInfo = this.myUserSessionCheck.getTheBoards();
                 this.myBoardsInfo.setLastPostID(this.myForumInfo.getID2());
             this.myBoardsInfo.setLastPostTime(this.myForumInfo.getPostTime());
             this.myBoardsInfo.setLastPostTitle(this.myForumInfo.getTitle());
             this.myBoardsInfo.setLastPostUser(this.myForumInfo.getUserName());
             this.myBoardsInfo.setLastPostUserID(this.myForumInfo.getUserID());
                 myBoards.setBoardsInfo(this.myBoardsInfo);
                 myBoards.updateBoards(myDBTrans, "PostMainNum");
                 myBoards.updateBoards(myDBTrans, "LastPost");*/

        if (this.myForumInfo.getEmail_Inform() == 1 ||
            this.myForumInfo.getMsg_Inform() == 1) {
          SubscibeInfo aSubscibeInfo = new SubscibeInfo();
          aSubscibeInfo.setID(String.valueOf(this.myForumInfo.getPostTime()) +
                              String.valueOf(this.myForumInfo.getUserID()));
          aSubscibeInfo.setBID(this.myForumInfo.getBoardID());
          aSubscibeInfo.setUserID(this.myForumInfo.getUserID());
          aSubscibeInfo.setUname(this.myForumInfo.getUserName());
          aSubscibeInfo.setRID(this.myForumInfo.getID());
          aSubscibeInfo.setPostTitle(this.myForumInfo.getTitle());
          aSubscibeInfo.setEmail_inform(this.myForumInfo.getEmail_Inform());
          aSubscibeInfo.setMsg_inform(this.myForumInfo.getMsg_Inform());
          Subscibe aSubscibe = SubscibeFactory.getInstance();
          aSubscibe.setSubscibeInfo(aSubscibeInfo);
          aSubscibe.createSubscibe(myDBTrans);
          aSubscibeInfo = null;
          aSubscibe = null;
        }
        if (!this.myUserSessionCheck.getiAttribs()[2] &&
            !this.myUserSessionCheck.getiAttribs()[3]) {
          NewPost.intoNewPost(this.myForumInfo);
        }
      }
      if (key.equals("re")) {
        ForumInfo mainPost = new ForumInfo();
        String lastReName = this.myUserInfo.getNickName() + "[" +
            this.myUserInfo.getUserName() + "]";
        mainPost.setBoardID(this.myForumInfo.getBoardID());
        mainPost.setID(this.myForumInfo.getID2());
        mainPost.setLastTime(this.myForumInfo.getPostTime());
        mainPost.setLastPostUserName(lastReName);
        mainPost.setLastPostTitle(this.myForumInfo.getTitle());
        Forum mForum = ForumFactory.getInstance();
        mForum.setForumInfo(mainPost);
        mForum.updatePost(myDBTrans, "addReNum");
        mainPost = null;
        mainPost = new ForumInfo();
        mainPost.setBoardID(this.myForumInfo.getBoardID());
        mainPost.setID(this.myForumInfo.getID1());
        mForum.setForumInfo(mainPost);
        mForum.updatePost(myDBTrans, "canotre");
        mainPost = null;
        mForum = null;

        SubscibeInfo aSubscibeInfo = new SubscibeInfo();
        aSubscibeInfo.setBID(this.myForumInfo.getBoardID());
        aSubscibeInfo.setRID(this.myForumInfo.getID2());
        Subscibe aSubscibe = SubscibeFactory.getInstance();
        aSubscibe.setSubscibeInfo(aSubscibeInfo);
        List alist = aSubscibe.getSubscibeList(myDBTrans, "sendlist");
        if (alist != null && alist.size() > 0) {
          GuestBookInfo aGuestBookInfo = new GuestBookInfo();
          GuestBook aGuestBook = GuestBookFactory.getInstance();
          String note = "";
          long atime = Util.getaLongTime();
          for (int i = 0; i < alist.size(); i++) {
            aSubscibeInfo = (SubscibeInfo) alist.get(i);
            aGuestBookInfo.setFID(aSubscibeInfo.getUserID());
            aGuestBookInfo.setFname(aSubscibeInfo.getUname());
            aGuestBookInfo.setUserID(this.myForumInfo.getUserID());
            aGuestBookInfo.setUname(this.myForumInfo.getUserName());
            aGuestBookInfo.setMtype(1);
            note = "<!--note--><a href=" + Sys.getURL() +

⌨️ 快捷键说明

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