Exemple #1
0
 public async Task <ActionResult> MonthExpenseStatistics(MonthExpenseStatisticsSM sm)
 {
     if (Request.IsAjaxRequest())
     {
         var nameList = new List <string>();
         if (!sm.SDate.HasValue)
         {
             sm.SDate = DateTime.Now.AddYears(-1);
         }
         if (!sm.EDate.HasValue)
         {
             sm.EDate = DateTime.Now;
         }
         var cateList = changeCateRepo.GetList(ViewHelp.GetRoleType(), CateDropType.Report, ViewHelp.GetCateIds());
         sm.CompanyIds = ViewHelp.GetCompanyIds();
         sm.RoleType   = ViewHelp.GetRoleType();
         var dtos = expenseAccountRepo.GetMonthCateList(sm);
         var list = new Dictionary <string, List <ExpenseAccountMonthCateDTO> >();
         if (dtos.Count > 0)
         {
             //补全信息
             foreach (var cate in cateList)
             {
                 var BeginDate = new DateTime(sm.SDate.Value.Year, sm.SDate.Value.Month, 1);
                 var EndDate   = new DateTime(sm.EDate.Value.Year, sm.EDate.Value.Month, 1);
                 list.Add(cate.Value, new List <ExpenseAccountMonthCateDTO>());
                 if (BeginDate != EndDate)
                 {
                     //不是同月的
                     while (BeginDate != EndDate)
                     {
                         var Dto = new ExpenseAccountMonthCateDTO()
                         {
                             CateName = cate.Value, ECMonth = BeginDate.Month, ECYear = BeginDate.Year, SumMoney = 0
                         };
                         Dto.SumMoney = dtos.Where(o => o.CateName == cate.Value && o.ECYear == BeginDate.Year && o.ECMonth == BeginDate.Month).Select(o => o.SumMoney).FirstOrDefault();
                         Dto.SumMoney = Dto.SumMoney ?? 0;
                         list[cate.Value].Add(Dto);
                         nameList.Add(BeginDate.GetMonthName());
                         BeginDate = BeginDate.AddMonths(1);
                     }
                 }
                 else
                 {
                     //同月的
                     var Dto = new ExpenseAccountMonthCateDTO()
                     {
                         CateName = cate.Value, ECMonth = BeginDate.Month, ECYear = BeginDate.Year, SumMoney = 0
                     };
                     Dto.SumMoney = dtos.Where(o => o.CateName == cate.Value && o.ECYear == BeginDate.Year && o.ECMonth == BeginDate.Month).Select(o => o.SumMoney).FirstOrDefault();
                     Dto.SumMoney = Dto.SumMoney ?? 0;
                     list[cate.Value].Add(Dto);
                     nameList.Add(BeginDate.GetMonthName());
                     BeginDate = BeginDate.AddMonths(1);
                 }
             }
         }
         return(Json(new { NameList = nameList, List = list }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         ViewBag.MonthList = ViewHelp.GetRecentlyMonthList();
     }
     return(View());
 }