Exemplo n.º 1
0
        /// <summary>
        /// 建立欄位並加入資料表中。
        /// </summary>
        /// <param name="fieldName">欄位名稱。</param>
        /// <param name="caption">欄位標題。</param>
        /// <param name="dataType">資料型別。</param>
        /// <param name="defaultValue">預設值。</param>
        /// <param name="dateTimeMode">設定資料行的 DateTimeMode。</param>
        public DataColumn AddColumn(string fieldName, string caption, Type dataType, object defaultValue, DataSetDateTime dateTimeMode = DataSetDateTime.Unspecified)
        {
            DataColumn oDataColumn;
            string     sFieldName;

            // 欄位名稱全轉為大寫
            sFieldName  = StrFunc.StrUpper(fieldName);
            oDataColumn = new DataColumn(sFieldName, dataType);
            oDataColumn.DefaultValue = defaultValue;

            if (dataType == typeof(DateTime))
            {
                oDataColumn.DateTimeMode = dateTimeMode;
            }

            if (!BaseFunc.IsDBNull(defaultValue))
            {
                oDataColumn.AllowDBNull = false;
            }

            if (StrFunc.StrIsNotEmpty(caption))
            {
                oDataColumn.Caption = caption;
            }

            this.DataTable.Columns.Add(oDataColumn);
            return(oDataColumn);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 判斷二個欄位值是否相同。
 /// </summary>
 /// <param name="value1">第一個欄位值。</param>
 /// <param name="value2">第二個欄位值。</param>
 public static bool FieldValueIsEquals(object value1, object value2)
 {
     if (BaseFunc.IsNotNull(value1) && BaseFunc.IsNotNull(value1))
     {
         if (!BaseFunc.IsDBNull(value1) && !BaseFunc.IsDBNull(value2))
         {
             return(value1.Equals(value2));
         }
         else if (BaseFunc.IsDBNull(value1) && BaseFunc.IsDBNull(value2))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 將傳入值轉型為指定欄位資料型別。
        /// </summary>
        /// <param name="fieldDbType">欄位資料型別。</param>
        /// <param name="value">傳入值。</param>
        public static object CFieldValue(EFieldDbType fieldDbType, object value)
        {
            switch (fieldDbType)
            {
            case EFieldDbType.String:
                return(BaseFunc.CStr(value).Trim());     // 去除左右空白

            case EFieldDbType.Text:
                return(BaseFunc.CStr(value).Trim());     // 去除左右空白

            case EFieldDbType.Boolean:
                return(BaseFunc.CBool(value));

            case EFieldDbType.Integer:
                return(BaseFunc.CInt(value));

            case EFieldDbType.Double:
                return(BaseFunc.CDouble(value));

            case EFieldDbType.Currency:
                return(BaseFunc.CDecimal(value));

            case EFieldDbType.DateTime:
                if (BaseFunc.IsDBNull(value))
                {
                    return(value);
                }
                else
                {
                    return(BaseFunc.CDateTime(value));
                }

            case EFieldDbType.GUID:
                return(BaseFunc.CGuid(value));

            default:
                return(value);
            }
        }