/// <summary> /// 取得主檔資料列。 /// </summary> /// <param name="dataSet">資料集。</param> public static DataRow GetMasterRow(DataSet dataSet) { DataTable oTable; if (DataFunc.IsEmpty(dataSet)) { return(null); } oTable = dataSet.Tables[dataSet.DataSetName]; if (!DataFunc.IsEmpty(oTable)) { if (oTable.Rows.Count > 0) { return(oTable.Rows[0]); } else { return(null); } } else { return(null); } }
/// <summary> /// 取得欄位值後轉型成Guid。 /// </summary> /// <param name="row">資料列。</param> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataRowVersion">資料列版本。</param> public static Guid ValueAsGuid(this DataRow row, string fieldName, DataRowVersion dataRowVersion) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CGuid(row[fieldName, dataRowVersion])); } return(Guid.Empty); }
/// <summary> /// 取得欄位值後轉型成DateTime。 /// </summary> /// <param name="row">資料列。</param> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataRowVersion">資料列版本。</param> public static DateTime ValueAsDateTime(this DataRow row, string fieldName, DataRowVersion dataRowVersion) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CDateTime(row[fieldName, dataRowVersion])); } return(default(DateTime)); }
/// <summary> /// 取得欄位值後轉型成bool。 /// </summary> /// <param name="row">資料列。</param> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataRowVersion">資料列版本。</param> public static bool ValueAsBool(this DataRow row, string fieldName, DataRowVersion dataRowVersion) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CBool(row[fieldName, dataRowVersion])); } return(false); }
/// <summary> /// 取得欄位值後轉型成string。 /// </summary> /// <param name="row">資料列。</param> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataRowVersion">資料列版本。</param> public static string ValueAsString(this DataRow row, string fieldName, DataRowVersion dataRowVersion) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CStr(row[fieldName, dataRowVersion])); } return(""); }
/// <summary> /// 取得欄位值後轉型成decimal。 /// </summary> /// <param name="row">資料列。</param> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataRowVersion">資料列版本。</param> public static decimal ValueAsDecimal(this DataRow row, string fieldName, DataRowVersion dataRowVersion) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CDecimal(row[fieldName, dataRowVersion])); } return(0); }
/// <summary> /// 取得欄位值後轉型成float /// </summary> /// <param name="row">資料列</param> /// <param name="fieldName">欄位名稱</param> /// <returns></returns> public static float ValueAsFloat(this DataRow row, string fieldName) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CFloat(row[fieldName])); } return(0); }
/// <summary> /// 取得欄位值後轉型成double /// </summary> /// <param name="row">資料列</param> /// <param name="fieldName">欄位名稱</param> /// <returns></returns> public static double ValueAsDouble(this DataRow row, string fieldName) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CDouble(row[fieldName])); } return(0); }
/// <summary> /// 建立欄位並加入資料表。 /// </summary> /// <param name="fieldName">欄位名稱。</param> /// <param name="fieldDbType">欄位資料型別。</param> public DataColumn AddColumn(string fieldName, EFieldDbType fieldDbType) { Type oDataType; oDataType = DbTypeConverter.ToType(fieldDbType); object oDefaultValue = DataFunc.GetDefaultValue(oDataType); return(this.AddColumn(fieldName, oDataType, oDefaultValue)); }
/// <summary> /// 根據來源單指定欄位資料,新增目的單指定欄位資料列 /// </summary> /// <param name="destTable"></param> /// <param name="srcTable"></param> /// <param name="destField"></param> /// <param name="srcField"></param> public static void AddSrcTableRow(DataTable destTable, DataTable srcTable, string destField, string srcField) { if (DataFunc.HasField(destTable, destField) && DataFunc.HasField(srcTable, srcField)) { foreach (DataRow row in srcTable.Rows) { DataRow newRow = destTable.NewRow(); newRow[destField] = row[srcField].ToString(); destTable.Rows.Add(newRow); } } }
/// <summary> /// 對目的資料表新增來源資料表中的資料列,有相同欄位時才會塞值。 /// </summary> /// <param name="destDataTable">目的資料表。</param> /// <param name="sourceTable">來源資料表。</param> /// <param name="allowNull">是否允許Null值</param> public static void AddTableRows(DataTable destDataTable, DataTable sourceTable, bool allowNull = true) { if (BaseFunc.IsNull(destDataTable)) { return; } if (DataFunc.IsEmpty(sourceTable)) { return; } foreach (DataRowView sourceRow in sourceTable.DefaultView) { AddRow(destDataTable, sourceRow.Row, allowNull); } }
/// <summary> /// 建立欄位並加入資料表中。 /// </summary> /// <param name="fieldName">欄位名稱。</param> /// <param name="caption">欄位標題。</param> /// <param name="dataType">資料型別。</param> public DataColumn AddColumn(string fieldName, string caption, Type dataType) { object oDefaultValue = DataFunc.GetDefaultValue(dataType); return(AddColumn(fieldName, caption, dataType, oDefaultValue)); }
/// <summary> /// 建構函式。 /// </summary> /// <param name="tableName">資料表名稱。</param> public GDataTableHelper(string tableName) { DataTable = DataFunc.CreateDataTable(tableName); DataTable.RemotingFormat = SerializationFormat.Binary; }
/// <summary> /// 設定資料表的主索引鍵。 /// </summary> /// <param name="fieldNames">主索引鍵的欄位集合字串(以逗點分隔多個欄位名稱)。</param> public void SetPrimaryKey(string fieldNames) { DataFunc.DataTableSetPrimaryKey(this.DataTable, fieldNames); }
/// <summary> /// 建立欄位並加入資料表。 /// </summary> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataType">資料型別。</param> public DataColumn AddColumn(string fieldName, Type dataType) { object oDefaultValue = DataFunc.GetDefaultValue(dataType); return(this.AddColumn(fieldName, dataType, oDefaultValue)); }