/// <summary> /// 获取和构造报表10的数据 /// </summary> /// <param name="para"></param> /// <returns></returns> private List <HdayExEnViewModel> GetData(Common.QueryParameters para) { RepairData(para);//补数据 List <HdayExEnViewModel> list = new List <HdayExEnViewModel>(); using (DataSubmittedEntities db = new DataSubmittedEntities()) { //构造数据最小日期与查询最小日期之间的数据 if (StrWhere(db, para) != null && StrWhere(db, para).Count() > 0) { DateTime dt = StrWhere(db, para).Min(a => a.CalculTime); int countMin = (dt - (DateTime)para.StartTime.Value).Days; for (int i = 0; i < countMin; i++) { HdayExEnViewModel model1 = new HdayExEnViewModel(); model1.LineEnSum = null; model1.LineExSum = null; model1.Total = 0; model1.DataDate = para.StartTime.Value.AddDays(i).ToString("M月d日"); list.Add(model1); } } //查询数据 var lst = StrWhere(db, para).OrderBy(a => a.CalculTime).Select(a => new HdayExEnViewModel { DataDate = ((DateTime)a.CalculTime).Month + "月" + ((DateTime)a.CalculTime).Day + "日", LineEnSum = (double)a.LineEnSum, LineExSum = (double)a.LineExSum, Total = (double)a.LineEnSum + (double)a.LineExSum }).ToList(); list.AddRange(lst); //按条件查询后有数据 if (list != null && list.Count > 0) { //计算数据最大日期与查询最大日期之间的差值 int countMax = ((DateTime)para.EndTime - StrWhere(db, para).Max(a => a.CalculTime)).Days; //构造已有数据的最大日期到最大查询日期之间的数据 for (int i = 1; i <= countMax; i++) { HdayExEnViewModel model1 = new HdayExEnViewModel(); model1.LineEnSum = null; model1.LineExSum = null; model1.Total = 0; model1.DataDate = StrWhere(db, para).Max(a => a.CalculTime).AddDays(i).ToString("M月d日"); list.Add(model1); } } else//查询后无数据则按照查询时间构造数据 { for (int i = 0; i < ((DateTime)para.EndTime - (DateTime)para.StartTime).Days + 1; i++) { HdayExEnViewModel model2 = new HdayExEnViewModel(); model2.LineEnSum = null; model2.LineExSum = null; model2.Total = 0; model2.DataDate = ((DateTime)para.StartTime).AddDays(i).ToString("M月d日"); list.Add(model2); } } //添加合计行 HdayExEnViewModel modelTotal = new HdayExEnViewModel(); modelTotal.LineEnSum = list.Sum(a => a.LineEnSum); modelTotal.LineExSum = list.Sum(a => a.LineExSum); modelTotal.Total = list.Sum(a => a.Total); modelTotal.DataDate = "合计"; list.Add(modelTotal); //存储到缓存中 listExport.Clear(); listExport.AddRange(list); } return(list); }
/// <summary> /// 获取和构造报表10的数据 /// </summary> /// <param name="para"></param> /// <returns></returns> private List<HdayExEnViewModel> GetData(Common.QueryParameters para) { RepairData(para);//补数据 List<HdayExEnViewModel> list = new List<HdayExEnViewModel>(); using (DataSubmittedEntities db = new DataSubmittedEntities()) { //构造数据最小日期与查询最小日期之间的数据 if (StrWhere(db, para) != null && StrWhere(db, para).Count() > 0) { DateTime dt = StrWhere(db, para).Min(a => a.CalculTime); int countMin = (dt - (DateTime)para.StartTime.Value).Days; for (int i = 0; i < countMin; i++) { HdayExEnViewModel model1 = new HdayExEnViewModel(); model1.LineEnSum = null; model1.LineExSum = null; model1.Total = 0; model1.DataDate = para.StartTime.Value.AddDays(i).ToString("M月d日"); list.Add(model1); } } //查询数据 var lst = StrWhere(db, para).OrderBy(a => a.CalculTime).Select(a => new HdayExEnViewModel { DataDate = ((DateTime)a.CalculTime).Month + "月" + ((DateTime)a.CalculTime).Day + "日", LineEnSum = (double)a.LineEnSum, LineExSum = (double)a.LineExSum, Total = (double)a.LineEnSum + (double)a.LineExSum }).ToList(); list.AddRange(lst); //按条件查询后有数据 if (list != null && list.Count > 0) { //计算数据最大日期与查询最大日期之间的差值 int countMax = ((DateTime)para.EndTime - StrWhere(db, para).Max(a => a.CalculTime)).Days; //构造已有数据的最大日期到最大查询日期之间的数据 for (int i = 1; i <= countMax; i++) { HdayExEnViewModel model1 = new HdayExEnViewModel(); model1.LineEnSum = null; model1.LineExSum = null; model1.Total = 0; model1.DataDate = StrWhere(db, para).Max(a => a.CalculTime).AddDays(i).ToString("M月d日"); list.Add(model1); } } else//查询后无数据则按照查询时间构造数据 { for (int i = 0; i < ((DateTime)para.EndTime - (DateTime)para.StartTime).Days + 1; i++) { HdayExEnViewModel model2 = new HdayExEnViewModel(); model2.LineEnSum = null; model2.LineExSum = null; model2.Total = 0; model2.DataDate = ((DateTime)para.StartTime).AddDays(i).ToString("M月d日"); list.Add(model2); } } //添加合计行 HdayExEnViewModel modelTotal = new HdayExEnViewModel(); modelTotal.LineEnSum = list.Sum(a => a.LineEnSum); modelTotal.LineExSum = list.Sum(a => a.LineExSum); modelTotal.Total = list.Sum(a => a.Total); modelTotal.DataDate = "合计"; list.Add(modelTotal); //存储到缓存中 listExport.Clear(); listExport.AddRange(list); } return list; }