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

📄 serviceaction.java

📁 客户关系管理系统主要管理新老客户的一些信息并可以发现潜在客户
💻 JAVA
字号:
/**
 * 
 */
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.DeptDAO;
import com.qrsx.qrsxcrm.dao.DutyDAO;
import com.qrsx.qrsxcrm.dao.ServiceDAO;
import com.qrsx.qrsxcrm.form.ServiceForm;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.model.Dept;
import com.qrsx.qrsxcrm.model.Duty;
import com.qrsx.qrsxcrm.model.Employee;
import com.qrsx.qrsxcrm.model.Service;
import com.qrsx.qrsxcrm.model.ServiceType;
import com.qrsx.qrsxcrm.web.Pager;
/**
 * @author Administrator
 *
 */
public class ServiceAction extends BaseDispatchAction 
{

		@SuppressWarnings("unchecked")
		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);
			}
			ServiceForm serviceForm = (ServiceForm)form;
			String clientId= serviceForm.getClientId();
			String employeeId= serviceForm.getEmployeeId();
			String serviceTypeId = serviceForm.getServiceTypeId();
			ServiceDAO serviceDAO=new ServiceDAO(Service.class);
			Service service=new Service();
			BeanUtils.copyProperties(service,form);
			Client client = (Client) serviceDAO.findById(Client.class, clientId);
			Employee employee = ( Employee )serviceDAO.findById(Employee.class, employeeId);
			ServiceType serviceType = (ServiceType)serviceDAO.findById(ServiceType.class, serviceTypeId);
			service.setClient(client);
			service.setEmployee(employee);
			service.setServiceType(serviceType);
			
			if( service.getId()==null||service.getId().trim().length()==0 ){
				serviceDAO.create(service);
				saveMessage(request,"addressForm.added" ,service.getRemark());
			}
			else{
				serviceDAO.updates(service);
				saveMessage(request,"addressForm.updated",service.getRemark());
			}
			return mapping.findForward("success");
		}
			
		@SuppressWarnings("unchecked")
		public ActionForward list(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
				ServiceDAO serviceDao=new ServiceDAO(Service.class);	
			
				Service service=new Service();
				BeanUtils.copyProperties(service,form);
				ServiceForm serviceForm = ( ServiceForm) form;
				String clientId = serviceForm.getClientId();
				String employeeId = serviceForm.getEmployeeId();
				String serviceTypeId = serviceForm.getServiceTypeId();
				if( clientId != null )//检索信息组装
				{
					Client client = (Client) serviceDao.findById(Client.class, clientId);
					service.setClient(client);
				}
				if( employeeId != null )
				{
					Employee employee = (Employee) serviceDao.findById(Employee.class, employeeId);
					service.setEmployee(employee);
				}
				if(serviceTypeId != null )
				{
					ServiceType serviceType = (ServiceType) serviceDao.findById(ServiceType.class, serviceTypeId);
					service.setServiceType(serviceType);
				}
				
				List<Client> clients = serviceDao.findAll("from Client");
				List<Employee> employees = serviceDao.findAll("from Employee");
				List<ServiceType> serviceTypes = serviceDao.findAll("from ServiceType");
				request.setAttribute("clients",clients);
				request.setAttribute("employees",employees);
				request.setAttribute("serviceTypes", serviceTypes);
				
				try {
					Pager pager = null;
					
					List results = serviceDao.findAll("from Service");//得到总数据
					
					pager = new Pager(); // 构造分页对象
					int totalRows = results.size(); // 得到总数据量
					pager.init(totalRows);

					if (request.getParameter("action") != null) {
						pager.doAction(request.getParameter("action").toString());
					}
					// 使用分页标签的方法
					List list = serviceDao.findAllByPage(service, (pager.getCurrentPage() - 1)* pager.getPageSize(),pager.getPageSize());
					request.getSession().setAttribute("pagerstruts", pager);
					request.setAttribute("services", 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{
			ServiceDAO serviceDAO=new ServiceDAO(Service.class);
			String id=request.getParameter("id");
			List<Client> clients = serviceDAO.findAll("from Client");
			List<Employee> employees = serviceDAO.findAll("from Employee");
			List<ServiceType> serviceTypes = serviceDAO.findAll("from ServiceType");
			request.setAttribute("clients",clients);
			request.setAttribute("employees",employees);
			request.setAttribute("serviceTypes", serviceTypes);
			if(id!=null&&id.trim().length()>0){
				
				Service service =(Service) serviceDAO.findById( Service.class, id);
				if( service.getClient() != null )
				{
					service.setClientId(service.getClient().getId());
				}
				if( service.getEmployee() != null )
				{
					service.setEmployeeId(service.getEmployee().getId());
				}
				if( service.getServiceType() != null )
				{
					service.setServiceTypeId(service.getServiceType().getId());
				}
				if (service!=null){
					BeanUtils.copyProperties(form,service);
				}
			}
			return mapping.findForward("edit");
		}
		
		
		@SuppressWarnings("unchecked")
		public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
			String id=request.getParameter("id");
			ServiceDAO serviceDAO=new ServiceDAO(Service.class);
			Service service =(Service) serviceDAO.findById( Service.class, id);
			serviceDAO.delete(service);
//			saveMessage(request,"addressForm.deleted",service.getRemark());
			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){
				ServiceDAO serviceDAO=new ServiceDAO(Service.class);
				Service service =(Service) serviceDAO.findById( Service.class, id);
				request.setAttribute("service",service);
			}
			return mapping.findForward("info");
		}
	}


⌨️ 快捷键说明

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