📄 smsmanager.java
字号:
package net.acai.forum;
/**
* Title: 阿菜网络
* Description:
* Copyright: Copyright (c) 2002
* Company: www.justhis.com
* @author: acai
* @version 1.0
*/
import net.acai.forum.*;
import net.acai.database.*;
import javax.servlet.http.*;
import java.sql.*;
import net.acai.util.*;
import java.util.Vector;
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{
DBConnect dbc=new DBConnect();
String sql="Select Count(id) From Message Where flag=0 and issend=1 and delR=0 And incept=?";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
if(rs.next())
smsSign=true;
dbc.close();
}
catch(Exception e){
e.printStackTrace();
}
return smsSign;
}
public static SMSMSG getNewSMS(HttpServletRequest request){
String userName=GCookie.getCookieValue(request,"UJBBUName","");
try{
DBConnect dbc=new DBConnect();
String sql="Select id,sender From Message Where flag=0 and issend=1 and delR=0 And incept=? limit 0,1";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
if(!rs.next()){
dbc.close();
return null;
}
rs.next();
SMSMSG sms=new SMSMSG();
sms.setID(rs.getInt(1));
sms.setSender(rs.getString(2));
dbc.close();
return sms;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
public SMSMSG getSMSMSG(HttpServletRequest request,String sign) throws Exception {
DBConnect dbc=new DBConnect();
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=? or sender=?) and id="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
dbc.setBytes(2,userName.getBytes("GBK"));
}
else if(sign.equals("edit")){
sql="select * from message where sender=? and issend=0 and id="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
}
else if(sign.equals("read")){
sql="update message set flag=1 where ID="+ID;
dbc.executeUpdate(sql);
sql="select * from message where (incept=? or sender=?) and id="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
dbc.setBytes(2,userName.getBytes("GBK"));
}
else {
sql="select * from message where incept=? and id="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
}
ResultSet rs=dbc.executeQuery();
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));
dbc.close();
return sms;
}
public Vector getInBox() throws Exception{
Vector smsVector=new Vector();
DBConnect dbc=new DBConnect();
sql="select * from message where incept=? and issend=1 and delR=0 order by flag,sendtime desc";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
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);
}
dbc.close();
return smsVector;
}
public Vector getOutBox() throws Exception{
Vector smsVector=new Vector();
DBConnect dbc=new DBConnect();
sql="select * from message where sender=? and issend=0 and delS=0 order by sendtime desc";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
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);
}
dbc.close();
return smsVector;
}
public Vector getRecycle() throws Exception{
Vector smsVector=new Vector();
DBConnect dbc=new DBConnect();
sql="select * from message where ((sender=? and delS=1) or (incept=? and delR=1)) and delS!=2 order by sendtime desc";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
dbc.setBytes(2,userName.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
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);
}
dbc.close();
return smsVector;
}
public Vector getIsSend() throws Exception{
Vector smsVector=new Vector();
DBConnect dbc=new DBConnect();
sql="select * from message where sender=? and issend=1 and delS=0 order by sendtime desc";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
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);
}
dbc.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("请指定相关参数。");
}
DBConnect dbc=new DBConnect();
sql="update message set delR=1 where incept=? and id ="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
dbc.executeUpdate();
sql="update message set delS=2 where sender=? and delS=1 and id ="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
dbc.executeUpdate();
sql="update message set delS=2 where sender=? and delS=1";
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,userName.getBytes("GBK"));
dbc.executeUpdate();
sql="update message set delS=1 where sender=? and id="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,userName.getBytes("GBK"));
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.setBytes(1,users[i].getBytes("GBK"));
rs=dbc.executeQuery();
if(!rs.next()){
dbc.close();
throw new Exception("论坛没有这个用户,看看你的发送对象写对了嘛?");
}
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.setBytes(1,users[i].getBytes("GBK"));
dbc.setBytes(2,userName.getBytes("GBK"));
dbc.setBytes(3,title.getBytes("GBK"));
dbc.setBytes(4,message.getBytes("GBK"));
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.setBytes(1,incept.getBytes("GBK"));
ResultSet rs=dbc.executeQuery();
if(!rs.next()){
dbc.close();
throw new Exception("论坛没有这个用户,看看你的发送对象写对了嘛?");
}
rs.close();
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.setBytes(1,incept.getBytes("GBK"));
dbc.setBytes(2,userName.getBytes("GBK"));
dbc.setBytes(3,title.getBytes("GBK"));
dbc.setBytes(4,message.getBytes("GBK"));
dbc.executeUpdate();
dbc.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -