sort page 정렬 과 페이지 분할 의 작은 예

5258 단어 sortpage

/* :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 //
 }
 }
 } 

좋은 웹페이지 즐겨찾기