www.pudn.com > erp0.1.zip > OrderAction.java


package com.easyjf.asp.action; 
 
import java.math.BigDecimal; 
 
import java.text.DecimalFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Collection; 
import java.util.Date; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 
 
import com.easyjf.asp.business.ActiveUser; 
import com.easyjf.asp.business.Customer; 
 
import com.easyjf.asp.business.OrderInfo; 
import com.easyjf.asp.business.OrderList; 
import com.easyjf.asp.business.SystemDept; 
import com.easyjf.util.CommUtil; 
import com.easyjf.web.ActionContext; 
import com.easyjf.web.Module; 
import com.easyjf.web.Page; 
import com.easyjf.web.WebForm; 
import com.easyjf.web.tools.AbstractCmdAction; 
import com.easyjf.web.tools.DbPageList; 
import com.easyjf.web.tools.IActiveUser; 
 
public class OrderAction extends AbstractCmdAction { 
	private final DecimalFormat df=new DecimalFormat("0"); 
	private final static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); 
	public IActiveUser getCurrentUser(WebForm form) { 
		return (IActiveUser)ActionContext.getContext().getSession().getAttribute("user");		 
	} 
	//执行登录检验 
	public Object doBefore(WebForm form,Module module) { 
		if(ActionContext.getContext().getSession().getAttribute("user")==null)return new Page("goto","/nologin.htm","html"); 
		return null; 
	} 
	public Page doInit(WebForm form, Module module) { 
		// TODO Auto-generated method stub 
		return doNew(form,module); 
	} 
	public Page doNew(WebForm form, Module module) { 
		doEditLastInputOrder(form,(ActiveUser)this.getCurrentUser(form)); 
		return module.findPage("edit"); 
	} 
	public Page doTempSave(WebForm form, Module module) { 
		doSave(form,(ActiveUser)this.getCurrentUser(form)); 
		doEditLastInputOrder(form,(ActiveUser)this.getCurrentUser(form)); 
		return module.findPage("edit"); 
	} 
	public Page doSave(WebForm form, Module module) { 
		doSave(form,(ActiveUser)this.getCurrentUser(form)); 
		doEditLastInputOrder(form,(ActiveUser)this.getCurrentUser(form)); 
		return module.findPage("edit"); 
	} 
	public Page doEdit(WebForm form, Module module) { 
		String cid=CommUtil.null2String(form.get("cid")); 
		String sn=CommUtil.null2String(form.get("orderSn"));		 
		OrderInfo order=null; 
		if(!cid.equals(""))order=OrderInfo.read(cid); 
		else if(!sn.equals(""))order=OrderInfo.readBySn(sn);		 
		if(order!=null) 
		{ 
			form.addResult("cid",order.getCid()); 
			form.addResult("totalAmount",order.getAmount()); 
			form.addResult("status",order.getStatus()); 
			form.addResult("payment",order.getPayment()); 
			form.addResult("delivery",order.getDelivery()); 
			if(order.getDeliveryDept()!=null && (!order.getDeliveryDept().equals("")))					 
			form.addResult("deliveryDept",Customer.readBySn(order.getDeliveryDept())); 
			form.addResult("vdate",CommUtil.format(order.getVdate())); 
			form.addResult("customer",Customer.readBySn(order.getCustomerSn()));			 
			form.addResult("orderSn",order.getSn()); 
			form.addResult("linkMan",order.getLinkMan()); 
			List list=order.children(); 
			if(list!=null){ 
			form.addResult("orderList",order.children()); 
			form.addResult("childNum",new Integer(list.size())); 
			} 
			list=OrderInfo.query("status=-1 and cid<>'"+order.getCid()+"'");			 
			form.addResult("otherList",list); 
		} 
		return module.findPage("edit"); 
	} 
	public Page doDel(WebForm form, Module module) { 
		ActiveUser user=(ActiveUser)this.getCurrentUser(form); 
		String cid=CommUtil.null2String(form.get("cid")); 
		String sn=CommUtil.null2String(form.get("orderSn"));		 
		OrderInfo order=null; 
		if(!cid.equals(""))order=OrderInfo.read(cid); 
		else if(!sn.equals(""))order=OrderInfo.readBySn(sn); 
		if(order!=null) 
		{ 
			order.del(); 
			form.addResult("msg","删除成功!"); 
		} 
		else 
			form.addResult("msg","删除失败!"); 
		//doQuery(form,user); 
		doEditLastInputOrder(form,user); 
		return module.findPage("edit"); 
	} 
	public Page doList(WebForm form, Module module) { 
		doQuery(form,(ActiveUser)this.getCurrentUser(form)); 
		return module.findPage("list"); 
	} 
	public Page doQuery(WebForm form, Module module) { 
		return doList(form,module); 
	} 
	public Page doManage(WebForm form, Module module) { 
		doEdit(form,module); 
		return module.findPage("manage"); 
	} 
	public Page doManageSave(WebForm form, Module module) { 
		ActiveUser user=(ActiveUser)this.getCurrentUser(form); 
		doManageSave(form,user); 
		doEdit(form,module); 
		return module.findPage("manage"); 
	} 
	public Page doPrint(WebForm form, Module module) { 
		ActiveUser user=(ActiveUser)this.getCurrentUser(form); 
		SystemDept dept=SystemDept.readBySn(user.getDept()); 
		if(dept!=null)form.addResult("deptTitle",dept.getTitle()); 
		String cid=CommUtil.null2String(form.get("cid")); 
		String sn=CommUtil.null2String(form.get("orderSn"));		 
		OrderInfo order=null; 
		//System.out.println(cid); 
		if(!cid.equals(""))order=OrderInfo.read(cid); 
		else if(!sn.equals(""))order=OrderInfo.readBySn(sn);		 
		if(order!=null) 
		{ 
			form.addResult("cid",order.getCid()); 
			form.addResult("totalAmount",df.format(order.getAmount().setScale(2))); 
			form.addResult("status",order.getStatus()); 
			//form.addResult("vdate",CommUtil.format(order.getVdate())); 
			form.addResult("vdate",CommUtil.format(new Date())); 
			form.addResult("linkMan",order.getLinkMan()); 
			form.addResult("tel",order.getTel()); 
			form.addResult("customer",Customer.readBySn(order.getCustomerSn()));			 
			form.addResult("orderSn",order.getSn()); 
			List list=order.children(); 
			if(list!=null){ 
			Map map=new HashMap(); 
			map.put("sequence",new Integer(list.size()+1)); 
			map.put("productSn"," "); 
			map.put("title","合    计"); 
			//Format f=new DecimalFormat(".00");			 
			map.put("amount",order.getAmount().setScale(2)); 
			list.add(map); 
			form.addResult("orderList",list); 
			form.addResult("childNum",new Integer(list.size())); 
			} 
			list=OrderInfo.query("status=-1 and cid<>'"+order.getCid()+"'");			 
			form.addResult("otherList",list); 
		}		 
		return module.findPage("print"); 
	} 
	public Page doTotalPrint(WebForm form, Module module) { 
		ActiveUser user=(ActiveUser)this.getCurrentUser(form); 
		SystemDept dept=SystemDept.readBySn(user.getDept()); 
		if(dept!=null)form.addResult("deptTitle",dept.getTitle()); 
		String orderType=CommUtil.null2String(form.get("orderType")); 
		String orderField=CommUtil.null2String(form.get("orderField")); 
		String scope="status>=0 and belongDept=?"; 
		Collection paras=new ArrayList(); 
		paras.add(user.getDept()); 
		String customerSn=CommUtil.null2String(form.get("customerSn"));		 
		String vdate1=CommUtil.null2String(form.get("vdate1")); 
		String vdate2=CommUtil.null2String(form.get("vdate2")); 
		if(!customerSn.equals("")) 
		{ 
			scope+=" and customerSn=?"; 
			paras.add(customerSn); 
		}		 
		if(vdate2.equals("")&& !vdate1.equals("")) 
		{ 
			scope+=" and vdate=?"; 
			paras.add(vdate1); 
		} 
		else if(!vdate1.equals("")) 
		{ 
			scope+=" and vdate>=?"; 
			paras.add(vdate1); 
		} 
		if(!vdate2.equals("")) 
		{ 
			scope+=" and vdate=0 and belongDept=?"; 
		Collection paras=new ArrayList(); 
		paras.add(u.getDept()); 
		String customerSn=CommUtil.null2String(form.get("customerSn"));		 
		String vdate1=CommUtil.null2String(form.get("vdate1")); 
		String vdate2=CommUtil.null2String(form.get("vdate2")); 
		if(!customerSn.equals("")) 
		{ 
			scope+=" and customerSn=?"; 
			paras.add(customerSn); 
		}		 
		if(vdate2.equals("")&& !vdate1.equals("")) 
		{ 
			scope+=" and vdate=?"; 
			paras.add(vdate1); 
		} 
		else if(!vdate1.equals("")) 
		{ 
			scope+=" and vdate>=?"; 
			paras.add(vdate1); 
		} 
		if(!vdate2.equals("")) 
		{ 
			scope+=" and vdate'"+order.getCid()+"'");		 
			form.addResult("otherList",list); 
		}		 
	} 
	private void doManageSave(WebForm form,ActiveUser user) 
	{ 
		String cid=CommUtil.null2String(form.get("cid")); 
		String sn=CommUtil.null2String(form.get("orderSn"));		 
		OrderInfo order=null; 
		if(!cid.equals(""))order=OrderInfo.read(cid); 
		else if(!sn.equals(""))order=OrderInfo.readBySn(sn); 
		boolean op=false; 
		if(order!=null) 
		{ 
			String payment=CommUtil.null2String(form.get("payment")); 
			String delivery=CommUtil.null2String(form.get("delivery")); 
			String deliveryDept=CommUtil.null2String(form.get("deliveryDeptSn"));			 
			if(!payment.equals(""))order.setPayment(new Integer(payment)); 
			if(!delivery.equals(""))order.setDelivery(new Integer(delivery)); 
			order.setDeliveryDept(deliveryDept); 
			op=order.update(); 
		} 
		if(op) 
		{ 
		form.addResult("msg","保存成功!");	 
		} 
		else 
		{ 
	    form.addResult("msg","保存失败!"); 
		} 
	}	 
 
	private void doSave(WebForm form,ActiveUser user) 
	{ 
		Object[] s=form.getTextElement().keySet().toArray(); 
		if(s!=null) 
		{ 
			String orderSn=CommUtil.null2String(form.get("orderSn")); 
			String cid=CommUtil.null2String(form.get("cid")); 
			OrderInfo order=null; 
			boolean isNew=true; 
			List cList=new ArrayList(); 
			String ids=""; 
			for(int i=0;i