package com.toolsBean;

public class CreatePage {
	private int currentP;			//µ±Ç°Ò³Âë
	private int allP;				//×ÜÒ³Êý
	private int allR;				//×Ü¼ÇÂ¼Êý
	private int perR;				//Ã¿Ò³ÏÔÊ¾¼ÇÂ¼Êý
	private String pageLink;		//·ÖÒ³µ¼º½À¸ÐÅÏ¢
	private String pageInfo;		//·ÖÒ³×´Ì¬ÏÔÊ¾ÐÅÏ¢
	
	public CreatePage(){
		currentP=1;
		allP=1;
		allR=0;
		perR=3;
		pageLink="";
		pageInfo="";
	}
	
	/** ÉèÖÃÃ¿Ò³ÏÔÊ¾¼ÇÂ¼Êý */
	public void setPerR(int perR){
		this.perR=perR;
	}
	
	/** ÉèÖÃ×Ü¼ÇÂ¼Êý */
	public void setAllR(int allR){
		this.allR=allR;
	}
	/** ¼ÆËã×ÜÒ³Êý */
	public void setAllP(){
		allP=(allR%perR==0)?(allR/perR):(allR/perR+1);
	}
	
	/** ÉèÖÃµ±Ç°Ò³Âë */
	public void setCurrentP(String currentP) {		
		if(currentP==null||currentP.equals(""))
			currentP="1";
		try{
			this.currentP=Integer.parseInt(currentP);
		}catch(NumberFormatException e){
			this.currentP=1;
			e.printStackTrace();
		}
		if(this.currentP<1)
			this.currentP=1;
		if(this.currentP>allP)
			this.currentP=allP;		
	}

	/** ÉèÖÃ·ÖÒ³×´Ì¬ÏÔÊ¾ÐÅÏ¢ */
	public void setPageInfo(){
		if(allP>=1){
			pageInfo="<table border='0' cellpadding='3'><tr><td>";
			pageInfo+="Ã¿Ò³ÏÔÊ¾£º"+perR+"/"+allR+" Ìõ¼ÇÂ¼£¡";
			pageInfo+="&nbsp;&nbsp;&nbsp;&nbsp;";
			pageInfo+="µ±Ç°Ò³£º"+currentP+"/"+allP+" Ò³£¡";
			pageInfo+="</td></tr></table>";			
		}				
	}
	
    /** ÉèÖÃ·ÖÒ³µ¼º½À¸ÐÅÏ¢ */
	public void setPageLink(String goWhich){
		if(goWhich==null)
			goWhich="";
		if(goWhich.indexOf("?")>=0)
			goWhich+="&";
		else
			goWhich+="?";
		if(allP>1){
			pageLink="<table border='0' cellpadding='3'><tr><td>";
			if(currentP>1){
				pageLink+="<a href='"+goWhich+"showPage=1'>Ê×Ò³</a>&nbsp;&nbsp;";
				pageLink+="<a href='"+goWhich+"showPage="+(currentP-1)+"'>ÉÏÒ»Ò³</a>&nbsp;&nbsp;";
			}
			if(currentP<allP){
				pageLink+="<a href='"+goWhich+"showPage="+(currentP+1)+"'>ÏÂÒ»Ò³</a>&nbsp;&nbsp;";
				pageLink+="<a href='"+goWhich+"showPage="+allP+"'>Î²Ò³</a>";
			}
			pageLink+="</td></tr></table>";			
		}		
	}
	
	
	/** ·µ»ØÃ¿Ò³¼ÇÂ¼Êý */
	public int getPerR(){
		return perR;
	}
	
	/** ·µ»Ø×Ü¼ÇÂ¼Êý */
	public int getAllR() {
		return allR;
	}	
	
    /** ·µ»Ø×ÜÒ³Êý */
	public int getAllP() {		
		return allP;
	}

	/** ·µ»Øµ±Ç°Ò³Âë */
	public int getCurrentP() {
		return currentP;
	}
	
	/** ·µ»Ø·ÖÒ³×´Ì¬ÏÔÊ¾ÐÅÏ¢ */
	public String getPageInfo(){
		return pageInfo;
	}

	/** ·µ»Ø·ÖÒ³µ¼º½À¸ÐÅÏ¢ */
	public String getPageLink(){
		return pageLink;
	}
}