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

📄 forumadmin.java

📁 BBS论坛设计JSP+MYSQL
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			sql = "delete from bbs1 where boardid=" + forumID;
			dbc.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			dbc.close();
		}
	}

	public static void dell(HttpServletRequest request) throws Exception {
		checkAdmin(request);
		int ID;
		try {
			ID = ParamUtil.getInt(request, "id");
		} catch (Exception e) {
			throw new Exception("请您选择您要删除的分类的ID");
		}
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			String sql = "delete from class where id=" + ID;
			dbc.executeUpdate(sql);
			sql = "delete from board where class=" + ID;
			dbc.executeUpdate(sql);
			sql = "select boardid from board where class=" + ID;
			ResultSet rs = dbc.executeQuery(sql);
			while (rs.next()) {
				sql = "delete from bbs1 where boardid=" + rs.getInt(1);
				dbc.executeUpdate(sql);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			dbc.close();
		}
	}

	public static void updateOrders(HttpServletRequest request)
			throws Exception {
		checkAdmin(request);
		int newID;
		try {
			newID = ParamUtil.getInt(request, "newid");
		} catch (Exception e) {
			throw new Exception("请您选择您想要更新的类别!");
		}
		int ID;
		try {
			ID = ParamUtil.getInt(request, "id");
		} catch (Exception e) {
			throw new Exception("请您选择您想要更新的类别!");
		}
		String className = ParamUtil.getString(request, "classname", "");
		if ("".equals(className)) {
			throw new Exception("请输入论坛类别名称!");
		}
		if (newID == ID) {
			return;
		}
		DBConnect dbc = null;
		try {
			dbc = new DBConnect();
			String sql = "select id from class where id=" + newID;
			ResultSet rs = dbc.executeQuery(sql);
			if (rs.next()) {
				dbc.close();
				throw new Exception("您输入的序号和其他分类序号相同,请重新输入。");
			}
			sql = "update class set id=" + newID + ",class=? where id=" + ID;
			System.out.println(sql);
			dbc.prepareStatement(sql);
			dbc.setString(1, className);
			dbc.executeUpdate();
			sql = "update board set class=" + newID + " where class=" + ID;
			dbc.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			dbc.close();
		}
	}

	public static void saveClass(HttpServletRequest request) throws Exception {
		checkAdmin(request);
		String classname = ParamUtil.getString(request, "classname");
		if (classname == null)
			throw new Exception("请您输入您想添加分类的名字!");
		String sql = "insert into class(class) values(?)";
		DBConnect dbc = null;
		try {
			dbc = new DBConnect(sql);
			dbc.setString(1, classname);
			dbc.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			dbc.close();
		}
	}

	public String update() throws Exception {
		String sql = "select boardid,boardtype from board";
		SqlQuery rs = new SqlQuery(sql);
		//
		if (!rs.next()) {
			throw new Exception("论坛还没有版面,请先添加版面。");
		}
		//
		DBConnect dbc = null;
		StringBuffer sb = new StringBuffer();
		try {
			dbc = new DBConnect();
			//
			String newuser = newuser();
			do {
				sql = "Select count(announceid) from bbs1 where boardid="
						+ rs.getInt(1);
				int allArticle = rs.doIntSearch(sql);
				//
				sql = "Select count(announceid) from bbs1 where boardid="
						+ rs.getInt(1) + " and parentID=0";
				int allTopic = rs.doIntSearch(sql);
				//
				sql = "select Max(announceid) from bbs1 where boardid="
						+ rs.getInt(1);
				String tmpID = rs.doSearch(sql);
				String userName, dateandtime;
				if (tmpID == null) {
					userName = "无";
					dateandtime = Format.getDateTime();
				} else {
					sql = "select username,dateandtime from bbs1 where announceid="
							+ tmpID;
					SqlQuery maxRs = new SqlQuery(sql);
					maxRs.next();
					userName = maxRs.getString(1);
					dateandtime = maxRs.getString(2);
				}
				//
				sql = "update board set lastpostuser='" + userName
						+ "',lastposttime='" + dateandtime + "',lastbbsnum="
						+ allArticle + ",lasttopicnum=" + allTopic
						+ ",TodayNum=" + todays(rs.getInt(1), dbc)
						+ " where boardid=" + rs.getInt(1);
				rs.doUpdate(sql);
				sb.append("更新论坛数据成功," + rs.getString(2) + "共有" + allArticle
						+ "篇贴子," + allTopic + "篇主题,今日有"
						+ todays(rs.getInt(1), dbc) + "篇帖子。<br>");
			} while (rs.next());
			//
			sql = "update config set TopicNum=" + titlenum(dbc) + ",BbsNum="
					+ gettipnum(dbc) + ",TodayNum=" + alltodays(dbc)
					+ ",UserNum=" + allusers(dbc) + ",lastUser=?";
			dbc.prepareStatement(sql);
			dbc.setString(1, newuser);
			dbc.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			dbc.close();
		}
		ForumPropertiesManager.resetManager();
		return sb.toString();

	}

	public int todays(int boardid, DBConnect dbc) throws Exception {
		ResultSet tmprs = dbc
				.executeQuery("Select count(announceid) from bbs1 Where  to_days(dateandtime)=to_days(now()) and boardid="
						+ boardid);
		tmprs.next();
		String tempString = tmprs.getString(1);
		int temp = (tempString == null) ? 0 : tmprs.getInt(1);
		return temp;
	}

	public int alltodays(DBConnect dbc) throws Exception {
		ResultSet tmprs = dbc
				.executeQuery("Select count(announceid) from bbs1 Where  to_days(dateandtime)=to_days(now())");
		tmprs.next();
		String tempString = tmprs.getString(1);
		int temp = (tempString == null) ? 0 : tmprs.getInt(1);
		return temp;

	}

	public int allusers(DBConnect dbc) throws Exception {
		ResultSet tmprs = dbc.executeQuery("Select count(userid) from user");
		tmprs.next();
		String tempString = tmprs.getString(1);
		int temp = (tempString == null) ? 0 : tmprs.getInt(1);
		return temp;
	}

	public String newuser() throws Exception {
		SqlQuery tmprs = new SqlQuery(
				"Select  username from user order by userid desc limit 0,1");
		String newuser;
		if (!tmprs.next()) {
			newuser = "没有会员";
		} else {
			newuser = tmprs.getString(1);
		}
		return newuser;
	}

	public int gettipnum(DBConnect dbc) throws Exception {
		ResultSet tmprs = dbc
				.executeQuery("Select Count(announceID) from bbs1");
		tmprs.next();
		String tempString = tmprs.getString(1);
		int temp = (tempString == null) ? 0 : tmprs.getInt(1);
		return temp;
	}

	public int titlenum(DBConnect dbc) throws Exception {
		ResultSet tmprs = dbc
				.executeQuery("Select Count(announceID) from bbs1 where parentID=0");
		tmprs.next();
		String tempString = tmprs.getString(1);
		int temp = (tempString == null) ? 0 : tmprs.getInt(1);
		return temp;
	}

	public static void addMaster(String masters, DBConnect dbc)
			throws Exception {

		String[] arr = masters.split("\\|");
		ResultSet rs;
		String sql;
		for (int i = 0; i < arr.length; i++) {
			sql = "select userID from user where userName=?";
			dbc.prepareStatement(sql);
			dbc.setString(1, arr[i]);
			rs = dbc.executeQuery();
			if (!rs.next()) {
				dbc.close();
				throw new Exception("没有发现此用户" + arr[i]);
			}
			sql = "update user set userclass=19 where username=?";
			dbc.prepareStatement(sql);
			dbc.setString(1, arr[i]);
			dbc.executeUpdate();
		}
	}

	public static void delMaster(String masters, DBConnect dbc)
			throws Exception {
		String[] arr = masters.split("\\|");
		ResultSet rs;
		String sql;
		for (int i = 0; i < arr.length; i++) {
			//检查在其它版块是否版主
			sql = " select boardmaster from board where boardmaster like '%"+arr[i]+"%'";
			dbc.prepareStatement(sql);
			rs = dbc.executeQuery();
			if (!rs.next()) {
				sql = "update user set userclass=18 where username=?";
				dbc.prepareStatement(sql);
				dbc.setString(1, arr[i]);
				dbc.executeUpdate();
			}
		}
	}

}

⌨️ 快捷键说明

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