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

📄 smsmanager.java

📁 一个用jsp写的完整的论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.bcxy.bbs.forum;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: </p>
 * <p>Company: www.liyunet.com </p>
 * 
 * @author lishujiang
 * @version 1.0
 */

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.db.JdbcWrapper;

public class SMSManager {

	private static Logger log = Logger.getLogger(SMSManager.class);

	String userName, sql;

	User theUser;

	public SMSManager(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		userName = GCookie.getCookieValue(request, "UJBBUName", "");
		theUser = SkinUtil.checkUser(request, response, 4);
	}

	public SMSMSG getSMSMSG(HttpServletRequest request) throws Exception {
		return this.getSMSMSG(request, "inbox");
	}

	public static boolean checkSMS(HttpServletRequest request) {
		String userName = GCookie.getCookieValue(request, "UJBBUName", "");
		JdbcWrapper jw = new JdbcWrapper();
		try {
			String sql = "Select Count(id) From " + BBSConst.TABLE_MESSAGE
					+ " Where flag=0 and issend=1 and delR=0 And incept='"
					+ userName + "'";
			return jw.isExists(sql);
		} catch (Exception e) {
			log.error("检查新站内短信息出错", e);
			return false;
		} finally {
			jw.close();
		}
	}

	public static SMSMSG getNewSMS(HttpServletRequest request) {
		// 默认为空格,防止收件为空时在页面提示
		String userName = GCookie.getCookieValue(request, "UJBBUName", " ");
		JdbcWrapper jw = new JdbcWrapper();
		SMSMSG sms = null;
		try {
			String sql = "Select  id,sender From " + BBSConst.TABLE_MESSAGE
					+ " Where flag=0 and issend=1 and delR=0 And incept='"
					+ userName + "' limit 0,1";
			jw.executeQuery(sql);
			if (jw.next()) {
				sms = new SMSMSG();
				sms.setID(jw.getInt(1));
				sms.setSender(jw.getString(2));
			}
		} catch (Exception e) {
			log.error("取得新站内短信息出错", e);
		} finally {
			jw.close();
		}
		return sms;
	}

