2
0

SelectedDatesCollection.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: SelectedDatesCollection
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.Colletion;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. public sealed class SelectedDatesCollection : ICollection, IEnumerable
  20. {
  21. ArrayList dateList;
  22. public SelectedDatesCollection(ArrayList dateList)
  23. {
  24. this.dateList = dateList;
  25. }
  26. public int Count
  27. {
  28. get
  29. {
  30. return dateList.Count;
  31. }
  32. }
  33. public bool IsReadOnly
  34. {
  35. get
  36. {
  37. return false;
  38. }
  39. }
  40. public bool IsSynchronized
  41. {
  42. get
  43. {
  44. return false;
  45. }
  46. }
  47. public DateTime this[int index]
  48. {
  49. get
  50. {
  51. return (DateTime)(dateList[index]);
  52. }
  53. }
  54. public object SyncRoot
  55. {
  56. get
  57. {
  58. return this;
  59. }
  60. }
  61. public void Add(DateTime date)
  62. {
  63. dateList.Add(date);
  64. }
  65. public void Clear()
  66. {
  67. dateList.Clear();
  68. }
  69. public bool Contains(DateTime date)
  70. {
  71. return dateList.Contains(date);
  72. }
  73. public void CopyTo(Array array, int index)
  74. {
  75. foreach(DateTime current in this)
  76. {
  77. array.SetValue(current, index++);
  78. }
  79. }
  80. public IEnumerator GetEnumerator()
  81. {
  82. return dateList.GetEnumerator();
  83. }
  84. public void Remove(DateTime date)
  85. {
  86. dateList.Remove(date);
  87. }
  88. public void SelectRange(DateTime fromDate, DateTime toDate)
  89. {
  90. dateList.Clear();
  91. //FIXME: Probable bug in MS implementation. It SHOULD NOT
  92. // clear the list if fromDate > toDate
  93. if(fromDate > toDate)
  94. {
  95. return;
  96. }
  97. DateTime local = fromDate;
  98. do
  99. {
  100. dateList.Add(local);
  101. local = local.AddDays(1);
  102. } while(local < toDate);
  103. }
  104. }
  105. }