public ActionResult List(int departmentId)
        {
            var listLine      = _lineService.SearchLines(departmentId: departmentId, active: true).Result;
            var listModel     = new List <DdsConfigModel>();
            var listDdsConfig = _ddsConfigService.GetDdsConfigByDepartmentId(departmentId);
            var listMeasure   = _measureService.GetAllMeasureByDepartmentId(departmentId).OrderBy(d => d.Dms.Order).ThenBy(d => d.Order).Distinct();;

            foreach (var measure in listMeasure)
            {
                var model = new DdsConfigModel()
                {
                    DepartmentId = departmentId,
                    Dms          = measure.Dms.Description,
                    MeasureId    = measure.Id,
                    Measure      = measure.MeasureName,
                    MeasureType  = measure.MeasureType.ToString() == "Null" ? "" : (measure.MeasureType.ToString() == "IPorOP" ? "IP/OP" : measure.MeasureType.ToString()),
                    Owner        = string.Join(",", measure.Users.Select(u => u.Username)),
                    Target       = measure.Target,
                    Unit         = measure.Unit
                };

                foreach (var line in listLine)
                {
                    var measureResult = listDdsConfig.FirstOrDefault(d => d.LineId == line.Id && d.MeasureId == measure.Id);

                    var ResultModel = new LineResultOfDdsConfig()
                    {
                        Id       = line.Id,
                        LineName = line.LineName,
                        LineCode = line.LineCode,
                        Colspan  = ((listLine.FirstOrDefault() == line) && (measure.MeasureSystemTypeId == 15)) ? listLine.Count.ToString() : "",
                        IsHiddenForSpanColumns = ((listLine.FirstOrDefault() != line) && (measure.MeasureSystemTypeId == 15))
                    };
                    if (measureResult != null)
                    {
                        ResultModel.DdsConfigId = measureResult.Id;
                        ResultModel.ReadOnly    = true;
                    }
                    else
                    {
                        ResultModel.ReadOnly = false;
                    }

                    model.Lines.Add(ResultModel);
                }
                listModel.Add(model);
            }

            var gridModel = new DataSourceResult
            {
                Data  = listModel,
                Total = listModel.Count()
            };

            return(Json(gridModel));
        }
Beispiel #2
0
        public void Execute()
        {
            //if (DateTime.Now.TimeOfDay < new TimeSpan(11,0,0) ||
            //    DateTime.Now.TimeOfDay > new TimeSpan(11,30,0))
            //    return;

            if (DateTime.Now.TimeOfDay < new TimeSpan(7, 0, 0))
            {
                return;
            }

            var departments = _departmentService.SearchDepartment(null, true);

            var date = DateTime.Today;

            foreach (var department in departments)
            {
                var readyDdsMeeting = _ddsMeetingService.GetDdsMeetingByDate(date, department.Id).Result;
                if (readyDdsMeeting != null)
                {
                    continue;
                }

                //Next Leader
                if (date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday)
                {
                    var meeting = _meetingService.GetMeetingByDepartmentId(department.Id).Result;
                    if (meeting != null && meeting.CurrentLeaderId > 0)
                    {
                        // find current in meeting
                        var currentLeaderId = meeting.CurrentLeaderId;
                        var currentLeader   = meeting.UserInMeetings.FirstOrDefault(x => x.UserId == currentLeaderId);
                        if (currentLeader != null)
                        {
                            var query = meeting.UserInMeetings.Where(um => um.IsLeader).OrderBy(um => um.Order);

                            var nextLeader = query.FirstOrDefault(um => um.Order > currentLeader.Order) ?? query.FirstOrDefault();

                            if (nextLeader != null)
                            {
                                _meetingService.UpdateMeetingLeader(meeting.Id, meeting.CurrentLeaderId, nextLeader.UserId).Wait();

                                meeting.CurrentLeaderId         = nextLeader.UserId;
                                meeting.UpdateCurrentLeaderDate = DateTime.Now.Date;
                                _meetingService.UpdateAsync(meeting).Wait();
                            }
                        }
                    }
                }
                //

                var ddsMeeting = new DdsMeeting
                {
                    DepartmentId    = department.Id,
                    CreatedDateTime = date
                };
                _ddsMeetingService.InsertAsync(ddsMeeting).Wait();

                var ddsConfig = _ddsConfigService.GetDdsConfigByDepartmentId(department.Id);

                //var lines = _lineService.SearchLines(departmentId: department.Id, active:true).Result;
                var lines    = _lineService.SearchLines(departmentId: department.Id).Result;
                var measures = _measureService.GetAllMeasureByDepartmentId(department.Id);

                foreach (var measure in measures)
                {
                    foreach (var line in lines)
                    {
                        var value = "";
                        if (measure.MeasureSystemType == MeasureSystemType.QuanlityAlert)
                        {
                            try
                            {
                                value = _qualityAlertService.CountQuanlityAllertByLineAndDate(line.Id, DateTime.Now).ToString();
                                UpdateQualityAlertToSupplyChain(line, value);
                            }
                            catch
                            {
                            }
                        }
                        if (line.Active)
                        {
                            var configuration = ddsConfig.FirstOrDefault(c => c.MeasureId == measure.Id && c.LineId == line.Id);

                            var ddsMeetingResult = new DdsMeetingResult
                            {
                                DdsMeetingId = ddsMeeting.Id,
                                MeasureId    = measure.Id,
                                LineId       = line.Id,
                                ReadOnly     = configuration != null,
                                Result       = value
                            };
                            ddsMeeting.DdsMeetingResults.Add(ddsMeetingResult);
                        }
                    }
                }

                _ddsMeetingService.UpdateAsync(ddsMeeting).Wait();
            }
        }