📄 books_commonbypage.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using KeYou.Books.DB;
namespace KeYou.Books.DL
{
public class books_CommonByPage
{
public DataSet GetListByPage(string tblName, string fldName, string strWhere, string ID, string Sort, int PageSize, int Page)
{
SqlParameter[] parameters ={
new SqlParameter("@tblName",SqlDbType.VarChar,200),
new SqlParameter("@fldName",SqlDbType.VarChar,200),
new SqlParameter("@strWhere",SqlDbType.VarChar,500),
new SqlParameter("@ID",SqlDbType.VarChar,20),
new SqlParameter("@Sort",SqlDbType.VarChar,100),
new SqlParameter("PageSize",SqlDbType.Int,4),
new SqlParameter("Page",SqlDbType.Int,4)};
parameters[0].Value = tblName;
parameters[1].Value = fldName;
parameters[2].Value = strWhere;
parameters[3].Value = ID;
parameters[4].Value = Sort;
parameters[5].Value = PageSize;
parameters[6].Value = Page;
return DbHelperSQL.RunProcedure("UP_CommomDataByPage", parameters, "ds");
}
public bool isNumber(string s)
{
int Flag = 0;
char[] str = s.ToCharArray();
for (int i = 0; i < str.Length; i++)
{
if (Char.IsNumber(str[i]))
{
Flag++;
}
else
{
Flag = -1;
break;
}
}
if (Flag > 0)
{
return false;
}
else
{
return true;
}
}
/// </summary>
/// 对文本内容实现分页
/// <param name="total">总记录数</param>
/// <param name="per">每页记录数</param>
/// <param name="page">当前页数</param>
/// <param name="query_string">Url参数</param>
/// <param name="ID">参数</param>
/// <param name="currentpage">当前页</param>
/// <param name="PageSize">每页分页大小</param>
public string pagination(int total, int per, int page, string query_string, int ID, int currentpage, int PageSize)
{
int allpage = 0;
int next = 0;
int pre = 0;
int startcount = 0;
int endcount = 0;
string pagestr = "";
if (page < 1) { page = 1; }
//计算总页数
if (per != 0)
{
allpage = (total / per);
allpage = ((total % per) != 0 ? allpage + 1 : allpage);
allpage = (allpage == 0 ? 1 : allpage);
}
next = page + 1;
pre = page - 1;
startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
//中间页终止序号
endcount = page < 5 ? 10 : page + 5;
if (startcount < 1) { startcount = 1; } //为了避免输出的时候产生负数,设置如果小于1就从序号1开始
if (allpage < endcount) { endcount = allpage; }//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内
// pagestr = "共<font color=\"green\">" + allpage + "</font>页 共有<font color=\"green\">" + total + "</font>条记录 当前页<font color=\"green\">" + currentpage + "</font>/" + allpage + " 每页<font color=\"green\">" + PageSize + "</font>条 ";
pagestr += page > 1 ? "<a href=\"" + query_string + "&page=1\">首 页</a> <a href=\"" + query_string + "&page=" + pre + "\">上一页</a>" : "首 页 上一页";
//中间页处理,这个增加时间复杂度,减小空间复杂度
for (int i = startcount; i <= endcount; i++)
{
pagestr += page == i ? " <font color=\"green\">" + i + "</font>" : " <a href=\"" + query_string + "&page=" + i + "\">" + i + "</a>";
}
pagestr += page != allpage ? " <a href=\"" + query_string + "&page=" + next + "\">下一页</a> <a href=\"" + query_string + "&page=" + allpage + "\">尾 页</a>" : " 下一页 尾 页";
pagestr += "<br>" + "共<font color=\"green\">" + allpage + "</font>页 共有<font color=\"green\">" + total + "</font>条记录 当前页<font color=\"green\">" + currentpage + "</font>/" + allpage + " 每页<font color=\"green\">" + PageSize + "</font>条 ";
return pagestr;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -