コード例 #1
0
        public JsonResult GetSummaryData(FormCollection fc)
        {
            var year   = int.Parse(fc.Get("year"));
            var deptid = fc.Get("deptid");

            var deptbll = new DepartmentBLL();
            var teams   = deptbll.GetSubDepartments(deptid, "班组");

            var databll   = new DataItemDetailBLL();
            var dataitems = databll.GetDataItems("费用类型");

            var budgetbll = new BudgetBLL();
            var budget    = budgetbll.GetBudgetSummary(year, teams.Select(x => x.DepartmentId).ToArray());
            var costbll   = new CostBLL();
            var cost      = costbll.GetCostSummary(year, teams.Select(x => x.DepartmentId).ToArray());
            var result    = new List <BudgetSummaryModel>();

            result.AddRange(dataitems.GroupJoin(budget, x => x.ItemValue, y => y.Category, (x, y) => new BudgetSummaryModel {
                Category = x.ItemValue + "预算", Data = new decimal[] { y.Sum(z => z.Budget1), y.Sum(z => z.Budget2), y.Sum(z => z.Budget3), y.Sum(z => z.Budget4), y.Sum(z => z.Budget5), y.Sum(z => z.Budget6), y.Sum(z => z.Budget7), y.Sum(z => z.Budget8), y.Sum(z => z.Budget9), y.Sum(z => z.Budget10), y.Sum(z => z.Budget11), y.Sum(z => z.Budget12), }
            }));
            result.AddRange(dataitems.GroupJoin(cost, x => x.ItemValue, y => y.Category, (x, y) => new BudgetSummaryModel {
                Category = x.ItemValue + "支出", Data = new decimal[] { y.Where(z => z.Month == 1).Sum(z => z.Amount), y.Where(z => z.Month == 2).Sum(z => z.Amount), y.Where(z => z.Month == 3).Sum(z => z.Amount), y.Where(z => z.Month == 4).Sum(z => z.Amount), y.Where(z => z.Month == 5).Sum(z => z.Amount), y.Where(z => z.Month == 6).Sum(z => z.Amount), y.Where(z => z.Month == 7).Sum(z => z.Amount), y.Where(z => z.Month == 8).Sum(z => z.Amount), y.Where(z => z.Month == 9).Sum(z => z.Amount), y.Where(z => z.Month == 10).Sum(z => z.Amount), y.Where(z => z.Month == 11).Sum(z => z.Amount), y.Where(z => z.Month == 12).Sum(z => z.Amount), }
            }));

            result = result.OrderBy(x => x.Category).ToList();

            return(Json(result));
        }