SMSManager.java
上传用户:toby834
上传日期:2013-10-21
资源大小:2613k
文件大小:16k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package net.acai.forum;
  2. /**
  3.  * Title:        清清网络
  4.  * Description:
  5.  * Copyright:    Copyright (c) 2002
  6.  * Company:      www.SuperSpace.com
  7.  * @author:       SuperSpace
  8.  * @version 1.0
  9.  */
  10. import net.acai.forum.*;
  11. import net.acai.database.*;
  12. import javax.servlet.http.*;
  13. import java.sql.*;
  14. import net.acai.util.*;
  15. import java.util.Vector;
  16. public class SMSManager{
  17. String userName,sql;
  18. User theUser;
  19. public SMSManager(HttpServletRequest request,HttpServletResponse response) throws Exception{
  20. userName=GCookie.getCookieValue(request,"UJBBUName","");
  21. theUser=SkinUtil.checkUser(request,response,4);
  22. }
  23. public SMSMSG getSMSMSG(HttpServletRequest request) throws Exception {
  24. return this.getSMSMSG(request,"inbox");
  25. }
  26. public static boolean checkSMS(HttpServletRequest request){
  27. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  28. boolean smsSign=false;
  29. try{
  30. DBConnect dbc=new DBConnect();
  31. String sql="Select Count(id) From bbs.Message Where flag=0 and issend=1 and delR=0 And incept=?";
  32. dbc.prepareStatement(sql);
  33. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  34. ResultSet rs=dbc.executeQuery();
  35. if(rs.next())
  36. smsSign=true;
  37. dbc.close();
  38. }
  39. catch(Exception e){
  40. e.printStackTrace();
  41. }
  42. return smsSign;
  43. }
  44. public static SMSMSG getNewSMS(HttpServletRequest request){
  45. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  46. try{
  47. DBConnect dbc=new DBConnect();
  48. String sql="Select  id,sender From bbs.Message Where flag=0 and issend=1 and delR=0 And incept=?";
  49. dbc.prepareStatement(sql);
  50. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  51. ResultSet rs=dbc.executeQuery();
  52. if(!rs.next()){
  53. dbc.close();
  54. return null;
  55. }
  56. SMSMSG sms=new SMSMSG();
  57. sms.setID(rs.getInt(1));
  58. sms.setSender(rs.getString(2));
  59. dbc.close();
  60. return sms;
  61. }
  62. catch(Exception e){
  63. e.printStackTrace();
  64. return null;
  65. }
  66. }
  67. public SMSMSG getSMSMSG(HttpServletRequest request,String sign) throws Exception {
  68. DBConnect dbc=new DBConnect();
  69. int ID=0;
  70. try{
  71. ID=ParamUtil.getInt(request,"id");
  72. }
  73. catch(Exception e){
  74. throw new Exception("请指定相关参数。");
  75. }
  76. if(sign.equals("fw")){
  77. sql="select * from bbs.message where (incept=? or sender=?) and id="+ID;
  78. dbc.prepareStatement(sql);
  79. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  80. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  81. }
  82. else if(sign.equals("edit")){
  83. sql="select * from bbs.message where sender=? and issend=0 and id="+ID;
  84. dbc.prepareStatement(sql);
  85. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  86. }
  87. else if(sign.equals("read")){
  88. sql="update bbs.message set flag=1 where ID="+ID;
  89. dbc.executeUpdate(sql);
  90. sql="select * from bbs.message where (incept=? or sender=?) and id="+ID;
  91. dbc.prepareStatement(sql);
  92. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  93. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  94. }
  95. else {
  96. sql="select * from bbs.message where incept=? and id="+ID;
  97. dbc.prepareStatement(sql);
  98. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  99. }
  100. ResultSet rs=dbc.executeQuery();
  101. rs.next();
  102. SMSMSG sms=new SMSMSG();
  103. sms.setID(rs.getInt(1));
  104. sms.setSender(rs.getString(2));
  105. sms.setIncept(rs.getString(3));
  106. sms.setTitle(rs.getString(4));
  107. sms.setContent(rs.getString(5));
  108. sms.setFlag(rs.getInt(6));
  109. sms.setSendtime(rs.getString(7));
  110. sms.setDelR(rs.getInt(8));
  111. sms.setDelS(rs.getInt(9));
  112. sms.setIsSend(rs.getInt(10));
  113. dbc.close();
  114. return sms;
  115. }
  116. public Vector getInBox() throws Exception{
  117. Vector smsVector=new Vector();
  118. DBConnect dbc=new DBConnect();
  119. sql="select * from bbs.message where incept=? and issend=1 and delR=0 order by flag,sendtime desc";
  120. dbc.prepareStatement(sql);
  121. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  122. ResultSet rs=dbc.executeQuery();
  123. while(rs.next()){
  124. SMSMSG sms=new SMSMSG();
  125. sms.setID(rs.getInt(1));
  126. sms.setSender(rs.getString(2));
  127. sms.setIncept(rs.getString(3));
  128. sms.setTitle(rs.getString(4));
  129. sms.setContent(rs.getString(5));
  130. sms.setFlag(rs.getInt(6));
  131. sms.setSendtime(rs.getString(7));
  132. sms.setDelR(rs.getInt(8));
  133. sms.setDelS(rs.getInt(9));
  134. sms.setIsSend(rs.getInt(10));
  135. smsVector.add(sms);
  136. }
  137. dbc.close();
  138. return smsVector;
  139. }
  140. public Vector getOutBox() throws Exception{
  141. Vector smsVector=new Vector();
  142. DBConnect dbc=new DBConnect();
  143. sql="select * from bbs.message where sender=? and issend=0 and delS=0 order by sendtime desc";
  144. dbc.prepareStatement(sql);
  145. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  146. ResultSet rs=dbc.executeQuery();
  147. while(rs.next()){
  148. SMSMSG sms=new SMSMSG();
  149. sms.setID(rs.getInt(1));
  150. sms.setSender(rs.getString(2));
  151. sms.setIncept(rs.getString(3));
  152. sms.setTitle(rs.getString(4));
  153. sms.setContent(rs.getString(5));
  154. sms.setFlag(rs.getInt(6));
  155. sms.setSendtime(rs.getString(7));
  156. sms.setDelR(rs.getInt(8));
  157. sms.setDelS(rs.getInt(9));
  158. sms.setIsSend(rs.getInt(10));
  159. smsVector.add(sms);
  160. }
  161. dbc.close();
  162. return smsVector;
  163. }
  164. public Vector getRecycle() throws Exception{
  165. Vector smsVector=new Vector();
  166. DBConnect dbc=new DBConnect();
  167. sql="select * from bbs.message where ((sender=? and delS=1) or (incept=? and delR=1)) and delS!=2 order by sendtime desc";
  168. dbc.prepareStatement(sql);
  169. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  170. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  171. ResultSet rs=dbc.executeQuery();
  172. while(rs.next()){
  173. SMSMSG sms=new SMSMSG();
  174. sms.setID(rs.getInt(1));
  175. sms.setSender(rs.getString(2));
  176. sms.setIncept(rs.getString(3));
  177. sms.setTitle(rs.getString(4));
  178. sms.setContent(rs.getString(5));
  179. sms.setFlag(rs.getInt(6));
  180. sms.setSendtime(rs.getString(7));
  181. sms.setDelR(rs.getInt(8));
  182. sms.setDelS(rs.getInt(9));
  183. sms.setIsSend(rs.getInt(10));
  184. smsVector.add(sms);
  185. }
  186. dbc.close();
  187. return smsVector;
  188. }
  189. public Vector getIsSend() throws Exception{
  190. Vector smsVector=new Vector();
  191. DBConnect dbc=new DBConnect();
  192. sql="select * from bbs.message where sender=? and issend=1 and delS=0 order by sendtime desc";
  193. dbc.prepareStatement(sql);
  194. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  195. ResultSet rs=dbc.executeQuery();
  196. while(rs.next()){
  197. SMSMSG sms=new SMSMSG();
  198. sms.setID(rs.getInt(1));
  199. sms.setSender(rs.getString(2));
  200. sms.setIncept(rs.getString(3));
  201. sms.setTitle(rs.getString(4));
  202. sms.setContent(rs.getString(5));
  203. sms.setFlag(rs.getInt(6));
  204. sms.setSendtime(rs.getString(7));
  205. sms.setDelR(rs.getInt(8));
  206. sms.setDelS(rs.getInt(9));
  207. sms.setIsSend(rs.getInt(10));
  208. smsVector.add(sms);
  209. }
  210. dbc.close();
  211. return smsVector;
  212. }
  213. public void  delInBox(HttpServletRequest request) throws Exception{
  214. int ID=0;
  215.         String[] ids = request.getParameterValues("id");
  216. if(ids.length==0)
  217. throw new Exception("请指定相关参数。");
  218.         for(int i=0;i<ids.length;i++)
  219.         {
  220.             ID = Integer.parseInt(ids[i]);
  221.             DBConnect dbc = new DBConnect();
  222.             sql = "update bbs.message set delR=1 where incept=? and id =" + ID;
  223.             dbc.prepareStatement(sql);
  224.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  225.             dbc.executeUpdate();
  226.             dbc.close();
  227.         }
  228. }
  229. public void  allDelInBox() throws Exception{
  230. sql="update bbs.message set delR=1 where incept=? and delR=0";
  231. DBConnect dbc=new DBConnect();
  232. dbc.prepareStatement(sql);
  233. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  234. dbc.executeUpdate();
  235. dbc.close();
  236. }
  237. public void  delOutBox(HttpServletRequest request) throws Exception{
  238. int ID=0;
  239.         String[] ids = request.getParameterValues("id");
  240.         if(ids.length==0)
  241.             throw new Exception("请指定相关参数。");
  242.         for(int i=0;i<ids.length;i++)
  243.         {
  244.             ID = Integer.parseInt(ids[i]);
  245.             DBConnect dbc = new DBConnect();
  246.             sql = "update bbs.message set delS=1 where sender=? and issend=0 and id =" + ID;
  247.             dbc.prepareStatement(sql);
  248.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  249.             dbc.executeUpdate();
  250.             dbc.close();
  251.         }
  252. }
  253. public void  allDelOutBox() throws Exception{
  254. sql="update bbs.message set delS=1 where sender=? and delS=0 and issend=0";
  255. DBConnect dbc=new DBConnect();
  256. dbc.prepareStatement(sql);
  257. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  258. dbc.executeUpdate();
  259. dbc.close();
  260. }
  261. public void  delIsSend(HttpServletRequest request) throws Exception{
  262. int ID=0;
  263.         String[] ids = request.getParameterValues("id");
  264.         if(ids.length==0)
  265.             throw new Exception("请指定相关参数。");
  266.         for(int i=0;i<ids.length;i++)
  267.         {
  268.             ID = Integer.parseInt(ids[i]);
  269.             DBConnect dbc = new DBConnect();
  270.             sql = "update bbs.message set delS=1 where sender=? and issend=1 and id =" + ID;
  271.             dbc.prepareStatement(sql);
  272.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  273.             dbc.executeUpdate();
  274.             dbc.close();
  275.         }
  276. }
  277. public void  allDelIsSend() throws Exception{
  278. sql="update bbs.message set delS=1 where sender=? and delS=0 and issend=1";
  279. DBConnect dbc=new DBConnect();
  280. dbc.prepareStatement(sql);
  281. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  282. dbc.executeUpdate();
  283. dbc.close();
  284. }
  285. public void  delRecycle(HttpServletRequest request) throws Exception{
  286. int ID=0;
  287.         String[] ids = request.getParameterValues("id");
  288.         if(ids.length==0)
  289.             throw new Exception("请指定相关参数。");
  290.         for(int i=0;i<ids.length;i++)
  291.         {
  292.             ID = Integer.parseInt(ids[i]);
  293.             DBConnect dbc = new DBConnect();
  294.             sql = "delete from bbs.message where incept=? and delR=1 and id=" + ID;
  295.             dbc.prepareStatement(sql);
  296.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  297.             dbc.executeUpdate();
  298.             sql = "update bbs.message set delS=2 where sender=? and delS=1 and id =" + ID;
  299.             dbc.prepareStatement(sql);
  300.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  301.             dbc.executeUpdate();
  302.             dbc.close();
  303.         }
  304. }
  305. public void  allDelRecycle() throws Exception{
  306. DBConnect dbc=new DBConnect();
  307. sql="delete from bbs.message where incept=? and delR=1";
  308. dbc.prepareStatement(sql);
  309. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  310. dbc.executeUpdate();
  311. sql="update bbs.message set delS=2 where sender=? and delS=1";
  312. dbc.prepareStatement(sql);
  313. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  314. dbc.executeUpdate();
  315. dbc.close();
  316. }
  317. public void  delete(HttpServletRequest request) throws Exception{
  318. int ID=0;
  319.         String[] ids = request.getParameterValues("id");
  320.         if(ids.length==0)
  321.             throw new Exception("请指定相关参数。");
  322.         for(int i=0;i<ids.length;i++)
  323.         {
  324.             ID = Integer.parseInt(ids[i]);
  325.             DBConnect dbc = new DBConnect();
  326.             sql = "update bbs.message set delR=1 where incept=? and id=" + ID;
  327.             dbc.prepareStatement(sql);
  328.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  329.             dbc.executeUpdate();
  330.             sql = "update bbs.message set delS=1 where sender=? and id=" + ID;
  331.             dbc.prepareStatement(sql);
  332.             dbc.setBytes(1, (new String(userName.getBytes("ISO-8859-1"), "GBK")).getBytes());
  333.             dbc.executeUpdate();
  334.             dbc.close();
  335.         }
  336. }
  337. ///////////////////////////////////////////////////////////
  338. public void  saveSMS(HttpServletRequest request) throws Exception{
  339. String touser=ParamUtil.getString(request,"touser");
  340. if(touser==null||touser.trim().equals(""))
  341. throw new Exception("您忘记填写发送对象了吧。");
  342. String title=ParamUtil.getString(request,"title");
  343. if(title==null||title.trim().equals(""))
  344. throw new Exception("您还没有填写标题呀。");
  345. String message=ParamUtil.getString(request,"message");
  346. if(message==null||message.trim().equals(""))
  347. throw new Exception("内容是必须要填写的噢。");
  348. String [] users=touser.split(",");
  349. DBConnect dbc=new DBConnect();
  350. ResultSet rs;
  351. for(int i=0;i<users.length;i++){
  352. if (i>4){
  353. dbc.close();
  354. throw new Exception("最多只能发送给5个用户,您的名单5位以后的请重新发送");
  355. }
  356. sql="select username from bbs.myuser where username=?";
  357. dbc.prepareStatement(sql);
  358. dbc.setBytes(1,(new String(users[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  359. rs=dbc.executeQuery();
  360. if(!rs.next()){
  361. dbc.close();
  362. throw new Exception("论坛没有这个用户,看看你的发送对象写对了嘛?");
  363. }
  364. String submit=new String(ParamUtil.getString(request,"Submit","").getBytes("ISO-8859-1"),"GBK");;
  365. if(submit.equals("发送")){
  366. sql="insert into bbs.message (incept,sender,title,content,sendtime,flag,issend) values (?,?,?,?,getdate(),0,1)";
  367. }
  368. else{
  369. sql="insert into bbs.message (incept,sender,title,content,sendtime,flag,issend) values (?,?,?,?,getdate(),0,0)";
  370. }
  371. dbc.prepareStatement(sql);
  372. dbc.setBytes(1,(new String(users[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  373. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  374. dbc.setBytes(3,(new String(title.getBytes("ISO-8859-1"),"GBK")).getBytes());
  375. dbc.setBytes(4,(new String(message.getBytes("ISO-8859-1"),"GBK")).getBytes());
  376. dbc.executeUpdate();
  377. }
  378. dbc.close();
  379. }
  380. public void saveEdit(HttpServletRequest request) throws Exception{
  381. int ID=0;
  382. try{
  383. ID=ParamUtil.getInt(request,"id");
  384. }
  385. catch(Exception e){
  386. throw new Exception("请指定相关参数。");
  387. }
  388. String touser=ParamUtil.getString(request,"touser");
  389. if(touser==null||touser.trim().equals(""))
  390. throw new Exception("您忘记填写发送对象了吧。");
  391. String title=ParamUtil.getString(request,"title");
  392. if(title==null||title.trim().equals(""))
  393. throw new Exception("您还没有填写标题呀。");
  394. String message=ParamUtil.getString(request,"message");
  395. if(message==null||message.trim().equals(""))
  396. throw new Exception("内容是必须要填写的噢。");
  397. String incept=touser;
  398. DBConnect dbc=new DBConnect();
  399. sql="select username from bbs.myuser where username=?";
  400. dbc.prepareStatement(sql);
  401. dbc.setBytes(1,(new String(incept.getBytes("ISO-8859-1"),"GBK")).getBytes());
  402. ResultSet rs=dbc.executeQuery();
  403. if(!rs.next()){
  404. dbc.close();
  405. throw new Exception("论坛没有这个用户,看看你的发送对象写对了嘛?");
  406. }
  407. rs.close();
  408. String submit=new String(ParamUtil.getString(request,"Submit","").getBytes("ISO-8859-1"),"GBK");
  409. if(submit.equals("发送")){
  410. sql="update bbs.message set incept=?,sender=?,title=?,content=?,sendtime=getdate(),flag=0,issend=1 where id="+ID;
  411. }
  412. else{
  413. sql="update bbs.message set incept=?,sender=?,title=?,content=?,sendtime=getdate(),flag=0,issend=0 where id="+ID;
  414. }
  415. dbc.prepareStatement(sql);
  416. dbc.setBytes(1,(new String(incept.getBytes("ISO-8859-1"),"GBK")).getBytes());
  417. dbc.setBytes(2,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  418. dbc.setBytes(3,(new String(title.getBytes("ISO-8859-1"),"GBK")).getBytes());
  419. dbc.setBytes(4,(new String(message.getBytes("ISO-8859-1"),"GBK")).getBytes());
  420. dbc.executeUpdate();
  421. dbc.close();
  422. }
  423. }