⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 403a89979b30001d1f81bebe3c68a6df

📁 客户关系管理系统主要管理新老客户的一些信息并可以发现潜在客户
💻
字号:
/**
 * 
 */
package com.qrsx.qrsxcrm.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.qrsx.qrsxcrm.dao.ChanceDAO;
import com.qrsx.qrsxcrm.form.ChanceForm;
import com.qrsx.qrsxcrm.model.Chance;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.model.Employee;
import com.qrsx.qrsxcrm.web.Pager;

/**
 * @author Administrator
 *
 */
public class ChanceAction extends BaseDispatchAction
{
	@SuppressWarnings({ "unchecked", "deprecation" })
	public ActionForward save(ActionMapping mapping,ActionForm form ,HttpServletRequest request,HttpServletResponse response)throws Exception{
		ActionErrors errors=form.validate(mapping,request);
		if(!errors.isEmpty()){
			saveErrors(request,errors);
			return edit(mapping,form,request,response);
		}
		ChanceDAO chanceDao=new ChanceDAO(Chance.class);
		ChanceForm chanceForm = (ChanceForm)form;
		String clientId=chanceForm.getClientId();
		String employeeId=chanceForm.getEmployeeId();
		Client client = (Client) chanceDao.findById(Client.class, clientId);
		Employee employee=( Employee)chanceDao.findById(Employee.class, employeeId);
		
		Chance chance=new Chance();
		BeanUtils.copyProperties(chance,form);
		chance.setClient(client);
		chance.setEmployee(employee);
		
		if( chance.getId()==null||chance.getId().trim().length()==0 ){
			chanceDao.create(chance);
			saveMessage(request,"create" ,chance.getMotif());
		}
		else{
			chanceDao.updates(chance);
			saveMessage(request,"update",chance.getMotif());
		}
		return mapping.findForward("success");
	}
		
	@SuppressWarnings("unchecked")
	public ActionForward list(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
			
			ChanceDAO chanceDao=new ChanceDAO(Chance.class);	
			Chance chance=new Chance();
			BeanUtils.copyProperties(chance,form);
			List<Client> clients = chanceDao.findAll("from Client");
			List<Employee> employees = chanceDao.findAll("from Employee");
			request.setAttribute("clients",clients);
			request.setAttribute("employees",employees);
			
			
			try {
				Pager pager = null;
				
				List results = chanceDao.findAll("from Chance");//得到总数据
				
				pager = new Pager(); // 构造分页对象
				int totalRows = results.size(); // 得到总数据量
				pager.init(totalRows);

				if (request.getParameter("action") != null) {
					pager.doAction(request.getParameter("action").toString());
				}
				// 使用分页标签的方法
//				List list = chanceDao.findAllByPage(chance, (pager.getCurrentPage() - 1)* pager.getPageSize(),pager.getPageSize());
				List list = chanceDao.findAll("from Chance");//得到总数据
				request.getSession().setAttribute("pagerstruts", pager);
				request.setAttribute("chances", list);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			
			
			
			return mapping.findForward("list");
		}
	
	@SuppressWarnings("unchecked")
	public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String id=request.getParameter("id");
		ChanceDAO chanceDAO=new ChanceDAO(Chance.class);
		List<Client> clients = chanceDAO.findAll("from Client");
		List<Employee> employees = chanceDAO.findAll("from Employee");
		request.setAttribute("clients",clients);
		request.setAttribute("employees",employees);
		if(id!=null&&id.trim().length()>0){
			Chance chance =(Chance) chanceDAO.findById( Chance.class, id);
			if( chance.getClient() != null )
			{
				chance.setClientId(chance.getClient().getId());
			}
			if( chance.getEmployee() != null )
			{
				chance.setEmployeeId(chance.getEmployee().getId());
			}
			if (chance!=null){
				BeanUtils.copyProperties(form,chance);
			}
		}
		return mapping.findForward("edit");
	}
	
	
	@SuppressWarnings("unchecked")
	public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String id=request.getParameter("id");
		ChanceDAO chanceDAO=new ChanceDAO(Chance.class);
		Chance chance =(Chance) chanceDAO.findById( Chance.class, id);
		chanceDAO.delete(chance);
		
		return mapping.findForward("success");
	}

	
	public ActionForward info(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String id=request.getParameter("id");
		if(id!=null&&id.trim().length()>0){
			ChanceDAO chanceDAO=new ChanceDAO(Chance.class);
			Chance chance =(Chance) chanceDAO.findById( Chance.class, id);
			request.setAttribute("chance",chance);
		}
		return mapping.findForward("info");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -