package com.bbs.struts.action;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import com.bbs.struts.DAO.ResponseDAO;
import com.bbs.struts.DAO.TopicDAO;
import com.bbs.struts.DAO.UserDAO;
import com.bbs.struts.model.TbResponse;
import com.bbs.struts.model.TbTopic;
import com.bbs.struts.model.TbUser;
import com.bbs.struts.util.Time;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ResponseAction extends ActionSupport {
private HttpServletRequest request;
private int topicid;
private String topicname;
private List<TbResponse> responseList = null;
private int forumid;
private TbTopic tview = null;
private TopicDAO topicDAO;
private ResponseDAO responseDAO;
private UserDAO userDAO;
private int pageid;
private int pagecount;
private int id;
private String result;
private TbResponse rp;
public TbResponse getRp() {
return rp;
}
public void setRp(TbResponse rp) {
this.rp = rp;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPageid() {
return pageid;
}
public void setPageid(int pageid) {
this.pageid = pageid;
}
public TbTopic getTview() {
return tview;
}
public void setTview(TbTopic tview) {
this.tview = tview;
}
public int getTopicid() {
return topicid;
}
public void setTopicid(int topicid) {
this.topicid = topicid;
}
public String getTopicname() {
return topicname;
}
public void setTopicname(String topicname) {
this.topicname = topicname;
}
public int getForumid() {
return forumid;
}
public void setForumid(int forumid) {
this.forumid = forumid;
}
public void setResponseList(List<TbResponse> responseList) {
this.responseList = responseList;
}
public List<TbResponse> getResponseList() {
return responseList;
}
public String doResponselist() {
tview = topicDAO.getTopicview(topicid);
topicname = tview.getTitle();
responseList = responseDAO.getResponseview(topicid);
return SUCCESS;
}
public String responsetopic() { //分页显示所有的回复
request = ServletActionContext.getRequest();
responseList = responseDAO.getResponseByPage(pageid);
pagecount = responseDAO.getResponsePageCount();
request.setAttribute("responseList", responseList);
request.setAttribute("pagecount", pagecount);
return SUCCESS;
}
public String doDeleteReponse() { //删除回复
if (responseDAO.deleResponse(id)) {
setResult("恭喜,成功删除!");
} else
setResult("删除失败,请稍后再试!");
return SUCCESS;
}
public String doResponse() { //回帖
String name = (String) ActionContext.getContext().getSession().get(
"name");
rp.setAuthor(name);
responseDAO.InsertResponseRecord(rp);
TbUser user = null;
user = userDAO.getRecordForUser(name);
result ="<tr>"+
"<td width='1002' height='183' valign='top'background='images/r3.gif'>"+
"<table width='100%' height='177' border='0'>"+
"<tr><td height='28' colspan='2'> </td><td width='8%'> </td>"+
"<td width='20%' class='zczi' valign='baseline'>"+user.getEmail()+"</td>"+
"<td width='15%' class='zczi' valign='baseline'>"+user.getQq()+"</td>"+
"<td width='30%' class='fyzi' valign='baseline'>"+rp.getSubmittime()+"</td></tr>"+
"<tr><td height='66' colspan='2' align='center'>"+
"<img src='images/touxiang/"+user.getTx()+"' width='60' height='60'></td>"+
"<td colspan='5' rowspan='2' valign='top' class='zczi'>"+rp.getContent()+"</td></tr>"+
"<tr><td height='27' colspan='2' align='center' valign='middle' class='zczi'>作者:"+rp.getAuthor()+"</td></tr><tr>"+
"<td width='9%' height='42' align='center' valign='top'> </td>"+
"<td width='8%' valign='top'>"+
"<img src='images/xq/"+rp.getXq()+"' width='20'height='20'>"+
"</td><td colspan='4'> </td><td width='10%'> </td></tr></table></td></tr>";
return SUCCESS;
}
public void setTopicDAO(TopicDAO topicDAO) {
this.topicDAO = topicDAO;
}
public TopicDAO getTopicDAO() {
return topicDAO;
}
public void setResponseDAO(ResponseDAO responseDAO) {
this.responseDAO = responseDAO;
}
public ResponseDAO getResponseDAO() {
return responseDAO;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
public int getPagecount() {
return pagecount;
}
public void setResult(String result) {
this.result = result;
}
public String getResult() {
return result;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
public UserDAO getUserDAO() {
return userDAO;
}
}