📄 clubactionaction.java
字号:
package com.jn0801.clubmanage.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.jn0801.clubmanage.Clubaction;
import com.jn0801.clubmanage.dao.ClubActionInf;
import com.jn0801.clubmanage.form.ClubActionForm;
/**
* 俱乐部活动的Action类
* @author jzh
*
*/
public class ClubActionAction extends DispatchAction {
private ClubActionInf clubActionInf;
public ClubActionInf getClubActionInf() {
return clubActionInf;
}
public void setClubActionInf(ClubActionInf clubActionInf) {
this.clubActionInf = clubActionInf;
}
/**
* 显示所有活动列表
*/
public ActionForward show(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List<Clubaction> actionlist = this.clubActionInf
.searchClubaction(request);
request.setAttribute("actionlist", actionlist);
return mapping.findForward("show");
}
/**
* 删除俱乐部活动
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Long nid = Long.parseLong(request.getParameter("nid"));
boolean tag = this.clubActionInf.deleteClubaction(nid);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if (tag) {
String url = "clubAction.do?tag=show";
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
url = url + "¤tpage="
+ request.getParameter("currentpage") + "";
}
out.println("<script>" + "alert('删除成功');"
+ "window.location.href = '" + url +"';</script>");
} else {
out.println("<script>" + "alert('删除失败');"
+ "window.history.back();" + "</script>");
}
out.flush();
if (out != null)
out.close();
return null;
}
/**
* 显示添加页面
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List list = this.clubActionInf.searchAllClub();
request.setAttribute("clublist", list);
return mapping.findForward("edit");
}
/**
* 添加俱乐部活动
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
Clubaction clubaction = new Clubaction();
try {
BeanUtils.copyProperties(clubaction, clubActionForm);
} catch (Exception e) {
e.printStackTrace();
}
clubaction.setIschecked("未");
clubaction.setFactcharge(null);
clubaction.setFactnum(null);
boolean tag = this.clubActionInf.saveClubaction(clubaction);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if(tag){
out.println("<script>" +
"alert('添加成功');" +
"window.location.href='" + request.getContextPath() +
"/clubAction.do?tag=show';" +
"</script>");
}else{
out.println("<script>alert('添加失败');" +
"window.history.back();" +
"</script>");
}
out.flush();
if (out != null)
out.close();
return null;
}
/**
* 显示更新页面
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
//记录页数
Map map = new HashMap();
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
map.put("currentpage", request.getParameter("currentpage"));
}
request.setAttribute("map", map);
Long nid = Long.parseLong(request.getParameter("nid"));
Clubaction clubaction = this.clubActionInf.searchClubactionById(nid);
try {
BeanUtils.copyProperties(clubActionForm, clubaction);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
List list = this.clubActionInf.searchAllClub();
request.setAttribute("clublist", list);
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
format.setTimeZone(TimeZone.getTimeZone("GMT+08"));
String systime = format.format(date);
String actiontime = clubaction.getActiontime();
int i = systime.compareTo(actiontime);
if(i>0){
//修改已经结束的活动
return mapping.findForward("edit2");
}
else{
//修改还未开始的活动
return mapping.findForward("edit");
}
}
/**
* 修改俱乐部活动
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
Clubaction clubaction = new Clubaction();
try {
BeanUtils.copyProperties(clubaction, clubActionForm);
} catch (Exception e) {
e.printStackTrace();
}
if(clubaction.getFactnum() == 0)
clubaction.setFactnum(null);
if(clubaction.getFactcharge() == 0)
clubaction.setFactcharge(null);
boolean tag = this.clubActionInf.updateClubaction(clubaction);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if(tag){
String url = "clubAction.do?tag=show";
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
url = url + "¤tpage="
+ request.getParameter("currentpage") + "";
}
out.println("<script>" + "alert('修改成功');"
+ "window.location.href = '" + url +"';</script>");
}else{
out.println("<script>alert('修改失败');" +
"window.history.back();" +
"</script>");
}
out.flush();
if (out != null)
out.close();
return null;
}
/**
* 查看详细信息
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward detail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
Long nid = Long.parseLong(request.getParameter("nid"));
Clubaction clubaction = this.clubActionInf.searchClubactionById(nid);
try {
BeanUtils.copyProperties(clubActionForm, clubaction);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return mapping.findForward("detail");
}
/**
* 导出列表
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward importlist(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
List<Clubaction> list = this.clubActionInf.searchClubaction();
String dir = this.servlet.getServletContext().getRealPath("tempfile");
String filename = "俱乐部活动资料";
try {
WritableWorkbook wwb = Workbook.createWorkbook(new File(dir
+ File.separator + filename + ".xls"));
//建立工作簿
WritableSheet ws = wwb.createSheet("俱乐部活动资料", 0);
Label label1 = new Label(0, 0, "活动编号");
ws.addCell(label1);
Label label2 = new Label(1, 0, "俱乐部名称");
ws.addCell(label2);
Label label3 = new Label(2, 0, "活动时间");
ws.addCell(label3);
Label label4 = new Label(3, 0, "活动地点");
ws.addCell(label4);
Label label5 = new Label(4, 0, "活动内容");
ws.addCell(label5);
Label label6 = new Label(5, 0, "活动组织者");
ws.addCell(label6);
Label label7 = new Label(6, 0, "活动预算");
ws.addCell(label7);
Label label8 = new Label(7, 0, "预计参加人数");
ws.addCell(label8);
Label label9 = new Label(8, 0, "实际费用");
ws.addCell(label9);
Label label10 = new Label(9, 0, "实际参加人数");
ws.addCell(label10);
Label label11 = new Label(10, 0, "是否已经审核");
ws.addCell(label11);
Label label12 = new Label(11, 0, "审核是否通过");
ws.addCell(label12);
Label label13 = new Label(12, 0, "审核意见");
ws.addCell(label13);
//设置格式(单元格的大小)
ws.setColumnView(1, 12);
ws.setColumnView(2, 16);
ws.setColumnView(7, 12);
ws.setColumnView(9, 12);
ws.setColumnView(10, 12);
ws.setColumnView(11, 12);
for (int i = 1; i <= list.size(); i++) {
Clubaction clubaction = list.get(i - 1);
label1 = new Label(0, i, String.valueOf(clubaction.getNid()));
ws.addCell(label1);
label2 = new Label(1, i, clubaction.getClubname());
ws.addCell(label2);
label3 = new Label(2, i, clubaction.getActiontime());
ws.addCell(label3);
label4 = new Label(3, i, clubaction.getSaddress());
ws.addCell(label4);
label5 = new Label(4, i, clubaction.getContent());
ws.addCell(label5);
label6 = new Label(5, i, clubaction.getOrganiger());
ws.addCell(label6);
label7 = new Label(6, i, String.valueOf(clubaction.getBudget()));
ws.addCell(label7);
label8 = new Label(7, i, String.valueOf(clubaction
.getIntendnum()));
ws.addCell(label8);
String factcharge = "";
if (clubaction.getFactcharge() != null)
factcharge = String.valueOf(clubaction.getFactcharge());
label9 = new Label(8, i, factcharge);
ws.addCell(label9);
String factnum = "";
if (clubaction.getFactnum() != null)
factnum = String.valueOf(clubaction.getFactnum());
label10 = new Label(9, i, factnum);
ws.addCell(label10);
label11 = new Label(10, i, clubaction.getIschecked());
ws.addCell(label11);
label12 = new Label(11, i, clubaction.getIspass());
ws.addCell(label12);
label13 = new Label(12, i, clubaction.getOpinion());
ws.addCell(label13);
}
//写入Excel工作表
wwb.write();
//关闭Excel工作簿对象
wwb.close();
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(dir + File.separator + filename
+ ".xls");
String temp = filename + ".xls";
response
.setHeader("Content-disposition",
"attachment;filename="
+ new String(temp.getBytes("GBK"),
"ISO-8859-1"));
response
.setContentType("application/x-msdownload;charset=UTF-8");
os = response.getOutputStream();
int i = 0;
byte[] b = new byte[10240];
while ((i = is.read(b, 0, b.length)) != -1) {
os.write(b, 0, i);
}
os.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (os != null)
os.close();
if (is != null)
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
File file = new File(dir + File.separator + filename + ".xls");
file.delete();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 显示审核页面
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward check(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
//记录页数
Map map = new HashMap();
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
map.put("currentpage", request.getParameter("currentpage"));
}
request.setAttribute("map", map);
Long nid = Long.parseLong(request.getParameter("nid"));
Clubaction clubaction = this.clubActionInf.searchClubactionById(nid);
try {
BeanUtils.copyProperties(clubActionForm, clubaction);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("check");
}
/**
* 审核俱乐部活动
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward checkAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClubActionForm clubActionForm = (ClubActionForm) form;
Long nid = clubActionForm.getNid();
String ispass = clubActionForm.getIspass();
String opinion = clubActionForm.getOpinion();
boolean tag = this.clubActionInf.updateClubactionForcheck(nid, ispass,
opinion);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if (tag) {
String url = "clubAction.do?tag=show";
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
url = url + "¤tpage="
+ request.getParameter("currentpage") + "";
}
out.println("<script>" + "alert('审核完毕');"
+ "window.location.href = '" + url +"';</script>");
} else {
out.println("<script>" + "alert('审核失败');" + "window.history.back();"
+ "</script>");
}
out.flush();
if (out != null)
out.close();
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -