package com.jisan.common.util.page;
public class Paging {
private int totalCount;
private int currentPage;
private int listLimit;
private int pageLimit;
private int totalPage;
private int startPage;
private int endPage;
private int startNum;
private int endNum;
private String btnStart="";
private String btnEnd="";
private String btnListPrev="";
private String btnListNext="";
private String btnPageList="";
private String btnListTenPrev= "";
private String btnListTenNext= "";
public Paging(int totalCount, int currentPage, String queryOption) {
this.totalCount = totalCount;
this.currentPage = currentPage;
this.listLimit = 15;
this.pageLimit = 5;
}
public Paging(int totalCount, int currentPage, String queryOption, int listLimit, int pageLimit) {
this.totalCount = totalCount;
this.currentPage = currentPage;
this.listLimit = listLimit;
this.pageLimit = pageLimit;
}
public PagingBean pagingProcess() throws Exception {
PagingBean pb = new PagingBean();
totalPage = (totalCount - 1) / listLimit + 1;
startPage = ( (currentPage - 1) / pageLimit) * pageLimit + 1;
endPage = startPage + pageLimit - 1;
if (totalPage < endPage) {
endPage = totalPage;
}
if (totalCount == 0) {
totalPage = 0;
}
startNum = (currentPage - 1) * listLimit;
endNum = listLimit;
//제일 처음 페이지로.
if (currentPage > 1) {
btnStart = "<a href=\"javascript:go_Page('1')\"><img src=\"/spi/images/board/pag_rr.jpg\" border=\"0\" class=\"m_lr2\" /></a> ";
} else{
btnStart = "<a href=\"#\"><img src=\"/spi/images/board/pag_rr.jpg\" border=\"0\" class=\"m_lr2\" /></a> ";
}
//바로 이전 페이지 목록으로. (예: 이전 10 페이지로)
if (currentPage > pageLimit) {
int prevListPage = startPage - 1;
btnListPrev = "<a href=\"javascript:go_Page('"+prevListPage+"')\"><img src=\"/spi/images/board/pag_r.jpg\" border=\"0\" class=\"m_lr5\" /></a> ";
} else{
btnListPrev = " ";
}
//페이지 목록
btnPageList = "";
for (int i = startPage; i <= endPage; i++) {
if (currentPage == i) {
btnPageList += "<b><a href=\"#\" align=\"center\" valign=\"middle\" class=\"text_05\">" + i + "</a></b>";
} else {
btnPageList += "<a href=\"javascript:go_Page('"+i+"')\" align=\"center\" valign=\"middle\" class=\"text_05\"> " + i + "</a>";
}
if (i < endPage) {
btnPageList += "<img src=\"/spi/images/board/icon_pagingdot.jpg\" class=m_lr2>";
}
}
//바로 다음 페이지 목록으로. (예: 다음 10 페이지로)
int nextListPage = endPage + 1;
if (nextListPage <= totalPage) {
btnListNext = " <a href=\"javascript:go_Page('"+nextListPage+"')\"><img src=\"/spi/images/board/pag_f.jpg\" border=\"0\" class=\"m_lr5\" /></a> ";
} else {
btnListNext = " ";
}
//제일 마지막 페이지로.
if (currentPage < totalPage) {
btnEnd = " <a href=\"javascript:go_Page('"+totalPage+"')\"><img src=\"/spi/images/board/pag_ff.jpg\" border=\"0\" class=\"m_lr2\" /></a>";
} else {
btnEnd = " <a href=\"#\"><img src=\"/spi/images/board/pag_ff.jpg\" border=\"0\" class=\"m_lr2\" /></a>";
}
StringBuffer pageInfo = new StringBuffer();
pb.setPageInfo(pageInfo.toString());
StringBuffer pageHtml= new StringBuffer();
pageHtml.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
pageHtml.append(" <tr>");
pageHtml.append(" <td align=\"center\">" );
pageHtml.append( btnStart);
pageHtml.append( btnListPrev);
pageHtml.append( btnPageList);
pageHtml.append( btnListNext);
pageHtml.append( btnEnd);
pageHtml.append(" </td>");
pageHtml.append(" </tr>");
pageHtml.append("</table>");
pb.setPageHtml(pageHtml.toString());
//페이징 처리 내용을 넘기기 위해 PagingBean에 처리한 값들을 담는다.
pb.setTotalCount(totalCount);
pb.setCurrentPage(currentPage);
pb.setTotalPage(totalPage);
pb.setStartPage(startPage);
pb.setEndPage(endPage);
pb.setStartNum(startNum);
pb.setEndNum(endNum);
pb.setBtnStart(btnStart);
pb.setBtnEnd(btnEnd);
pb.setBtnListPrev(btnListPrev);
pb.setBtnListNext(btnListNext);
pb.setBtnPageList(btnPageList);
return pb;
}
public PagingBean pagingProcess2() throws Exception {
PagingBean pb = new PagingBean();
totalPage = (totalCount - 1) / listLimit + 1;
startPage = ( (currentPage - 1) / pageLimit) * pageLimit + 1;
endPage = startPage + pageLimit - 1;
if (totalPage < endPage) {
endPage = totalPage;
}
if (totalCount == 0) {
totalPage = 0;
}
startNum = (currentPage - 1) * listLimit;
endNum = listLimit;
//제일 처음 페이지로.
if (currentPage > 1) {
btnStart = "<a href=\"javascript:go_Page('1')\"><img src=\"/spi/images/board/button_start_be.gif\" border=\"0\" class=\"m_lr2\" /></a> ";
} else{
//btnStart = "<a href=\"#\"><img src=\"/spi/images/board_img/button_start.gif\" border=\"0\" align=\"middle\" /></a> ";
}
//이전 10 페이지
int pretenpage = (currentPage/pageLimit-1)*10+1;
if (pretenpage > 0) {
btnListTenPrev += "<a href=\"javascript:go_Page('"+pretenpage+"')\"><img src=\"/spi/images/board/pag_rr.jpg\" border=\"0\" class=\"m_lr2\" /></a> ";
} else{
//btnStart = "<a href=\"#\"><img src=\"/spi/images/board_img/button_start.gif\" border=\"0\" align=\"middle\" /></a> ";
}
//바로 이전 페이지 목록으로.
//if (currentPage > pageLimit) {
if (totalPage > 1) {
int prevListPage = currentPage - 1;
if(prevListPage < 1){
//btnListPrev = "<a href=\"#\"><img src=\"/spi/images/board_img/button_pre.gif\" border=\"0\" align=\"middle\" /></a> ";
}else{
btnListPrev = "<a href=\"javascript:go_Page('"+prevListPage+"')\"><img src=\"/spi/images/board/pag_r.jpg\" border=\"0\" class=\"m_lr5\" /></a> ";
}
} else{
btnListPrev = " ";
}
//페이지 목록
btnPageList = "";
for (int i = startPage; i <= endPage; i++) {
if (currentPage == i) {
btnPageList += "<a href=\"#\" align=\"center\" valign=\"middle\" ><b>" + i + "</b></a>";
} else {
btnPageList += "<a href=\"javascript:go_Page('"+i+"')\" align=\"center\" valign=\"middle\">" + i + "</a>";
}
if (i < endPage) {
btnPageList += " <img src=\"/spi/images/board/icon_pagingdot.jpg\" class=\"m_lr2\">";
}
if(endPage==1){
}else{
btnPageList += " ";
}
}
//바로 다음 페이지 목록으로. (예: 다음 10 페이지로)
int nextListPage = currentPage + 1;
if (nextListPage <= totalPage) {
btnListNext = "<a href=\"javascript:go_Page('"+nextListPage+"')\"><img src=\"/spi/images/board/pag_f.jpg\" border=\"0\" class=\"m_lr5\" /></a> ";
} else {
//btnListNext = " ";
}
//다음 10 페이지
int nexttenpage = (1+currentPage/pageLimit)*10+1;
if (totalPage > nexttenpage) {
btnListTenNext += "<a href=\"javascript:go_Page('"+nexttenpage+"')\"><img src=\"/spi/images/board/pag_ff.jpg\" border=\"0\" class=\"m_lr2\" /></a> ";
} else{
//btnStart = "<a href=\"#\"><img src=\"/spi/images/board_img/button_start.gif\" border=\"0\" align=\"middle\" /></a> ";
}
//제일 마지막 페이지로.
if (currentPage < totalPage) {
btnEnd = "<a href=\"javascript:go_Page('"+totalPage+"')\"><img src=\"/spi/images/board/button_end_last.gif\" border=\"0\" class=\"m_lr2\" /></a>";
} else {
//btnEnd = " <a href=\"#\"><img src=\"/spi/images/board_img/button_end.gif\" border=\"0\" align=\"middle\" /></a>";
}
StringBuffer pageInfo = new StringBuffer();
pb.setPageInfo(pageInfo.toString());
StringBuffer pageHtml= new StringBuffer();
pageHtml.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
pageHtml.append(" <tr>");
pageHtml.append(" <td align=\"center\" >" );
pageHtml.append( btnStart);
pageHtml.append( btnListTenPrev);
pageHtml.append( btnListPrev);
pageHtml.append( btnPageList);
pageHtml.append( btnListNext);
pageHtml.append( btnListTenNext);
pageHtml.append( btnEnd);
pageHtml.append(" </td>");
pageHtml.append(" </tr>");
pageHtml.append("</table>");
pb.setPageHtml(pageHtml.toString());
//페이징 처리 내용을 넘기기 위해 PagingBean에 처리한 값들을 담는다.
pb.setTotalCount(totalCount);
pb.setCurrentPage(currentPage);
pb.setTotalPage(totalPage);
pb.setStartPage(startPage);
pb.setEndPage(endPage);
pb.setStartNum(startNum);
pb.setEndNum(endNum);
pb.setBtnStart(btnStart);
pb.setBtnEnd(btnEnd);
pb.setBtnListPrev(btnListPrev);
pb.setBtnListNext(btnListNext);
pb.setBtnPageList(btnPageList);
return pb;
}
}