package cn.feast.coding.tools;

import javax.servlet.http.HttpServletRequest;

public class PageUtils
{
	public static int pageSize(HttpServletRequest request, Integer pageSize)
	{
		int size;
		if (pageSize == null)
			size = SysContants.MAX_PAGE_ROWS;
		else
			size = pageSize;
		request.getSession().setAttribute("pageSize", size);
		return size;
	}

	public static int getPageNum(Integer pageNum)
	{
		return (pageNum == null || pageNum < 1) ? 1 : pageNum;
	}

	public static int getPage(int pageNumber,int totalPage,int totalNumber,int maxRows){
		totalNumber = totalNumber/maxRows+(totalNumber%maxRows==0?0:1);
		totalPage = totalNumber;
		if(pageNumber>totalPage)pageNumber=totalNumber;
		if(totalPage == 0){
			return 0;
		}else{
			return (pageNumber-1)*maxRows;
		}
	}

	public static int getTotalPage(int pageNumber,int totalPage,int totalNumber,int maxRows){
		return totalNumber/maxRows+(totalNumber%maxRows==0?0:1);
	}
}