📄 doplan.java~216~
字号:
package bbs.beans.plan;
import bbs.beans.plan.*;
import bbs.beans.dbcontact.ContactBean;
import java.sql.*;
import java.util.Date;
public class DoPlan
{ private Statement stm;
private ResultSet result;
public DoPlan()
{ ContactBean contact=new ContactBean();
stm=contact.getStm();
}
//AddPlan()方法中的形参planinfo在传来时其应有ownername,boardname,topic,text,属性值
public void AddPlan(TopicPlan planinfo)
{ int parent=planinfo.getParentId() ;
int child ;
int user=planinfo.getUserId() ;
int board=planinfo.getBoardId() ;
String tpc=planinfo.getTopic() ;
String txt=planinfo.getText() ;
int mood=planinfo.getMoodNum() ;
java.text.SimpleDateFormat format=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date Da = new Date();
String date = format.format(Da);
try {
if(parent==0)
{
result=stm.executeQuery("select * from topicplan where parentid=(select max(parentid) from topicplan where boardid="+board+")");
if(result.next())
parent=1+result.getInt("parentid") ;
else
parent=1;
stm.executeUpdate("insert into topicplan(parentid,userid,boardid,clicksnum,pubtime,topic,[text],state,replynum,moodnum) values("+
parent+","+user+","+board+",0,'"+date+"','" + tpc +"','"+txt+"',0,0,"+mood+")");
stm.executeUpdate("insert into useradd(userid,parentid,childid,boardid) values("+user+","+parent+",0,"+board);
result=stm.executeQuery("select boardtopices from boardinfo where boardid="+board);//所属版块的主题数加1
result.next() ;
stm.executeUpdate("update boardinfo set boardtopices="+(1+result.getInt(1))+" where boardid="+board);
}
else
{
result=stm.executeQuery("select * from replyplan where childid=(select max(childid) from replyplan where parentid="+parent+" and boardid="+board+")");
if(result.next())
child=1+result.getInt("childid");
else
child=1;
stm.executeUpdate("insert into replyplan(parentid,childid,userid,boardid,pubtime,topic,[text],moodnum) values("+
parent+","+child+"," +user+ "," + board + ",'" + date + "','" + tpc +"','" + txt + "',"+mood+")");
result=stm.executeQuery("select replynum from topicplan where parentid="+parent+" and boardid="+board);//所属主题的回复数加1
result.next() ;
stm.executeUpdate("update topicplan set replynum="+(1+result.getInt("replynum"))+" where parentid="+parent+" and boardid="+board);
}
result=stm.executeQuery("select plans from userinfo where userid="+user);
result.next();
stm.executeUpdate("update userinfo set plans="+(1+result.getInt("plans"))+" where userid="+user);
stm.close();
result.close();
}
catch (Exception e)
{ e.printStackTrace() ;
}
}
public void ModifyPlan(TopicPlan planinfo)
{
int parent=planinfo.getParentId() ;
int child=planinfo.getChildId() ;
int board=planinfo.getBoardId() ;
String tpc=planinfo.getTopic() ;
String txt=planinfo.getText() ;
int mood=planinfo.getMoodNum() ;
Date date=new java.sql.Date (new java.util.Date().getTime());
try
{
txt=txt+"[此帖子作者以于"+date+"修改过]";
if(child==0)
stm.executeUpdate("update topicplan set topic='"+tpc+"',[text]='"+txt+"',moodnum="+mood+" where parentid="+parent+" and boardid="+board);
else
stm.executeUpdate("update replyplan set topic='"+tpc+"',[text]='"+txt+"',moodnum="+mood+" where parentid="+parent+" and childid="+child+" and boardid="+board);
}
catch(Exception e)
{
e.printStackTrace() ;
}
}
public void DeletePlan(TopicPlan planinfo)
{ int parent=planinfo.getParentId() ;
int child=planinfo.getChildId() ;
int board=planinfo.getBoardId() ;
try
{
if(child==0)
{stm.executeUpdate("delete * from topicplan where parentid=" + parent + " and boardid=" + board);
stm.executeUpdate("delete * from replyplan where parentid=" + parent + " and boardid=" + board);
}
else
stm.executeUpdate("delete * from replyplan where parentid=" + parent + " and childid="+child+" and boardid=" + board);
}
catch(Exception e)
{
e.printStackTrace() ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -