public ActionResult MonthAnalyze(string[] Grid1_fields, DateTime?yearMonth, DateTime?toYearMonth) { List <MonthAnalyze> prList = new List <MonthAnalyze>(); int year = yearMonth.Value.Year; int month = yearMonth.Value.Month; int toYear = toYearMonth.Value.Year; int toMonth = toYearMonth.Value.Month; List <SaleManage> smList = db.SaleManage.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth).ToList(); MonthAnalyze pr4 = new MonthAnalyze(); pr4.Content = "年/月计划"; pr4.ZZSYB = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT != "制造事业部").Sum(p => p.MANAGE_PLAN) / 12; pr4.JGGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "精工工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.JAGGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "加工工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.MJGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "模具工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.ZNSBGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "智能设备工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.ZNJQ = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "智能机器").Sum(p => p.MANAGE_PLAN) / 12; prList.Add(pr4); MonthAnalyze pr1 = new MonthAnalyze(); pr1.Content = "月计划"; pr1.ZZSYB = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT != "制造事业部").Sum(p => p.SALE_PLAN); pr1.JGGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "精工工厂").Sum(p => p.SALE_PLAN); pr1.JAGGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "加工工厂").Sum(p => p.SALE_PLAN); pr1.MJGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "模具工厂").Sum(p => p.SALE_PLAN); pr1.ZNSBGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "智能设备工厂").Sum(p => p.SALE_PLAN); pr1.ZNJQ = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "智能机器").Sum(p => p.SALE_PLAN); prList.Add(pr1); MonthAnalyze pr2 = new MonthAnalyze(); pr2.Content = "月实际"; pr2.ZZSYB = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT != "制造事业部").Sum(p => p.SALE_FINISH); pr2.JGGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "精工工厂").Sum(p => p.SALE_FINISH); pr2.JAGGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "加工工厂").Sum(p => p.SALE_FINISH); pr2.MJGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "模具工厂").Sum(p => p.SALE_FINISH); pr2.ZNSBGC = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "智能设备工厂").Sum(p => p.SALE_FINISH); pr2.ZNJQ = (double)smList.Where(p => p.PLAN_DATE.Year >= yearMonth.Value.Year && p.PLAN_DATE.Month >= yearMonth.Value.Month && p.PLAN_DATE.Year <= toYear && p.PLAN_DATE.Month <= toMonth && p.RSPO_DEPT == "智能机器").Sum(p => p.SALE_FINISH); prList.Add(pr2); MonthAnalyze pr3 = new MonthAnalyze(); pr3.Content = "月完成率"; pr3.ZZSYB = Convert.ToDouble((pr2.ZZSYB / pr1.ZZSYB * 100.0).ToString("0")); pr3.JGGC = Convert.ToDouble((pr2.JGGC / pr1.JGGC * 100.0).ToString("0")); pr3.JAGGC = Convert.ToDouble((pr2.JAGGC / pr1.JAGGC * 100.0).ToString("0")); pr3.MJGC = Convert.ToDouble((pr2.MJGC / pr1.MJGC * 100.0).ToString("0")); pr3.ZNSBGC = Convert.ToDouble((pr2.ZNSBGC / pr1.ZNSBGC * 100.0).ToString("0")); pr3.ZNJQ = Convert.ToDouble((pr2.ZNJQ / pr1.ZNJQ * 100.0).ToString("0")); prList.Add(pr3); var grid1 = UIHelper.Grid("Grid1"); var dataSource = prList; grid1.DataSource(dataSource, Grid1_fields); return(UIHelper.Result()); }
public ActionResult MonthAnalyze() { List <MonthAnalyze> prList = new List <MonthAnalyze>(); int year = DateTime.Now.Year; int month = DateTime.Now.Month; List <SaleManage> smList = db.SaleManage.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month).ToList(); MonthAnalyze pr4 = new MonthAnalyze(); pr4.Content = "年/月计划"; pr4.ZZSYB = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT != "制造事业部").Sum(p => p.MANAGE_PLAN) / 12; pr4.JGGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "精工工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.JAGGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "加工工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.MJGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "模具工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.ZNSBGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "智能设备工厂").Sum(p => p.MANAGE_PLAN) / 12; pr4.ZNJQ = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "智能机器").Sum(p => p.MANAGE_PLAN) / 12; prList.Add(pr4); MonthAnalyze pr1 = new MonthAnalyze(); pr1.Content = "月计划"; pr1.ZZSYB = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT != "制造事业部").Sum(p => p.SALE_PLAN); pr1.JGGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "精工工厂").Sum(p => p.SALE_PLAN); pr1.JAGGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "加工工厂").Sum(p => p.SALE_PLAN); pr1.MJGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "模具工厂").Sum(p => p.SALE_PLAN); pr1.ZNSBGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "智能设备工厂").Sum(p => p.SALE_PLAN); pr1.ZNJQ = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "智能机器").Sum(p => p.SALE_PLAN); prList.Add(pr1); MonthAnalyze pr2 = new MonthAnalyze(); pr2.Content = "月实际"; pr2.ZZSYB = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT != "制造事业部").Sum(p => p.SALE_FINISH); pr2.JGGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "精工工厂").Sum(p => p.SALE_FINISH); pr2.JAGGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "加工工厂").Sum(p => p.SALE_FINISH); pr2.MJGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "模具工厂").Sum(p => p.SALE_FINISH); pr2.ZNSBGC = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "智能设备工厂").Sum(p => p.SALE_FINISH); pr2.ZNJQ = (double)smList.Where(p => p.PLAN_DATE.Year == year && p.PLAN_DATE.Month == month && p.RSPO_DEPT == "智能机器").Sum(p => p.SALE_FINISH); prList.Add(pr2); MonthAnalyze pr3 = new MonthAnalyze(); pr3.Content = "月完成率"; pr3.ZZSYB = Convert.ToDouble((pr2.ZZSYB / pr1.ZZSYB * 100.0).ToString("0")); pr3.JGGC = Convert.ToDouble((pr2.JGGC / pr1.JGGC * 100.0).ToString("0")); pr3.JAGGC = Convert.ToDouble((pr2.JAGGC / pr1.JAGGC * 100.0).ToString("0")); pr3.MJGC = Convert.ToDouble((pr2.MJGC / pr1.MJGC * 100.0).ToString("0.00")); pr3.ZNSBGC = Convert.ToDouble((pr2.ZNSBGC / pr1.ZNSBGC * 100.0).ToString("0")); pr3.ZNJQ = Convert.ToDouble((pr2.ZNJQ / pr1.ZNJQ * 100.0).ToString("0")); prList.Add(pr3); foreach (var pr in prList) { if (double.IsNaN(pr.JAGGC)) { pr.JAGGC = 0; } if (double.IsNaN(pr.JGGC)) { pr.JGGC = 0; } if (double.IsNaN(pr.MJGC)) { pr.MJGC = 0; } if (double.IsNaN(pr.ZNJQ)) { pr.ZNJQ = 0; } if (double.IsNaN(pr.ZNSBGC)) { pr.ZNSBGC = 0; } if (double.IsNaN(pr.ZZSYB)) { pr.ZZSYB = 0; } } return(View(prList)); }