FriendsManager.java
上传用户:yuyunping
上传日期:2013-03-21
资源大小:1844k
文件大小:4k
源码类别:

Java书籍

开发平台:

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. import net.acai.database.*;
  17. public class FriendsManager
  18. {
  19. String userName;
  20. String sql;
  21. public FriendsManager(HttpServletRequest request){
  22. userName=GCookie.getCookieValue(request,"UJBBUName","");
  23. }
  24. public static Vector getFriendList(HttpServletRequest request) throws Exception{
  25. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  26. String sql="select F_friend from bbs.Friend where F_username=? order by F_addtime desc";
  27. DBConnect dbc=new DBConnect();
  28. dbc.prepareStatement(sql);
  29. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  30. ResultSet rs=dbc.executeQuery();
  31. Vector friendList=new Vector();
  32. while(rs.next()){
  33. Friend friend=new Friend();
  34. friend.setFriendFriend(rs.getString(1));
  35. friendList.add(friend);
  36. }
  37. dbc.close();
  38. return friendList;
  39. }
  40. public Vector getFriendInfo(HttpServletRequest request) throws Exception{
  41. sql="select F.*,U.useremail,U.homepage,U.oicq from bbs.Friend F inner join bbs.myuser U on F.F_Friend=U.username where F.F_username=? order by F.f_addtime desc";
  42. DBConnect dbc=new DBConnect();
  43. dbc.prepareStatement(sql);
  44. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  45. ResultSet rs=dbc.executeQuery();
  46. Vector friendInfo=new Vector();
  47. while(rs.next()){
  48. Friend friend=new Friend();
  49. friend.setFriendID(rs.getInt(1));
  50. friend.setFriendUserName(rs.getString(2));
  51. friend.setFriendFriend(rs.getString(3));
  52. friend.setFriendAddTime(rs.getString(4));
  53. friend.setFriendEmail(rs.getString(5));
  54. friend.setFriendHomePage(rs.getString(6));
  55. friend.setFriendOicq(rs.getString(7));
  56. friendInfo.add(friend);
  57. }
  58. dbc.close();
  59. return friendInfo;
  60. }
  61. public void delFriend(HttpServletRequest request) throws Exception{
  62. int ID=0;
  63. try{
  64. ID=ParamUtil.getInt(request,"id");
  65. }
  66. catch(Exception e){
  67. throw new Exception("请指定相关参数。");
  68. }
  69. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  70. DBConnect dbc=new DBConnect();
  71. sql="delete from bbs.Friend where F_username=? and F_id="+ID;
  72. dbc.prepareStatement(sql);
  73. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  74. dbc.executeUpdate();
  75. dbc.close();
  76. }
  77. public void allDelFriend() throws Exception{
  78. DBConnect dbc=new DBConnect();
  79. sql="delete from bbs.Friend where F_username=? ";
  80. dbc.prepareStatement(sql);
  81. dbc.executeUpdate();
  82. dbc.close();
  83. }
  84. public void saveFriend(HttpServletRequest request) throws Exception{
  85. String touser=ParamUtil.getString(request,"touser");
  86. if(touser==null||"".equals(touser.trim()))
  87. throw new Exception("您忘记填写发送对象了吧。");
  88. String userName=GCookie.getCookieValue(request,"UJBBUName","");
  89. touser=touser.trim();
  90. String [] incept=touser.split(",");
  91. DBConnect dbc=new DBConnect();
  92. ResultSet rs;
  93. for(int i=0;i<incept.length;i++){
  94. if(i>4){
  95. dbc.close();
  96. throw new Exception("每次最多只能添加5位用户,您的名单5位以后的请重新填写");
  97. }
  98. sql="select username from bbs.myuser where username=?";
  99. dbc.prepareStatement(sql);
  100. dbc.setBytes(1,(new String(incept[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  101. rs=dbc.executeQuery();
  102. if(!rs.next()){
  103. dbc.close();
  104. throw new Exception("论坛没有这个用户,操作未成功。");
  105. }
  106. rs.close();
  107. sql="select F_friend from bbs.friend where F_username=? and  F_friend=?";
  108. dbc.prepareStatement(sql);
  109. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  110. dbc.setBytes(2,(new String(incept[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  111. rs=dbc.executeQuery();
  112. if(!rs.next()){
  113. sql="insert into bbs.friend (F_username,F_friend,F_addtime) values (?,?,getdate())";
  114. dbc.prepareStatement(sql);
  115. dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
  116. dbc.setBytes(2,(new String(incept[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
  117. dbc.executeUpdate();
  118. }
  119. rs.close();
  120. }
  121. dbc.close();
  122. }
  123. }