コード例 #1
0
        /// <summary>
        /// 對目的資料表新增資料列,有相同欄位時才會塞值。
        /// </summary>
        /// <param name="destDataTable">目的資料表。</param>
        /// <param name="sourceRow">來源資料列。</param>
        /// <param name="allowNull">是否允許Null值</param>
        public static void AddRow(DataTable destDataTable, DataRow sourceRow, bool allowNull = true)
        {
            DataRow oNewRow;
            string  sColumnName;

            if (BaseFunc.IsNull(destDataTable))
            {
                return;
            }
            if (BaseFunc.IsEmpty(sourceRow))
            {
                return;
            }

            oNewRow = destDataTable.NewRow();
            foreach (DataColumn column in destDataTable.Columns)
            {
                sColumnName = column.ColumnName;
                if (sourceRow.Table.Columns.Contains(sColumnName))
                {
                    var value = sourceRow[sColumnName];
                    if (allowNull || !BaseFunc.IsNullOrDBNull(value))
                    {
                        oNewRow[sColumnName] = value;
                    }
                }
            }
            destDataTable.Rows.Add(oNewRow);
        }
コード例 #2
0
        /// <summary>
        /// 由來源資料列異動目前資料列,目的資料列存在相同欄位,且不在排除欄位中時才會進行異動。
        /// </summary>
        /// <param name="sourceRow">來源資料列。</param>
        /// <param name="destRow">目的資料列。</param>
        /// <param name="excludeFields">排除欄位</param>
        public static void UpdateRow(DataRow sourceRow, DataRow destRow, params string[] excludeFields)
        {
            DataTable oSoruceTable;
            DataTable oDestTable;

            if (BaseFunc.IsEmpty(sourceRow))
            {
                return;
            }
            if (BaseFunc.IsEmpty(destRow))
            {
                return;
            }

            oSoruceTable = sourceRow.Table;
            oDestTable   = destRow.Table;

            foreach (DataColumn oColumn in oSoruceTable.Columns)
            {
                //確認該欄位是否存在於排除欄位中
                var matchExcludeFields = from excludeField in excludeFields
                                         where StrFunc.SameText(excludeField, oColumn.ColumnName)
                                         select excludeField;

                if (matchExcludeFields.ToList().Count == 0 && oDestTable.Columns.Contains(oColumn.ColumnName) &&
                    !BaseFunc.IsNullOrDBNull(sourceRow[oColumn.ColumnName]))
                {
                    destRow[oColumn.ColumnName] = sourceRow[oColumn.ColumnName];
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 由來源資料列異動目前資料列,目的資料列存在相同欄位時才會進行異動。
        /// </summary>
        /// <param name="sourceRow">來源資料列。</param>
        /// <param name="destRow">目的資料列。</param>
        /// <param name="allowNull">是否允許Null值</param>
        public static void UpdateRow(DataRow sourceRow, DataRow destRow, bool allowNull = true)
        {
            DataTable oSoruceTable;
            DataTable oDestTable;

            if (BaseFunc.IsEmpty(sourceRow))
            {
                return;
            }
            if (BaseFunc.IsEmpty(destRow))
            {
                return;
            }

            oSoruceTable = sourceRow.Table;
            oDestTable   = destRow.Table;

            foreach (DataColumn oColumn in oSoruceTable.Columns)
            {
                if (oDestTable.Columns.Contains(oColumn.ColumnName) &&
                    (allowNull || !BaseFunc.IsNullOrDBNull(sourceRow[oColumn.ColumnName])))
                {
                    destRow[oColumn.ColumnName] = sourceRow[oColumn.ColumnName];
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 由來源資料列異動目前資料列,更新指定欄位值
        /// </summary>
        /// <param name="sourceRow">來源資料列。</param>
        /// <param name="destRow">目的資料列。</param>
        /// <param name="includeFields">指定欄位</param>
        public static void UpdateDesignateRow(DataRow sourceRow, DataRow destRow, params string[] includeFields)
        {
            if (BaseFunc.IsEmpty(sourceRow))
            {
                return;
            }
            if (BaseFunc.IsEmpty(destRow))
            {
                return;
            }

            foreach (var s in includeFields)
            {
                if (HasField(sourceRow, s) && HasField(destRow, s))
                {
                    destRow[s] = sourceRow[s];
                }
            }
        }
コード例 #5
0
ファイル: ExtensionMethod.cs プロジェクト: Sway0308/Gatchan
 /// <summary>
 /// 是否為空值。
 /// </summary>
 /// <param name="dateTime">日期。</param>
 public static bool IsEmpty(this DateTime dateTime)
 {
     return(BaseFunc.IsEmpty(dateTime));
 }