/// <summary> /// 将DataTabel中指定的字段转换成指定的C#时间格式 /// </summary> /// <param name="dt">指定</param> public static DataTable ToDataTableIntoSysTime(this DataTable dt, string fileds) { if (dt == null) { return(null); } if (dt.Rows.Count == 0) { return(dt); } DataTable dtmpe = dt.Copy(); foreach (string columnnName in fileds.Split(new char[] { ',' })) { dtmpe.Columns.Remove(columnnName); dtmpe.Columns.Add(columnnName, typeof(string)); } foreach (string columnnName in fileds.Split(new char[] { ',' })) { for (Int32 i = 0; i < dt.Rows.Count; i++) { //if (dt.Rows[i][columnnName] == null || string.IsNullOrEmpty(dt.Rows[i][columnnName].ToString())) //{ // dtmpe.Rows[i][columnnName] = defalutValue; //} //else //{ // dtmpe.Rows[i][columnnName] = TryCast.CastTo<long?>(dt.Rows[i][columnnName]).ToSafeLongDataTime(); //} dtmpe.Rows[i][columnnName] = TryCast.CastTo <long?>(dt.Rows[i][columnnName]).ToSafeLongDataTime(); } } return(dtmpe); }
/// <summary> /// 取出DataTable的Rows[0][0] 数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dt"></param> /// <returns></returns> public static T TryGet <T>(this DataTable dt) { if (dt == null || dt.Rows.Count <= 0) { return(default(T)); } else { return(TryCast.CastTo <T>(dt.Rows[0][0])); } }
public Result <T> SyncRequestByResourcePath <T>(RestRequest rest, ExtendParams restExtendParams, string resourcePath) { Result <T> t = new Result <T>(); try { this._uri = resourcePath; Result r = SyncRequest(rest, restExtendParams, ApiUr); t.code = r.code; t.message = r.message; t.errorCode = r.errorCode; if (r.code == 0) { return(t); } if (r.code == 1) { try { string resultInfo = TryCast.CastTo <string>(r.@object); t = JsonConvert.DeserializeObject <Result <T> >(resultInfo); } catch (Exception ex) { LogService.Default.Fatal("转化TResult 中的T对象出错:对象【" + typeof(T).FullName + "】,转化对象:JSON:" + JsonConvert.SerializeObject(t.@object)); return(t); } } } catch (Exception ex) { t.code = 0; t.message = ex.Message; return(t); } finally { } return(t); }