using System; using System.Collections.Generic; using System.Text; namespace Ant.ORM.Table { /// /// 头列表集合 /// public class MDataColumn : List { private MDataTable _Table; public MDataColumn() : base() { } internal MDataColumn(MDataTable table) { _Table = table; } public MDataColumn Clone() { MDataColumn mcs = new MDataColumn(); for (int i = 0; i < base.Count; i++) { CellStruct mcb = base[i]; mcs.Add(mcb); } return mcs; } /// /// 获取列所在的索引位置 /// public int GetIndex(string columnName) { for (int i = 0; i < base.Count; i++) { if (string.Compare(base[i].ColumnName, columnName, true) == 0) { return i; } } return -1; } /// /// /// /// /// public bool Contains(string columnName) { for (int i = 0; i < this.Count; i++) { if (string.Compare(this[i].ColumnName, columnName, true) == 0) { return true; } } return false; } /// /// /// /// public void Add(string columnName) { Add(columnName, System.Data.SqlDbType.NVarChar); } /// /// /// /// /// public void Add(string columnName, System.Data.SqlDbType SqlType) { CellStruct mdcStruct = new CellStruct(columnName, SqlType, false, true, 0, System.Data.ParameterDirection.Input); this.Add(mdcStruct); if (_Table != null) { for (int i = 0; i < _Table.Rows.Count; i++) { _Table.Rows[i].Add(new MDataCell(ref mdcStruct)); } } } /// /// 移除列 /// /// public void Remove(string columnName) { int index = -1; for (int i = 0; i < this.Count; i++) { if (string.Compare(this[i].ColumnName, columnName, true) == 0) { index = i; break; } } if (index > -1) { RemoveAt(index); } } /// /// /// /// public new void RemoveAt(int index) { if (_Table != null) { foreach (MDataRow row in _Table.Rows) { row.RemoveAt(index); } } base.RemoveAt(index); } } }