?? forumadmin.java
字號:
}
public static void dell(HttpServletRequest request) throws Exception{
int ID;
try{
ID=ParamUtil.getInt(request,"id");
}
catch(Exception e){
throw new Exception("請您選擇您要刪除的分類的ID");
}
DBConnect dbc=new DBConnect();
String sql = "delete from bbs.class where id="+ID;
dbc.executeUpdate(sql);
sql = "delete from bbs.board where class="+ID;
dbc.executeUpdate(sql);
sql="select boardid from bbs.board where class="+ID;
ResultSet rs=dbc.executeQuery(sql);
while(rs.next()){
sql="delete from bbs.bbs1 where boardid="+rs.getInt(1);
dbc.executeUpdate(sql);
}
dbc.close();
}
public static void updateOrders(HttpServletRequest request) throws Exception{
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("請您選擇您想要更新的類別!");
}
if(newID==ID)
return;
DBConnect dbc=new DBConnect();
String sql="select * from bbs.class where id="+newID;
ResultSet rs=dbc.executeQuery(sql);
if(rs.next())
throw new Exception("您輸入的序號和其他分類序號相同,請重新輸入。");
sql="update bbs.class set id="+newID+",class=? where id="+ID;
dbc.prepareStatement(sql);
dbc.setBytes(1,(new String(ParamUtil.getString(request,"classname","").getBytes("ISO-8859-1"),"GBK")).getBytes());
dbc.executeUpdate();
sql="update bbs.board set class="+newID+" where class="+ID;
dbc.executeUpdate(sql);
sql="update bbs.board set class="+newID+" where class="+ID;
dbc.executeUpdate(sql);
dbc.close();
}
public static void saveClass(HttpServletRequest request) throws Exception{
String classname=ParamUtil.getString(request,"classname");
if(classname==null)
throw new Exception("請您輸入您想添加分類的名字!");
String sql="insert into bbs.class(class) values(?)";
DBConnect dbc=new DBConnect(sql);
dbc.setBytes(1,(new String(classname.getBytes("ISO-8859-1"),"GBK")).getBytes());
dbc.executeUpdate();
dbc.close();
}
public String update() throws Exception{
String sql="select boardid,boardtype from bbs.board";
DBConnect dbc1=new DBConnect(sql);
ResultSet rs=dbc1.executeQuery();
StringBuffer sb=new StringBuffer();
if(!rs.next()){
dbc1.close();
throw new Exception("論壇還沒有版面,請先添加版面。");
}
// temprs;
DBConnect dbc=new DBConnect();
String newuser=newuser(dbc);
do{
sql="Select count(announceid) from bbs.bbs1 where boardid="+rs.getInt(1);
ResultSet temprs=dbc.executeQuery(sql);
temprs.next();
String tempString=temprs.getString(1);
int allArticle=(tempString==null)?0:temprs.getInt(1);
temprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 where boardid="+rs.getInt(1) +" and parentID=0");
temprs.next();
tempString=temprs.getString(1);
int allTopic=(tempString==null)?0:temprs.getInt(1);
ResultSet ers=dbc.executeQuery("select Max(announceid) from bbs.bbs1 where boardid="+rs.getInt(1));
ers.next();
tempString=ers.getString(1);
//int maxID=(tempString==null)?"無":ers.getInt(1);
String userName,dateandtime;
if(tempString==null){
userName="無";
dateandtime=Format.getDateTime();
}
else {
int maxID=ers.getInt(1);
ers=dbc.executeQuery("select username,dateandtime from bbs.bbs1 where announceid="+maxID);
ers.next();
userName=ers.getString(1);
dateandtime=ers.getString(2);
}
sql="update bbs.board set lastpostuser=?,lastposttime='"+dateandtime+"',lastbbsnum="+allArticle+",lasttopicnum="+allTopic+",TodayNum="+todays(rs.getInt(1),dbc)+" where boardid="+rs.getInt(1);
dbc.prepareStatement(sql);
dbc.setBytes(1,(new String(userName.getBytes("ISO-8859-1"),"GBK")).getBytes());
dbc.executeUpdate();
sb.append("更新論壇數據成功,"+rs.getString(2)+"共有"+allArticle+"篇貼子,"+allTopic+"篇主題,今日有"+todays(rs.getInt(1),dbc)+"篇帖子。<br>");
}
while(rs.next());
sql="update bbs.config set TopicNum="+titlenum(dbc)+",BbsNum="+gettipnum(dbc)+",TodayNum="+alltodays(dbc)+",UserNum="+allusers(dbc)+",lastUser=?";
dbc.prepareStatement(sql);
dbc.setBytes(1,(new String(newuser.getBytes("ISO-8859-1"),"GBK")).getBytes());
dbc.executeUpdate();
dbc.close();
dbc1.close();
ForumPropertiesManager.resetManager();
return sb.toString();
}
public int todays(int boardid,DBConnect dbc) throws Exception{
ResultSet tmprs=dbc.executeQuery("Select count(announceid) from bbs.bbs1 Where day(dateandtime)=day(getdate()) 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 bbs.bbs1 Where day(dateandtime)=day(getdate())");
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 bbs.myuser");
tmprs.next();
String tempString=tmprs.getString(1);
int temp=(tempString==null)?0:tmprs.getInt(1);
return temp;
}
public String newuser(DBConnect dbc) throws Exception{
ResultSet tmprs=dbc.executeQuery("Select username from bbs.myuser order by userid desc");
String newuser;
if(!tmprs.next()){
newuser="沒有會員";
}
else{
//tmprs.next();
newuser=tmprs.getString(1);
}
return newuser;
}
public int gettipnum(DBConnect dbc) throws Exception{
ResultSet tmprs=dbc.executeQuery("Select Count(announceID) from bbs.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 bbs.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("\\|");
//DBConnect dbc=
ResultSet rs;
String sql;
for(int i=0;i<arr.length;i++){
sql="select userID from bbs.myuser where userName=?";
dbc.prepareStatement(sql);
dbc.setBytes(1,(new String(arr[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
rs=dbc.executeQuery();
if(!rs.next()){
dbc.close();
throw new Exception("沒有發現此用戶"+arr[i]);
}
sql="update bbs.myuser set userclass=19 where username=?";
dbc.prepareStatement(sql);
dbc.setBytes(1,(new String(arr[i].getBytes("ISO-8859-1"),"GBK")).getBytes());
dbc.executeUpdate();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -