ListViewPagedDataSource.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // System.Web.UI.WebControls.ListView
  3. //
  4. // Authors:
  5. // Marek Habersack ([email protected])
  6. //
  7. // (C) 2007 Novell, Inc
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_3_5
  30. using System;
  31. using System.Collections;
  32. using System.ComponentModel;
  33. namespace System.Web.UI.WebControls
  34. {
  35. public class ListViewPagedDataSource : ICollection, IEnumerable, ITypedList
  36. {
  37. public ListViewPagedDataSource ()
  38. {
  39. StartRowIndex = 0;
  40. MaximumRows = 0;
  41. AllowServerPaging = false;
  42. TotalRowCount = 0;
  43. }
  44. public void CopyTo (Array array, int index)
  45. {
  46. }
  47. public IEnumerator GetEnumerator ()
  48. {
  49. IEnumerable ds = DataSource;
  50. if (ds == null)
  51. return null;
  52. return ds.GetEnumerator ();
  53. }
  54. public PropertyDescriptorCollection GetItemProperties (PropertyDescriptor [] listAccessors)
  55. {
  56. IEnumerable ds = DataSource;
  57. if (ds == null || !(ds is ITypedList))
  58. return null;
  59. return ((ITypedList) ds).GetItemProperties (listAccessors);
  60. }
  61. public string GetListName (PropertyDescriptor [] listAccessors)
  62. {
  63. return String.Empty;
  64. }
  65. public bool AllowServerPaging {
  66. get;
  67. set;
  68. }
  69. public int Count {
  70. get {
  71. IEnumerable ds = DataSource;
  72. if (ds == null)
  73. return 0;
  74. bool onLastPage = OnLastPage;
  75. int maxRows = MaximumRows;
  76. if (!onLastPage && maxRows >= 0)
  77. return maxRows;
  78. // LAMESPEC: MSDN says that DataSourceCount should be subtracted
  79. // from StartRowIndex, but that would result in a negative number,
  80. // which is not what we want.
  81. return DataSourceCount - StartRowIndex;
  82. }
  83. }
  84. public IEnumerable DataSource {
  85. get;
  86. set;
  87. }
  88. public int DataSourceCount {
  89. get {
  90. IEnumerable ds = DataSource;
  91. if (ds == null)
  92. return 0;
  93. if (!(ds is ICollection))
  94. throw new InvalidOperationException ("The data source object does not implement the System.Collections..::.ICollection interface.");
  95. if (IsServerPagingEnabled)
  96. return TotalRowCount;
  97. return ((ICollection) ds).Count;
  98. }
  99. }
  100. public bool IsReadOnly {
  101. get { return false; }
  102. }
  103. public bool IsServerPagingEnabled {
  104. get { return AllowServerPaging; }
  105. }
  106. public bool IsSynchronized {
  107. get { return false; }
  108. }
  109. public int MaximumRows {
  110. get;
  111. set;
  112. }
  113. public int StartRowIndex {
  114. get;
  115. set;
  116. }
  117. public object SyncRoot {
  118. get { return this; }
  119. }
  120. public int TotalRowCount {
  121. get;
  122. set;
  123. }
  124. bool OnLastPage {
  125. get { return ((StartRowIndex + MaximumRows) >= DataSourceCount); }
  126. }
  127. }
  128. }
  129. #endif