private void FindNextCheck() { //вычисление самого последнего выполненного чека, вне зависимости от типа //последний выполненый чек по типу может нессответствовать текущему типу программы //в случае переключения MaintenanceCheck lastComplianceCheck = _checkItems.Where(c => c.LastPerformance != null).OrderByDescending(c => c.LastPerformance.RecordDate).FirstOrDefault(); if (lastComplianceCheck != null && lastComplianceCheck.Schedule != _schedule && _schedule) { //тип программмы Maintenance был переключен, переключение с Unschedule на Schedule //вычисление самого последнего выполненного чека, заданного типа MaintenanceCheck lastComplianceScheduleTypeCheck = _checkItems.Where(c => c.LastPerformance != null && c.Schedule == _schedule).OrderByDescending(c => c.LastPerformance.RecordDate).FirstOrDefault(); MaintenanceCheckGroupByType group = new List <MaintenanceCheck>(_checkItems).GetNextCheckBySourceDifference(lastComplianceScheduleTypeCheck, _aircraftLifelength.Days); //название чеков MaintenanceCheck maxIntervalCheckInGroup = group.GetMaxIntervalCheck(); string tNext = maxIntervalCheckInGroup.Name + " ("; tNext += group.Checks.Aggregate("", (current, maintenanceCheck) => current + (maintenanceCheck.Name + " ")); tNext += ") "; string tNextDate = UsefulMethods.NormalizeDate(group.GroupComplianceDate); group.GroupComplianceLifelength.Cycles = group.GroupComplianceLifelength.Hours = null; string tNextLl = group.GroupComplianceLifelength.ToRepeatIntervalsFormat(); group.GroupComplianceLifelength.Substract(_aircraftLifelength); group.GroupComplianceLifelength.Cycles = group.GroupComplianceLifelength.Hours = null; string tRemainLl = Convert.ToInt32(group.GroupComplianceLifelength.Days).ToString(); Action <string, string, string, string> addLast = AddNextCheckItem; if (InvokeRequired) { Invoke(addLast, tNext, tNextDate, tNextLl, tRemainLl); } else { addLast.Invoke(tNext, tNextDate, tNextLl, tRemainLl); } } else { if (_complianceGroupCollection == null) { _complianceGroupCollection = _checkItems.GetNextComplianceCheckGroups(_schedule).OrderBy(c => c.GetNextComplianceDate()); } foreach (MaintenanceCheckComplianceGroup complianceGroup in _complianceGroupCollection) { string tNext, tNextDate, tNextLl, tRemainLl; MaintenanceCheck maxIntervalCheckInGroup; if ((maxIntervalCheckInGroup = complianceGroup.GetMaxIntervalCheck()) == null) { continue; } complianceGroup.Sort(); string prefix = complianceGroup.GetGroupName(); if (complianceGroup.Grouping) { MaintenanceCheck lastOrMinCheck = complianceGroup.GetLastComplianceChecks().FirstOrDefault() != null ? complianceGroup.GetLastComplianceChecks().First() : complianceGroup.GetMinIntervalCheck(); //дата следующего выполнения группы чеков if (lastOrMinCheck.Interval.Days != null && lastOrMinCheck.Interval.Days > 0) { DateTime nextDate = lastOrMinCheck.NextPerformances.Count != 0 && lastOrMinCheck.NextPerformances[0].PerformanceDate != null ? lastOrMinCheck.NextPerformances[0].PerformanceDate.Value : lastOrMinCheck.LastPerformance != null ? lastOrMinCheck.LastPerformance.RecordDate.AddDays(Convert.ToInt32(lastOrMinCheck.Interval.Days)) : lastOrMinCheck.ParentAircraft.ManufactureDate.AddDays(Convert.ToInt32(lastOrMinCheck.Interval.Days)); tNextDate = UsefulMethods.NormalizeDate(nextDate); if (lastOrMinCheck.NextPerformances.Count != 0 && lastOrMinCheck.NextPerformances[0].Remains != null) { //Остаток до выполнения Lifelength remains = lastOrMinCheck.NextPerformances[0].Remains; tRemainLl = remains.IsNullOrZero() ? "N/A" : remains.ToString(); } else { tRemainLl = " N/A "; } } else { tNextDate = lastOrMinCheck.NextPerformances.Count != 0 && lastOrMinCheck.NextPerformances[0].PerformanceDate != null ? " aprx. " + UsefulMethods.NormalizeDate(lastOrMinCheck.NextPerformances[0].PerformanceDate.Value) : " N/A "; if (lastOrMinCheck.NextPerformances.Count != 0 && lastOrMinCheck.NextPerformances[0].Remains != null) { //Остаток до выполнения Lifelength remains = lastOrMinCheck.NextPerformances[0].Remains; tRemainLl = remains.IsNullOrZero() ? "N/A" : remains.ToString(); } else { tRemainLl = " N/A "; } } //ресурс, на котором надо поризвести выполнение //след выполнение Lifelength next = lastOrMinCheck.NextPerformances.Count != 0 ? lastOrMinCheck.NextPerformances[0].PerformanceSource : Lifelength.Null; next.Resemble(maxIntervalCheckInGroup.Interval); tNextLl = next.IsNullOrZero() ? "N/A" : next.ToString(); //название чеков tNext = prefix; if (lastOrMinCheck.ParentAircraft != null && lastOrMinCheck.ParentAircraft.MSG < MSG.MSG3) { tNext += " ("; tNext += complianceGroup.Checks.Aggregate("", (current, maintenanceCheck) => current + (maintenanceCheck.Name + " ")); tNext += ") "; } Action <string, string, string, string> addLast = AddNextCheckItem; if (InvokeRequired) { Invoke(addLast, tNext, tNextDate, tNextLl, tRemainLl); } else { addLast.Invoke(tNext, tNextDate, tNextLl, tRemainLl); } } else { foreach (MaintenanceCheck maintenanceCheck in complianceGroup.Checks) { DateTime nextDate; if (maintenanceCheck.Interval.Days != null && maintenanceCheck.Interval.Days > 0) { nextDate = maintenanceCheck.NextPerformances.Count != 0 && maintenanceCheck.NextPerformances[0].PerformanceDate != null ? maintenanceCheck.NextPerformances[0].PerformanceDate.Value : maintenanceCheck.LastPerformance != null ? maintenanceCheck.LastPerformance.RecordDate.AddDays(Convert.ToInt32(maintenanceCheck.Interval.Days)) : maintenanceCheck.ParentAircraft.ManufactureDate.AddDays(Convert.ToInt32(maintenanceCheck.Interval.Days)); tNextDate = UsefulMethods.NormalizeDate(nextDate); if (maintenanceCheck.NextPerformances.Count != 0 && maintenanceCheck.NextPerformances[0].Remains != null) { //Остаток до выполнения Lifelength remains = maintenanceCheck.NextPerformances[0].Remains; tRemainLl = (remains.IsNullOrZero() ? "N/A" : remains.ToString()); } else { tRemainLl = "N/A"; } } else { if (maintenanceCheck.NextPerformanceDate != null) { nextDate = maintenanceCheck.NextPerformanceDate.Value; tNextDate = "aprx. " + UsefulMethods.NormalizeDate(nextDate); } else { tNextDate = "(N/A) "; } if (maintenanceCheck.NextPerformances.Count != 0 && maintenanceCheck.NextPerformances[0].Remains != null) { //Остаток до выполнения Lifelength remains = maintenanceCheck.NextPerformances[0].Remains; tRemainLl = (remains.IsNullOrZero() ? "N/A" : remains.ToString()); } else { tRemainLl = "(N/A)"; } } //след выполнение Lifelength next = maintenanceCheck.NextPerformances.Count != 0 ? maintenanceCheck.NextPerformances[0].PerformanceSource : Lifelength.Null; tNextLl = (next.IsNullOrZero() ? "N/A" : next.ToString()); //название чеков tNext = maintenanceCheck.Name + " "; Action <string, string, string, string> addLast = AddNextCheckItem; if (InvokeRequired) { Invoke(addLast, tNext, tNextDate, tNextLl, tRemainLl); } else { addLast.Invoke(tNext, tNextDate, tNextLl, tRemainLl); } } } } } }
private void HeaderControlButtonPrintDisplayerRequested(object sender, ReferenceEventArgs e) { if (sender == itemPrintReportStatusSchedule || sender == itemPrintReportStatusUnschedule) { MaintenanceStatusReportBuilder builder = new MaintenanceStatusReportBuilder(); string caption = CurrentAircraft.RegistrationNumber + "." + "Maintenance Status report"; builder.ReportedAircraft = CurrentAircraft; builder.LifelengthAircraftSinceNew = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); if (sender == itemPrintReportStatusSchedule) { builder.FilterSelection = true;//(Schedule) builder.ReportedDirectives = new MaintenanceCheckCollection(_checkItems.Where(c => c.Schedule).ToList()); GlobalObjects.AuditRepository.WriteReportAsync(GlobalObjects.CasEnvironment.IdentityUser, "MaintenanceScreen (Status Schedule)"); } if (sender == itemPrintReportStatusUnschedule) { builder.FilterSelection = false;//(Unschedule) builder.ReportedDirectives = new MaintenanceCheckCollection(_checkItems.Where(c => c.Schedule == false).ToList()); GlobalObjects.AuditRepository.WriteReportAsync(GlobalObjects.CasEnvironment.IdentityUser, "MaintenanceScreen (Status Store)"); } builder.ForecastData = null; e.DisplayerText = caption; e.TypeOfReflection = ReflectionTypes.DisplayInNew; e.RequestedEntity = new ReportScreen(builder); } if (sender == itemPrintReportProgramSchedule || sender == itemPrintReportProgramUnschedule) { MaintenanceProgramReportBuilder builder = new MaintenanceProgramReportBuilder(); string caption = CurrentAircraft.RegistrationNumber + "." + "Maintenance Program report"; builder.ReportedAircraft = CurrentAircraft; builder.LifelengthAircraftSinceNew = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); if (sender == itemPrintReportProgramSchedule) { builder.FilterSelection = true;//(Schedule) builder.ReportedDirectives = new MaintenanceCheckCollection(_checkItems.Where(c => c.Schedule).ToList()); GlobalObjects.AuditRepository.WriteReportAsync(GlobalObjects.CasEnvironment.IdentityUser, "MaintenanceScreen (Program Schedule)"); } if (sender == itemPrintReportProgramUnschedule) { builder.FilterSelection = false;//(Unschedule) builder.ReportedDirectives = new MaintenanceCheckCollection(_checkItems.Where(c => c.Schedule == false).ToList()); GlobalObjects.AuditRepository.WriteReportAsync(GlobalObjects.CasEnvironment.IdentityUser, "MaintenanceScreen (Program Store)"); } builder.ForecastData = null; e.DisplayerText = caption; e.TypeOfReflection = ReflectionTypes.DisplayInNew; e.RequestedEntity = new ReportScreen(builder); } if (sender == itemPrintReportRecords) { MaintenanceRecordReportBuilder builder = new MaintenanceRecordReportBuilder(); string caption = CurrentAircraft.RegistrationNumber + "." + "Maintenance Record report"; builder.ReportedAircraft = CurrentAircraft; builder.LifelengthAircraftSinceNew = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); builder.FilterSelection = true;//(Schedule) builder.ReportedDirectives = new MaintenanceCheckCollection(_checkItems.ToList()); builder.ForecastData = null; e.DisplayerText = caption; e.TypeOfReflection = ReflectionTypes.DisplayInNew; e.RequestedEntity = new ReportScreen(builder); GlobalObjects.AuditRepository.WriteReportAsync(GlobalObjects.CasEnvironment.IdentityUser, "MaintenanceScreen (Records)"); } if (sender == itemPrintReportHistory) { List <MaintenanceCheckRecord> records = new List <MaintenanceCheckRecord>(complianceControl.GetItemsArray()); MaintenanceHistoryReportBuilder builder = new MaintenanceHistoryReportBuilder(); string caption = CurrentAircraft.RegistrationNumber + "." + "Maintenance History report"; builder.ReportedAircraft = CurrentAircraft; builder.LifelengthAircraftSinceNew = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); builder.FilterSelection = true;//(Schedule) builder.ReportedDirectives = records; builder.ForecastData = null; e.DisplayerText = caption; e.TypeOfReflection = ReflectionTypes.DisplayInNew; e.RequestedEntity = new ReportScreen(builder); GlobalObjects.AuditRepository.WriteReportAsync(GlobalObjects.CasEnvironment.IdentityUser, "MaintenanceScreen (Compliance history)"); } }
protected override void AnimatedThreadWorkerDoWork(object sender, DoWorkEventArgs e) { #region Загрузка элементов AnimatedThreadWorker.ReportProgress(0, "load directives"); if (_preResult == null) { _preResult = new MaintenanceCheckCollection(); } _preResult.Clear(); _aircraftDocs.Clear(); try { _preResult.AddRange(GlobalObjects.MaintenanceCore.GetMaintenanceCheck(CurrentAircraft)); } catch (Exception ex) { Program.Provider.Logger.Log("Error while loading directives", ex); } if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } AnimatedThreadWorker.ReportProgress(20, "load directives"); List <Document> aircraftDocs = GlobalObjects.DocumentCore.GetDocuments(CurrentAircraft, DocumentType.Certificate); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } #endregion #region Калькуляция состояния директив AnimatedThreadWorker.ReportProgress(40, "calculation of directives"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } //прогнозируемый ресурс var current = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); var groupingChecks = _preResult.Where(c => c.Grouping); int?offsetMinutes = groupingChecks.Select(c => c.Interval.GetSubresource(LifelengthSubResource.Minutes)) .OrderBy(r => r) .LastOrDefault(); int?offsetCycles = groupingChecks.Select(c => c.Interval.GetSubresource(LifelengthSubResource.Cycles)) .OrderBy(r => r) .LastOrDefault(); int?offsetDays = groupingChecks.Select(c => c.Interval.GetSubresource(LifelengthSubResource.Calendar)) .OrderBy(r => r) .LastOrDefault(); var offset = new Lifelength(offsetDays, offsetCycles, offsetMinutes); var aircraftFrame = GlobalObjects.ComponentCore.GetBaseComponentById(CurrentAircraft.AircraftFrameId); var approxDays = Convert.ToDouble(AnalystHelper.GetApproximateDays(offset, aircraftFrame.AverageUtilization)); var forecastData = new ForecastData(DateTime.Now.AddDays(approxDays), aircraftFrame.AverageUtilization, current); GlobalObjects.MaintenanceCheckCalculator.GetNextPerformanceGroup(_preResult, CurrentAircraft.Schedule, forecastData); var cs = ConditionState.NotEstimated; foreach (MaintenanceCheck check in _preResult) { if (check.Condition == ConditionState.Satisfactory && cs == ConditionState.NotEstimated) { cs = check.Condition; } if (check.Condition == ConditionState.Notify && cs != ConditionState.Notify) { cs = check.Condition; } if (check.Condition == ConditionState.Overdue) { cs = check.Condition; break; } } e.Result = cs; AnimatedThreadWorker.ReportProgress(55, "calculation of documents"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } foreach (Document aircraftDoc in aircraftDocs) { GlobalObjects.PerformanceCalculator.GetNextPerformance(aircraftDoc); if (!aircraftDoc.IsClosed && aircraftDoc.IssueValidTo && aircraftDoc.Condition != ConditionState.NotEstimated) { _aircraftDocs.Add(aircraftDoc); } } #endregion #region Фильтрация директив AnimatedThreadWorker.ReportProgress(70, "filter directives"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } #endregion #region Сравнение с рабочими пакетами AnimatedThreadWorker.ReportProgress(90, "comparison with the Work Packages"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } #endregion AnimatedThreadWorker.ReportProgress(100, "Complete"); }
protected override void AnimatedThreadWorkerDoWork(object sender, DoWorkEventArgs e) { #region Загрузка элементов AnimatedThreadWorker.ReportProgress(0, "load directives"); if (_preResult == null) { _preResult = new MaintenanceCheckCollection(); } _preResult.Clear(); try { _preResult.AddRange(GlobalObjects.MaintenanceCore.GetMaintenanceCheck(CurrentAircraft)); } catch (Exception ex) { Program.Provider.Logger.Log("Error while loading directives", ex); } if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } AnimatedThreadWorker.ReportProgress(20, "load directives"); if (_maintenanceDirectives != null) { _maintenanceDirectives.Clear(); } try { _maintenanceDirectives = GlobalObjects.MaintenanceCore.GetMaintenanceDirectives(CurrentAircraft); var bindedItems = GlobalObjects.BindedItemsCore.GetBindedItemsFor(CurrentAircraft.ItemId, _maintenanceDirectives.Where(m => m.WorkItemsRelationType == WorkItemsRelationType.CalculationDepend).Cast <IBindedItem>()); foreach (var mpd in _maintenanceDirectives) { GlobalObjects.PerformanceCalculator.GetNextPerformance(mpd); if (bindedItems.ContainsKey(mpd)) { var directives = bindedItems[mpd]; foreach (var componentDirective in directives) { if (componentDirective is ComponentDirective) { GlobalObjects.PerformanceCalculator.GetNextPerformance(componentDirective); var firstNextPerformance = bindedItems[mpd].SelectMany(t => t.NextPerformances).OrderBy(n => n.NextPerformanceDate).FirstOrDefault(); if (firstNextPerformance == null) { continue; } mpd.BindedItemNextPerformance = firstNextPerformance; mpd.BindedItemNextPerformanceSource = firstNextPerformance.NextPerformanceSource ?? Lifelength.Null; mpd.BindedItemRemains = firstNextPerformance.Remains ?? Lifelength.Null; mpd.BindedItemNextPerformanceDate = firstNextPerformance.NextPerformanceDate; mpd.BindedItemCondition = firstNextPerformance.Condition ?? ConditionState.NotEstimated; } } } } } catch (Exception ex) { Program.Provider.Logger.Log("Error while loading directives", ex); } if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } #endregion #region Калькуляция состояния директив AnimatedThreadWorker.ReportProgress(40, "calculation of directives"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } //прогнозируемый ресурс var current = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); var groupingChecks = _preResult.Where(c => c.Grouping); int?offsetMinutes = groupingChecks.Select(c => c.Interval.GetSubresource(LifelengthSubResource.Minutes)) .OrderBy(r => r) .LastOrDefault(); int?offsetCycles = groupingChecks.Select(c => c.Interval.GetSubresource(LifelengthSubResource.Cycles)) .OrderBy(r => r) .LastOrDefault(); int?offsetDays = groupingChecks.Select(c => c.Interval.GetSubresource(LifelengthSubResource.Calendar)) .OrderBy(r => r) .LastOrDefault(); var offset = new Lifelength(offsetDays, offsetCycles, offsetMinutes); var aircraftFrame = GlobalObjects.ComponentCore.GetBaseComponentById(CurrentAircraft.AircraftFrameId); var approxDays = Convert.ToDouble(AnalystHelper.GetApproximateDays(offset, aircraftFrame.AverageUtilization)); var forecastData = new ForecastData(DateTime.Now.AddDays(approxDays), aircraftFrame.AverageUtilization, current); GlobalObjects.MaintenanceCheckCalculator.GetNextPerformanceGroup(_preResult, CurrentAircraft.Schedule, forecastData); var cs = ConditionState.NotEstimated; foreach (MaintenanceCheck check in _preResult) { if (check.Condition == ConditionState.Satisfactory && cs == ConditionState.NotEstimated) { cs = check.Condition; } if (check.Condition == ConditionState.Notify && cs != ConditionState.Notify) { cs = check.Condition; } if (check.Condition == ConditionState.Overdue) { cs = check.Condition; break; } } e.Result = cs; #endregion #region Фильтрация директив AnimatedThreadWorker.ReportProgress(70, "filter directives"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } #endregion #region Сравнение с рабочими пакетами AnimatedThreadWorker.ReportProgress(90, "comparison with the Work Packages"); if (AnimatedThreadWorker.CancellationPending) { e.Cancel = true; return; } #endregion AnimatedThreadWorker.ReportProgress(100, "Complete"); }