access|datagrid| Dynamic | pagination | statement DataGrid Connect Access Quick Pagination Method (4)--Dynamically generate SQL statements
Using System;
Using System.Text;
namespace paging
{
<summary>
Summary description of the fastpaging.
</summary>
public class Fastpaging {
Private fastpaging () {
}
<summary>
Gets a SELECT statement that sorts and pages the query based on the specified field.
</summary>
<param name= "PageSize" > The number of records to display per page. </param>
<param name= "PageIndex" > The index of the page to display. </param>
<param name= The total number of records in the "RecordCount" > Datasheet. </param>
<param name= "TableName" > The data table to query. </param>
<param name= "QueryFields" > Fields to query. </param>
<param name= "PrimaryKey" > Primary key field. </param>
<param name= "Ascending" > is in ascending order. </param>
<param Name= the filter criteria for the "condition" > Query. </param>
<returns> returns a SELECT statement that sorts and pages the query. </returns>
public static String Paging (
int PageSize,
int PageIndex,
int RecordCount,
String TableName,
String QueryFields,
String PrimaryKey,
BOOL Ascending,
String condition)
{
#region Realize
StringBuilder sb = new StringBuilder ();
int pagecount = Getpagecount (recordcount,pagesize); Total number of pages paged
int middleindex = Getmidpageindex (PageCount); Index of intermediate pages
int firstindex = 0; Index of the first page
int lastindex = pageCount-1; Index of last page
<summary>
Gets a SELECT statement that sorts and pages the query based on the specified field.
</summary>
<param name= "PageSize" > The number of records to display per page. </param>
<param name= "PageIndex" > The index of the page to display. </param>
<param name= The total number of records in the "RecordCount" > Datasheet. </param>
<param name= "TableName" > The data table to query. </param>
<param name= "QueryFields" > Fields to query. </param>
<param name= "PrimaryKey" > Primary key field. </param>
public static String Paging (
int PageSize,
int PageIndex,
int RecordCount,
String TableName,
String QueryFields,
String PrimaryKey)
{
return paging (PageSize, PageIndex, RecordCount, TableName, queryfields, PrimaryKey,
True, String.Empty);
}
<summary>
Gets a SELECT statement that sorts and pages the query based on the specified field.
</summary>
<param name= "PageSize" > The number of records to display per page. </param>
<param name= "PageIndex" > The index of the page to display. </param>
<param name= The total number of records in the "RecordCount" > Datasheet. </param>
<param name= "TableName" > The data table to query. </param>
<param name= "QueryFields" > Fields to query. </param>
<param name= "PrimaryKey" > Primary key field. </param>
<param name= "Ascending" > is in ascending order. </param>
<returns> returns a SELECT statement that sorts and pages the query. </returns>
public static String Paging (
int PageSize,
int PageIndex,
int RecordCount,
String TableName,
String QueryFields,
String PrimaryKey,
BOOL Ascending)
{
return paging (PageSize, PageIndex, RecordCount, TableName, queryfields, PrimaryKey,
Ascending, String.Empty);
}
<summary>
Gets a SELECT statement that sorts and pages the query based on the specified field.
</summary>
<param name= "PageSize" > The number of records to display per page. </param>
<param name= "PageIndex" > The index of the page to display. </param>
<param name= The total number of records in the "RecordCount" > Datasheet. </param>
<param name= "TableName" > The data table to query. </param>
<param name= "QueryFields" > Fields to query. </param>
<param name= "PrimaryKey" > Primary key field. </param>
<param Name= the filter criteria for the "condition" > Query. </param>
<returns> returns a SELECT statement that sorts and pages the query. </returns>
public static String Paging (
int PageSize,
int PageIndex,
int RecordCount,
String TableName,
String QueryFields,
String PrimaryKey,
String condition)
{
return paging (PageSize, PageIndex, RecordCount, TableName, queryfields, PrimaryKey,
true, condition);
}
<summary>
Calculates the number of pages.
</summary>
The total number of <param name= "RecordCount" > Tables is recorded. </param>
<param name= "PageSize" > The number of records displayed per page. </param>
<returns> number of pages. </returns>
public static int Getpagecount (int recordCount, int pageSize)
{
return (int) math.ceiling (double) recordcount/pagesize);
}
<summary>
Calculates the page index of an intermediate page.
</summary>
<param name= "PageCount" > Number of pages. </param>
<returns> the page index of the middle page. </returns>
public static int Getmidpageindex (int pagecount)
{
return (int) math.ceiling ((double) PAGECOUNT/2)-1;
}
<summary>
Gets the way the sort is sorted ("ASC" means ascending, and "DESC" indicates descending).
</summary>
<param name= "Ascending" > is ascending. </param>
<returns> sort ("ASC" means ascending, "DESC" means descending). </returns>
public static String Getsorttype (bool ascending)
{
Return (ascending?) "ASC": "DESC");
}
<summary>
Gets a Boolean value that indicates whether the sort is in ascending order.
</summary>
<param name= "OrderType" > Sort ("ASC" means ascending, "DESC" indicates descending). </param>
<returns> "ASC" is true; "DESC" is false; other is true. </returns>
public static bool Isascending (String OrderType)
{
Return ((ordertype.toupper () = = "DESC") (false:true);
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.