/*
 * 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.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yuntong.form.X_loseForm;
import com.yuntong.hibernate.database.po.TDisrepareInfo;

/** 
 * MyEclipse Struts
 * Creation date: 04-09-2007
 * 
 * XDoclet definition:
 * @struts.action path="/x_lose" name="x_loseForm" scope="request" validate="true"
 */
public class X_loseAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	
	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 execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		X_loseForm x_loseForm = (X_loseForm) form;// TODO Auto-generated method stub

		Long regId=x_loseForm.getRegId();

		List list=(List) request.getSession().getAttribute("listlose1");
		List listlose=new ArrayList();
	
		for(int i=0;i<list.size();i++){
			TDisrepareInfo info=(TDisrepareInfo) list.get(i);
			if(info.getTRegisterInfo().getRegisterGlideId().equals(regId)){
				listlose.add(info);
			}
		}

		
		if(listlose.size()==0){
			request.setAttribute("null", "n");
		}else{
			request.setAttribute("notnull", "");
		}
		
		this.fenye(listlose, request);
		if(listlose.size()>4){
			request.setAttribute("Selectfenye", "fenye");
		}
		
		request.getSession().setAttribute("listlose", listlose);
		
		
		return mapping.findForward("lose");
	}
}