首页>代码>基于SSH框架的java CRM客户关系管理系统,网上下载的模板>/crmmanager7 (1)/src/edu/cdio/action/ContractAction.java
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;
		}	
		
}
	

最近下载更多
晴风8815  LV2 2023年2月27日
彭斌java  LV6 2022年12月1日
暮江吟  LV8 2022年11月12日
lwp011  LV27 2022年9月19日
gangan85  LV2 2022年8月1日
adminadminsqwqe  LV8 2022年7月13日
xiaohe229  LV8 2022年5月19日
wangyang520  LV6 2022年4月29日
安东尼online  LV11 2022年4月24日
杨豫川  LV12 2022年4月12日
最近浏览更多
张春青  LV6 11月14日
sunlea  LV20 5月22日
李俊雄  LV3 4月30日
FFF112233  LV8 3月27日
爱丽淇  LV5 3月18日
ChenZheMeng  LV3 3月9日
PSSDZH  LV3 1月22日
wuge123  LV8 2023年12月18日
WBelong  LV8 2023年12月11日
飞呀飞呀飞不放  LV7 2023年8月10日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友