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

📄 dbuserpic.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 JAVA
字号:
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 com.laoer.bbscs.util.*;
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 DBUserPic
    extends UserPic
    implements DBInf {

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

  private static final String INSERT_USERPIC =
      "insert into userpic (ID,UserID,UserName,PicFileName,IsStar) values (?,?,?,?,?)";
  private static final String UPDATE_USERPIC =
      "update userpic set PicFileName = ? where UserID = ?";
  private static final String UPDATE_USERPIC_ISSTAR =
      "update userpic set IsStar = 1 where UserID = ?";
  private static final String UPDATE_USERPIC_NOSTAR =
      "update userpic set IsStar = 0 where IsStar = 1";
  private static final String LOAD_USERPICUSERID =
      "select * from userpic where UserID = ?";
  private static final String LOAD_USERPICPID =
      "select * from userpic where ID = ?";
  private static final String LOAD_PICTOTAL =
      "select count(*) as total from userpic";
  private static final String DEL_USERPIC = "delete from userpic where ID = ?";

  public DBUserPic() {
  }

  public int delUserPic(TranContext aTranContext, String key) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.delDB(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 getUserPicNum(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      int total = 0;
      myDBTrans.prepareStatement(LOAD_PICTOTAL);
      rs = myDBTrans.executeQuery();
      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 int getUserPic(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 setStar() {
    TranContext myDBTrans = new TranContext();
    try {
      updateDB(myDBTrans, "nostar");
      updateDB(myDBTrans, "isStar");
      loadDB(myDBTrans, "UserID", true);
      createStarFile();
      return Sys.RESULT_RIGHT;
    }
    catch (ObjectException e) {
      logger.error(e);
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    catch (ObjectNoExistException e) {
      return Sys.RESULT_OBJECTNOEXISTEXCEPTION;
    }
    finally {
      try {
        if (myDBTrans != null) {
          myDBTrans.close();
        }
      }
      catch (SQLException e) {
      }
      myDBTrans.freeCon();
    }
  }

  public List getUserPicList(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 updateUserPic(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 createUserPic(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.insertDB(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 createStarFile() {
    String filepath = Util.getPubFilePath();
    try {
      StringBuffer sb = new StringBuffer();
      File file = new File(filepath + "starpic.htm");
      if (file.exists()) {
        file.delete();
      }
      sb.append("<a href='" + Sys.getURL() +
                "userInfoAction.do?sid=###&showtype=userID&uid=" +
                this.myUserPicInfo.getUserID() +
                "'><img src='" +
                Util.getUserImgSrcPath(this.myUserPicInfo.getUserName(),
                                       this.myUserPicInfo.getUserID(),
                                       this.myUserPicInfo.getPicFileName())
                + "' width=200 height=150 border=0></a>");
      FileOutputStream wf = new FileOutputStream(filepath + "starpic.htm");
      if (Sys.isLocale()) {
        wf.write(sb.toString().getBytes());
      }
      else {
        wf.write(sb.toString().getBytes("UTF8"));
      }
      wf.close();
      sb = null;
      File file1 = new File(filepath + "staruser.htm");
      if (file1.exists()) {
        file1.delete();
      }
      sb = new StringBuffer();
      UserInfo afi = new UserInfo();
      afi.setID(this.myUserPicInfo.getUserID());
      UserDetailInfo aUi = new UserDetailInfo();
      aUi.setUserID(this.myUserPicInfo.getUserID());
      UserDetail aUd = UserDetailFactory.getInstance();
      aUd.setUserInfo(afi);
      aUd.setUserDetailInfo(aUi);
      if (aUd.getUserDetail(null, "UserID") == Sys.RESULT_RIGHT) {
        sb.append("<a href='" + Sys.getURL() +
                  "userInfoAction.do?sid=###&showtype=userID&uid=" +
                  aUd.getUserDetailInfo().getUserID() + "'>" +
                  aUd.getUserDetailInfo().getBrief() + "</a>");
      }
      FileOutputStream wf1 = new FileOutputStream(filepath + "staruser.htm");
      if (Sys.isLocale()) {
        wf1.write(sb.toString().getBytes());
      }
      else {
        wf1.write(sb.toString().getBytes("UTF8"));
      }
      wf1.close();
    }
    catch (Exception e) {
      logger.error(e);
    }
  }

  public void loadDB(TranContext myDB, String key, boolean isLoad) throws
      ObjectException, ObjectNoExistException {
    try {
      if (key.equals("UserID")) {
        myDB.prepareStatement(LOAD_USERPICUSERID);
        myDB.setLong(1, this.myUserPicInfo.getUserID());
      }
      if (key.equals("PID")) {
        myDB.prepareStatement(LOAD_USERPICPID);
        myDB.setString(1, this.myUserPicInfo.getID());
      }
      rs = myDB.executeQuery();
      if (rs.next()) {
        if (isLoad) {
          this.myUserPicInfo.setID(rs.getString("ID"));
          this.myUserPicInfo.setUserID(rs.getLong("UserID"));
          this.myUserPicInfo.setUserName(rs.getString("UserName"));
          this.myUserPicInfo.setPicFileName(rs.getString("PicFileName"));
          this.myUserPicInfo.setIsStar(rs.getInt("IsStar"));
        }
      }
      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 alist = ListFactory.getInstance(2);
    UserPicInfo aUserPicInfo = null;
    try {
      if (key.equals("list")) {
        String strSQL = "select * from userpic order by UserID";
        this.pages.setTotals(this.getUserPicNum(myDB));
        this.pages.doPageBreak();
        this.sListPageBreak = this.pages.getListPageBreak();
        this.pages.setSQL(strSQL);
        myDB.prepareStatement(this.pages.getSQLString("ID"));
        rs = myDB.executeQuery();
      }
      while (rs.next()) {
        aUserPicInfo = new UserPicInfo();
        aUserPicInfo.setID(rs.getString("ID"));
        aUserPicInfo.setUserID(rs.getLong("UserID"));
        aUserPicInfo.setUserName(rs.getString("UserName"));
        aUserPicInfo.setPicFileName(rs.getString("PicFileName"));
        aUserPicInfo.setIsStar(rs.getInt("IsStar"));
        alist.add(aUserPicInfo);
        aUserPicInfo = null;
      }
      return alist;
    }
    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_USERPIC);
      myDB.setString(1, this.myUserPicInfo.getID());
      myDB.setLong(2, this.myUserPicInfo.getUserID());
      myDB.setString(3, this.myUserPicInfo.getUserName());
      myDB.setString(4, this.myUserPicInfo.getPicFileName());
      myDB.setInt(5, this.myUserPicInfo.getIsStar());
      myDB.executeUpdate();
      myDB.close();
    }
    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("PicFileName")) {
        myDB.prepareStatement(UPDATE_USERPIC);
        myDB.setString(1, this.myUserPicInfo.getPicFileName());
        myDB.setLong(2, this.myUserPicInfo.getUserID());
      }
      if (key.equals("isStar")) {
        myDB.prepareStatement(UPDATE_USERPIC_ISSTAR);
        myDB.setLong(1, this.myUserPicInfo.getUserID());
      }
      if (key.equals("nostar")) {
        myDB.prepareStatement(UPDATE_USERPIC_NOSTAR);
      }
      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("delID")) {
        myDB.prepareStatement(DEL_USERPIC);
        myDB.setString(1, this.myUserPicInfo.getID());
      }
      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 + -