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

📄 6095aea6f931001d139f992bfca89756

📁 客户关系管理系统主要管理新老客户的一些信息并可以发现潜在客户
💻
字号:
/**
 * 
 */
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.ClientTypeDAO;
import com.qrsx.qrsxcrm.dao.DutyDAO;
import com.qrsx.qrsxcrm.dao.ProductionTypeDAO;
import com.qrsx.qrsxcrm.dao.ServiceTypeDAO;
import com.qrsx.qrsxcrm.dao.UserDAO;
import com.qrsx.qrsxcrm.form.UserForm;
import com.qrsx.qrsxcrm.model.ClientType;
import com.qrsx.qrsxcrm.model.Duty;
import com.qrsx.qrsxcrm.model.ProductionType;
import com.qrsx.qrsxcrm.model.Role;
import com.qrsx.qrsxcrm.model.ServiceType;
import com.qrsx.qrsxcrm.model.User;
import com.qrsx.qrsxcrm.web.Pager;

/**
 * @author Administrator
 *
 */
public class SetAction 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);
		}
		String flag=request.getParameter("flag");
		if("client".equals(flag))
		{
			ClientType clientType=new ClientType();
			BeanUtils.copyProperties(clientType,form);
			ClientTypeDAO clientTypeDao=new ClientTypeDAO(ClientType.class);
			if( clientType.getId()==null||clientType.getId().trim().length()==0 ){
				clientTypeDao.create(clientType);
				saveMessage(request,"create" ,clientType.getName());
			}
			else{
				clientTypeDao.updates(clientType);//需要修改的地方
				saveMessage(request,"update",clientType.getName());
			}
			return mapping.findForward("success");
		  }
		else if("production".equals(flag))
		{
			ProductionType productionType=new ProductionType();
			BeanUtils.copyProperties(productionType,form);
			ProductionTypeDAO productionTypeDao=new ProductionTypeDAO(ProductionType.class);
			if( productionType.getId()==null||productionType.getId().trim().length()==0 ){
				productionTypeDao.create(productionType);
				saveMessage(request,"create" ,productionType.getName());
			}
			else{
				productionTypeDao.updates(productionType);//需要修改的地方
				saveMessage(request,"update",productionType.getName());
			}
			return mapping.findForward("success");
		  }
		else if("service".equals(flag))
		{
			ServiceType serviceType=new ServiceType();
			BeanUtils.copyProperties(serviceType,form);
			ServiceTypeDAO serviceTypeDao=new ServiceTypeDAO(ServiceType.class);
			if( serviceType.getId()==null||serviceType.getId().trim().length()==0 ){
				serviceTypeDao.create(serviceType);
				saveMessage(request,"create" ,serviceType.getName());
			}
			else{
				serviceTypeDao.updates(serviceType);//需要修改的地方
				saveMessage(request,"update",serviceType.getName());
			}
			return mapping.findForward("success");
		  }
		else
			return mapping.findForward("success");
	}
		
	public ActionForward list(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
			String flag=request.getParameter("flag");
			if("client".equals(flag))
			{
				
//				
//				
//				UserDAO userDAO = new UserDAO(User.class);
//				User user = new User();
//				BeanUtils.copyProperties(user, form);
//				UserForm userForm = (UserForm) form;
//				String roleId = userForm.getRoleId();
//				if (roleId != null && !roleId.trim().equals("")) {
//					Role role = (Role) userDAO.findById(Role.class, roleId);
//					user.setRole(role);
//				}
//				List<Role> roles = userDAO.findAll("from Role");
//				request.setAttribute("roles", roles);
//
//				try {
//					Pager pager = null;
//					List results = userDAO.findAll("from User");// 得到总数据
//
//					pager = new Pager(); // 构造分页对象
//					int totalRows = results.size(); // 得到总数据量
//					pager.init(totalRows);
//
//					if (request.getParameter("action") != null) {
//						pager.doAction(request.getParameter("action").toString());
//					}
//					// 使用分页标签的方法
//					List list = userDAO.findAllByPage(user,
//							(pager.getCurrentPage() - 1) * pager.getPageSize(), pager
//									.getPageSize());
//					request.getSession().setAttribute("pagerstruts", pager);
//					request.setAttribute("users", list);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//				
//				
//				
//				
//				
				
				
				
				
				
				
				
				
				
				
				
				ClientType clientType=new ClientType();
				BeanUtils.copyProperties(clientType,form);
				//String page=request.getParameter("requestPage");
				ClientTypeDAO clientTypeDao=new ClientTypeDAO(ClientType.class);
				List<ClientType> list1=clientTypeDao.lists(clientType);
				request.setAttribute("clientTypes",list1);
			}
			if("production".equals(flag))
			{
				ProductionType productionType=new ProductionType();
				BeanUtils.copyProperties(productionType,form);
				//String page=request.getParameter("requestPage");
				ProductionTypeDAO productionTypeDao=new ProductionTypeDAO(ProductionType.class);
				List<ProductionType> list2=productionTypeDao.lists(productionType);
				request.setAttribute("productionTypes",list2);
			}
			if("service".equals(flag))
			{
				ServiceType serviceType=new ServiceType();
				BeanUtils.copyProperties(serviceType,form);
				//String page=request.getParameter("requestPage");
				ServiceTypeDAO serviceTypeDao=new ServiceTypeDAO(ServiceType.class);
				List<ServiceType> list3=serviceTypeDao.lists(serviceType);
				request.setAttribute("serviceTypes",list3);
			}
			
			return mapping.findForward("list");
		}
	
	public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String flag = request.getParameter("flag");
		if("client".equals(flag))
		{
			String id=request.getParameter("id");
			if(id!=null&&id.trim().length()>0){
				ClientTypeDAO clientTypeDAO=new ClientTypeDAO(ClientType.class);
				ClientType clientType =(ClientType) clientTypeDAO.findById( ClientType.class, id);
				if (clientType!=null){
					BeanUtils.copyProperties(form,clientType);
				}
			}
		}
		if("production".equals(flag))
		{
			String id=request.getParameter("id");
			if(id!=null&&id.trim().length()>0){
				ProductionTypeDAO productionTypeDAO=new ProductionTypeDAO(ProductionType.class);
				ProductionType productionType =(ProductionType) productionTypeDAO.findById( ProductionType.class, id);
				if (productionType!=null){
					BeanUtils.copyProperties(form,productionType);
				}
			}
		}
		if("service".equals(flag))
		{
			String id=request.getParameter("id");
			if(id!=null&&id.trim().length()>0){
				ServiceTypeDAO serviceTypeDAO=new ServiceTypeDAO(ServiceType.class);
				ServiceType serviceType =(ServiceType) serviceTypeDAO.findById( ServiceType.class, id);
				if (serviceType!=null){
					BeanUtils.copyProperties(form,serviceType);
				}
			}
		}
		return mapping.findForward("edit");
	}
	
	
	@SuppressWarnings("unchecked")
	public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String flag = request.getParameter("flag");
		if("client".equals(flag))
		{
			String id=request.getParameter("id");
			ClientTypeDAO clientTypeDAO=new ClientTypeDAO(ClientType.class);
			ClientType clientType =(ClientType) clientTypeDAO.findById( ClientType.class, id);
			try
			{
				clientTypeDAO.delete(clientType);
			}
			catch (Exception e) {
				return mapping.findForward("failure");
			}
		}
		if("production".equals(flag))
		{
			String id=request.getParameter("id");
			ProductionTypeDAO productionTypeDAO=new ProductionTypeDAO(ProductionType.class);
			ProductionType productionType =(ProductionType) productionTypeDAO.findById( ProductionType.class, id);
			productionTypeDAO.delete(productionType);
		}
		if("service".equals(flag))
		{
			String id=request.getParameter("id");
			ServiceTypeDAO serviceTypeDAO=new ServiceTypeDAO(ServiceType.class);
			ServiceType serviceType =(ServiceType) serviceTypeDAO.findById( ServiceType.class, id);
			serviceTypeDAO.delete(serviceType);
		}
		return mapping.findForward("success");
	}
	
}

⌨️ 快捷键说明

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