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); } } } } } }
///<summary> ///</summary> ///<param name="checkItems"></param> ///<param name="aircraft"></param> ///<param name="schedule"></param> public void UpdateInformation(MaintenanceCheckCollection checkItems, Aircraft aircraft, bool schedule) { CheckItems = checkItems; Schedule = schedule; _complianceGroupCollection = CheckItems.GetNextComplianceCheckGroups(Schedule).OrderBy(GetNextComplianceDate); TsnCsn = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(aircraft); listViewLastCheck.Items.Clear(); listViewNextCheck.Items.Clear(); if (CheckItems.Count == 0) { return; } if (!BackGroundWorker.IsBusy) { BackGroundWorker.RunWorkerAsync(); } List <MaintenanceCheck> orderedBySchedule = checkItems.OrderBy(c => c.Schedule) .OrderByDescending(c => c.Grouping) .OrderBy(c => c.Resource) .ToList(); List <MaintenanceCheckGroupByType> checkGroups = new List <MaintenanceCheckGroupByType>(); foreach (MaintenanceCheck check in orderedBySchedule) { MaintenanceCheckGroupByType group = checkGroups .FirstOrDefault(g => g.Schedule == check.Schedule && g.Grouping == check.Grouping && g.Resource == check.Resource); if (group != null) { group.Checks.Add(check); } else { group = new MaintenanceCheckGroupByType(check.Schedule) { Grouping = check.Grouping, Resource = check.Resource }; group.Checks.Add(check); checkGroups.Add(group); } } List <MaintenanceProgramControl> mpcs = flowLayoutPanel1.Controls.OfType <MaintenanceProgramControl>().ToList(); for (int j = 0; j < mpcs.Count; j++) { if (j >= checkGroups.Count) { //Если кол-во контролов превышает кол-во групп чеков //то необходимо убрать лишние контролы flowLayoutPanel1.Controls.Remove(mpcs[j]); continue; } mpcs[j].SetParameters(checkGroups[j].Checks, checkGroups[j].Schedule, checkGroups[j].Grouping, checkGroups[j].Resource); } for (int j = mpcs.Count; j < checkGroups.Count; j++) { MaintenanceProgramControl mpc = new MaintenanceProgramControl(checkGroups[j].Checks, checkGroups[j].Schedule, checkGroups[j].Grouping, checkGroups[j].Resource) { Extended = false }; flowLayoutPanel1.Controls.Add(mpc); flowLayoutPanel1.Controls.SetChildIndex(mpc, j); } mpcs = flowLayoutPanel1.Controls.OfType <MaintenanceProgramControl>().ToList(); if (mpcs.Count == 1) { mpcs[0].EnableExtendedControl = false; } else if (mpcs.Count >= 1) { mpcs[0].EnableExtendedControl = true; } maintenancePerformanceControl1.Reload(checkItems, aircraft); }
///<summary> ///</summary> ///<param name="checkItems"></param> ///<param name="aircraftDocuments"></param> ///<param name="aircraft"></param> ///<param name="schedule"></param> public void UpdateInformation(MaintenanceCheckCollection checkItems, IEnumerable <Document> aircraftDocuments, Aircraft aircraft, bool schedule) { _aircraftDocuments.Clear(); _aircraftDocuments.AddRange(aircraftDocuments); _checkItems = checkItems; _schedule = schedule; _currentAircraft = aircraft; _complianceGroupCollection = _checkItems.GetNextComplianceCheckGroups(_schedule).OrderBy(c => c.GetNextComplianceDate()); _aircraftLifelength = GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(aircraft); labelMSGValue.Text = aircraft.MSG.ToString(); labelManufactureDateValue.Text = SmartCore.Auxiliary.Convert.GetDateFormat(aircraft.ManufactureDate); labelOwnerValue.Text = aircraft.Owner; labelOperatorValue.Text = GlobalObjects.CasEnvironment.Operators.First(o => o.ItemId == _currentAircraft.OperatorId).Name; labelAircraftTypeCertificateNoValue.Text = aircraft.TypeCertificateNumber; labelCurrentValue.Text = _aircraftLifelength.ToHoursMinutesAndCyclesFormat("FH", "FC"); labelBasicEmptyWeightValue.Text = aircraft.BasicEmptyWeight.ToString(); labelBasicEmptyWeightCargoConfigValue.Text = aircraft.BasicEmptyWeightCargoConfig.ToString(); labelCargoCapacityContainerValue.Text = aircraft.CargoCapacityContainer; labelCruiseValue.Text = aircraft.Cruise; labelCruiseFuelFlowValue.Text = aircraft.CruiseFuelFlow; labelFuelCapacityValue.Text = aircraft.FuelCapacity; labelMaxCruiseAltitudeValue.Text = aircraft.MaxCruiseAltitude; labelMaxLandingWeightValue.Text = aircraft.MaxLandingWeight.ToString(); labelMaxPayloadValue.Text = aircraft.MaxPayloadWeight.ToString(); labelMaxTakeOffCrossWeightValue.Text = aircraft.MaxTakeOffCrossWeight.ToString(); labelMaxZeroFuelWeightValue.Text = aircraft.MaxZeroFuelWeight.ToString(); labelMaxTaxiWeightValue.Text = aircraft.MaxTaxiWeight.ToString(); labelOpertionalEmptyWeightValue.Text = aircraft.OperationalEmptyWeight.ToString(); labelCockpitSeatingValue.Text = aircraft.CockpitSeating; labelGalleysValue.Text = aircraft.Galleys; labelLavatoryValue.Text = aircraft.Lavatory; labelSeatingEconomyValue.Text = aircraft.SeatingEconomy.ToString(); labelSeatingBusinessValue.Text = aircraft.SeatingBusiness.ToString(); labelSeatingFirstValue.Text = aircraft.SeatingFirst.ToString(); labelOvenValue.Text = aircraft.Oven; labelBoilerValue.Text = aircraft.Boiler; labelAirStairDoorsValue.Text = aircraft.AirStairsDoors; var aircraftEquipment = _currentAircraft.AircraftEquipments.Where(a => a.AircraftEquipmetType == AircraftEquipmetType.Equipmet); var aircraftApproval = _currentAircraft.AircraftEquipments.Where(a => a.AircraftEquipmetType == AircraftEquipmetType.TapeOfOperationApproval); var row = 4; foreach (var equipmentse in aircraftApproval) { var labelTitle = new Label { Text = equipmentse.AircraftOtherParameter + " :", Font = new Font("Verdana", 14, GraphicsUnit.Pixel), ForeColor = Color.FromArgb(122, 122, 122), Width = 150 }; var labelValue = new Label { Text = equipmentse.Description, Font = new Font("Verdana", 14, GraphicsUnit.Pixel), ForeColor = Color.FromArgb(122, 122, 122), Width = 150 }; row++; tableLayoutPanelMain.Controls.Add(labelTitle, 2, row); tableLayoutPanelMain.Controls.Add(labelValue, 3, row); } row = 4; foreach (var equipmentse in aircraftEquipment) { var labelTitle = new Label { Text = equipmentse.AircraftOtherParameter + " :", Font = new Font("Verdana", 14, GraphicsUnit.Pixel), ForeColor = Color.FromArgb(122, 122, 122), Width = 150 }; var labelValue = new Label { Text = equipmentse.Description, Font = new Font("Verdana", 14, GraphicsUnit.Pixel), ForeColor = Color.FromArgb(122, 122, 122), Width = 150 }; row++; tableLayoutPanelMain.Controls.Add(labelTitle, 6, row); tableLayoutPanelMain.Controls.Add(labelValue, 7, row); } //List<Document> operatorDocs = // GlobalObjects.CasEnvironment.Loader.GetDocuments(aircraft.Operator, DocumentType.Certificate, true); //DocumentSubType aocType = (DocumentSubType) // GlobalObjects.CasEnvironment.Dictionaries[typeof(DocumentSubType)].ToArray().FirstOrDefault(d => d.FullName == "AOC"); //Document awDoc = aocType != null ? operatorDocs.FirstOrDefault(d => d.DocumentSubType == aocType) : null; //string aocUpTo = awDoc != null && awDoc.ValidTo // ? awDoc.DateValidTo.ToString(new GlobalTermsProvider()["DateFormat"].ToString()) // : ""; var aircraftDocs = GlobalObjects.DocumentCore.GetAircraftDocuments(aircraft); var awType = (DocumentSubType) GlobalObjects.CasEnvironment.GetDictionary <DocumentSubType>().ToArray().FirstOrDefault(d => d.FullName == "AW"); var awDoc = awType != null?aircraftDocs.FirstOrDefault(d => d.DocumentSubType.ItemId == awType.ItemId) : null; string awUpTo = awDoc != null && awDoc.IssueValidTo ? awDoc.IssueDateValidTo.ToString(new GlobalTermsProvider()["DateFormat"].ToString()) : ""; labelAWCValue.Text = awUpTo; tableLayoutPanelLastChecks.RowCount = 1; tableLayoutPanelLastChecks.RowStyles.Clear(); tableLayoutPanelLastChecks.RowStyles.Add(new RowStyle()); tableLayoutPanelLastChecks.Controls.Clear(); tableLayoutPanelLastChecks.Controls.Add(labelLastCheck, 0, 0); tableLayoutPanelLastChecks.Controls.Add(labelLastDate, 1, 0); tableLayoutPanelLastChecks.Controls.Add(labelLastTsnCsn, 2, 0); tableLayoutPanelNextChecks.RowCount = 1; tableLayoutPanelNextChecks.RowStyles.Clear(); tableLayoutPanelNextChecks.RowStyles.Add(new RowStyle()); tableLayoutPanelNextChecks.Controls.Clear(); tableLayoutPanelNextChecks.Controls.Add(labelNextCheck, 0, 0); tableLayoutPanelNextChecks.Controls.Add(labelNextDate, 1, 0); tableLayoutPanelNextChecks.Controls.Add(labelNextTsnCan, 2, 0); tableLayoutPanelNextChecks.Controls.Add(labelRemains, 3, 0); tableLayoutPanelDocs.RowCount = 1; tableLayoutPanelDocs.RowStyles.Clear(); tableLayoutPanelDocs.RowStyles.Add(new RowStyle()); tableLayoutPanelDocs.Controls.Clear(); tableLayoutPanelDocs.Controls.Add(labelDocDescription, 0, 0); tableLayoutPanelDocs.Controls.Add(labelDocNumber, 1, 0); tableLayoutPanelDocs.Controls.Add(labelDocIssue, 2, 0); tableLayoutPanelDocs.Controls.Add(labelDocValidTo, 3, 0); tableLayoutPanelDocs.Controls.Add(labelDocRemain, 4, 0); if (_checkItems.Count == 0) { return; } if (!BackGroundWorker.IsBusy) { BackGroundWorker.RunWorkerAsync(); } List <MaintenanceCheck> orderedBySchedule = checkItems.OrderBy(c => c.Schedule) .ThenByDescending(c => c.Grouping) .OrderBy(c => c.Resource) .ToList(); List <MaintenanceCheckGroupByType> checkGroups = new List <MaintenanceCheckGroupByType>(); foreach (MaintenanceCheck check in orderedBySchedule) { MaintenanceCheckGroupByType group = checkGroups .FirstOrDefault(g => g.Schedule == check.Schedule && g.Grouping == check.Grouping && g.Resource == check.Resource); if (group != null) { group.Checks.Add(check); } else { group = new MaintenanceCheckGroupByType(check.Schedule) { Grouping = check.Grouping, Resource = check.Resource }; group.Checks.Add(check); checkGroups.Add(group); } } }