首页 > 代码库 > 关于数据源翻页

关于数据源翻页

最近项目要对采集的数据图谱进行翻页,然而数据源类型不一致,不过其本质都是集合.

 1  public class MyPage<T> 2     { 3         /// <summary> 4         /// 当前显示页 5         /// </summary> 6         private int _currentIndex; 7  8         public int CurrentIndex 9         {10             get11             {12                 return _currentIndex;13             }14         }15 16         /// <summary>17         /// 比较数据源18         /// </summary>19         private ICollection<T> _dataSource;20 21         /// <summary>22         /// 数据总条数23         /// </summary>24         private int _total;25 26         public bool IsBigOne27         {28             get29             {30                 return _dataSource.Count > 1;31             }32         }33 34         /// <summary>35         /// 初始化36         /// </summary>37         /// <param name="data"></param>38         public ComParisonPage(ICollection<T> data)39         {40             if (data != null)41             {42                 _dataSource = data;43                 _currentIndex = 0;44 45             }46         }47 48         /// <summary>49         /// 上一页50         /// </summary>51         public void Prev()52         {53             _currentIndex -= 1;54             if (_currentIndex < 0) _currentIndex = 0;55         }56 57         /// <summary>58         /// 下一页59         /// </summary>60         public void Next()61         {62             _currentIndex += 1;63             if (_currentIndex >= _dataSource.Count - 1) _currentIndex = _dataSource.Count - 1;64         }65 66         public T Current67         {68             get69             {70                 return _dataSource.ElementAt(_currentIndex);71             }72         }73 74 75         public bool IsTop76         {77             get78             {79                 return _currentIndex == 0;80             }81         }82 83         public bool IsBottom84         {85             get86             {87                 return _currentIndex >= _dataSource.Count - 1;88             }89         }90     }
View Code


下面就可以实例这个类了:

      private Page<KeyValuePair<double, Spectrum>> P1 = null;

      private Page<model> p2 = null;

关于数据源翻页