/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuntong.action;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yuntong.action.ajaxaction.Y_FindRegisterByIDAction;
import com.yuntong.business.vo.Y_R2selectInfoVO;
import com.yuntong.business.vo.Y_splitInfoVO;
import com.yuntong.service.Y_ISplitRegister;

/** 
 * MyEclipse Struts
 * Creation date: 04-08-2007
 * 未估货票高级查询
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class Y_FindR2Action extends Action {
	private Log log = LogFactory.getLog(Y_FindRegisterByIDAction.class);
	private Y_ISplitRegister register;	
	public Y_ISplitRegister getRegister() {
		return register;
	}
	public void setRegister(Y_ISplitRegister register) {
		this.register = register;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//得到查询条件
		String strFactroyID=request.getParameter("factroyID");
		String strClientID=request.getParameter("clientID");
		String strFreightID=request.getParameter("freightID");
		String strFinsertDate=request.getParameter("insertDate");
		//分解时间条件		
		String temp[]=strFinsertDate.split("-");		
		int y=Integer.parseInt(temp[0]);
		int m=Integer.parseInt(temp[1]);
		int d=Integer.parseInt(temp[2]);
		//格式化为Date类型
		Calendar calendar=Calendar.getInstance();
		calendar.clear();
		calendar.set(y, m, d);
		//得到时间
		Date insertDate=calendar.getTime();
		log.info(""+insertDate);
		//厂商编号
		int factroyID=Integer.parseInt(strFactroyID);
		//客户编号
		int clientID=Integer.parseInt(strClientID);
		log.info("客户编号action:"+clientID);
		//结算方式
		int freightID=Integer.parseInt(strFreightID);
		
		//封装分页信息
		Y_splitInfoVO spInfo=new Y_splitInfoVO();
//		1.得到总页数
		int pageNum=register.getPageNum(16, clientID, factroyID, freightID, insertDate);
		spInfo.setPageNum(pageNum+1);
		log.info("总页数:"+pageNum);
		//设置每页大小
		spInfo.setPageSize(14);
		//设置当前页
		spInfo.setCurPage(1);
		//得到第一页
		List list=register.findSplitRegisterInfo(16, 1, clientID, factroyID, freightID, insertDate);
//		保存页面信息
		HttpSession session=request.getSession();
		session.setAttribute("Y_pageinfo", list);
		//保存分页信息		
		session.setAttribute("Y_spInfo", spInfo);
		//保存查询条件
		Y_R2selectInfoVO rvo=new Y_R2selectInfoVO();
		rvo.setClientID(clientID);
		rvo.setFactroyID(factroyID);
		rvo.setFreightID(freightID);
		rvo.setInsertDate(insertDate);
		session.setAttribute("Y_selectr2", rvo);
		log.info("--------------------------------范围查询成功-----------------------------------");
		return  mapping.findForward("gowghp");
	}
}