/// <summary> /// 隨機取得一個整數值。 /// </summary> /// <param name="min">最小值。</param> /// <param name="max">最大值。</param> public static int RndInt(int min, int max) { Random oRnd = new Random(Guid.NewGuid().GetHashCode()); int iValue = 0; iValue = BaseFunc.CInt(oRnd.Next(min, max)); return(iValue); }
/// <summary> /// 取得欄位值後轉型成int。 /// </summary> /// <param name="row">資料列。</param> /// <param name="fieldName">欄位名稱。</param> /// <param name="dataRowVersion">資料列版本。</param> public static int ValueAsInt(this DataRow row, string fieldName, DataRowVersion dataRowVersion) { if (BaseFunc.IsNotNull(row) && DataFunc.HasField(row, fieldName)) { return(BaseFunc.CInt(row[fieldName, dataRowVersion])); } return(0); }
/// <summary> /// 轉型成時間間格值 /// </summary> /// <param name="time"></param> /// <returns></returns> public static TimeSpan CTimeSpan(string time) { var result = new TimeSpan(); if (StrFunc.StrIsNotEmpty(time)) { int hours = BaseFunc.CInt(StrFunc.StrLeft(time, 2)); int minutes = BaseFunc.CInt(StrFunc.StrRight(time, 2)); result = new TimeSpan(hours, minutes, 0); } return(result); }
/// <summary> /// 取得指定名稱的整數 /// </summary> /// <param name="source"></param> /// <param name="propertyName"></param> /// <returns></returns> public static int TokenAsInt(this JObject source, string propertyName) { var value = source.TokenValue(propertyName); if (BaseFunc.IsNull(value)) { return(0); } else { return(BaseFunc.CInt(value.ToString())); } }
/// <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); }
/// <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); } }
/// <summary> /// 取得指定名稱的參數值,並轉型為整數。 /// </summary> /// <param name="name">參數名稱。</param> public int GetParameterAsInt(string name) { return(BaseFunc.CInt(GetParameterValue(name, 0))); }