ComparerBase.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //#########################################################################################
  2. //★★★★★★★ http://www.cnpopsoft.com [华普软件] ★★★★★★★
  3. //★★★★★★★ 华普软件 - VB & C#.NET 专业论文与源码荟萃! ★★★★★★★
  4. //#########################################################################################
  5. /*
  6. * Copyright ?2005, Mathew Hall
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  25. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. * OF SUCH DAMAGE.
  29. */
  30. using System;
  31. using System.Collections;
  32. using System.Windows.Forms;
  33. using XPTable.Models;
  34. namespace XPTable.Sorting
  35. {
  36. /// <summary>
  37. /// Base class for comparers used to sort the Cells contained in a TableModel
  38. /// </summary>
  39. public abstract class ComparerBase : IComparer
  40. {
  41. #region Class Data
  42. /// <summary>
  43. /// The TableModel that contains the Cells to be sorted
  44. /// </summary>
  45. private TableModel tableModel;
  46. /// <summary>
  47. /// The index of the Column to be sorted
  48. /// </summary>
  49. private int column;
  50. /// <summary>
  51. /// Specifies how the Column is to be sorted
  52. /// </summary>
  53. private SortOrder sortOrder;
  54. #endregion
  55. #region Constructor
  56. /// <summary>
  57. /// Initializes a new instance of the ComparerBase class with the specified
  58. /// TableModel, Column index and SortOrder
  59. /// </summary>
  60. /// <param name="tableModel">The TableModel that contains the data to be sorted</param>
  61. /// <param name="column">The index of the Column to be sorted</param>
  62. /// <param name="sortOrder">Specifies how the Column is to be sorted</param>
  63. public ComparerBase(TableModel tableModel, int column, SortOrder sortOrder)
  64. {
  65. this.tableModel = tableModel;
  66. this.column = column;
  67. this.sortOrder = sortOrder;
  68. }
  69. #endregion
  70. #region Methods
  71. /// <summary>
  72. /// Compares two objects and returns a value indicating whether one is less
  73. /// than, equal to or greater than the other
  74. /// </summary>
  75. /// <param name="a">First object to compare</param>
  76. /// <param name="b">Second object to compare</param>
  77. /// <returns>-1 if a is less than b, 1 if a is greater than b, or 0 if a equals b</returns>
  78. public abstract int Compare(object a, object b);
  79. #endregion
  80. #region Properties
  81. /// <summary>
  82. /// Gets the TableModel that contains the Cells to be sorted
  83. /// </summary>
  84. public TableModel TableModel
  85. {
  86. get
  87. {
  88. return this.tableModel;
  89. }
  90. }
  91. /// <summary>
  92. /// Gets the index of the Column to be sorted
  93. /// </summary>
  94. public int SortColumn
  95. {
  96. get
  97. {
  98. return this.column;
  99. }
  100. }
  101. /// <summary>
  102. /// Gets how the Column is to be sorted
  103. /// </summary>
  104. public SortOrder SortOrder
  105. {
  106. get
  107. {
  108. return this.sortOrder;
  109. }
  110. }
  111. #endregion
  112. }
  113. }