private ListViewItem GetListViewItem(MaintenanceCheck check) { ListViewItem listViewItem = new ListViewItem { Tag = check, Text = check.Name }; if (check.Grouping) { MaintenanceNextPerformance np = check.NextPerformances.FirstOrDefault() as MaintenanceNextPerformance; MaintenanceProgramChangeRecord mpcr = np != null && np.PerformanceDate != null ? _currentAircraft.MaintenanceProgramChangeRecords. GetLastKnownRecord(Convert.ToDateTime(np.PerformanceDate)) : null; if (mpcr != null && mpcr.MSG >= MSG.MSG3) { string lastPerformanceDate = "N/A"; string lastPerformanceSource = "N/A"; string lastPerformaceGroup = "N/A"; string lastCheckName = "N/A"; string nextPerformanceDate = "N/A"; string nextPerformanceSource = "N/A"; string nextPerformaceGroup = "N/A"; string nextCheckName = "N/A"; string remains = "N/A"; MaintenanceNextPerformance mnp = check.GetNextPergormanceGroupWhereCheckIsSenior(); if (mnp != null) { nextPerformanceDate = UsefulMethods.NormalizeDate(Convert.ToDateTime(mnp.PerformanceDate)); nextPerformanceSource = mnp.PerformanceSource.ToString(); nextPerformaceGroup = mnp.PerformanceGroupNum + "/" + mnp.PerformanceNum; nextCheckName = mnp.PerformanceGroup.GetGroupName(); remains = mnp.Remains.ToString(); } if (check.LastPerformance != null) { MaintenanceCheckRecord mcr = _checkItems.GetLastCheckRecordWhereCheckIsSenior(check); if (mcr != null) { lastPerformanceDate = UsefulMethods.NormalizeDate(mcr.RecordDate); lastPerformanceSource = mcr.OnLifelength.ToString(); lastPerformaceGroup = mcr.NumGroup + "/" + mcr.PerformanceNum; lastCheckName = _currentAircraft != null && _currentAircraft.MaintenanceProgramCheckNaming ? (!string.IsNullOrEmpty(mcr.ComplianceCheckName) ? mcr.ComplianceCheckName : check.Name) : check.Name; } } listViewItem.SubItems.Add(lastPerformanceDate); listViewItem.SubItems.Add(lastPerformanceSource); listViewItem.SubItems.Add(lastPerformaceGroup); listViewItem.SubItems.Add(lastCheckName); listViewItem.SubItems.Add(nextPerformanceDate); listViewItem.SubItems.Add(nextPerformanceSource); listViewItem.SubItems.Add(nextPerformaceGroup); listViewItem.SubItems.Add(nextCheckName); listViewItem.SubItems.Add(remains); } else { if (check.LastPerformance == null) { listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add(np != null && np.PerformanceDate != null ? UsefulMethods.NormalizeDate((DateTime)np.PerformanceDate) : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceSource.ToString() : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceGroupNum + "/" + np.PerformanceNum : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceGroup.GetGroupName() : "N/A"); listViewItem.SubItems.Add(np != null ? np.Remains.ToString() : "N/A"); } else { string lastCheckName = _currentAircraft != null && _currentAircraft.MaintenanceProgramCheckNaming ? (!string.IsNullOrEmpty(check.LastPerformance.ComplianceCheckName) ? check.LastPerformance.ComplianceCheckName : check.Name) : check.Name; listViewItem.SubItems.Add(UsefulMethods.NormalizeDate(check.LastPerformance.RecordDate)); listViewItem.SubItems.Add(check.LastPerformance.OnLifelength.ToString()); listViewItem.SubItems.Add(check.LastPerformance.NumGroup + "/" + check.LastPerformance.PerformanceNum); listViewItem.SubItems.Add(lastCheckName); listViewItem.SubItems.Add(np != null && np.PerformanceDate != null ? UsefulMethods.NormalizeDate((DateTime)np.PerformanceDate) : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceSource.ToString() : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceGroupNum + "/" + np.PerformanceNum : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceGroup.GetGroupName() : "N/A"); listViewItem.SubItems.Add(np != null ? np.Remains.ToString() : "N/A"); } } if (np != null && np.Condition == ConditionState.Overdue) { listViewItem.BackColor = Color.FromArgb(255, 170, 170); } else if (np != null && np.Condition == ConditionState.Notify) { listViewItem.BackColor = Color.FromArgb(255, 255, 170); } else if (np == null || np.Condition == ConditionState.NotEstimated) { listViewItem.BackColor = Color.FromArgb(170, 170, 255); } } else { NextPerformance np = check.NextPerformances.FirstOrDefault(); if (check.LastPerformance == null) { listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add(np != null && np.PerformanceDate != null ? UsefulMethods.NormalizeDate((DateTime)np.PerformanceDate) : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceSource.ToString() : "N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add(np != null ? np.Remains.ToString() : "N/A"); } else { listViewItem.SubItems.Add(UsefulMethods.NormalizeDate(check.LastPerformance.RecordDate)); listViewItem.SubItems.Add(check.LastPerformance.OnLifelength.ToString()); listViewItem.SubItems.Add(check.LastPerformance.NumGroup.ToString()); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add(np != null && np.PerformanceDate != null ? UsefulMethods.NormalizeDate((DateTime)np.PerformanceDate) : "N/A"); listViewItem.SubItems.Add(np != null ? np.PerformanceSource.ToString() : "N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add("N/A"); listViewItem.SubItems.Add(np != null ? np.Remains.ToString() : "N/A"); } if (np != null && np.Condition == ConditionState.Overdue) { listViewItem.BackColor = Color.FromArgb(255, 170, 170); } else if (np != null && np.Condition == ConditionState.Notify) { listViewItem.BackColor = Color.FromArgb(255, 255, 170); } else if (np == null || np.Condition == ConditionState.NotEstimated) { listViewItem.BackColor = Color.FromArgb(170, 170, 255); } } listViewItem.Group = GetGroup(check); return(listViewItem); }