	public SMSMSG getSMSMSG(HttpServletRequest request, String sign)
			throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		int ID = 0;
		try {
			ID = ParamUtil.getInt(request, "id");
		} catch (Exception e) {
			throw new Exception("请指定相关参数。");
		}
		if (sign.equals("fw")) {
			sql = "select * from " + BBSConst.TABLE_MESSAGE
					+ " where (incept='" + userName + "' or sender='"
					+ userName + "') and id=" + ID;
		} else if (sign.equals("edit")) {
			sql = "select * from " + BBSConst.TABLE_MESSAGE + " where sender='"
					+ userName + "' and issend=0 and id=" + ID;
		} else if (sign.equals("read")) {
			sql = "update " + BBSConst.TABLE_MESSAGE + " set flag=1 where ID="
					+ ID;
			jw.executeUpdate(sql);
			sql = "select * from " + BBSConst.TABLE_MESSAGE
					+ " where (incept='" + userName + "' or sender='"
					+ userName + "') and id=" + ID;
		} else {
			sql = "select * from " + BBSConst.TABLE_MESSAGE + " where incept='"
					+ userName + "' and id=" + ID;
		}
		SMSMSG sms = new SMSMSG();
		try {
			jw.executeQuery(sql);
			if (jw.next()) {
				sms.setID(jw.getInt(1));
				sms.setSender(jw.getString(2));
				sms.setIncept(jw.getString(3));
				sms.setTitle(jw.getString(4));
				sms.setContent(jw.getString(5));
				sms.setFlag(jw.getInt(6));
				sms.setSendtime(jw.getString(7));
				sms.setDelR(jw.getInt(8));
				sms.setDelS(jw.getInt(9));
				sms.setIsSend(jw.getInt(10));
			} else {
				throw new Exception("该信息不存在");
			}
		} catch (Exception e) {
			throw e;
		} finally {
			jw.close();
		}
		return sms;
	}

	public Vector getInBox() throws Exception {
		Vector smsVector = new Vector();
		JdbcWrapper jw = new JdbcWrapper();
		sql = "select * from " + BBSConst.TABLE_MESSAGE + " where incept='"
				+ userName
				+ "' and issend=1 and delR=0 order by flag,sendtime desc";
		try {
			jw.executeQuery(sql);
			while (jw.next()) {
				SMSMSG sms = new SMSMSG();
				sms.setID(jw.getInt(1));
				sms.setSender(jw.getString(2));
				sms.setIncept(jw.getString(3));
				sms.setTitle(jw.getString(4));
				sms.setContent(jw.getString(5));
				sms.setFlag(jw.getInt(6));
				sms.setSendtime(jw.getString(7));
				sms.setDelR(jw.getInt(8));
				sms.setDelS(jw.getInt(9));
				sms.setIsSend(jw.getInt(10));
				smsVector.add(sms);
			}
		} catch (Exception e) {
			log.error("取得收件箱信息出错", e);
			throw new Exception("取得收件箱信息出错");
		} finally {
			jw.close();
		}
		return smsVector;

	}

	public Vector getOutBox() throws Exception {
		Vector smsVector = new Vector();
		JdbcWrapper jw = new JdbcWrapper();
		sql = "select * from " + BBSConst.TABLE_MESSAGE + " where sender='"
				+ userName + "' and issend=0 and delS=0 order by sendtime desc";
		try {
			jw.executeQuery(sql);
			while (jw.next()) {
				SMSMSG sms = new SMSMSG();
				sms.setID(jw.getInt(1));
				sms.setSender(jw.getString(2));
				sms.setIncept(jw.getString(3));
				sms.setTitle(jw.getString(4));
				sms.setContent(jw.getString(5));
				sms.setFlag(jw.getInt(6));
				sms.setSendtime(jw.getString(7));
				sms.setDelR(jw.getInt(8));
				sms.setDelS(jw.getInt(9));
				sms.setIsSend(jw.getInt(10));
				smsVector.add(sms);
			}
		} catch (Exception e) {
			log.error("取得发件箱信息出错", e);
			throw new Exception("取得发件箱信息出错");
		} finally {
			jw.close();
		}
		return smsVector;

	}

	public Vector getRecycle() throws Exception {
		Vector smsVector = new Vector();
		JdbcWrapper jw = new JdbcWrapper();
		sql = "select * from " + BBSConst.TABLE_MESSAGE + " where ((sender='"
				+ userName + "' and delS=1) or (incept='" + userName
				+ "' and delR=1)) and delS!=2 order by sendtime desc";
		try {
			jw.executeQuery(sql);
			while (jw.next()) {
				SMSMSG sms = new SMSMSG();
				sms.setID(jw.getInt(1));
				sms.setSender(jw.getString(2));
				sms.setIncept(jw.getString(3));
				sms.setTitle(jw.getString(4));
				sms.setContent(jw.getString(5));
				sms.setFlag(jw.getInt(6));
				sms.setSendtime(jw.getString(7));
				sms.setDelR(jw.getInt(8));
				sms.setDelS(jw.getInt(9));
				sms.setIsSend(jw.getInt(10));
				smsVector.add(sms);
			}
		} catch (Exception e) {
			log.error("取得回收站信息出错", e);
			throw new Exception("取得回收站信息出错");
		} finally {
			jw.close();
		}
		return smsVector;

	}

	public Vector getIsSend() throws Exception {
		Vector smsVector = new Vector();
		JdbcWrapper jw = new JdbcWrapper();
		sql = "select * from " + BBSConst.TABLE_MESSAGE + " where sender='"
				+ userName + "' and issend=1 and delS=0 order by sendtime desc";
		try {
			jw.executeQuery(sql);
			while (jw.next()) {
				SMSMSG sms = new SMSMSG();
				sms.setID(jw.getInt(1));
				sms.setSender(jw.getString(2));
				sms.setIncept(jw.getString(3));
				sms.setTitle(jw.getString(4));
				sms.setContent(jw.getString(5));
				sms.setFlag(jw.getInt(6));
				sms.setSendtime(jw.getString(7));
				sms.setDelR(jw.getInt(8));
				sms.setDelS(jw.getInt(9));
				sms.setIsSend(jw.getInt(10));
				smsVector.add(sms);
			}
		} catch (Exception e) {
			log.error("取得草稿箱信息出错", e);
			throw new Exception("取得草稿箱信息出错");
		} finally {
			jw.close();
		}
		return smsVector;

	}

	public void delInBox(HttpServletRequest request) throws Exception {
		int ID = 0;
		try {
			ID = ParamUtil.getInt(request, "id");
		} catch (Exception e) {
			throw new Exception("请指定相关参数。");
		}
		JdbcWrapper jw = new JdbcWrapper();
		sql = "update " + BBSConst.TABLE_MESSAGE
				+ " set delR=1 where incept=? and id =?";
		try {
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setInt(2, ID);
			jw.executeUpdate();
		} catch (Exception e) {
			log.error("删除收件箱信息出错", e);
			throw new Exception("删除收件箱信息出错");
		} finally {
			jw.close();
		}
	}

	public void allDelInBox() throws Exception {
		sql = "update " + BBSConst.TABLE_MESSAGE

⌨️ 快捷键说明

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