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

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.yuntong.form.X_perForm;
import com.yuntong.hibernate.database.po.TRegisterInfo;
import com.yuntong.myexception.Y_MyNullResultException;
import com.yuntong.service.X_IfinancialManageService;

/** 
 * MyEclipse Struts
 * Creation date: 04-03-2007
 * 
 * XDoclet definition:
 * @struts.action parameter="test" validate="true"
 */
public class X_pickAction extends DispatchAction {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	
	private X_IfinancialManageService service;
	public X_IfinancialManageService getService() {
		return service;
	}

	public void setService(X_IfinancialManageService service) {
		this.service = service;
	}
	
	private static final int PAGE_SiZE=4;
	//分页
	public void fenye(List list ,HttpServletRequest request){
		int totalpage=(list.size()-1)/PAGE_SiZE+1;
		//currentPage设置当前
		int currentPage=1; 
		try
		{
		 currentPage=Integer.parseInt(request.getParameter("currentPage"));
		}catch(NumberFormatException ex)
		{	
		  ex.printStackTrace();
		}
		if(currentPage<1)
		{
			currentPage=1;
		}
		if(currentPage>=totalpage)
		{
			currentPage=totalpage;
		}
		//保存分页信息
		request.setAttribute("currentPage",currentPage+"");
		request.setAttribute("totalpage", totalpage+"");
		request.setAttribute("PageSixze", PAGE_SiZE+"");
		request.setAttribute("offset", ((currentPage-1)*PAGE_SiZE)+""); //offset为本页第一条记录在集合中的位置
		
	}

	//提付的已收货票
	public ActionForward have(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try{
			request.getSession().setAttribute("have", "have");//动态页面的标志
			request.setAttribute("havepick", "");//动态页面的标志
			List listpickinfo =new ArrayList();
			List list=(List) request.getSession().getAttribute("listpick");
			for(int i=0;i<list.size();i++){
				TRegisterInfo info=(TRegisterInfo) list.get(i);
				if(info.getTRegisterState().getRstateName().equals("提付已付款")){
					listpickinfo.add(info);
				}
			}
			
			this.fenye(listpickinfo, request);
			if(listpickinfo.size()>4){
				request.setAttribute("fenye", "fenye");
			}
			request.getSession().setAttribute("listpickinfo1", listpickinfo);
			request.getSession().setAttribute("listpickinfo", listpickinfo);
		}catch(Exception ex){
			ex.printStackTrace();
			return null;
		}
		return mapping.findForward("info");
	}
	
//	提付的未收货票
	public ActionForward nothave(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try{
			request.getSession().setAttribute("have", "nothave");
		
			List listpickinfo =new ArrayList();
			List list=(List) request.getSession().getAttribute("listpick");
			for(int i=0;i<list.size();i++){
				TRegisterInfo info=(TRegisterInfo) list.get(i);
				if(info.getTRegisterState().getRstateName().equals("提付未付款")){
					listpickinfo.add(info);
				}
			}
			
			this.fenye(listpickinfo, request);
			if(listpickinfo.size()>4){
				request.setAttribute("fenye", "fenye");
			}
			request.getSession().setAttribute("listpickinfo1", listpickinfo);
			request.getSession().setAttribute("listpickinfo", listpickinfo);
		}catch(Exception ex){
			ex.printStackTrace();
			return null;
		}
		
		return mapping.findForward("info");
	}

}