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

📄 000e86ed592c001d1b27e18734f52652

📁 客户关系管理系统主要管理新老客户的一些信息并可以发现潜在客户
💻
字号:
/**
 * 
 */
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.EmployeeDAO;
import com.qrsx.qrsxcrm.dao.OrderDAO;
import com.qrsx.qrsxcrm.form.OrderForm;
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.Order;
import com.qrsx.qrsxcrm.model.User;
import com.qrsx.qrsxcrm.web.Pager;

/**
 * @author Administrator
 *
 */
public class OrderAction 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);
//		}
		Dept dept=new Dept();
		BeanUtils.copyProperties(dept,form);
		DeptDAO deptDao=new DeptDAO(Dept.class);
		if( dept.getId()==null||dept.getId().trim().length()==0 ){
			deptDao.create(dept);
			saveMessage(request,"create" ,dept.getDeptName());
		}
		else{
			deptDao.updates(dept);
			saveMessage(request,"update",dept.getDeptName());
		}
		return mapping.findForward("success");
	}
		
	@SuppressWarnings("unchecked")
	public ActionForward list(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
			Order order=new Order();
			OrderForm orderForm = (OrderForm)form;
			BeanUtils.copyProperties(order,form);
			//String page=request.getParameter("requestPage");
//			DeptDAO deptDaqo=new DeptDAO(Dept.class);
//			List<Dept> lisdt=deptDao.lists(dept);
//			request.setAttribute("depts",list);
			
			
			try {
				Pager pager = null;
				OrderDAO orderDAO=new OrderDAO(Order.class);
				List results = orderDAO.findAll("from Order");//得到总数据
//				List results = orderDAO.lists(order);
				
				pager = new Pager(); // 构造分页对象
				int totalRows = results.size(); // 得到总数据量
				pager.init(totalRows);

				if (request.getParameter("action") != null) {
					pager.doAction(request.getParameter("action").toString());
				}
				// 使用分页标签的方法
				List list = orderDAO.findAllByPage(order, (pager.getCurrentPage() - 1)* pager.getPageSize(),pager.getPageSize());
				request.getSession().setAttribute("pagerstruts", pager);
				request.setAttribute("orders", list);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			
			
			return mapping.findForward("list");
		}
	
	@SuppressWarnings("unchecked")
	public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		OrderDAO orderDAO=new OrderDAO(Order.class);
		String id=request.getParameter("id");
		List<User> users = orderDAO.findAll("from User");
		List<Client> clients = orderDAO.findAll("from Client");
		List<Employee> employees = orderDAO.findAll("from Employee");
		request.setAttribute("users",users);
		request.setAttribute("clients",clients);
		request.setAttribute("employees",employees);
		if(id!=null&&id.trim().length()>0){
			Employee employee =(Employee) employeeDAO.findById( Employee.class, id);
			if( employee.getDept() != null )
			{
				employee.setDeptId(employee.getDept().getId());
			}
			if( employee.getDuty() != null )
			{
				employee.setDutyId(employee.getDuty().getId());
			}
			if (employee!=null){
				BeanUtils.copyProperties(form,employee);
			}
		}
		return mapping.findForward("edit");
	}
	
	
	@SuppressWarnings("unchecked")
	public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String id=request.getParameter("id");
		DeptDAO deptDao=new DeptDAO(Dept.class);
		Dept dept =(Dept) deptDao.findById( Dept.class, id);
		deptDao.delete(dept);
		
		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){
			DeptDAO deptDao=new DeptDAO(Dept.class);
			Dept dept =(Dept) deptDao.findById( Dept.class, id);
			request.setAttribute("dept",dept);
		}
		return mapping.findForward("info");
	}
}

⌨️ 快捷键说明

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