package edu.cdio.action; import java.io.IOException; import java.io.PrintWriter; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import org.springframework.beans.factory.annotation.Autowired; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import edu.cdio.domain.Contract; import edu.cdio.service.ContractService; import edu.cdio.util.PageBean; public class ContractAction extends ActionSupport implements ModelDriven<Contract>{ /** * */ private static final long serialVersionUID = 1L; @SuppressWarnings("unused") @Autowired //注入adminService接口 private ContractService contractService; //封装数据 private Contract contract = new Contract(); public Contract getModel() { return this.contract; } private PageBean pageBean; private int pageNum =1; //表示网页中返回的当前的值,默认为1 //实现分页功能 public String page(){ HttpServletRequest request=ServletActionContext.getRequest(); String skipPage = request.getParameter("skipPage"); //跳转页面输入是否为空 if(skipPage!=null && !skipPage.equals("")){ pageNum = Integer.parseInt(request.getParameter("skipPage")); } this.pageBean = contractService.pageOfContract(5, pageNum); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCount", pageBean.getCount()); context.getSession().put("totalPageo", pageBean.getTotalPage()); context.getSession().put("currentPageo", pageBean.getCurrentPage()); context.getSession().put("listContract", pageBean.getList()); return "page"; } public String pages(){ HttpServletRequest request=ServletActionContext.getRequest(); String skipPage = request.getParameter("skipPage"); //跳转页面输入是否为空 if(skipPage!=null && !skipPage.equals("")){ pageNum = Integer.parseInt(request.getParameter("skipPage")); } String state="已审核"; this.pageBean = contractService.pageOfContracts(5, pageNum,state); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCount", pageBean.getCount()); context.getSession().put("totalPageo", pageBean.getTotalPage()); context.getSession().put("currentPageo", pageBean.getCurrentPage()); context.getSession().put("listContracts", pageBean.getList()); return "pages"; } public String pageo(){ HttpServletRequest request=ServletActionContext.getRequest(); String skipPage = request.getParameter("skipPage"); //跳转页面输入是否为空 if(skipPage!=null && !skipPage.equals("")){ pageNum = Integer.parseInt(request.getParameter("skipPage")); } this.pageBean = contractService.pageOfContract(5, pageNum); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCount", pageBean.getCount()); context.getSession().put("totalPageo", pageBean.getTotalPage()); context.getSession().put("currentPageo", pageBean.getCurrentPage()); context.getSession().put("listContract", pageBean.getList()); return "pageo"; } public String pagea(){ HttpServletRequest request=ServletActionContext.getRequest(); String skipPage = request.getParameter("skipPage"); //跳转页面输入是否为空 if(skipPage!=null && !skipPage.equals("")){ pageNum = Integer.parseInt(request.getParameter("skipPage")); } this.pageBean = contractService.pageOfContract(5, pageNum); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCounta", pageBean.getCount()); context.getSession().put("totalPagea", pageBean.getTotalPage()); context.getSession().put("currentPagea", pageBean.getCurrentPage()); context.getSession().put("listContracta", pageBean.getList()); return "pagea"; } //添加 public String add(){ ActionContext context = ActionContext.getContext(); context.getSession().remove("msg1"); context.getSession().remove("msg2"); //获取参数 HttpServletRequest request=ServletActionContext.getRequest(); //String repwd = request.getParameter("repeatPassword"); String name = contract.getContractname(); //String pwd = admin.getAdminPassword(); if (this.contractService.findOneContract(name).size()>0) { context.getSession().put("msg1", "用户名已存在!"); return "errorAdd"; }else if (name==null || name.equals("")) { context.getSession().put("msg1", "用户名不能为空!"); return "errorAdd"; } //执行方法 this.contractService.saveContract(contract); //弹出提示 HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); try { PrintWriter out = response.getWriter(); out.println("<script type='text/javascript'>alert('添加成功!');" + "window.location.href='contract/add_contract.jsp';</script>"); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return null; } //跳转页面 public String skipAdd(){ ActionContext context = ActionContext.getContext(); context.getSession().remove("msg1"); context.getSession().remove("msg2"); //context.getSession().remove("msg3"); return "skipAdd"; } public String updatesate(){ //String state = "已提交"; List<Contract> cs = contractService.findOneContract(contract.getContractname()); if(cs.get(0).getContractstate().equals("已订立")){ this.contractService.updateState("已提交",contract.getContractname()); }else if (cs.get(0).getContractstate().equals("已提交")){ this.contractService.updateState("已审核",contract.getContractname()); }else { this.contractService.updateState("已执行",contract.getContractname()); } //this.contractService.updateState(state,contract.getContractname()); return "updatestate"; } public String updatesateo(){ //String state = "已提交"; List<Contract> cs = contractService.findOneContract(contract.getContractname()); if(cs.get(0).getContractstate().equals("已订立")){ this.contractService.updateState("已提交",contract.getContractname()); }else if (cs.get(0).getContractstate().equals("已提交")){ this.contractService.updateState("已审核",contract.getContractname()); }else { this.contractService.updateState("已执行",contract.getContractname()); } //this.contractService.updateState(state,contract.getContractname()); return "updatestateo"; } //删除 public String delete(){ this.contractService.deleteContract(contract.getContractid()); return "delete"; } //查找一个管理员信息 public String show(){ contract = this.contractService.findOneContract(contract.getContractname()).get(0); ActionContext context = ActionContext.getContext(); context.getSession().put("contract", contract); return "show"; } //修改信息 public String update() throws IOException{ this.contractService.update(contract); return "update"; } //根据名字关键字搜索 public String selecto(){ //获取输入内容 HttpServletRequest request=ServletActionContext.getRequest(); String input = request.getParameter("searcher"); String skipPage = request.getParameter("skipPager"); //跳转页面输入是否空 if(skipPage!=null && !skipPage.equals("")){ pageNum = Integer.parseInt(request.getParameter("skipPager")); } //执行方法 pageBean = this.contractService.pageOfName(5, pageNum, input); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCount2", pageBean.getCount()); context.getSession().put("totalPageoo", pageBean.getTotalPage()); context.getSession().put("currentPageoo", pageBean.getCurrentPage()); context.getSession().put("listContract2", pageBean.getList()); return "selecto"; } public String selectx(){ //获取输入内容 HttpServletRequest request=ServletActionContext.getRequest(); String input = request.getParameter("sear"); String skipPage = request.getParameter("skip"); //跳转页面输入是否空 if(skipPage!=null && !skipPage.equals("")){ pageNum = Integer.parseInt(request.getParameter("skip")); } //执行方法 pageBean = this.contractService.pageOfName(5, pageNum, input); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCountx", pageBean.getCount()); context.getSession().put("totalPagex", pageBean.getTotalPage()); context.getSession().put("currentPagex", pageBean.getCurrentPage()); context.getSession().put("listContractx", pageBean.getList()); return "selectx"; } public String select(){ //获取输入内容 HttpServletRequest request=ServletActionContext.getRequest(); // String input = request.getParameter("searcher"); // String skipPage = request.getParameter("skipPager"); String input="已提交"; //跳转页面输入是否空 // if(skipPage!=null && !skipPage.equals("")){ // pageNum = Integer.parseInt(request.getParameter("skipPager")); // } //执行方法 pageBean = this.contractService.pageOfName(5, pageNum, input); ActionContext context = ActionContext.getContext(); context.getSession().put("contractCount2", pageBean.getCount()); context.getSession().put("totalPageoo", pageBean.getTotalPage()); context.getSession().put("currentPageoo", pageBean.getCurrentPage()); context.getSession().put("listContract2", pageBean.getList()); return "select"; } public int getPageNum() { return pageNum; } public void setPageNum(int pageNum) { this.pageNum = pageNum; } public PageBean getPageBean() { return pageBean; } public void setPageBean(PageBean pageBean) { this.pageBean = pageBean; } }