欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

文字翻页 防Google分页

程序员文章站 2022-05-23 09:41:40
...

//文字翻页 private void InitWap() { string mC = ""; System.IO.FileInfo oF = new System.IO.FileInfo(Request.PhysicalPath); System.IO.StreamReader oReader = new System.IO.StreamReader(oF.DirectoryName + "//" + "1.txt", System.Text.Encoding.D

//文字翻页

private void InitWap()

{

string mC = "";

System.IO.FileInfo oF = new System.IO.FileInfo(Request.PhysicalPath);

System.IO.StreamReader oReader = new System.IO.StreamReader(oF.DirectoryName + "//" + "1.txt", System.Text.Encoding.Default);

mC = oReader.ReadToEnd();

Response.Write(mC.Length / 20);

string yemian = "";

for (int i = 1; i

{

yemian += "" + i.ToString() + " ";

}

int n = 0;

if (Request.QueryString["page"] != null)

{

n = int.Parse(Request.QueryString["page"].ToString());

}

oReader.Close();

if (mC.Length

{

if (mC.Length >= 40)

mC = mC.Substring(n * 20, 20);

mC = mC.Replace("/r/n", "
");

}

Response.Write(yemian);

Response.Write(mC);

}

/// 总记录数

/// 每页记录数

/// 当前页数

/// Url参数

/// 返回一个带HTML代码的分页样式(字符串)

public string Pagination(int total, int per, int page, string query_string)

{

int allpage = 0;

int next = 0;

int pre = 0;

int startcount = 0;

int endcount = 0;

string pagestr = "";

if (page

{

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

if (startcount

{

startcount = 1;

} //为了避免输出的时候产生负数,设置如果小于1就从序号1开始

if (allpage

{

endcount = allpage;

}//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内

//pagestr = "第" + page + "页 ";

//中间页处理,这个增加时间复杂度,减小空间复杂度

for (int i = startcount; i

{

pagestr += page == i ? " " + i + "" : " " + i + "";

}

return pagestr;

}