MDataColumn.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Ant.ORM.Table
  5. {
  6. /// <summary>
  7. /// 头列表集合
  8. /// </summary>
  9. public class MDataColumn : List<CellStruct>
  10. {
  11. private MDataTable _Table;
  12. public MDataColumn()
  13. : base()
  14. {
  15. }
  16. internal MDataColumn(MDataTable table)
  17. {
  18. _Table = table;
  19. }
  20. public MDataColumn Clone()
  21. {
  22. MDataColumn mcs = new MDataColumn();
  23. for (int i = 0; i < base.Count; i++)
  24. {
  25. CellStruct mcb = base[i];
  26. mcs.Add(mcb);
  27. }
  28. return mcs;
  29. }
  30. /// <summary>
  31. /// 获取列所在的索引位置
  32. /// </summary>
  33. public int GetIndex(string columnName)
  34. {
  35. for (int i = 0; i < base.Count; i++)
  36. {
  37. if (string.Compare(base[i].ColumnName, columnName, true) == 0)
  38. {
  39. return i;
  40. }
  41. }
  42. return -1;
  43. }
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. /// <param name="columnName"></param>
  48. /// <returns></returns>
  49. public bool Contains(string columnName)
  50. {
  51. for (int i = 0; i < this.Count; i++)
  52. {
  53. if (string.Compare(this[i].ColumnName, columnName, true) == 0)
  54. {
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. /// <summary>
  61. ///
  62. /// </summary>
  63. /// <param name="columnName"></param>
  64. public void Add(string columnName)
  65. {
  66. Add(columnName, System.Data.SqlDbType.NVarChar);
  67. }
  68. /// <summary>
  69. ///
  70. /// </summary>
  71. /// <param name="columnName"></param>
  72. /// <param name="SqlType"></param>
  73. public void Add(string columnName, System.Data.SqlDbType SqlType)
  74. {
  75. CellStruct mdcStruct = new CellStruct(columnName, SqlType, false, true, 0, System.Data.ParameterDirection.Input);
  76. this.Add(mdcStruct);
  77. if (_Table != null)
  78. {
  79. for (int i = 0; i < _Table.Rows.Count; i++)
  80. {
  81. _Table.Rows[i].Add(new MDataCell(ref mdcStruct));
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 移除列
  87. /// </summary>
  88. /// <param name="columnName"></param>
  89. public void Remove(string columnName)
  90. {
  91. int index = -1;
  92. for (int i = 0; i < this.Count; i++)
  93. {
  94. if (string.Compare(this[i].ColumnName, columnName, true) == 0)
  95. {
  96. index = i;
  97. break;
  98. }
  99. }
  100. if (index > -1)
  101. {
  102. RemoveAt(index);
  103. }
  104. }
  105. /// <summary>
  106. ///
  107. /// </summary>
  108. /// <param name="index"></param>
  109. public new void RemoveAt(int index)
  110. {
  111. if (_Table != null)
  112. {
  113. foreach (MDataRow row in _Table.Rows)
  114. {
  115. row.RemoveAt(index);
  116. }
  117. }
  118. base.RemoveAt(index);
  119. }
  120. }
  121. }