using System;
namespace Qzsoft
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class DataGridDivPage
{
private string myPageCount;
/// <summary>
/// 每页的显示数目
/// </summary>
private string pageCount
{
get
{
return myPageCount;
}
set
{
myPageCount = value;
}
}
private string myTblFields;
/// <summary>
/// 设定访问的表的字段--"name,age,sex"
/// </summary>
private string tblFields
{
get
{
return myTblFields;
}
set
{
myTblFields = value;
}
}
private string myTblName;
/// <summary>
/// 设定访问的表的名称--"myTable"
/// </summary>
private string tblName
{
get
{
return myTblName;
}
set
{
myTblName = value;
}
}
private string myOrderField;
/// <summary>
/// 设定排序字段--"id,age"
/// </summary>
private string orderField
{
get
{
return myOrderField;
}
set
{
myOrderField = value;
}
}
private string myOrderType = "";
/// <summary>
/// 设定排序类型--"asc/desc"
/// </summary>
private string orderType
{
get
{
return myOrderType;
}
set
{
myOrderType = value;
}
}
private string myWhereStr;
/// <summary>
/// 设定DataGrid的Id--"DataGrid1"
/// </summary>
private string whereStr
{
get
{
return myWhereStr;
}
set
{
myWhereStr = value;
}
}
private string myReturnDivHtml;
/// <summary>
/// 返回分页的Html
/// </summary>
public string returnDivHtml
{
get
{
return myReturnDivHtml;
}
set
{
myReturnDivHtml = value;
}
}
private System.Data.DataTable myReturnTable;
/// <summary>
/// 返回绑定的表
/// </summary>
public System.Data.DataTable DataGridTable
{
get
{
return myReturnTable;
}
set
{
myReturnTable = value;
}
}
Modal_dal mod_dal = new Modal_dal();
public string currentPage = "1";
/// <summary>
/// 返回分页代码,及DataTable
/// </summary>
/// <param name="tableName">要查询的表名</param>
/// <param name="tableFields">要查询的字段name,age</param>
/// <param name="pageCount">一页中显示的个数</param>
/// <param name="orderField">排序字段</param>
/// <param name="whereStr">条件</param>
/// <param name="orderType">排序类型</param>
public DataGridDivPage(string tableName,string tableFields,string pageCount,string orderField,string whereStr,string orderType)
{
//
// TODO: 在此处添加构造函数逻辑
//
this.tblName = tableName;
this.tblFields = tableFields;
this.pageCount = pageCount;
this.orderField = orderField;
this.whereStr = whereStr;
this.orderType = orderType;
string pageHtml = "";
//得到当前页数
if(System.Web.HttpContext.Current.Request.Form["DataGridPageDiv_currentPage"] != null) //初始化运行
{
currentPage = System.Web.HttpContext.Current.Request.Form["DataGridPageDiv_currentPage"].Trim();
}
//得到总数目
string myWhereStr = "";
if(whereStr != "")
myWhereStr = " where " + whereStr;
int i_count = Convert.ToInt16(mod_dal.getAllCount("select count(*) from " + tableName + myWhereStr));
//总页数
int i_pageAllCount = 0;
if(i_count%Convert.ToInt16(pageCount) != 0)
i_pageAllCount = i_count/Convert.ToInt16(pageCount) + 1 ;
else
i_pageAllCount = i_count/Convert.ToInt16(pageCount);
string s_div0 = "<span>共" + i_count + "条记录</span>";
string s_div1 = "<span>页次:" + currentPage + "/" + i_pageAllCount.ToString() + "</span>";
string s_div21 = "<a href='#' οnclick=/"JavaScript:currentPageChange('F','')/">首页</a>";
string s_div22 = "<a href='#' οnclick=/"JavaScript:currentPageChange('P','')/">上页</a>";
string s_div31 = "<a href='#' οnclick=/"JavaScript:currentPageChange('N','')/">下页</a>";
string s_div32 = "<a href='#' οnclick=/"JavaScript:currentPageChange('L','" + i_pageAllCount.ToString() + "')/">末页</a>";
string s_div4 = "<select οnchange=/"JavaScript:currentPageChange('S',this.options[this.selectedIndex].value);/">";
for(int i=1; i<=i_pageAllCount; i++)
{
if(currentPage == i.ToString())
s_div4 += "<option value='" + i.ToString() + "' selected>" + i.ToString() + "</option>";
else
s_div4 += "<option value='" + i.ToString() + "'>" + i.ToString() + "</option>";
}
s_div4 += "</select>";
if(currentPage == "1")
{
s_div21 = "<a disabled href='#'/">首页</a>";
s_div22 = "<a disabled href='#'/">上页</a>";
}
if(currentPage == i_pageAllCount.ToString() || i_pageAllCount.ToString() == "0")
{
s_div31 = "<a disabled href='#'/">下页</a>";
s_div32 = "<a disabled href='#'/">末页</a>";
}
pageHtml += "<table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td noWrap>" + "<input type='hidden' name='DataGridPageDiv_currentPage' value='" + currentPage + "'>" + s_div0 + "</td><td noWrap>" + s_div1 + "</td><td noWrap>" + s_div21 + "</td><td noWrap>" + s_div22
+ "</td><td noWrap>" + s_div31+ "</td><td noWrap>" + s_div32 + "</td><td align='right' noWrap>" + "跳转至</td><td noWrap width='1px'>" + s_div4 + "</td><td align='left' noWrap>页" + "</td></tr></table>";
pageHtml += pageDivScript();
this.returnDivHtml = pageHtml;
this.DataGridTable = getDataTable();
}
private System.Data.DataTable getDataTable()
{
//数据库取得表
string maxOrMinMark = ">";
string maxOrMin = "max";
string myOrderField = "";
myOrderField = this.orderField;
if(this.orderField.IndexOf(".") > 0)
myOrderField = orderField.Substring(this.orderField.IndexOf(".")+1);
if(orderType != "" && orderType.ToLower() != "asc")
{
maxOrMinMark = "<";
maxOrMin = "min";
}
string sqlStr1 = "";
if(currentPage != "1")
{
string selectCount = Convert.ToString(Convert.ToInt16(pageCount)*(Convert.ToInt16(currentPage) - 1));
string myWhereStr1 = " where " + whereStr;
if(whereStr == "")
myWhereStr1 = "";
if(whereStr != "")
sqlStr1 = orderField + maxOrMinMark + " (select " + maxOrMin + "(" +
myOrderField + ") from (select top " + selectCount + " " + orderField + " from " + tblName + myWhereStr1 + " order by " + orderField + " " + orderType + " ) as tblTmp) and ";
else
sqlStr1 = orderField + maxOrMinMark + " (select " + maxOrMin + "(" +
myOrderField + ") from (select top " + selectCount + " " + orderField + " from " + tblName + myWhereStr1 + " order by " + orderField + " " + orderType + " ) as tblTmp) ";
}
string myWhereStr = "where " + sqlStr1 + " " + whereStr;
if(sqlStr1 == "" && whereStr == "")
myWhereStr = "";
string sqlStr = "select top " + pageCount + " " + tblFields + " from " + tblName + " " + myWhereStr + " order by " + orderField + " " + orderType;
//绑定表
return mod_dal.getDataTable(sqlStr);
}
private string pageDivScript()
{
string myScript = "";
myScript = "<script language='JavaScript'><!--/n" +
"function currentPageChange(type,val)/n" +
"{/n" +
"switch(type)/n" +
"{/n" +
"case 'S':/n" +
"document.all.DataGridPageDiv_currentPage.value=val;break;/n" +
"case 'F':/n" +
"document.all.DataGridPageDiv_currentPage.value='1';break;/n" +
"case 'N':/n" +
"document.all.DataGridPageDiv_currentPage.value=parseInt(document.all.DataGridPageDiv_currentPage.value)+1;break;/n" +
"case 'P':/n" +
"document.all.DataGridPageDiv_currentPage.value=parseInt(document.all.DataGridPageDiv_currentPage.value)-1;break;/n" +
"case 'L':/n" +
"document.all.DataGridPageDiv_currentPage.value=val;/n" +
"}/n" +
"document.all.Form1.submit();/n" +
"}/n" +
"//--></script>";
return myScript;
}
}
/// <summary>
/// 与数据库相关,可自己定义,
/// </summary>
public class Modal_dal
{
Qzsoft.Db.DbExec dbExec = new Qzsoft.Db.DbExec();
public string getAllCount(string sqlStr)
{
return dbExec.getOneVal(sqlStr);
}
public System.Data.DataTable getDataTable(string sqlStr)
{
return dbExec.getDataTable(sqlStr);
}
}
}
namespace Qzsoft
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class DataGridDivPage
{
private string myPageCount;
/// <summary>
/// 每页的显示数目
/// </summary>
private string pageCount
{
get
{
return myPageCount;
}
set
{
myPageCount = value;
}
}
private string myTblFields;
/// <summary>
/// 设定访问的表的字段--"name,age,sex"
/// </summary>
private string tblFields
{
get
{
return myTblFields;
}
set
{
myTblFields = value;
}
}
private string myTblName;
/// <summary>
/// 设定访问的表的名称--"myTable"
/// </summary>
private string tblName
{
get
{
return myTblName;
}
set
{
myTblName = value;
}
}
private string myOrderField;
/// <summary>
/// 设定排序字段--"id,age"
/// </summary>
private string orderField
{
get
{
return myOrderField;
}
set
{
myOrderField = value;
}
}
private string myOrderType = "";
/// <summary>
/// 设定排序类型--"asc/desc"
/// </summary>
private string orderType
{
get
{
return myOrderType;
}
set
{
myOrderType = value;
}
}
private string myWhereStr;
/// <summary>
/// 设定DataGrid的Id--"DataGrid1"
/// </summary>
private string whereStr
{
get
{
return myWhereStr;
}
set
{
myWhereStr = value;
}
}
private string myReturnDivHtml;
/// <summary>
/// 返回分页的Html
/// </summary>
public string returnDivHtml
{
get
{
return myReturnDivHtml;
}
set
{
myReturnDivHtml = value;
}
}
private System.Data.DataTable myReturnTable;
/// <summary>
/// 返回绑定的表
/// </summary>
public System.Data.DataTable DataGridTable
{
get
{
return myReturnTable;
}
set
{
myReturnTable = value;
}
}
Modal_dal mod_dal = new Modal_dal();
public string currentPage = "1";
/// <summary>
/// 返回分页代码,及DataTable
/// </summary>
/// <param name="tableName">要查询的表名</param>
/// <param name="tableFields">要查询的字段name,age</param>
/// <param name="pageCount">一页中显示的个数</param>
/// <param name="orderField">排序字段</param>
/// <param name="whereStr">条件</param>
/// <param name="orderType">排序类型</param>
public DataGridDivPage(string tableName,string tableFields,string pageCount,string orderField,string whereStr,string orderType)
{
//
// TODO: 在此处添加构造函数逻辑
//
this.tblName = tableName;
this.tblFields = tableFields;
this.pageCount = pageCount;
this.orderField = orderField;
this.whereStr = whereStr;
this.orderType = orderType;
string pageHtml = "";
//得到当前页数
if(System.Web.HttpContext.Current.Request.Form["DataGridPageDiv_currentPage"] != null) //初始化运行
{
currentPage = System.Web.HttpContext.Current.Request.Form["DataGridPageDiv_currentPage"].Trim();
}
//得到总数目
string myWhereStr = "";
if(whereStr != "")
myWhereStr = " where " + whereStr;
int i_count = Convert.ToInt16(mod_dal.getAllCount("select count(*) from " + tableName + myWhereStr));
//总页数
int i_pageAllCount = 0;
if(i_count%Convert.ToInt16(pageCount) != 0)
i_pageAllCount = i_count/Convert.ToInt16(pageCount) + 1 ;
else
i_pageAllCount = i_count/Convert.ToInt16(pageCount);
string s_div0 = "<span>共" + i_count + "条记录</span>";
string s_div1 = "<span>页次:" + currentPage + "/" + i_pageAllCount.ToString() + "</span>";
string s_div21 = "<a href='#' οnclick=/"JavaScript:currentPageChange('F','')/">首页</a>";
string s_div22 = "<a href='#' οnclick=/"JavaScript:currentPageChange('P','')/">上页</a>";
string s_div31 = "<a href='#' οnclick=/"JavaScript:currentPageChange('N','')/">下页</a>";
string s_div32 = "<a href='#' οnclick=/"JavaScript:currentPageChange('L','" + i_pageAllCount.ToString() + "')/">末页</a>";
string s_div4 = "<select οnchange=/"JavaScript:currentPageChange('S',this.options[this.selectedIndex].value);/">";
for(int i=1; i<=i_pageAllCount; i++)
{
if(currentPage == i.ToString())
s_div4 += "<option value='" + i.ToString() + "' selected>" + i.ToString() + "</option>";
else
s_div4 += "<option value='" + i.ToString() + "'>" + i.ToString() + "</option>";
}
s_div4 += "</select>";
if(currentPage == "1")
{
s_div21 = "<a disabled href='#'/">首页</a>";
s_div22 = "<a disabled href='#'/">上页</a>";
}
if(currentPage == i_pageAllCount.ToString() || i_pageAllCount.ToString() == "0")
{
s_div31 = "<a disabled href='#'/">下页</a>";
s_div32 = "<a disabled href='#'/">末页</a>";
}
pageHtml += "<table border='0' cellspacing='0' cellpadding='0' width='100%'><tr><td noWrap>" + "<input type='hidden' name='DataGridPageDiv_currentPage' value='" + currentPage + "'>" + s_div0 + "</td><td noWrap>" + s_div1 + "</td><td noWrap>" + s_div21 + "</td><td noWrap>" + s_div22
+ "</td><td noWrap>" + s_div31+ "</td><td noWrap>" + s_div32 + "</td><td align='right' noWrap>" + "跳转至</td><td noWrap width='1px'>" + s_div4 + "</td><td align='left' noWrap>页" + "</td></tr></table>";
pageHtml += pageDivScript();
this.returnDivHtml = pageHtml;
this.DataGridTable = getDataTable();
}
private System.Data.DataTable getDataTable()
{
//数据库取得表
string maxOrMinMark = ">";
string maxOrMin = "max";
string myOrderField = "";
myOrderField = this.orderField;
if(this.orderField.IndexOf(".") > 0)
myOrderField = orderField.Substring(this.orderField.IndexOf(".")+1);
if(orderType != "" && orderType.ToLower() != "asc")
{
maxOrMinMark = "<";
maxOrMin = "min";
}
string sqlStr1 = "";
if(currentPage != "1")
{
string selectCount = Convert.ToString(Convert.ToInt16(pageCount)*(Convert.ToInt16(currentPage) - 1));
string myWhereStr1 = " where " + whereStr;
if(whereStr == "")
myWhereStr1 = "";
if(whereStr != "")
sqlStr1 = orderField + maxOrMinMark + " (select " + maxOrMin + "(" +
myOrderField + ") from (select top " + selectCount + " " + orderField + " from " + tblName + myWhereStr1 + " order by " + orderField + " " + orderType + " ) as tblTmp) and ";
else
sqlStr1 = orderField + maxOrMinMark + " (select " + maxOrMin + "(" +
myOrderField + ") from (select top " + selectCount + " " + orderField + " from " + tblName + myWhereStr1 + " order by " + orderField + " " + orderType + " ) as tblTmp) ";
}
string myWhereStr = "where " + sqlStr1 + " " + whereStr;
if(sqlStr1 == "" && whereStr == "")
myWhereStr = "";
string sqlStr = "select top " + pageCount + " " + tblFields + " from " + tblName + " " + myWhereStr + " order by " + orderField + " " + orderType;
//绑定表
return mod_dal.getDataTable(sqlStr);
}
private string pageDivScript()
{
string myScript = "";
myScript = "<script language='JavaScript'><!--/n" +
"function currentPageChange(type,val)/n" +
"{/n" +
"switch(type)/n" +
"{/n" +
"case 'S':/n" +
"document.all.DataGridPageDiv_currentPage.value=val;break;/n" +
"case 'F':/n" +
"document.all.DataGridPageDiv_currentPage.value='1';break;/n" +
"case 'N':/n" +
"document.all.DataGridPageDiv_currentPage.value=parseInt(document.all.DataGridPageDiv_currentPage.value)+1;break;/n" +
"case 'P':/n" +
"document.all.DataGridPageDiv_currentPage.value=parseInt(document.all.DataGridPageDiv_currentPage.value)-1;break;/n" +
"case 'L':/n" +
"document.all.DataGridPageDiv_currentPage.value=val;/n" +
"}/n" +
"document.all.Form1.submit();/n" +
"}/n" +
"//--></script>";
return myScript;
}
}
/// <summary>
/// 与数据库相关,可自己定义,
/// </summary>
public class Modal_dal
{
Qzsoft.Db.DbExec dbExec = new Qzsoft.Db.DbExec();
public string getAllCount(string sqlStr)
{
return dbExec.getOneVal(sqlStr);
}
public System.Data.DataTable getDataTable(string sqlStr)
{
return dbExec.getDataTable(sqlStr);
}
}
}