The automatic paging function is provided in the web control of the DataGrid, but I have never used it, because the paging implemented by it is just a false phase. Why do we need paging? That's because there may be a lot of qualified records. If you read all records at a time, it not only prolongs the data acquisition time, but it also wastes a lot of memory. The main purpose of pagination is to solve these two problems (of course, it is not ruled out that pagination is used for the sake of UI appearance ). But how does the web version of DataGrid implement paging? It does not intend to solve the above two problems, but it still reads all the data at a time and then displays it in pages. This is a huge damage to efficiency and memory!
So I implemented the page manager IPaginationManager. IPaginationManager reads any specified page from the database each time and can cache a specified number of pages. The main features of this paging manager are:
(1) supports random jump. This is achieved through nested Select statements.
(2) supports caching. Supported by EnterpriseServerBase. DataStructure. FixCacher.
Let's take a look at the definition of the IPaginationManager interface:
Public interface IPaginationManager
{
Void Initialize (DataPaginationParas paras );
Void Initialize (IDBAccesser accesser, int page_Size, string whereStr, string [] fields); // if you select all columns, fields can pass null
DataTable GetPage (int index); // retrieves the index page
DataTable CurrentPage ();
DataTable PrePage ();
DataTable NextPage ();
Int PageCount {get ;}
Int CacherSize {get; set ;}
}
In this interface definition, the most important thing is the GetPage () method, which implements this method, and the other three methods for obtaining the page are very easy: CurrentPage, PrePage, and NextPage. In addition, the CacherSize attribute allows us to specify the number of cached pages. If no cache is required, set its value to <= 0. If you need unlimited cache, the value is Int. MaxValue.
The second Initialize method in the IPaginationManager interface is used by the data layer generated by XCodeFactory. Let's take a look at the definition of the parameter type DataPaginationParas of the first Initialize method:
Public class DataPaginationParas
{
Public int PageSize = 10;
Public string [] Fields = {"*"}; // The column to be searched. "*" indicates all columns.
Public string ConnectString;
Public string TableName;
Public string WhereStr; // where clause of the Search Condition
Public DataPaginationParas (string connStr, string tableName, string whereStr)
{
This. ConnectString = connStr;
This. TableName = tableName;
This. WhereStr = whereStr;
}
# Region GetFiedString
Public string GetFiedString ()
{
If (this. Fields = null)
{
This. Fields = newstring [] {"*"};
}
String fieldStrs = "";
For (int I = 0; I {
FieldStrs + = "" + this. Fields [I];
If (I! = (This. Fields. Length-1 ))
{
FieldStrs + = ",";
}
Else
{
FieldStrs + = "";
}
}
Return fieldStrs;
}
# Endregion
}
DataPaginationParas. GetFiedString is used to form a string for the columns to be searched to be embedded into the SQL statement. Other fields in DataPaginationParas have obvious meanings.
Now let's take a look at the implementation of the paging Manager:
Public class PaginationManager: IPaginationManager
{
Private DataPaginationParas theParas;
Private IADOBase adoBase;
Private DataTable curPage = null;
Private int itemCount = 0;
Private int pageCount =-1;
Private int curPageIndex =-1;
Private FixCacher fixCacher = null;
Private string fieldStrs = "";
///
/// CacheSize less than or equal to 0 -- indicates no cache, Int. MaxValue -- cache all
///
Public PaginationManager (int cacheSize)
{
If (cacheSize = int. MaxValue)
{
This. fixCacher = new FixCacher ();
}
Else if (cacheSize> 0)
{
This. fixCacher = new FixCacher (cacheSize );
}
Else
{
This. fixCacher = null;
}
}
Public PaginationManager ()
{}
# Region IDataPaginationManager Member
Public int CacherSize
{
Get
{
If (this. fixCacher = null)
{
Return 0;
}
Return this. fixCacher. Size;
}
Set
{
If (this. fixCacher = null)
{
This. fixCacher = new FixCacher (value );
}
Else
{
This. fixCacher. Size = value;
}
There are two pages in this news. Currently, there are two pages in page 1st.