public static string SerializeDataTableRes <T>(DataTable dt, int count) { APIPageResult <T> res = new APIPageResult <T>(); try { if (dt != null && dt.Rows != null && dt.Rows.Count > 0) { res.code = (int)OperateResCodeEnum.成功; PageResult <T> pr = new PageResult <T>(); pr.Items = JsonConvert.DeserializeObject <List <T> >(SerializeToJson(dt)); pr.TotalItemsCount = count; res.data = pr; } else { res.code = (int)OperateResCodeEnum.查询不到需要的数据; res.msg = "查询不到需要的数据"; } } catch { res.code = (int)OperateResCodeEnum.内部错误; } return(JsonConvert.SerializeObject(res)); }
/// <summary> /// 查询分页列表成功返回json /// </summary> /// <param name="data"></param> /// <returns></returns> public static string SuccessPageResult <T>(IPagedItemsResult <T> data) { APIPageResult <T> jsonResult = new APIPageResult <T>(); jsonResult.code = OperateResCodeEnum.成功.GetHashCode(); jsonResult.msg = OperateResCodeEnum.成功.ToString(); jsonResult.data = data; return(SerializeToJson(jsonResult)); }
public static APIPageResult <T> PackageSuccess <T>(List <T> data, int totalCount = -1) { APIPageResult <T> jsonResult = new APIPageResult <T>(); PageResult <T> pr = new PageResult <T>(); pr.Items = data; pr.TotalItemsCount = totalCount < 0 ? data.Count : totalCount; jsonResult.code = OperateResCodeEnum.成功.GetHashCode(); jsonResult.msg = OperateResCodeEnum.成功.ToString(); jsonResult.data = pr; return(jsonResult); }
/// <summary> /// 查询分页列表成功返回json /// </summary> /// <param name="data"></param> /// <returns></returns> public static string SuccessPageResult <T>(List <T> data, int totalCount) { APIPageResult <T> jsonResult = new APIPageResult <T>(); PageResult <T> pr = new PageResult <T>(); pr.Items = data; pr.TotalItemsCount = totalCount; jsonResult.code = OperateResCodeEnum.成功.GetHashCode(); jsonResult.msg = OperateResCodeEnum.成功.ToString(); jsonResult.data = pr; return(SerializeToJson(jsonResult)); }