/// <summary> /// 依資料表定義建立 DataTable。 /// </summary> /// <param name="tableDefine">資料表定義。</param> public static DataTable CreateDataTable(GTableDefine tableDefine) { var helper = new GDataTableHelper(tableDefine.TableName); foreach (GFieldDefine fieldDefine in tableDefine.Fields) helper.AddColumn(fieldDefine.FieldName, fieldDefine.DbType, GetDefaultValue(fieldDefine)); return helper.DataTable; }
/// <summary> /// 執行建立虛擬欄位的作業。 /// </summary> public void Execute() { var oHelper = new GDataTableHelper(this.DataTable); foreach (GFieldDefine fieldDefine in TableDefine.Fields) { // 針對 VirtualField 欄位,動態加入 DataColumn if (fieldDefine.FieldType == EFieldType.VirtualField && !this.DataTable.Columns.Contains(fieldDefine.FieldName)) { var dataCol = oHelper.AddColumn(fieldDefine.FieldName, fieldDefine.DbType); SetAllowNullSetting(dataCol, fieldDefine); } } }
/// <summary> /// 判斷指定的欄位集合字串是是否有虛擬欄位,並執行建立虛擬欄位的作業。 /// </summary> public void Execute(string fields) { if (StrFunc.StrIsEmpty(fields)) { return; } var oHelper = new GDataTableHelper(this.DataTable); var oFields = StrFunc.StrSplit(fields, ","); foreach (string fieldName in oFields) { var oFieldDefine = this.TableDefine.Fields[fieldName]; // 針對 VirtualField 欄位,動態加入 DataColumn if (BaseFunc.IsNotNull(oFieldDefine) && oFieldDefine.FieldType == EFieldType.VirtualField && !this.DataTable.Columns.Contains(oFieldDefine.FieldName)) { var dataCol = oHelper.AddColumn(oFieldDefine.FieldName, oFieldDefine.DbType); SetAllowNullSetting(dataCol, oFieldDefine); } } }