/*
 * 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.service.Y_IFilialeManagerService;
import com.yuntong.service.Y_IUserManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 04-11-2007
 * 用户管理分页
 * XDoclet definition:
 * @struts.action validate="true"
 * @struts.action-forward name="go" path="/Y_CZY_1.jsp"
 */
public class Y_UserSplitAction extends Action {
	private static Log log = LogFactory.getLog(Y_GoCZYAction.class);
	private Y_IUserManagerService userManagerService;
	
	
	public Y_IUserManagerService getUserManagerService() {
		return userManagerService;
	}


	public void setUserManagerService(Y_IUserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}


	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session=request.getSession();
		//得到当前业		
		int curpage=Integer.parseInt(session.getAttribute("Y_usercurPate")+"");
		//得到跳转页数
		String page=request.getParameter("page");
		log.info("跳转页数："+page);
		//得到查询条件
		String strF=request.getParameter("filiale");
		String strD=request.getParameter("department");
		String strDate1=request.getParameter("Date1");
		String strDate2=request.getParameter("Date2");
		
		int F=0;
		int D=0;
		Date insertDate1=new Date();
		insertDate1=null;
		Date insertDate2=new Date();
		insertDate2=null;
		
		if(strF!=null){
			
		 F=Integer.parseInt(strF);
		 D=Integer.parseInt(strD);
		log.info("分公司========="+F);
		log.info("部门========="+D);
//		分解时间条件	1	
		String temp[]=strDate1.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);
		//得到时间
		 insertDate1=calendar.getTime();
		log.info(""+insertDate1);
//		分解时间条件	2	
		String temp2[]=strDate2.split("-");		
		int y2=Integer.parseInt(temp2[0]);
		int m2=Integer.parseInt(temp2[1]);
		int d2=Integer.parseInt(temp2[2]);
		//格式化为Date类型
		Calendar calendar2=Calendar.getInstance();
		calendar2.clear();
		calendar2.set(y2, m2, d2);
		//得到时间
		 insertDate2=calendar2.getTime();
		log.info(""+insertDate2);
		System.out.println(insertDate1.toString());
		System.out.println(insertDate2.toString());
		//得到总叶树
		int pageSize=userManagerService.getPageNum(10, F, D, insertDate1, insertDate2);
		log.info("============================================="+pageSize);
		//保存总叶树
		session.setAttribute("Y_userpageSize", pageSize);
		}
		
		
		//得到提交信息
		String pn=request.getParameter("pageNum");
		if(pn==null){												
				pn="E";			
		}
		
		//得到总页数
		int pageSize=Integer.parseInt(session.getAttribute("Y_userpageSize")+"");
		log.info("提交信息============="+pn);
		log.info("当前业============="+curpage);
		log.info("总页数============="+pageSize);
		//页面判断
		if(pn.equals("A")){
			curpage=1;
		}else if(pn.equals("C")){
			if(curpage>=pageSize){
				curpage=curpage;
			}else{
				curpage=curpage+1;
			}
		}else if(pn.equals("B")){
			if(curpage<=1){
				curpage=curpage;
			}else{
				curpage=curpage-1;
			}
		}else if(pn.equals("D")){
			
			curpage=pageSize;
		}else if(page!=null){
			curpage=Integer.parseInt(page);
			if(curpage>pageSize){
				curpage=pageSize;
			}
			if(curpage<=1){
				curpage=1;
			}
		}
		//保存分页信息
		session.setAttribute("Y_usercurPate", curpage);
		//session.setAttribute("Y_userpageSize", pageSize);
		//得到页面信息
		List list=userManagerService.findSplitRegister(10, curpage, F, D, insertDate1, insertDate2);
		//保存页面信息
		session.setAttribute("Y_userinfopage1", list);
		//保存查询条件
		session.setAttribute("y1", strF);
		session.setAttribute("y1", strD);
		session.setAttribute("y1", strDate1);
		session.setAttribute("y1", strDate2);
		return mapping.findForward("go");
	}
}