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

📄 forum.java

📁 BBS论坛设计JSP+MYSQL
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					String.valueOf(announceID));
			return "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + announceID + "#" + announceID;
		} catch (UserNotFoundException e) {
			throw new Exception("没有发现用户");
		} catch (Exception e) {
			log.error(e);
			throw new Exception(e.getMessage());
		} finally {
			dbc.close();
		}
	}

	public String addTopic(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		SqlQuery rs = new SqlQuery();
		DBConnect dbc = null;
		String userName = ParamUtil.getString(request, "userName", "guest");
		String sql = "";
		try {
			dbc = new DBConnect();
			// 发新帖子,增加用户的经验、魅力值
			SkinUtil.checkUser(request, response, 2);
			//
			int forumID = ParamUtil.getInt(request, "forumID", 1);
			String subject = ParamUtil.getString(request, "subject", "");
			subject = StringUtil.changeToFull(subject);
			String content = ParamUtil.getString(request, "content", "");
			String expression = ParamUtil.getString(request, "expression", "");
			int isVote = ParamUtil.getInt(request, "isVote", 0);
			int signFlag = ParamUtil.getInt(request, "signFlag", 1);
			int emailFlag = ParamUtil.getInt(request, "emailFlag", 0);
			int viewMode = ParamUtil.getInt(request, "viewMode", 0);
			int viewNumber = ParamUtil.getInt(request, "viewNumber", 0);
			if (subject.equals("")){
				throw new Exception("没有主体文字");
			}
			sql = "insert into bbs1(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times,viewmode,viewnumber) values "
					+ "("
					+ forumID
					+ ",0,0,?,?,?,'"
					+ Format.getDateTime()
					+ "',0,"
					+ content.length()
					+ ",0,1,0,'"
					+ request.getRemoteAddr()
					+ "',?,0,"
					//+ expression
					//+ ""
					+ signFlag + "," + emailFlag + ",0,0," + isVote + ",0,"+viewMode+","+viewNumber+")";

			dbc.prepareStatement(sql);
			dbc.setString(1, userName);
			dbc.setString(2, subject);
			dbc.setString(3, content);
			dbc.setString(4, expression);
			dbc.executeUpdate();
			//
			String aid = rs
					.doSearch("select announceid from bbs1 order by announceid desc");
			int announceID = StringUtil.parseInt(aid);
			voteID = announceID;
			sql = "update bbs1 set rootid=" + announceID + ",times="
					+ announceID + " where announceid=" + announceID;
			rs.doUpdate(sql);
			String shortTopic = "";
			if ("".equals(subject))
				if (content.length() > 21)
					shortTopic = content.substring(0, 20);
				else
					shortTopic = content;
			else if (subject.length() > 21)
				shortTopic = subject.substring(0, 20);
			else
				shortTopic = subject;
			String count = rs
					.doSearch("Select count(announceid) from bbs1 Where to_days(dateandtime)-to_days(Now())=0 and boardid="
							+ forumID);
			int forumToday = StringUtil.parseInt(count);
			//
			sql = "update board set lastpostuser='"
					+ userName
					+ "',lastposttime='"
					+ Format.getDateTime()
					+ "',lastbbsnum=lastbbsnum+1,lasttopicnum=lasttopicnum+1,todaynum="
					+ forumToday + ",lastrootid=" + announceID + ",lasttopic=?"
					+ " where  boardid=" + forumID;
			dbc.clearParameters();
			dbc.prepareStatement(sql);
			dbc.setString(1, shortTopic);
			dbc.executeUpdate();
			// rs.doUpdate(sql);
			//
			count = rs
					.doSearch("Select count(announceid) from bbs1 Where to_days(dateandtime)-to_days(Now())=0");
			int allTodays = StringUtil.parseInt(count);
			rs
					.doUpdate("update config set topicnum=topicnum+1,bbsnum=bbsnum+1,todayNum="
							+ allTodays);
			//
			CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
			//
			ForumPropertiesManager.resetManager();
			return "dispbbs.jsp?forumID=" + forumID + "&rootID=" + announceID
					+ "&announceID=" + announceID;
		} catch (UserNotFoundException e) {
			throw new Exception("没有发现用户");
		} catch (Exception e) {
			log.error(e);
			throw e;
		} finally {
			dbc.close();
		}
	}

	public void emailReplay(int announceID, String title, String content) throws Exception{
		SqlQuery rs = new SqlQuery("select a.emailflag,b.useremail from bbs1 a,user b where a.username=b.username and a.announceid="+announceID);
		if(rs.next()){
			int emailFlag = rs.getInt(1);
			if(emailFlag==1){
				SendMail.sendMail(rs.get(2), title, content);
			}
		}
	}
	
	public String addMSG(HttpServletRequest request,
			HttpServletResponse response) throws UserNotFoundException,
			Exception {
		SqlQuery rs = new SqlQuery();
		DBConnect dbc = null;
		//
		String userName = ParamUtil.getString(request, "userName", "guest");
		try {
			dbc = new DBConnect();
			// 回帖子,增加用户的经验,魅力值
			SkinUtil.checkUser(request, response, 3);
			int forumID = this.forumID;
			String subject = ParamUtil.getString(request, "subject", "");
			subject = StringUtil.changeToFull(subject);
			String content = ParamUtil.getString(request, "content", "");
			if ("".equals(content)) {
				throw new Exception("请输入回复内容!");
			}
			String expression = ParamUtil.getString(request, "expression","");
			String sql = "";
			int rootID = ParamUtil.getInt(request, "rootID");

			sql = "select locktopic from bbs1 where announceid=" + rootID;
			rs.doQuery(sql);
			if (!rs.next()) {
				throw new Exception("<li>对不起,没有发现此主题!</li>");
			} else {
				// rs.next();
				if (rs.getInt(1) == 1 || rs.getInt(1) == 2) {
					throw new Exception("对不起,此帖子已经锁定,您不能回复!");
				}
			}

			int iLayer, iOrders;
			int signFlag = ParamUtil.getInt(request, "signFlag", 1);
			int emailFlag = ParamUtil.getInt(request, "emailFlag", 0);

			int parentID = ParamUtil.getInt(request, "parentID", rootID);
			sql = "select layer,orders from bbs1 where announceid=" + parentID;
			rs.close();
			rs.doQuery(sql);
			if (rs.next()) {
				if (rs.getString(1) != null)
					iLayer = 0;
				else
					iLayer = rs.getInt(1);
				if (rs.getString(2) != null)
					iOrders = 0;
				else
					iOrders = rs.getInt(2);
			} else {
				iLayer = 0;
				iOrders = 0;
			}
			rs.close();
			if (rootID != 0) {
				iLayer = iLayer + 1;
				rs.doUpdate("update bbs1 set orders=orders+1 where rootid="
						+ rootID + " and orders>" + iOrders);
				iOrders = iOrders + 1;
			}

			sql = "insert into bbs1(Boardid,ParentID,Child,username,topic,body,DateAndTime,hits,length,rootid,layer,orders,ip,Expression,locktopic,signflag,emailflag,istop,isbest,isvote,times) values "
					+ "("
					+ forumID
					+ ","
					+ parentID
					+ ",0,"
					+ "?,?,?,'"
					+ Format.getDateTime()
					+ "',0,"
					+ content.length()
					+ ","
					+ rootID
					+ ","
					+ iLayer
					+ ","
					+ iOrders
					+ ",'"
					+ request.getRemoteAddr()
					+ "',?,0,"
					//+ expression
					//+ "',0,"
					+ signFlag + "," + emailFlag + ",0,0,0,0)";
			dbc.prepareStatement(sql);
			dbc.setString(1, userName);
			dbc.setString(2, subject);
			dbc.setString(3, content);
			dbc.setString(4, expression);
			dbc.executeUpdate();
			//
			int announceID = rs
					.doIntSearch("select announceid from bbs1 order by announceid desc limit 0,1");

			sql = "update bbs1 set child=child+1,times=" + announceID
					+ " where rootID=" + rootID;
			rs.doUpdate(sql);
			String shortTopic = "";

			if ("".equals(subject))
				if (content.length() > 21)
					shortTopic = content.substring(0, 20);
				else
					shortTopic = content;
			else if (subject.length() > 21)
				shortTopic = subject.substring(0, 20);
			else
				shortTopic = subject;
			int forumToday = rs
					.doIntSearch("Select count(announceid) from bbs1 Where to_days(dateandtime)-to_days(Now())=0 and boardid="
							+ forumID);

			sql = "update board set lastpostuser='" + userName
					+ "',lastposttime='" + Format.getDateTime()
					+ "',lastbbsnum=lastbbsnum+1,todaynum=" + forumToday
					+ ",lastrootid=" + rootID + ",lasttopic=?"
					+ " where  boardid=" + forumID;
			// rs.doUpdate(sql);
			dbc.clearParameters();
			dbc.prepareStatement(sql);
			dbc.setString(1, shortTopic);
			dbc.executeUpdate();
			//
			int allTodays = rs
					.doIntSearch("Select count(announceid) from bbs1 Where to_days(dateandtime)-to_days(Now())=0");

			rs.doUpdate("update config set bbsnum=bbsnum+1,todayNum="
					+ allTodays);
			//
			CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(parentID));
			//
			ForumPropertiesManager.resetManager();
			//发邮件
			String ret = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
			+ "&announceID=" + announceID + "#" + announceID;
			String url = "http://www.liyunet.com/bbs/" + ret;
			emailReplay(parentID,"您在鲤鱼论坛上的帖子有回复了!","帖子地址:<a href='"+url+"' target=_blank>"+url+"</a>");
			
			return ret;
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			dbc.close();
		}
	}

	public String addVote(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			//
			String vote = ParamUtil.getString(request, "vote");
			vote = StringUtil.changeToFull(vote);
			String userName = ParamUtil.getString(request, "userName", "");
			if (vote == null)
				throw new Exception("<li>请您输入选举内容</li>");
			String voteNum = "";

			String reg = "(\r|\n)";
			String[] tempString = vote.split(reg);

			for (int i = 0; i < tempString.length; i++) {
				if (!tempString[i].trim().equals("")) {
					if (i == tempString.length - 1) {
						voteNum += "0";
					} else {
						voteNum += "0|";
					}
				}
			}
			int voteType = ParamUtil.getInt(request, "voteType", 0);
			//
			String url = this.addTopic(request, response);
			/*
			 * String sql = "insert into
			 * vote(announceID,vote,voteNum,voteType,voteUser) values(" + voteID +
			 * ",'" + vote + "','" + voteNum + "'," + voteType + ",'" + userName +
			 * "')"; rs.doUpdate(sql);
			 */
			dbc.prepareStatement("insert into vote(announceID,vote,voteNum,voteType,voteUser) values(?,?,?,?,?)");
			dbc.setInt(1, voteID);
			dbc.setString(2, vote);
			dbc.setString(3, voteNum);
			dbc.setInt(4, voteType);
			dbc.setString(5, userName);
			dbc.executeUpdate();
			return url;
		} catch (Exception e) {
			log.error(e);
			throw new Exception(e.getMessage());
		} finally {
			dbc.close();
		}
	}

	public ForumVote getForumVote(int announceID) throws Exception {
		SqlQuery rs = new SqlQuery("select * from vote where announceID="
				+ announceID);
		if (rs.next()) {
			ForumVote forumVote = new ForumVote();
			forumVote.setVoteID(rs.getInt(1));
			forumVote.setAnnounceID(rs.getInt(2));
			forumVote.setVote(rs.getString(3));
			forumVote.setVoteNum(rs.getString(4));
			forumVote.setVoteUser(rs.getString(5));
			forumVote.setVoteType(rs.getInt(6));
			return forumVote;
		} else
			throw new Exception("<li>错误,对不起,没有发现投票!</li>");
	}

	public String addVoteNum(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		SqlQuery rs = new SqlQuery();
		String userName = GCookie.getCookieValue(request, "UJBBUName", "");
		try {
			SkinUtil.checkUser(request, response, 3);
			//
			int announceID = ParamUtil.getInt(request, "announceID");
			int forumID = ParamUtil.getInt(request, "forumID");
			ForumVote theVote = this.getForumVote(announceID);
			String voteNum = "";
			int[] voteNumS = theVote.getVoteNumS();
			if (theVote.getUserSign(userName)) {
				throw new Exception("<li>对不起,您已经投票了!</li>");
			} else {
				if (theVote.getVoteType() == 0) {
					int postID = ParamUtil.getInt(request, "postVote");
					voteNumS[postID]++;
				} else {
					for (int i = 0; i < voteNumS.length; i++) {
						if (ParamUtil.getString(request, "postVote_" + (i)) != null)
							voteNumS[i]++;
					}
				}
				for (int i = 0; i < voteNumS.length; i++)
					if (i == voteNumS.length - 1)
						voteNum += Integer.toString(voteNumS[i]);
					else
						voteNum += Integer.toString(voteNumS[i]) + "|";
			}
			rs.doQuery("select * from vote where announceID=" + announceID);
			rs.next();
			String voteUser = rs.getString(5);
			voteUser += "|" + userName;
			String sql = "update vote set voteNum='" + voteNum + "',voteUser='"
					+ voteUser + "' where announceID=" + announceID;
			rs.doUpdate(sql);

			return "dispbbs.jsp?forumID=" + forumID + "&rootID=" + announceID
					+ "&announceID=" + announceID;
		} catch (Exception e) {
			log.error(e);
			throw new Exception(e.getMessage());
		} finally {
			rs.close();
		}
	}
}

⌨️ 快捷键说明

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