Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SectionResultRows/TechnicalInnovationSectionResultRow.cs =================================================================== diff -u -r341edbfd5905c218dcbaacdc77b68ca67e5424cf -ra3d3c8428638ea47a37811456d34bb4c59949664 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SectionResultRows/TechnicalInnovationSectionResultRow.cs (.../TechnicalInnovationSectionResultRow.cs) (revision 341edbfd5905c218dcbaacdc77b68ca67e5424cf) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SectionResultRows/TechnicalInnovationSectionResultRow.cs (.../TechnicalInnovationSectionResultRow.cs) (revision a3d3c8428638ea47a37811456d34bb4c59949664) @@ -20,8 +20,14 @@ // All rights reserved. using System; +using Core.Common.Controls.DataGrid; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.Forms; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; +using Ringtoets.Integration.Data.StandAlone.AssemblyFactories; using Ringtoets.Integration.Data.StandAlone.SectionResults; namespace Ringtoets.Integration.Forms.Views.SectionResultRows @@ -31,17 +37,53 @@ /// public class TechnicalInnovationSectionResultRow : FailureMechanismSectionResultRow { + private readonly int simpleAssessmentResultIndex; + private readonly int tailorMadeAssessmentResultIndex; + private readonly int simpleAssemblyCategoryGroupIndex; + private readonly int tailorMadeAssemblyCategoryGroupIndex; + private readonly int combinedAssemblyCategoryGroupIndex; + private readonly int manualAssemblyCategoryGroupIndex; + + private FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; + /// /// Creates a new instance of . /// /// The to wrap /// so that it can be displayed as a row. - /// Thrown when is null. - public TechnicalInnovationSectionResultRow(TechnicalInnovationFailureMechanismSectionResult sectionResult) : base(sectionResult) {} + /// The property values required to create an instance of + /// . + /// Thrown when any parameter is null. + /// Thrown when + /// is a valid value, but unsupported. + public TechnicalInnovationSectionResultRow(TechnicalInnovationFailureMechanismSectionResult sectionResult, + ConstructionProperties constructionProperties) + : base(sectionResult) + { + if (constructionProperties == null) + { + throw new ArgumentNullException(nameof(constructionProperties)); + } + simpleAssessmentResultIndex = constructionProperties.SimpleAssessmentResultIndex; + tailorMadeAssessmentResultIndex = constructionProperties.TailorMadeAssessmentResultIndex; + simpleAssemblyCategoryGroupIndex = constructionProperties.SimpleAssemblyCategoryGroupIndex; + tailorMadeAssemblyCategoryGroupIndex = constructionProperties.TailorMadeAssemblyCategoryGroupIndex; + combinedAssemblyCategoryGroupIndex = constructionProperties.CombinedAssemblyCategoryGroupIndex; + manualAssemblyCategoryGroupIndex = constructionProperties.ManualAssemblyCategoryGroupIndex; + + CreateColumnStateDefinitions(); + + Update(); + } + /// /// Gets or sets the value representing the simple assessment result. /// + /// Thrown when + /// is a valid value, but unsupported. public SimpleAssessmentResultType SimpleAssessmentResult { get @@ -51,10 +93,245 @@ set { SectionResult.SimpleAssessmentResult = value; - SectionResult.NotifyObservers(); + UpdateInternalData(); } } - public override void Update() {} + /// + /// Gets or sets the value representing the tailor made assessment result. + /// + /// Thrown when + /// is a valid value, but unsupported. + public TailorMadeAssessmentResultType TailorMadeAssessmentResult + { + get + { + return SectionResult.TailorMadeAssessmentResult; + } + set + { + SectionResult.TailorMadeAssessmentResult = value; + UpdateInternalData(); + } + } + + /// + /// Gets the simple assembly category group. + /// + public string SimpleAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(simpleAssemblyCategoryGroup); + } + } + + /// + /// Gets the tailor made assembly category group. + /// + public string TailorMadeAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(tailorMadeAssemblyCategoryGroup); + } + } + + /// + /// Gets the combined assembly category group. + /// + public string CombinedAssemblyCategoryGroup + { + get + { + return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(combinedAssemblyCategoryGroup); + } + } + + /// + /// Gets or sets the indicator whether the combined assembly should be overwritten by . + /// + /// Thrown when + /// is a valid value, but unsupported. + public bool UseManualAssemblyCategoryGroup + { + get + { + return SectionResult.UseManualAssemblyCategoryGroup; + } + set + { + SectionResult.UseManualAssemblyCategoryGroup = value; + UpdateInternalData(); + } + } + + /// + /// Gets or sets the manually selected assembly category group. + /// + /// Thrown when + /// is a valid value, but unsupported. + public SelectableFailureMechanismSectionAssemblyCategoryGroup ManualAssemblyCategoryGroup + { + get + { + return SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertTo(SectionResult.ManualAssemblyCategoryGroup); + } + set + { + SectionResult.ManualAssemblyCategoryGroup = SelectableFailureMechanismSectionAssemblyCategoryGroupConverter.ConvertFrom(value); + UpdateInternalData(); + } + } + + /// + /// Thrown when + /// is a valid value, but unsupported. + public override void Update() + { + UpdateDerivedData(); + UpdateColumnStateDefinitionStates(); + } + + private void CreateColumnStateDefinitions() + { + ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(tailorMadeAssessmentResultIndex, new DataGridViewColumnStateDefinition()); + ColumnStateDefinitions.Add(simpleAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(tailorMadeAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(combinedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition + { + ReadOnly = true + }); + ColumnStateDefinitions.Add(manualAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition()); + } + + private void UpdateDerivedData() + { + ResetErrorTexts(); + TryGetSimpleAssemblyCategoryGroup(); + TryGetTailorMadeAssemblyCategoryGroup(); + TryGetCombinedAssemblyCategoryGroup(); + } + + private void ResetErrorTexts() + { + ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = string.Empty; + ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = string.Empty; + ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = string.Empty; + } + + private void TryGetSimpleAssemblyCategoryGroup() + { + try + { + simpleAssemblyCategoryGroup = TechnicalInnovationFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult); + } + catch (AssemblyException e) + { + simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetTailorMadeAssemblyCategoryGroup() + { + try + { + tailorMadeAssemblyCategoryGroup = TechnicalInnovationFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssessment(SectionResult); + } + catch (AssemblyException e) + { + tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetCombinedAssemblyCategoryGroup() + { + try + { + combinedAssemblyCategoryGroup = TechnicalInnovationFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssessment(SectionResult); + } + catch (AssemblyException e) + { + combinedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + /// + /// Updates the column state definitions. + /// + /// Thrown when + /// is a valid value, but unsupported. + private void UpdateColumnStateDefinitionStates() + { + bool simpleAssessmentSufficient = FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult); + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[simpleAssessmentResultIndex], UseManualAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentResultIndex], + simpleAssessmentSufficient || UseManualAssemblyCategoryGroup); + + if (UseManualAssemblyCategoryGroup) + { + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex]); + } + else + { + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex], + simpleAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex], + tailorMadeAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex], + combinedAssemblyCategoryGroup); + } + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[manualAssemblyCategoryGroupIndex], !UseManualAssemblyCategoryGroup); + } + + /// + /// Class holding the various construction parameters for . + /// + public class ConstructionProperties + { + /// + /// Sets the simple assessment result index. + /// + public int SimpleAssessmentResultIndex { internal get; set; } + + /// + /// Sets the tailor made assessment result index. + /// + public int TailorMadeAssessmentResultIndex { internal get; set; } + + /// + /// Sets the simple assembly category group index. + /// + public int SimpleAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the tailor made assembly category group index. + /// + public int TailorMadeAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the combined assembly category group index. + /// + public int CombinedAssemblyCategoryGroupIndex { internal get; set; } + + /// + /// Sets the manual assembly category group index. + /// + public int ManualAssemblyCategoryGroupIndex { internal get; set; } + } } } \ No newline at end of file