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

📄 cstlinkmanaction.java

📁 实现用户关系管理系统
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package org.jb.y2t308.team3.web.action;

import java.io.IOException;
import java.util.List;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jb.common.web.action.BaseAction;
import org.jb.y2t308.team3.biz.CstCustomerBiz;
import org.jb.y2t308.team3.biz.CstLinkmanBiz;
import org.jb.y2t308.team3.entity.CstCustomer;
import org.jb.y2t308.team3.entity.CstLinkman;
import org.jb.y2t308.team3.web.form.CstLinkmanForm;

/**
 * MyEclipse Struts Creation date: 01-09-2009
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/cstLinkman" name="cstLinkmanForm" scope="request"
 * @struts.action-forward name="success" path="/index.jsp"
 */
public class CstLinkmanAction extends BaseAction {
	/*
	 * Generated Methods
	 */

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	private CstLinkmanBiz cstLinkmanBiz = null;
	private CstCustomerBiz cstCustomerBiz = null;

	/**
	 * @param cstCustomerBiz
	 *            the cstCustomerBiz to set
	 */
	public void setCstCustomerBiz(CstCustomerBiz cstCustomerBiz) {
		this.cstCustomerBiz = cstCustomerBiz;
	}

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws IOException
	 */
	public ActionForward toAdd(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		CstLinkmanForm cstLinkmanForm = (CstLinkmanForm) form;
		String custNo = request.getParameter("custNo");
		request.setAttribute("custNo", custNo);
		return mapping.findForward("linkman_add");
	}

	public ActionForward doAdd(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		CstLinkmanForm cstLinkmanForm = (CstLinkmanForm) form;
		CstLinkman cstLinkman = cstLinkmanForm.getItem();
		/**
		 * 这是写死的恶心的东西
		 */
		String custNo = request.getParameter("custNo");
		CstCustomer cstCustomer = this.cstCustomerBiz.get(custNo);
		cstLinkman.setCstCustomer(cstCustomer);
		cstLinkmanBiz.add(cstLinkman);
		response.sendRedirect("cstLinkman.do?oper=toLinkMan&custNo=" + custNo);
		return null;
	}

	// 跳转到添加联系人页面
	public ActionForward toLinkMan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		CstLinkmanForm cstLinkmanForm = (CstLinkmanForm) form;// TODO

		String custNo = request.getParameter("custNo");

		CstCustomer customer = cstCustomerBiz.get(custNo);

		request.setAttribute("customer", customer);

		cstLinkmanForm.getItem().setCstCustomer(customer);
		List listCust = this.cstLinkmanBiz.getLinkMan(custNo.trim());

		request.setAttribute("listCust", listCust);

		return mapping.findForward("linkMan");
	}

	// 跳转到修改联系人页面
	public ActionForward toLinkmanEdit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		String lkmId = request.getParameter("lkmId"); // 得到联系人的ID

		String custNo = request.getParameter("custNo"); // 得到客户编号

		CstCustomer cstCustomer = cstCustomerBiz.get(custNo);

		request.setAttribute("cstCustomer", cstCustomer); // 保存一个客户对象 以便得到客户编号

		CstLinkman cstLinkman = cstLinkmanBiz.get(Long.parseLong(lkmId.trim()));

		request.setAttribute("cstLinkman", cstLinkman);

		return mapping.findForward("linkman_edit");
	}

	// 修改联系人
	public ActionForward doLinkmanEdit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		CstLinkmanForm cstLinkmanForm = (CstLinkmanForm) form;// TODO

		String lkmId = request.getParameter("lkmId"); // 从页面中得到传过来的联系人ID

		String custNo = request.getParameter("custNo"); // 从页面中得到传过来的客户的客户编号

		CstCustomer cstCustomer = cstCustomerBiz.get(custNo);

		// 保证不能为空

		CstLinkman cstLinkman = cstLinkmanForm.getItem();
		cstLinkman.setCstCustomer(cstCustomer);

		cstLinkman.setLkmId(Long.parseLong(lkmId)); // 得到联系人的编号并其保存

		this.cstLinkmanBiz.update(cstLinkman);

		// 老师新教的方法 带参数跳转 比response 安全
		ActionForward aForward = new ActionForward();
		String path = "/cstLinkman.do?oper=toLinkMan&custNo=" + custNo;
		aForward.setPath(path);
		return aForward;
	}

	// 删除联系人
	public ActionForward doLinkmanDelete(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {

		String lkmId = request.getParameter("lkmId"); // 得到联系人的ID
		String custNo = request.getParameter("custNo"); // 得到客户编号
		this.cstLinkmanBiz.delete(Long.parseLong(lkmId.trim()));

		try {
			response.sendRedirect("cstLinkman.do?oper=toLinkMan&custNo="
					+ custNo);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @return the cstLinkmanBiz
	 */
	public CstLinkmanBiz getCstLinkmanBiz() {
		return cstLinkmanBiz;
	}

	/**
	 * @param cstLinkmanBiz
	 *            the cstLinkmanBiz to set
	 */
	public void setCstLinkmanBiz(CstLinkmanBiz cstLinkmanBiz) {
		this.cstLinkmanBiz = cstLinkmanBiz;
	}

}

⌨️ 快捷键说明

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