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

📄 linkmanaction.java

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

import java.lang.reflect.InvocationTargetException;
import java.util.List;

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

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.ClientDAO;
import com.qrsx.qrsxcrm.dao.LinkManDAO;
import com.qrsx.qrsxcrm.form.LinkManForm;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.model.LinkMan;
import com.qrsx.qrsxcrm.web.Pager;

public class LinkManAction extends BaseDispatchAction {
	
	/**
	 * 检索联系人信息
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	@SuppressWarnings("unchecked")
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException {
		
//		HttpSession session = request.getSession();
//		String flag = (String) session.getAttribute("wrong");
//		if(  flag != null && ! flag.equals(""))
//		{
//			request.setAttribute("sorry", "数据已被使用,请释放后再删除!");
//		}
//		session.setAttribute("wrong", "");
		
		LinkMan linkMan = new LinkMan();					//新建一个联系人对象
		BeanUtils.copyProperties(linkMan, form);			//将form中的数据组装到联系人对象中

		try {
			Pager pager = null;									
			LinkManDAO ldao = new LinkManDAO(LinkMan.class);
			List results = ldao.findAll("from LinkMan");	//得到总数据
			
			pager = new Pager(); 						// 构造分页对象
			int totalRows = results.size(); 			// 得到总数据量
			pager.init(totalRows);						//初始化分页对象
			
			if (request.getParameter("action") != null) {
				pager.doAction(request.getParameter("action").toString());//根据传值执行分页的方法
			}
																			// 使用分页标签的方法
			List list = ldao.findAllByPage(linkMan, (pager.getCurrentPage() - 1)* pager.getPageSize(),pager.getPageSize());						
			request.getSession().setAttribute("pagerstruts", pager);		
			request.setAttribute("linkMen", list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward("list");
	}
	/**
	 * 编辑联系人信息
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	@SuppressWarnings("unchecked")
	public ActionForward edit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException {

		String id = request.getParameter("id");
		
		// 组装一个客户集合 
		ClientDAO cdao=new ClientDAO(Client.class);
		List<Client> clients=cdao.findAll("from Client");
		request.setAttribute("clients",clients);
		
		if (id != null && id.trim().length() > 0) {
			LinkManDAO ldao = new LinkManDAO(LinkMan.class);
			
			LinkMan linkMan = (LinkMan) ldao.findById(LinkMan.class, id);
			if( linkMan.getClient()!= null)
			linkMan.setClientId(linkMan.getClient().getId());
			if (linkMan != null) {
				BeanUtils.copyProperties(form, linkMan);
			}
		}
		return mapping.findForward("edit");
	}
	/**
	 * 保存联系人信息
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	public ActionForward save(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException {
		ActionErrors errors = form.validate(mapping, request);

		if (!errors.isEmpty()) {
			saveErrors(request, errors);
			return edit(mapping, form, request, response);
		}
		LinkManForm linkManForm=(LinkManForm)form;
		LinkMan linkMan=new LinkMan();
		BeanUtils.copyProperties(linkMan, linkManForm);
		LinkManDAO ldao=new LinkManDAO(LinkMan.class);
		ClientDAO cdao=new ClientDAO(Client.class);
		linkMan.setClient((Client)cdao.findById(Client.class, linkMan.getClientId()));
		if(linkManForm.getId()==null||linkManForm.getId().trim().length()==0){
			
			ldao.create(linkMan);
			saveMessage(request,"addressForm.added",linkMan.getLinkManName());
			//创建成功
		}else{
			ldao.updates(linkMan);
			saveMessage(request,"addressForm.updated",linkMan.getLinkManName());
			//更新成功
		}
		return mapping.findForward("success");
	}
	
	/**
	 * 删除联系人信息
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		String id=request.getParameter("id");
		if(id!=null&&id.trim().length()>0){
			LinkManDAO ldao=new LinkManDAO(LinkMan.class);
			LinkMan linkMan=(LinkMan) ldao.findById(LinkMan.class, id);
			ldao.delete(linkMan);
//			saveMessage(request,"addressForm.deleted",linkMan.getLinkManName());
			//saveMessage
		}
		return mapping.findForward("success");
	}
	/**
	 * 检索联系人信息
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward info(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		String id=request.getParameter("id");
		if(id!=null&&id.trim().length()>0){
			LinkManDAO ldao=new LinkManDAO(LinkMan.class);
			LinkMan linkMan=(LinkMan) ldao.findById(LinkMan.class, id);
			request.setAttribute("linkMan", linkMan);
			//saveMessage
		}
		return mapping.findForward("info");
	}
}

⌨️ 快捷键说明

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