コード例 #1
0
        public JsonResult jsonData(string DepartmentId, string SectionId, string MatNameId)
        {
            //add summary data
            List <OutboundedOntimeChartYearlyViewModels> viewSummaryModel = new List <OutboundedOntimeChartYearlyViewModels>();

            // filter by department
            var q = objBs.ontimeOutboundYearBs.GetAll().Where(x => !String.IsNullOrEmpty(x.DepartmentName) &&
                                                              !String.IsNullOrEmpty(x.SectionName) &&
                                                              !String.IsNullOrEmpty(x.MatName));

            //&& x.DepartmentId == DepartmentId
            //filter Department
            if (!String.IsNullOrEmpty(DepartmentId))
            {
                q = q.Where(x => x.DepartmentId == DepartmentId);
            }

            //filter Section
            if (!String.IsNullOrEmpty(SectionId))
            {
                q = q.Where(x => x.SectionId == SectionId);
            }

            //filter matname
            if (!String.IsNullOrEmpty(MatNameId))
            {
                q = q.Where(x => x.MatFriGrp == MatNameId);
            }


            var results = (from c in q
                           group c by new { c.Year } into g
                           select new {
                Year = g.Key.Year,
                Plan = 98.0,
                Actual = ((double)g.Sum(x => x.OnTime) / (double)g.Sum(x => x.SumOfOutbound)) * 100,
                Adjust = (((double)g.Sum(x => x.OnTime) + (double)g.Sum(x => x.AdjustOutbound))
                          / (double)g.Sum(x => x.SumOfOutbound)) * 100,
                SumOfInbound = g.Sum(x => x.SumOfOutbound)
            }).OrderBy(x => x.Year);

            foreach (var item in results.OrderBy(x => x.Year))
            {
                OutboundedOntimeChartYearlyViewModels model = new OutboundedOntimeChartYearlyViewModels();
                model.Year           = item.Year;
                model.Plan           = item.Plan;
                model.Actual         = Math.Round(item.Actual, 2);
                model.Adjust         = Math.Round(item.Adjust, 2);
                model.PlanOfOutbound = 500;
                model.SumOfOutbound  = item.SumOfInbound;
                viewSummaryModel.Add(model);
            }

            return(Json(viewSummaryModel, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public JsonResult jsonData(string DepartmentId, string SectionId, string MatNameId)
        {
            //add summary data
            List<OutboundedOntimeChartYearlyViewModels> viewSummaryModel = new List<OutboundedOntimeChartYearlyViewModels>();

            // filter by department
            var q = objBs.ontimeOutboundYearBs.GetAll().Where(x => !String.IsNullOrEmpty(x.DepartmentName)
                                               && !String.IsNullOrEmpty(x.SectionName)
                                               && !String.IsNullOrEmpty(x.MatName));

            //&& x.DepartmentId == DepartmentId
            //filter Department
            if (!String.IsNullOrEmpty(DepartmentId))
                q = q.Where(x => x.DepartmentId == DepartmentId);

            //filter Section
            if (!String.IsNullOrEmpty(SectionId))
                q = q.Where(x => x.SectionId == SectionId);

            //filter matname
            if (!String.IsNullOrEmpty(MatNameId))
                q = q.Where(x => x.MatFriGrp == MatNameId);

            var results = (from c in q
                           group c by new { c.Year } into g
                           select new {
                               Year = g.Key.Year,
                               Plan = 98.0,
                               Actual = ((double)g.Sum(x => x.OnTime) / (double)g.Sum(x => x.SumOfOutbound)) * 100,
                               Adjust = (((double)g.Sum(x => x.OnTime) + (double)g.Sum(x => x.AdjustOutbound))
                                        / (double)g.Sum(x => x.SumOfOutbound)) * 100,
                               SumOfInbound = g.Sum(x => x.SumOfOutbound)
                           }).OrderBy(x => x.Year);

            foreach (var item in results.OrderBy(x => x.Year)) {
                OutboundedOntimeChartYearlyViewModels model = new OutboundedOntimeChartYearlyViewModels();
                model.Year = item.Year;
                model.Plan = item.Plan;
                model.Actual = Math.Round(item.Actual, 2);
                model.Adjust = Math.Round(item.Adjust, 2);
                model.PlanOfOutbound = 500;
                model.SumOfOutbound = item.SumOfInbound;
                viewSummaryModel.Add(model);
            }

            return Json(viewSummaryModel, JsonRequestBehavior.AllowGet);
        }