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

📄 006e54907733001d1343bd2c684759cb

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

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 org.hibernate.Query;

import com.qrsx.qrsxcrm.dao.DeptDAO;
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.Employee;
import com.qrsx.qrsxcrm.model.Lists;
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);
		}
		OrderDAO orderDAO=new OrderDAO(Order.class);
		Order order=new Order();
		OrderForm orderForm = (OrderForm)form;
		String clientId= orderForm.getClientId();
		String userId = orderForm.getUserId();
		String employeeId = orderForm.getEmployeeId();
		Client client = (Client) orderDAO.findById(Client.class, clientId);
		User user = (User)orderDAO.findById(User.class, userId);
		Employee employee = (Employee) orderDAO.findById(Employee.class, employeeId);
		BeanUtils.copyProperties(order,form);
		order.setClient(client);
		order.setUser(user);
		order.setEmployee(employee);
		
		if( order.getId()==null||order.getId().trim().length()==0 ){
			orderDAO.create(order);
			saveMessage(request,"addressForm.added" ,order.getOrderId());
		}
		else{
			orderDAO.updates(order);
			saveMessage(request,"addressForm.updated",order.getOrderId());
		}
		return mapping.findForward("success");
	}
		
	@SuppressWarnings("unchecked")
	public ActionForward list(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
			
//			HttpSession session = request.getSession();
//			String flag = (String) session.getAttribute("wrong");
//			if(  flag != null && ! flag.equals(""))
//			{
//				request.setAttribute("sorry", "数据已被使用,请释放后再删除!");
//			}
//			session.setAttribute("wrong", "");
		
			Order order=new Order();
			OrderForm orderForm = (OrderForm)form;
			BeanUtils.copyProperties(order,form);
			
			try {
				Pager pager = null;
				OrderDAO orderDAO=new OrderDAO(Order.class);
				List results = orderDAO.findAll("from Order ob");//得到总数据
				
				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){
			Order order =(Order) orderDAO.findById( Order.class, id);
			if( order.getUser() != null )
			{
				order.setUserId(order.getUser().getId());
			}
			if( order.getClient() != null )
			{
				order.setClientId(order.getClient().getId());
			}
			if( order.getEmployee() != null )
			{
				order.setEmployeeId(order.getEmployee().getId());
			}
			if (order!=null){
				BeanUtils.copyProperties(form,order);
			}
		}
		return mapping.findForward("edit");
	}
	
	
	@SuppressWarnings("unchecked")
	public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String id=request.getParameter("id");
		OrderDAO orderDAO=new OrderDAO(Order.class);
		Order order =(Order) orderDAO.findById( Order.class, id);
		orderDAO.delete(order);
//		saveMessage(request,"addressForm.deleted",order.getOrderId());
		return mapping.findForward("success");
	}

	
	@SuppressWarnings("unchecked")
	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){
			OrderDAO orderDAO=new OrderDAO(Order.class);
			Order order =(Order) orderDAO.findById( Order.class, id);
			@SuppressWarnings("unused")
			
			String sql="from Lists l where l.orderId =:id";
		
			Query query=session.createQuery(sql);
			query.setString("uName", user.getUserName());
			query.setString("pws", user.getPassword());
			List list=query.list();
			
			
			Lists list = (Lists) orderDAO.findAll( "from Lists l where l.orderId =:id");
			query.setString("id", id);
			request.setAttribute("lists", list);
 			request.setAttribute("order",order);
		}
		return mapping.findForward("info");
	}
}

⌨️ 快捷键说明

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