📄 smsmanager.java
字号:
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.sql.ResultSet;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bcxy.bbs.database.DBConnect;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.db.SqlQuery;
public class SMSManager {
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", "");
boolean smsSign = false;
try {
SqlQuery rs = new SqlQuery();
String sql = "Select Count(id) From Message Where flag=0 and issend=1 and delR=0 And incept='"+userName+"'";
rs.doQuery(sql);
if (rs.next())
smsSign = true;
} catch (Exception e) {
e.printStackTrace();
}
return smsSign;
}
public static SMSMSG getNewSMS(HttpServletRequest request) {
String userName = GCookie.getCookieValue(request, "UJBBUName", "");
try {
SqlQuery rs = new SqlQuery();
String sql = "Select id,sender From Message Where flag=0 and issend=1 and delR=0 And incept='"+userName+"' limit 0,1";
rs.doQuery(sql);
if (!rs.next()) {
return null;
}
// rs.next();
SMSMSG sms = new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
return sms;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public SMSMSG getSMSMSG(HttpServletRequest request, String sign)
throws Exception {
SqlQuery rs = new SqlQuery();
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
if (sign.equals("fw")) {
sql = "select * from message where (incept='"+userName+"' or sender='"+userName+"') and id="
+ ID;
} else if (sign.equals("edit")) {
sql = "select * from message where sender='"+userName+"' and issend=0 and id="
+ ID;
} else if (sign.equals("read")) {
sql = "update message set flag=1 where ID=" + ID;
rs.doUpdate(sql);
sql = "select * from message where (incept='"+userName+"' or sender='"+userName+"') and id="
+ ID;
} else {
sql = "select * from message where incept='"+userName+"' and id=" + ID;
}
rs.doQuery(sql);
rs.next();
SMSMSG sms = new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
sms.setIncept(rs.getString(3));
sms.setTitle(rs.getString(4));
sms.setContent(rs.getString(5));
sms.setFlag(rs.getInt(6));
sms.setSendtime(rs.getString(7));
sms.setDelR(rs.getInt(8));
sms.setDelS(rs.getInt(9));
sms.setIsSend(rs.getInt(10));
return sms;
}
public Vector getInBox() throws Exception {
Vector smsVector = new Vector();
SqlQuery rs = new SqlQuery();
sql = "select * from message where incept='"+userName+"' and issend=1 and delR=0 order by flag,sendtime desc";
rs.doQuery(sql);
while (rs.next()) {
SMSMSG sms = new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
sms.setIncept(rs.getString(3));
sms.setTitle(rs.getString(4));
sms.setContent(rs.getString(5));
sms.setFlag(rs.getInt(6));
sms.setSendtime(rs.getString(7));
sms.setDelR(rs.getInt(8));
sms.setDelS(rs.getInt(9));
sms.setIsSend(rs.getInt(10));
smsVector.add(sms);
}
return smsVector;
}
public Vector getOutBox() throws Exception {
Vector smsVector = new Vector();
SqlQuery rs = new SqlQuery();
sql = "select * from message where sender='"+userName+"' and issend=0 and delS=0 order by sendtime desc";
rs.doQuery(sql);
while (rs.next()) {
SMSMSG sms = new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
sms.setIncept(rs.getString(3));
sms.setTitle(rs.getString(4));
sms.setContent(rs.getString(5));
sms.setFlag(rs.getInt(6));
sms.setSendtime(rs.getString(7));
sms.setDelR(rs.getInt(8));
sms.setDelS(rs.getInt(9));
sms.setIsSend(rs.getInt(10));
smsVector.add(sms);
}
return smsVector;
}
public Vector getRecycle() throws Exception {
Vector smsVector = new Vector();
SqlQuery rs = new SqlQuery();
sql = "select * from message where ((sender='"+userName+"' and delS=1) or (incept='"+userName+"' and delR=1)) and delS!=2 order by sendtime desc";
rs.doQuery(sql);
while (rs.next()) {
SMSMSG sms = new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
sms.setIncept(rs.getString(3));
sms.setTitle(rs.getString(4));
sms.setContent(rs.getString(5));
sms.setFlag(rs.getInt(6));
sms.setSendtime(rs.getString(7));
sms.setDelR(rs.getInt(8));
sms.setDelS(rs.getInt(9));
sms.setIsSend(rs.getInt(10));
smsVector.add(sms);
}
return smsVector;
}
public Vector getIsSend() throws Exception {
Vector smsVector = new Vector();
SqlQuery rs = new SqlQuery();
sql = "select * from message where sender='"+userName+"' and issend=1 and delS=0 order by sendtime desc";
rs.doQuery(sql);
while (rs.next()) {
SMSMSG sms = new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
sms.setIncept(rs.getString(3));
sms.setTitle(rs.getString(4));
sms.setContent(rs.getString(5));
sms.setFlag(rs.getInt(6));
sms.setSendtime(rs.getString(7));
sms.setDelR(rs.getInt(8));
sms.setDelS(rs.getInt(9));
sms.setIsSend(rs.getInt(10));
smsVector.add(sms);
}
return smsVector;
}
public void delInBox(HttpServletRequest request) throws Exception {
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
DBConnect dbc = new DBConnect();
sql = "update message set delR=1 where incept=? and id =" + ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void allDelInBox() throws Exception {
sql = "update message set delR=1 where incept=? and delR=0";
DBConnect dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void delOutBox(HttpServletRequest request) throws Exception {
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
DBConnect dbc = new DBConnect();
sql = "update message set delS=1 where sender=? and issend=0 and id ="
+ ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void allDelOutBox() throws Exception {
sql = "update message set delS=1 where sender=? and delS=0 and issend=0";
DBConnect dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void delIsSend(HttpServletRequest request) throws Exception {
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
DBConnect dbc = new DBConnect();
sql = "update message set delS=1 where sender=? and issend=1 and id ="
+ ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void allDelIsSend() throws Exception {
sql = "update message set delS=1 where sender=? and delS=0 and issend=1";
DBConnect dbc = new DBConnect();
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void delRecycle(HttpServletRequest request) throws Exception {
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
DBConnect dbc = new DBConnect();
sql = "delete from message where incept=? and delR=1 and id=" + ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
sql = "update message set delS=2 where sender=? and delS=1 and id ="
+ ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void allDelRecycle() throws Exception {
DBConnect dbc = new DBConnect();
sql = "delete from message where incept=? and delR=1";
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
sql = "update message set delS=2 where sender=? and delS=1";
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
public void delete(HttpServletRequest request) throws Exception {
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
DBConnect dbc = new DBConnect();
sql = "update message set delR=1 where incept=? and id=" + ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
sql = "update message set delS=1 where sender=? and id=" + ID;
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.executeUpdate();
dbc.close();
}
// /////////////////////////////////////////////////////////
public void saveSMS(HttpServletRequest request) throws Exception {
String touser = ParamUtil.getString(request, "touser");
if (touser == null || touser.trim().equals(""))
throw new Exception("您忘记填写发送对象了吧。");
String title = ParamUtil.getString(request, "title");
if (title == null || title.trim().equals(""))
throw new Exception("您还没有填写标题呀。");
String message = ParamUtil.getString(request, "message");
if (message == null || message.trim().equals(""))
throw new Exception("内容是必须要填写的噢。");
String[] users = touser.split(",");
DBConnect dbc = new DBConnect();
ResultSet rs;
for (int i = 0; i < users.length; i++) {
if (i > 4) {
dbc.close();
throw new Exception("最多只能发送给5个用户,您的名单5位以后的请重新发送");
}
sql = "select username from user where username=?";
dbc.prepareStatement(sql);
dbc.setString(1, users[i]);
rs = dbc.executeQuery();
if (!rs.next()) {
dbc.close();
throw new Exception("论坛没有这个用户,看看你的发送对象写对了嘛?");
}
//String submit = request.getParameter("Submit");
String submit = ParamUtil.getString(request, "Submit", "");
if (submit.equals("发送")) {
sql = "insert into message (incept,sender,title,content,sendtime,flag,issend) values (?,?,?,?,now(),0,1)";
} else {
sql = "insert into message (incept,sender,title,content,sendtime,flag,issend) values (?,?,?,?,now(),0,0)";
}
dbc.prepareStatement(sql);
dbc.setString(1, users[i]);
dbc.setString(2, userName);
dbc.setString(3, title);
dbc.setString(4, message);
dbc.executeUpdate();
}
dbc.close();
}
public void saveEdit(HttpServletRequest request) throws Exception {
int ID = 0;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请指定相关参数。");
}
String touser = ParamUtil.getString(request, "touser");
if (touser == null || touser.trim().equals(""))
throw new Exception("您忘记填写发送对象了吧。");
String title = ParamUtil.getString(request, "title");
if (title == null || title.trim().equals(""))
throw new Exception("您还没有填写标题呀。");
String message = ParamUtil.getString(request, "message");
if (message == null || message.trim().equals(""))
throw new Exception("内容是必须要填写的噢。");
String incept = touser;
DBConnect dbc = new DBConnect();
sql = "select username from user where username=?";
dbc.prepareStatement(sql);
dbc.setString(1, incept);
ResultSet rs = dbc.executeQuery();
if (!rs.next()) {
dbc.close();
throw new Exception("论坛没有这个用户,看看你的发送对象写对了嘛?");
}
rs.close();
//String submit = request.getParameter("Submit");
String submit = ParamUtil.getString(request, "Submit", "");
if (submit.equals("发送")) {
sql = "update message set incept=?,sender=?,title=?,content=?,sendtime=now(),flag=0,issend=1 where id="
+ ID;
} else {
sql = "update message set incept=?,sender=?,title=?,content=?,sendtime=now(),flag=0,issend=0 where id="
+ ID;
}
dbc.prepareStatement(sql);
dbc.setString(1, incept);
dbc.setString(2, userName);
dbc.setString(3, title);
dbc.setString(4, message);
dbc.executeUpdate();
dbc.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -