欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

sort page 排序和分頁的小例子

 更新時間:2013年05月08日 11:05:10   作者:  
花了一上午時間,終于寫了一個進行排序并且分頁的類,下面將代碼貼出來,望大家指正。
復(fù)制代碼 代碼如下:

/* 系統(tǒng)名:SaleManage
* 模塊名:SortPags
* 模塊說明:排序分頁類(傳入DataTable,及相關(guān)信息,然后分頁,并排序)
* 開發(fā)者:Peter Luo
* 開發(fā)時間:2012年4月6日
*/
using System;
using System.Collections.Generic;
using System.Linq;
 using System.Text;
 using System.Data ;

 namespace Sale_Core
 {
 public class SortPags
 {
 ///
 /// 存儲傳入的數(shù)據(jù)
 ///
 private DataTable _DtSource = null;
 private DataView _DvSource = null;

 ///
 /// 分頁排序類
 ///
 /// 要分頁或排序的數(shù)據(jù)源
 public SortPags(DataTable dt)
 {
 this._DtSource = dt;
 }

 ///
 /// 分頁排序類
 ///
 /// 要分頁或排序的數(shù)據(jù)源
 public SortPags(DataView dv)
 {
 this._DvSource = dv;
 }

 ///
 /// 頁面總數(shù)
 ///
 private int _PageCount;

 ///
 /// 每頁記錄數(shù)量
 ///
 private int _PageSiz;

 ///
 /// 記錄總數(shù)
 ///
 private int _RowCount;

 ///
 /// 排序類型
 /// ASC 升序
 /// DESC 降序
 ///
 private SortType _SortKind;

 ///
 /// 記錄當(dāng)前頁面Index
 ///
 private int _CurrentPageIndex;

 ///
 /// 數(shù)據(jù)源
 ///
 public DataTable DtSource
 {
 get
 {
 return _DtSource;
 }
 }

 ///
 /// 頁面數(shù)量
 ///
 public int PageCount
 {
 get
 {
 return _PageCount;
 }
 }

 ///
 /// 頁面顯示數(shù)量
 ///
 public int PageSize
 {
 get
 {
 return _PageSiz;
 }
 set
 {
 _PageSiz = value;
 }
 }

 ///
 /// 只讀、不能寫,獲取該數(shù)據(jù)源那數(shù)據(jù)總數(shù)
 ///
 public int RowCount
 {
 get
 {
 return _RowCount;
 }
 }

 public SortType SortKind
 {
 get
 {
 return _SortKind;
 }
 set
 {
 _SortKind = value;
 }
 }

 ///
 /// 記錄當(dāng)前頁面Index
 ///
 public int CurrentPageIndex
 {
 get
 {
 return _CurrentPageIndex;
 }
 }

 public DataView Sort(string sortName, SortType sortKind)
 {
 return new DataView();
 }

 ///
 /// 獲取按照給定字段分頁后的制定頁,(排序->分頁)
 ///
 /// 傳入排序的字段
 /// 排序的類型:SortType.ASC 升序 SortType.DESC 降序
 /// 頁面的大?。撁鎯?nèi)要顯示的記錄的數(shù)量)
 /// 當(dāng)前頁面的index
 ///
 public DataTable GetCurrentPageSortByFileName(string sortName, SortType sortKind, int pageSize, int currentPageIndex)
 {
 if (pageSize == 0)
 return DtSource;//如果沒有填寫pagesize那么返回整個數(shù)據(jù)源
 if (currentPageIndex <= 0)
 return DtSource; //如果沒有傳入當(dāng)前頁面index,則返回整個數(shù)據(jù)源
 if (sortName == "")
 return GetCurrentPage(pageSize, currentPageIndex);//如果排序字段沒寫,則只有分頁,不進行排序

 DataView dv = new DataView(DtSource);
 switch (sortKind)
 {
 case SortType.DESC :
 dv.Sort = sortName + "DESC";
 break;
 case SortType .ASC :
 dv.Sort = sortName + "ASC";
 break;
 default :
 break;
 }

 _PageSiz = pageSize;
 _CurrentPageIndex = currentPageIndex;

 this._RowCount = this.DtSource.Rows.Count;
 this._PageCount = this.RowCount / this.PageSize;
 if (_PageCount * PageSize < RowCount) //如果計算出的頁面數(shù)*頁面上的數(shù)據(jù)量小于記錄數(shù),那么頁面大小自動+1
 {
 _PageCount++;
 }

 int currentBeginRowIndex = pageSize * (currentPageIndex - 1); //當(dāng)前頁面的開始行
 int currentEndRowIndex = pageSize * currentPageIndex - 1;//當(dāng)前頁面的結(jié)束行
 DataTable dtRes = _DtSource.Clone(); //復(fù)制數(shù)據(jù)源表結(jié)構(gòu)
 for (int i = currentBeginRowIndex; i <= currentEndRowIndex; i++) //復(fù)制當(dāng)前頁面的數(shù)據(jù)到新的datatable中
 {
 if (i >= DtSource.Rows.Count)
 break; //當(dāng)前頁面的記錄小于該頁面應(yīng)該顯示的記錄時,就只取當(dāng)前頁面中的數(shù)據(jù)
 DataRow dr = dtRes.NewRow();
 for (int j = 0; j < _DtSource.Columns.Count; j++)
 {
 dr[j] = dv[i][j];
 }
 dtRes.Rows.Add(dr);
 }
 return dtRes;
 }

 ///
 ///
 ///
 /// 每頁面大?。總€頁面上記錄的數(shù)量)
 /// 當(dāng)前頁面索引
 ///
 public DataTable GetCurrentPage(int pageSize, int currentPageIndex)
 {
 if (pageSize ==0)
 {
 return DtSource;//如果沒有填寫pagesize那么返回整個數(shù)據(jù)源
 }
 if (currentPageIndex <= 0)
 {
 return DtSource;//如果沒有傳入當(dāng)前頁面index,則返回整個數(shù)據(jù)源
 }
 _PageSiz = pageSize;

 _CurrentPageIndex = currentPageIndex;
 this._RowCount = this.DtSource.Rows.Count;
 this._PageCount = this.RowCount / this.PageSize;
 if (_PageCount * PageSize < RowCount) //如果計算出的頁面數(shù)*頁面上的數(shù)據(jù)量小于記錄數(shù),那么頁面大小自動+1
 _PageCount++;
 int CurrentBeginRowIndex = PageSize * (currentPageIndex - 1); //當(dāng)前頁面的開始行
 int CurrentEndRowIndex = PageSize * currentPageIndex - 1; //當(dāng)前頁面的結(jié)束行
 DataView dv;
 if (_DvSource == null)
 dv = new DataView(DtSource);
 else
 dv = _DvSource;
 DataTable dtRes = _DtSource.Clone(); //復(fù)制數(shù)據(jù)源表結(jié)構(gòu)
 for (int i = CurrentBeginRowIndex; i <= CurrentEndRowIndex; i++) //復(fù)制當(dāng)前頁面的數(shù)據(jù)到新的datatable中
 {
 if (i >= DtSource.Rows.Count) break; //當(dāng)前頁面的記錄小于該頁面應(yīng)該顯示的記錄時,就只取當(dāng)前頁面中的數(shù)據(jù)
 DataRow dr = dtRes.NewRow();
 for (int j = 0; j < _DtSource.Columns.Count; j++)
 {
 dr[j] = dv[i][j];
 }
 dtRes.Rows.Add(dr);
 }
 return dtRes;
 }
 public enum SortType
 {
 ASC, //升序排列
 DESC //倒序排列
 }
 }
 } 

相關(guān)文章

  • C#中面向?qū)ο缶幊虣C制之繼承學(xué)習(xí)筆記

    C#中面向?qū)ο缶幊虣C制之繼承學(xué)習(xí)筆記

    這篇文章主要介紹了C#中面向?qū)ο缶幊虣C制之繼承學(xué)習(xí)筆記,本文給出一個簡單子實例講解C#中的繼承,并講解了一些C#繼承的知識技巧,需要的朋友可以參考下
    2015-01-01
  • 一起詳細聊聊C#中的Visitor模式

    一起詳細聊聊C#中的Visitor模式

    Visitor模式表示一個作用于某對象結(jié)構(gòu)中的各元素的操作,下面這篇文章主要給大家介紹了關(guān)于C#中Visitor模式的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-05-05
  • c#調(diào)用jar包的方法步驟(非常詳細)

    c#調(diào)用jar包的方法步驟(非常詳細)

    這篇文章主要給大家介紹了關(guān)于c#調(diào)用jar包的方法步驟,文中通過圖文介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • C#獲取指定目錄最后寫入時間的方法

    C#獲取指定目錄最后寫入時間的方法

    這篇文章主要介紹了C#獲取指定目錄最后寫入時間的方法,涉及C#中LastWriteTime屬性的使用技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • 詳解C# 利用反射根據(jù)類名創(chuàng)建類的實例對象

    詳解C# 利用反射根據(jù)類名創(chuàng)建類的實例對象

    這篇文章主要介紹了詳解C# 利用反射根據(jù)類名創(chuàng)建類的實例對象,“反射”其實就是利用程序集的元數(shù)據(jù)信息,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • C# 泛型參數(shù)轉(zhuǎn)換

    C# 泛型參數(shù)轉(zhuǎn)換

    本文介紹了C# 泛型參數(shù)轉(zhuǎn)換的相關(guān)知識,具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02
  • C# [ImportDll()] 知識小結(jié)

    C# [ImportDll()] 知識小結(jié)

    今天小編就為大家分享一篇關(guān)于C# [ImportDll()] 知識小結(jié),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • C#正則表達式的6個簡單例子

    C#正則表達式的6個簡單例子

    本文介紹了C#中的正則表達式的六個例子,都是經(jīng)常用到的,希望通過本文的介紹,能夠給你帶來收獲。
    2015-10-10
  • C#根據(jù)前臺傳入實體名稱實現(xiàn)動態(tài)查詢數(shù)據(jù)

    C#根據(jù)前臺傳入實體名稱實現(xiàn)動態(tài)查詢數(shù)據(jù)

    這篇文章主要為大家詳細介紹了C#如何根據(jù)前臺傳入實體名稱實現(xiàn)動態(tài)查詢數(shù)據(jù)的功能,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下
    2023-04-04
  • C# 啟用事務(wù)提交多條帶參數(shù)的SQL語句實例代碼

    C# 啟用事務(wù)提交多條帶參數(shù)的SQL語句實例代碼

    這篇文章主要介紹了C# 啟用事務(wù)提交多條帶參數(shù)的SQL語句實例代碼,需要的朋友可以參考下
    2018-02-02

最新評論