{
string sql = null;
if (CurrentPage == 1)
{
sql = "select top " + CurrentPage * PageSize + " " + Field + " from " + TableName + " " + Condition + " " + Condition2 + " group by " + Field;
}
else
{
sql = "select * from (";
sql += "select top " + CurrentPage * PageSize + " " + Field + " from " + TableName + " " + Condition + " " + Condition2 + " group by " + Field + " ) a ";
sql += "where " + Field + " not in (";
sql += "select top " + (CurrentPage - 1) * PageSize + " " + Field + " from " + TableName + " " + Condition + " " + Condition2 + " group by " + Field + ")";
}
return sql;
}
/// <summary>
/// 页面分页显示功能
/// </summary>
/// <param name="Parameters">参数串(a=1&b=2...)</param>
/// <param name="RecordCount">记录总数</param>
/// <param name="PageSize">页宽</param>
/// <param name="CurrentPage">当前页号</param>
/// <param name="ShowJump">是否显示跳转输入框及按钮</param>
/// <param name="Style">样式(1:上页下页...,2:1234...)</param>
/// <returns></returns>
public static string Paging(string Parameters, int RecordCount, int PageCount, int PageSize, int CurrentPage, bool ShowJump, int Style)
{
string str;
if (RecordCount <= PageSize) return "";
if (Parameters != "") Parameters += "&";
if (CurrentPage < 1) CurrentPage = 1;
if (CurrentPage > PageCount) CurrentPage = PageCount;
str = "<table align='center' width="100%"><tr><td align="center">";
str += "共 " + RecordCount + " 条记录 页次:" + CurrentPage + "/" + PageCount + "页 ";
str += PageSize + "条/页 ";
if (Style == 1)
{
if (CurrentPage == 1)
str += "<font color="#999999">首页 上页</font> ";
else
{
str += "<a href='?" + Parameters + "page=1' class="link">首页</a> ";
str += "<a href='?" + Parameters + "page=" + (CurrentPage - 1) + "' class="link">上页</a> "; ;
}
if (CurrentPage == PageCount )
{
str += "<font color="#999999">下页 尾页</font> ";
}
else
{
str += "<a href='?" + Parameters + "page=" + (CurrentPage + 1) + "' class="link">下页</a> ";
str += "<a href='?" + Parameters + "page=" + PageCount + "' class="link">尾页</a> ";
}
}
else if (Style == 2)
{
int NumberSize = 10;
int PageNumber = (CurrentPage - 1) / NumberSize;
if (PageNumber * NumberSize > 0)
str += "<a href='?" + Parameters + "page=" + PageNumber * NumberSize + "' title=上十页 >[<<]</a> ";
int i;
for (i = PageNumber * NumberSize + 1; i <= (PageNumber + 1) * NumberSize; i++)
{
if (i == CurrentPage)
str += "<strong><font color=#ff0000>[" + i + "]</font></strong> ";
else
str += "<a href='?" + Parameters + "page=" + i + "'>[" + i + "]</a> ";








