//分页
public string MadeButtonLink(int PageCount, int CurPage, string szUrl) //PageCount得到页数 CurPage当前页 szUrl连接地址
{
StringBuilder sb = new StringBuilder();
int i = 1, StartPage = 1, EndPage = 1;
sb.Append("<a class=/"p_pages/">" + CurPage.ToString() + "/" + PageCount.ToString() + "</a>");
if (CurPage > 1)
{
sb.Append("<a href=/"" + szUrl + Convert.ToString(CurPage - 1) + "/" class=/"p_num/">上一页</a>");
}
if (CurPage > 8)
StartPage = CurPage - 2;
else StartPage = 1;
EndPage = StartPage + 9;
if (EndPage > PageCount) EndPage = PageCount;
for (i = StartPage; i <= EndPage; i++)
{
if (i == CurPage)
sb.Append("<a class=/"p_curpage/">" + i.ToString() + "</a>");
else
sb.Append("<a href=/"" + szUrl + i.ToString() + "/" class=/"p_num/">" + i.ToString() + "</a>");
}
if (CurPage < PageCount)
{
sb.Append("<a href=/"" + szUrl + Convert.ToString(CurPage + 1) + "/" class=/"p_num/">下一页</a>");
}
return sb.ToString();
}
public int GetPageCount(string szTable, int listTxtRows, string szWhere)
{
return GetPageCount(szTable, listTxtRows, szWhere, null);
}
public int GetPageCount(string szTable, int listTxtRows, string szWhere, IDbDataParameter[] param)
{
string szSQL = "select count(*) from [" + szTable + "] " + szWhere;
int nPageCount = CDB.ExecuteScalar(szSQL, param);
int RePage = nPageCount / listTxtRows;
if (nPageCount % listTxtRows > 0) RePage += 1;
if (RePage < 1) RePage = 1;
return RePage;
}
public void Load_init()
{
/*DataTable dt = CDB.FillTable("select username, email, mobilphone, BuyType, regdate, enddate, isopen, closereson, id from [usertable] where buyType <> 5 order by id desc");
gvUser.DataSource = dt;
gvUser.DataBind();*/
int CurPages = 1;
if (WCB.GetRequestParamert("pages") != "" && WCB.IsNumber(WCB.GetRequestParamert("pages")))
{
CurPages = Convert.ToInt32(WCB.GetRequestParamert("pages"));
}
int Pages = GetPageCount("usertable", gvUser.PageSize, " where BuyType <> 5 ");
if (CurPages > Pages) CurPages = Pages;
if (CurPages < 1) CurPages = 1;
gvUser.DataSource = ListProduct(CurPages);
gvUser.DataBind();
UIpages.Text = MadeButtonLink(Pages, CurPages, "userTable_Manage.aspx?pages=");
}
public DataTable ListProduct(int PageIndex)
{
string szSQL = "";
if (PageIndex == 1)
szSQL = "select top " + gvUser.PageSize.ToString() + " username, email, mobilphone, BuyType, regdate, enddate, isopen, closereson, id from [usertable] where buyType <> 5 order by id desc";
else
szSQL = "select top " + gvUser.PageSize.ToString() + " username, email, mobilphone, BuyType, regdate, enddate, isopen, closereson, id from [usertable] where buyType <> 5 and id <(select min(id) from (select top " + Convert.ToString((PageIndex - 1) * gvUser.PageSize) + " id from [usertable] order by id desc) as t) order by id desc";
return CDB.FillTable(szSQL);
}