Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. public class TableRowInfo : IEquatable<GridRowInfo>
  2. {
  3. #region Ctor
  4.  
  5. public TableRowInfo(int rowIndex, object rowData, NodeEntry nodeEntry, bool isNewRow = false)
  6. {
  7. this.RowData = rowData;
  8. this.NodeEntry = nodeEntry;
  9. this.RowIndex = rowIndex;
  10. this.IsNewRow = isNewRow;
  11. }
  12.  
  13.  
  14. public TableRowInfo(int rowIndex, bool isNewRow)
  15. {
  16. this.RowData = null;
  17. this.NodeEntry = null;
  18. this.RowIndex = rowIndex;
  19. this.IsNewRow = isNewRow;
  20. }
  21.  
  22. #endregion
  23.  
  24. #region Properties
  25.  
  26.  
  27. public object RowData { get; private set; }
  28.  
  29.  
  30. public bool IsDataRow
  31. {
  32. get { return RowData != null; }
  33. }
  34.  
  35.  
  36. public bool IsNewRow
  37. {
  38. get;
  39. set;
  40. }
  41.  
  42.  
  43. public int RowIndex { get; internal set; }
  44.  
  45.  
  46. internal NodeEntry NodeEntry { get; private set; }
  47.  
  48. #endregion
  49.  
  50. public override int GetHashCode()
  51. {
  52. int rowDataHashCode = this.RowData == null ? 0 : this.RowData.GetHashCode();
  53. return rowDataHashCode ^ this.RowIndex;
  54. }
  55.  
  56. #region IEquatable<TableRowInfo> Members
  57.  
  58. public bool Equals(GridRowInfo other)
  59. {
  60. if (Object.ReferenceEquals(other, null)) return false;
  61.  
  62. if (Object.ReferenceEquals(this, other)) return true;
  63.  
  64. if (!this.IsDataRow == other.IsDataRow)
  65. return false;
  66. else if (this.IsDataRow)
  67. return this.RowData == other.RowData;
  68. else
  69. return this.RowIndex == other.RowIndex;
  70. }
  71.  
  72. #endregion
  73. }
  74.  
  75. public class TableSelectedRowsCollection : List<TableRowInfo>
  76. {
  77. #region Ctor
  78.  
  79. public TableSelectedRowsCollection()
  80. {
  81. }
  82.  
  83. #endregion
  84.  
  85. #region IList Members
  86.  
  87. public bool Contains(TableRowInfo rowInfo)
  88. {
  89. if (rowInfo.IsNewRow)
  90. return Find(rowInfo.RowIndex) != null;
  91. else
  92. return Find(rowInfo.NodeEntry) != null;
  93. }
  94.  
  95. public bool Contains(int rowIndex)
  96. {
  97. return Find(rowIndex) != null;
  98. }
  99.  
  100. public bool Contains(object rowData)
  101. {
  102. return Find(rowData) != null;
  103. }
  104.  
  105. public bool Contains(NodeEntry nodeEntry)
  106. {
  107. return Find(nodeEntry) != null;
  108. }
  109.  
  110. #endregion
  111.  
  112. #region Helper Methods
  113.  
  114. internal TableRowInfo Find(NodeEntry nodeEntry)
  115. {
  116. if (nodeEntry != null && this.Count > 0)
  117. {
  118. return this.FirstOrDefault(rowInfo => rowInfo.NodeEntry == nodeEntry);
  119. }
  120. return null;
  121. }
  122.  
  123. internal TableRowInfo Find(int rowIndex)
  124. {
  125. if (rowIndex > 0 && this.Count > 0)
  126. {
  127. return this.FirstOrDefault(rowInfo => rowInfo.RowIndex == rowIndex);
  128. }
  129. return null;
  130. }
  131.  
  132. internal TableRowInfo Find(object rowData)
  133. {
  134. if (rowData != null && this.Count > 0)
  135. {
  136. return this.FirstOrDefault(rowInfo => rowInfo.RowData == rowData);
  137. }
  138. return null;
  139. }
  140.  
  141. internal TableRowInfo Find(TableRowInfo rowInfo)
  142. {
  143. if (rowInfo != null && this.Count > 0)
  144. {
  145. return this.FirstOrDefault(item => item.NodeEntry == rowInfo.NodeEntry);
  146. }
  147. return null;
  148. }
  149.  
  150. internal List<int> GetRowIndexes()
  151. {
  152. var rowIndexes = new List<int>();
  153. if (this.Count > 0)
  154. {
  155. this.ForEach(rowInfo => rowIndexes.Add(rowInfo.RowIndex));
  156. }
  157. return rowIndexes;
  158. }
  159.  
  160. #endregion
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement