zoukankan
html css js c++ java
Pagination 分页类
public
class
Pagination
{
/**/
///
<summary>
///
页码显示
///
</summary>
///
<param name="curp">
当前页
</param>
///
<param name="pagecount">
总页数
</param>
///
<param name="maxcount">
最大显示页码行数
</param>
///
<param name="leftstr">
目标URL地址页码标记左边字符串
</param>
///
<param name="rightstr">
目标URL地址页码标记右边字符串
</param>
///
<returns>
页码字符串
</returns>
public
static
string
Show(
int
curp,
int
pagecount,
int
maxcount,
string
leftstr,
string
rightstr)
{
StringBuilder str
=
new
StringBuilder();
int
leftMin, RightMax;
if
(maxcount
%
2
==
0
)
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount)
+
1
;
}
else
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount);
}
if
(leftMin
<
2
)
leftMin
=
1
;
if
(RightMax
>
pagecount)
RightMax
=
pagecount;
if
(curp
<
intplus(maxcount)
&&
pagecount
>=
maxcount)
{
leftMin
=
1
;
RightMax
=
maxcount;
}
if
(leftMin
>
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
1
"
+ rightstr +
"
\
"
title=\
"
第1页\
"
>1</a><a class=\
"
around\
"
href=\
""
+ leftstr + (curp - 1).ToString() + rightstr +
"
\
"
title=\
"
上一页\
"
><<</a>
"
);
if
(leftMin
==
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
1
"
+ rightstr +
"
\
"
title=\
"
第1页\
"
>1</a>
"
);
for
(
int
i
=
leftMin; i
<=
RightMax; i
++
)
{
if
(i
==
curp)
str.Append(
"
<a class=\
"
pagenow\
"
>
"
+
i.ToString()
+
"
</a>
"
);
else
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + i.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ i.ToString() +
"
页\
"
>
"
+
i.ToString()
+
"
</a>
"
);
}
if
(RightMax
<
pagecount
-
1
)
str.Append(
"
<a class=\
"
around\
"
href=\
""
+ leftstr + (curp + 1).ToString() + rightstr +
"
\
"
title=\
"
下一页\
"
>>></a><a class=\
"
page\
"
href=\
""
+ leftstr + pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
if
(RightMax
==
pagecount
-
1
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
return
str.ToString();
}
/**/
///
<summary>
///
show page numbers: for long article.
///
</summary>
///
<param name="curp">
当前页
</param>
///
<param name="pagecount">
总页数
</param>
///
<param name="maxcount">
最大显示页码行数
</param>
///
<param name="leftstr">
目标URL地址页码标记左边字符串
</param>
///
<param name="rightstr">
目标URL地址页码标记右边字符串
</param>
///
<returns>
页码字符串
</returns>
public
static
string
Show2(
int
curp,
int
pagecount,
int
maxcount,
string
leftstr,
string
rightstr)
{
StringBuilder str
=
new
StringBuilder();
int
leftMin, RightMax;
if
(maxcount
%
2
==
0
)
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount)
+
1
;
}
else
{
leftMin
=
curp
-
intplus(maxcount);
RightMax
=
curp
+
intplus(maxcount);
}
if
(leftMin
<
2
)
leftMin
=
1
;
if
(RightMax
>
pagecount)
RightMax
=
pagecount;
if
(curp
<
intplus(maxcount)
&&
pagecount
>=
maxcount)
{
leftMin
=
1
;
RightMax
=
maxcount;
}
//
左侧
if
(curp
==
1
)
str.Append(
"
<a class=\
"
pagenow\
"
>上一页</a>
"
);
else
{
if
(curp
>
2
)
str.Append(
"
<a href=\
""
+ leftstr +
"
-
"
+ (curp - 1) + rightstr +
"
\
"
class=\
"
page\
"
>上一页</a>
"
);
else
str.Append(
"
<a href=\
""
+ leftstr + rightstr +
"
\
"
class=\
"
page\
"
>上一页</a>
"
);
}
if
(leftMin
>
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + rightstr +
"
\
"
title=\
"
第1页\
"
>1</a><a class=\
"
around\
"
href=\
""
+ leftstr +
"
-
"
+ (curp - 1).ToString() + rightstr +
"
\
"
title=\
"
上一页\
"
>‹‹</a>
"
);
if
(leftMin
==
2
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + rightstr +
"
\
"
title=\
"
第1页\
"
>1</a>
"
);
//
中间
for
(
int
i
=
leftMin; i
<=
RightMax; i
++
)
{
if
(i
==
curp)
str.Append(
"
<a class=\
"
pagenow\
"
>
"
+
i.ToString()
+
"
</a>
"
);
else
{
if
(i
>
1
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
-
"
+ i.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ i.ToString() +
"
页\
"
>
"
+
i.ToString()
+
"
</a>
"
);
else
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr + rightstr +
"
\
"
title=\
"
第
"
+ i.ToString() +
"
页\
"
>
"
+
i.ToString()
+
"
</a>
"
);
}
}
//
右侧
if
(RightMax
<
pagecount
-
1
)
str.Append(
"
<a class=\
"
around\
"
href=\
""
+ leftstr +
"
-
"
+(curp + 1).ToString() + rightstr +
"
\
"
title=\
"
下一页\
"
>››</a><a class=\
"
page\
"
href=\
""
+ leftstr +
"
-
"
+pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
if
(RightMax
==
pagecount
-
1
)
str.Append(
"
<a class=\
"
page\
"
href=\
""
+ leftstr +
"
-
"
+ pagecount.ToString() + rightstr +
"
\
"
title=\
"
第
"
+ pagecount.ToString() +
"
页\
"
>
"
+
pagecount.ToString()
+
"
</a>
"
);
if
(curp
==
pagecount)
str.Append(
"
<a class=\
"
pagenow\
"
>下一页</a>
"
);
else
str.Append(
"
<a href=\
""
+ leftstr +
"
-
"
+ (curp + 1) + rightstr +
"
\
"
class=\
"
page\
"
>下一页</a>
"
);
return
str.ToString();
}
/**/
///
<summary>
///
取得数除以2得数的整数部份
///
</summary>
///
<param name="i">
被2除的整数
</param>
///
<returns></returns>
public
static
int
intplus(
int
i)
{
if
(i
%
2
==
0
)
return
i
/
2
;
else
return
(i
-
1
)
/
2
;
}
}
查看全文
相关阅读:
2020/10/25周总结
软件需求---河北省重大需求进度报告05
软件需求---河北省重大需求进度报告04
软件需求---河北省重大需求进度报告03
软件需求---河北省重大需求进度报告02
解决js字符串传参未定义的问题
软件需求---河北省重大需求进度报告
2020/10/18周总结
环信EaseUI集成IM即时通信
第十二周学习进度总结
原文地址:https://www.cnblogs.com/cancer_xu/p/1607122.html
最新文章
软件工程作业-08
软件工程作业--找水王
典型用户及用户场景分析
第八周学习进度条
网页版四则运算(未全部完成)
代码管理仓库项目任务计划
学习进度条
第六周学习进度条
Codeforces #639 div2 A
Educational Codeforces Round 86 A
热门文章
Codeforces #638 div2 A
#635 div2 A
牛客OI周赛15-普及组
回文子串之Manacher算法
GarsiaWachs算法
二分图最大匹配之匈牙利算法
欧拉函数
#596 div2 A-C 题解
软件需求---河北省重大需求进度报告07
软件需求---河北省重大需求进度报告06
Copyright © 2011-2022 走看看