📄 page.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace Model
{
public class Page
{
private int totalRows; // 总行数
private int pageSize = 5; // 每页显示的行数
private int currentPage = 1; // 当前页号
private int totalPages; // 总页数
private int startRow; // 当前页在数据库中的起始行
/**
* 构造方法: 功能计算总页数
*
* @param _totalRows
*/
public Page(int _totalRows)
{
totalRows = _totalRows;
totalPages = totalRows / pageSize;
int mod = totalRows % pageSize;
if (mod > 0)
{
totalPages++;
}
// TODO Auto-generated constructor stub
}
/**
* @return the currentPage
*/
public int getCurrentPage()
{
return currentPage;
}
/**
* @param currentPage
* the currentPage to set
*/
public void setCurrentPage(int currentPage)
{
this.currentPage = currentPage;
}
/**
* @return the pageSize
*/
public int getPageSize()
{
return pageSize;
}
/**
* @param pageSize
* the pageSize to set
*/
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
}
/**
* @return the startRow
*/
public int getStartRow()
{
return startRow;
}
/**
* @param startRow
* the startRow to set
*/
public void setStartRow(int startRow)
{
this.startRow = startRow;
}
/**
* @return the totalPages
*/
public int getTotalPages()
{
return totalPages;
}
/**
* @param totalPages
* the totalPages to set
*/
public void setTotalPages(int totalPages)
{
this.totalPages = totalPages;
}
/**
* @return the totalRows
*/
public int getTotalRows()
{
return totalRows;
}
/**
* @param totalRows
* the totalRows to set
*/
public void setTotalRows(int totalRows)
{
this.totalRows = totalRows;
}
/**
* first()功能描述:返回首页
*/
public void first()
{
currentPage = 1;
startRow = 0;
}
/**
* previous()功能描述:上一页
*/
public void previous()
{
if (currentPage == 1)
{
return;
}
currentPage--;
startRow = (currentPage - 1) * pageSize;
}
/**
* next()功能描述:下一页
*/
public void next()
{
if (currentPage < totalPages)
{
currentPage++;
}
startRow = (currentPage - 1) * pageSize;
}
/**
* last()功能描述:尾页
*/
public void last()
{
currentPage = totalPages;
startRow = (currentPage - 1) * pageSize;
}
/**
* refresh()功能描述:根据页码,进行跳转
*/
public void refresh(int _currentPage)
{
currentPage = _currentPage;
startRow = (currentPage - 1) * pageSize;
if (currentPage > totalPages)
{
last();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -