Exemplo n.º 1
0
        /// <summary>
        /// 轉換為 DateTime 型別。
        /// </summary>
        /// <param name="date">日期字串。</param>
        /// <param name="time">時間字串。</param>
        public static DateTime ToDateTime(string date, string time)
        {
            string sValue;
            string sTime;

            sTime = time;
            // 若時間是四碼或六碼數值,則加上時間冒號
            if (BaseFunc.IsNumeric(sTime))
            {
                if (StrFunc.StrLen(sTime) == 4)
                {
                    sTime = StrFunc.StrFormat("{0}:{1}", StrFunc.StrLeft(sTime, 2), StrFunc.StrSubstring(sTime, 2, 2));
                }
                else if (StrFunc.StrLen(sTime) == 6)
                {
                    sTime = StrFunc.StrFormat("{0}:{1}:{2}", StrFunc.StrLeft(sTime, 2), StrFunc.StrSubstring(sTime, 2, 2), StrFunc.StrSubstring(sTime, 4, 2));
                }
            }

            sValue = StrFunc.StrFormat("{0} {1}", date, sTime);
            if (IsDate(sValue))
            {
                return(BaseFunc.CDateTime(sValue));
            }
            else
            {
                return(DateTime.MinValue);
            }
        }
Exemplo n.º 2
0
 /// <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));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 取得指定名稱的日期時間值
        /// </summary>
        /// <param name="source"></param>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public static DateTime TokenAsDateTime(this JObject source, string propertyName)
        {
            var value = source.TokenValue(propertyName);

            if (BaseFunc.IsNull(value))
            {
                return(DateTime.MinValue);
            }
            else
            {
                return(BaseFunc.CDateTime(value.ToString()));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 更新日期時間值的時間部分。
        /// </summary>
        /// <param name="value">日期時間值。</param>
        /// <param name="timeValue">要異動時間部分的時間字串。</param>
        public static DateTime UpdateTime(DateTime value, string timeValue)
        {
            DateTime oTime;

            if (IsDate(timeValue))
            {
                oTime = BaseFunc.CDateTime(timeValue);
            }
            else
            {
                oTime = DateTime.MinValue;
            }

            return(UpdateTime(value, oTime));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 依欄位資料型別設定欄位值
        /// </summary>
        /// <param name="dbType"></param>
        /// <param name="fieldValue"></param>
        /// <returns></returns>
        public static object SetFieldValue(EFieldDbType dbType, object fieldValue)
        {
            object result = null;

            switch (dbType)
            {
            case EFieldDbType.String:
            case EFieldDbType.Text:
                result = BaseFunc.CStr(fieldValue);
                break;

            case EFieldDbType.Boolean:
                result = BaseFunc.CBool(fieldValue);
                break;

            case EFieldDbType.Integer:
                result = BaseFunc.CInt(fieldValue);
                break;

            case EFieldDbType.Double:
                result = BaseFunc.CDouble(fieldValue);
                break;

            case EFieldDbType.Currency:
                result = BaseFunc.CDecimal(fieldValue);
                break;

            case EFieldDbType.DateTime:
                result = BaseFunc.CDateTime(fieldValue);
                break;

            case EFieldDbType.GUID:
                result = Guid.Parse(fieldValue.ToString());
                break;

            default:
                result = fieldValue;
                break;
            }

            return(result);
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 轉為日期格式,並傳出該日的啟始時間。
 /// </summary>
 /// <param name="date">日期。</param>
 public static DateTime ToDate(object date)
 {
     return(BaseFunc.CDateTime(date).Date);
 }
Exemplo n.º 8
0
 /// <summary>
 /// 取得指定名稱的參數值,並轉型為日期時間值。
 /// </summary>
 /// <param name="name">參數名稱。</param>
 public DateTime GetParameterAsDateTime(string name)
 {
     return(BaseFunc.CDateTime(GetParameterValue(name, DateTime.MinValue)));
 }