📄 potentialaction.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.ClientTypeDAO;
import com.qrsx.qrsxcrm.dao.EmployeeDAO;
import com.qrsx.qrsxcrm.dao.PotentialDAO;
import com.qrsx.qrsxcrm.form.PotentialForm;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.model.ClientType;
import com.qrsx.qrsxcrm.model.Employee;
import com.qrsx.qrsxcrm.model.Potential;
import com.qrsx.qrsxcrm.web.Pager;
public class PotentialAction extends BaseDispatchAction {
/**
* 列表,转发到列表页面
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
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", "");
Potential potential = new Potential();
BeanUtils.copyProperties(potential, form);
//组装客户类型集合
ClientTypeDAO ctDao=new ClientTypeDAO(ClientType.class);
List clientTypes=ctDao.findAll("from ClientType");
request.setAttribute("clientTypes", clientTypes);
//组装客户类型
if(potential.getClientTypeId()!=null&&potential.getClientTypeId().trim().length()>0){
ClientType clientType=(ClientType) ctDao.findById(ClientType.class, potential.getClientTypeId());
potential.setClientType(clientType);
}
try {
Pager pager = null;
PotentialDAO cdao = new PotentialDAO(Potential.class);
List results = cdao.findAll("from Potential");//得到总数据
pager = new Pager(); // 构造分页对象
int totalRows = results.size(); // 得到总数据量
pager.init(totalRows);
if (request.getParameter("action") != null) {
pager.doAction(request.getParameter("action").toString());
}
// 使用分页标签的方法
List list = cdao.findAllByPage(potential, (pager.getCurrentPage() - 1)* pager.getPageSize(),pager.getPageSize());
request.getSession().setAttribute("pagerstruts", pager);
request.setAttribute("potentials", list);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("list");
}
/**
* 编辑潜在客户资料,或者点击添加时转到客户编辑页面
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IllegalAccessException, InvocationTargetException {
String id = request.getParameter("id");
PotentialDAO pdao = new PotentialDAO(Potential.class);
// 组装客户类型
ClientTypeDAO ctDao=new ClientTypeDAO(ClientType.class);
List clientTypes=ctDao.findAll("from ClientType");
request.setAttribute("clientTypes", clientTypes);
//组装客户负责人
EmployeeDAO edao=new EmployeeDAO(Employee.class);
List employees=edao.findAll("from Employee");
request.setAttribute("employees", employees);
if (id != null && id.trim().length() > 0) {
Potential potential = (Potential) pdao.findById(Potential.class, id);
if(potential.getClientType()!=null){
potential.setClientTypeId(potential.getClientType().getId());
}
if(potential.getEmployee()!=null){
potential.setEmployeeId(potential.getEmployee().getId());
}
if (potential != null) {
BeanUtils.copyProperties(form, potential);
}
}
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);
}
PotentialForm potentialForm=(PotentialForm)form;
Potential potential=new Potential();
BeanUtils.copyProperties(potential, form);//将from组装到client对象中
//组装一个客户负责人
EmployeeDAO edao=new EmployeeDAO(Employee.class);
potential.setEmployee((Employee)edao.findById(Employee.class, potential.getEmployeeId()));
//组装一个客户类型
ClientTypeDAO ctDao=new ClientTypeDAO(ClientType.class);
potential.setClientType((ClientType)ctDao.findById(ClientType.class, potential.getClientTypeId()));
PotentialDAO cdao=new PotentialDAO(Potential.class);
if(potentialForm.getId()==null||potentialForm.getId().trim().length()==0){
cdao.create(potential);
saveMessage(request,"addressForm.updated",potential.getPotentiaName());
//saveMessage创建成功
}
else{
cdao.updates(potential);
saveMessage(request,"addressForm.updated",potential.getPotentiaName());
//saveMessage更新成功
}
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){
PotentialDAO pdao = new PotentialDAO(Potential.class);
Potential potential=(Potential) pdao.findById(Potential.class, id);
pdao.delete(potential);
// saveMessage(request,"addressForm.deleted",potential.getPotentiaName());
//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){
PotentialDAO pdao = new PotentialDAO(Potential.class);
Potential potential=(Potential) pdao.findById(Potential.class, id);
request.setAttribute("potentia", potential);
//saveMessage
}
return mapping.findForward("info");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -