a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

sort page 排序和分頁的小例子

2020-01-24 03:22:29
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

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

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

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

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

 ///
 /// 頁面總數
 ///
 private int _PageCount;

 ///
 /// 每頁記錄數量
 ///
 private int _PageSiz;

 ///
 /// 記錄總數
 ///
 private int _RowCount;

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

 ///
 /// 記錄當前頁面Index
 ///
 private int _CurrentPageIndex;

 ///
 /// 數據源
 ///
 public DataTable DtSource
 {
 get
 {
 return _DtSource;
 }
 }

 ///
 /// 頁面數量
 ///
 public int PageCount
 {
 get
 {
 return _PageCount;
 }
 }

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

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

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

 ///
 /// 記錄當前頁面Index
 ///
 public int CurrentPageIndex
 {
 get
 {
 return _CurrentPageIndex;
 }
 }

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

 ///
 /// 獲取按照給定字段分頁后的制定頁,(排序->分頁)
 ///
 /// 傳入排序的字段
 /// 排序的類型:SortType.ASC 升序 SortType.DESC 降序
 /// 頁面的大小(頁面內要顯示的記錄的數量)
 /// 當前頁面的index
 ///
 public DataTable GetCurrentPageSortByFileName(string sortName, SortType sortKind, int pageSize, int currentPageIndex)
 {
 if (pageSize == 0)
 return DtSource;//如果沒有填寫pagesize那么返回整個數據源
 if (currentPageIndex <= 0)
 return DtSource; //如果沒有傳入當前頁面index,則返回整個數據源
 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) //如果計算出的頁面數*頁面上的數據量小于記錄數,那么頁面大小自動+1
 {
 _PageCount++;
 }

 int currentBeginRowIndex = pageSize * (currentPageIndex - 1); //當前頁面的開始行
 int currentEndRowIndex = pageSize * currentPageIndex - 1;//當前頁面的結束行
 DataTable dtRes = _DtSource.Clone(); //復制數據源表結構
 for (int i = currentBeginRowIndex; i <= currentEndRowIndex; i++) //復制當前頁面的數據到新的datatable中
 {
 if (i >= DtSource.Rows.Count)
 break; //當前頁面的記錄小于該頁面應該顯示的記錄時,就只取當前頁面中的數據
 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 DataTable GetCurrentPage(int pageSize, int currentPageIndex)
 {
 if (pageSize ==0)
 {
 return DtSource;//如果沒有填寫pagesize那么返回整個數據源
 }
 if (currentPageIndex <= 0)
 {
 return DtSource;//如果沒有傳入當前頁面index,則返回整個數據源
 }
 _PageSiz = pageSize;

 _CurrentPageIndex = currentPageIndex;
 this._RowCount = this.DtSource.Rows.Count;
 this._PageCount = this.RowCount / this.PageSize;
 if (_PageCount * PageSize < RowCount) //如果計算出的頁面數*頁面上的數據量小于記錄數,那么頁面大小自動+1
 _PageCount++;
 int CurrentBeginRowIndex = PageSize * (currentPageIndex - 1); //當前頁面的開始行
 int CurrentEndRowIndex = PageSize * currentPageIndex - 1; //當前頁面的結束行
 DataView dv;
 if (_DvSource == null)
 dv = new DataView(DtSource);
 else
 dv = _DvSource;
 DataTable dtRes = _DtSource.Clone(); //復制數據源表結構
 for (int i = CurrentBeginRowIndex; i <= CurrentEndRowIndex; i++) //復制當前頁面的數據到新的datatable中
 {
 if (i >= DtSource.Rows.Count) break; //當前頁面的記錄小于該頁面應該顯示的記錄時,就只取當前頁面中的數據
 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 //倒序排列
 }
 }
 } 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 超碰美女| 在线观看视频91 | 欧美日韩激情在线 | 欧美啊v | 亚洲 精品 综合 精品 自拍 | 国产精品久久久久久久久久久久久久 | 精品一二区 | 国产精品99视频 | 色欧美片视频在线观看 | 久久精品99国产精品日本 | 99国产精品视频免费观看一公开 | 欧美日本韩国一区二区三区 | 精品人成 | 91亚洲视频| 亚洲成a人v欧美综合天堂麻豆 | 久久亚洲一区 | 精品亚洲一区二区三区 | 久久在线播放 | 天天草夜夜 | 日韩欧美一区二区三区免费观看 | 久久久一区二区三区 | 亚洲第一国产精品 | 精品久久久久久久久久久久久久 | 国产福利片在线 | 欧美极品在线 | 伊人免费视频二 | 日韩中文字幕一区二区 | 日韩一二三区在线观看 | 一区二区三区四区国产 | 久久久久无码国产精品一区 | 亚洲h在线观看 | 老牛嫩草一区二区三区眼镜 | 在线观看免费视频亚洲 | 久久免费精品视频 | 欧美国产综合色视频 | 亚洲成av人片一区二区三区 | www.99热这里只有精品 | 成人一区二区三区四区 | 欧美视频在线免费 | 中文字幕第66页 | 97电影在线观看 |