/// <summary> /// 获得字段在列表中的索引位置 /// </summary> /// <param name="field"></param> /// <returns></returns> public int GetIndex(SCField field) { if (field == null) { return(-1); } return(m_fieldsList.IndexOf(field)); }
/// <summary> /// 添加字段 /// </summary> /// <param name="field"></param> public void AddField(SCField field) { if (field == null || m_fieldsList.Contains(field)) { return; } m_fieldsList.Add(field); ClearCache(); }
public override bool Equals(object obj) { if (m_fieldName == null || obj == null || !(obj is SCField)) { return(false); } SCField f = (SCField)obj; return(f.FiledName.Equals(m_fieldName)); }
/// <summary> /// 从字段列表中删除字段 /// </summary> /// <param name="fieldName"></param> public void DropField(string fieldName) { SCField field = GetField(fieldName); if (field != null) { m_fieldsList.Remove(field); ClearCache(); } }
/// <summary> /// 根据字段名称获得索引 /// </summary> /// <param name="fieldName"></param> /// <returns></returns> public int GetIndex(string fieldName) { if (String.IsNullOrEmpty(fieldName)) { return(-1); } SCField f = GetField(fieldName); return(m_fieldsList.IndexOf(f)); }
public object Clone() { SCField f = new SCField(); f.Caption = this.m_caption; f.DataType = this.DataType; f.Expression = this.m_expression; f.FiledName = this.m_fieldName; f.IsKey = this.m_isKey; f.IsReadOnly = this.m_isReadOnly; f.IsRequire = this.m_isRequire; f.MaxLength = this.m_maxLength; //f.Note = this.note; //f.Precision = this.precision; //f.Scale = this.scale; return(f); }
/// <summary> /// 更新字段 /// </summary> /// <param name="oldField"></param> /// <param name="newField"></param> public void UpdateField(SCField oldField, SCField newField) { lock (m_lockObject) { if (oldField == null || newField == null) { return; } int index = GetIndex(oldField); if (index >= 0) { m_fieldsList.Remove(oldField); m_fieldsList.Insert(index, newField); ClearCache(); } } }
public static SCDataTable GetData(this DataTable dt) { SCDataTable dsd = new SCDataTable(); if (string.IsNullOrWhiteSpace(dt.TableName)) { throw new InvalidCastException("无效的表明"); } dsd.TableName = dt.TableName; SCMetaData md = new SCMetaData(); //提取元数据信息 foreach (DataColumn col in dt.Columns) { SCField f = new SCField(); f.Caption = col.Caption; f.DataType = col.DataType.ToString(); f.Expression = col.Expression; f.FiledName = col.ColumnName; f.IsKey = col.Unique; f.IsReadOnly = col.ReadOnly; f.IsRequire = !col.AllowDBNull; f.MaxLength = col.MaxLength; md.AddField(f); } dsd.MetaData = md; //装数据 List <List <object> > datas = new List <List <object> >(); for (int i = 0; i < dt.Rows.Count; i++) { List <object> rowData = new List <object>(); for (int j = 0; j < dt.Columns.Count; j++) { rowData.Add(dt.Rows[i][j]); } datas.Add(rowData); } dsd.Datas = datas; return(dsd); }