📄 609bfa72212d001d197ee5d5bdcefda6
字号:
/**
*
*/
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.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 ServiceAvtion 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);
// }
Duty duty=new Duty();
String id = request.getParameter("id");
BeanUtils.copyProperties(duty,form);
DutyDAO dutyDao=new DutyDAO(Duty.class);
if( duty.getId()==null||duty.getId().trim().length()==0 ){
dutyDao.create(duty);
saveMessage(request,"create" ,duty.getDutyName());
}
else{
dutyDao.updates(duty);
saveMessage(request,"update",duty.getDutyName());
}
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();
Client client = (Client) serviceDao.findById(Client.class, clientId);
Employee employee = (Employee) serviceDao.findById(Employee.class, employeeId);
ServiceType serviceType = (ServiceType) serviceDao.findById(ServiceType.class, serviceTypeId);
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");
}
public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
String id=request.getParameter("id");
if(id!=null&&id.trim().length()>0){
DutyDAO dutyDAO=new DutyDAO(Duty.class);
Duty duty =(Duty) dutyDAO.findById( Duty.class, id);
if (duty!=null){
BeanUtils.copyProperties(form,duty);
}
}
return mapping.findForward("edit");
}
@SuppressWarnings("unchecked")
public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
String id=request.getParameter("id");
DutyDAO dutyDAO=new DutyDAO(Duty.class);
Duty duty =(Duty) dutyDAO.findById( Duty.class, id);
dutyDAO.delete(duty);
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){
DutyDAO dutyDAO=new DutyDAO(Duty.class);
Duty duty =(Duty) dutyDAO.findById( Duty.class, id);
request.setAttribute("duty",duty);
}
return mapping.findForward("info");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -