// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Util; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.WaveImpactAsphaltCover.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.WaveImpactAsphaltCover.Forms.Views { /// /// The view for a collection of . /// public class WaveImpactAsphaltCoverFailureMechanismResultView : FailureMechanismResultView { /// /// Creates a new instance of . /// /// public WaveImpactAsphaltCoverFailureMechanismResultView( IObservableEnumerable failureMechanismSectionResults, WaveImpactAsphaltCoverFailureMechanism failureMechanism) : base(failureMechanismSectionResults, failureMechanism) { DataGridViewControl.CellFormatting += OnCellFormatting; UpdateDataGridViewDataSource(); } protected override object CreateFailureMechanismSectionResultRow(WaveImpactAsphaltCoverFailureMechanismSectionResult sectionResult) { return new WaveImpactAsphaltCoverFailureMechanismSectionResultRow(sectionResult); } protected override void Dispose(bool disposing) { DataGridViewControl.CellFormatting -= OnCellFormatting; base.Dispose(disposing); } protected override void AddDataGridColumns() { base.AddDataGridColumns(); EnumDisplayWrapper[] simpleAssessmentDataSource = Enum.GetValues(typeof(SimpleAssessmentResultType)) .OfType() .Select(sa => new EnumDisplayWrapper(sa)) .ToArray(); DataGridViewControl.AddComboBoxColumn( nameof(WaveImpactAsphaltCoverFailureMechanismSectionResultRow.SimpleAssessmentResult), RingtoetsCommonFormsResources.FailureMechanismResultView_SimpleAssessmentResult_ColumnHeader, simpleAssessmentDataSource, nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); EnumDisplayWrapper[] twoAResultDataSource = Enum.GetValues(typeof(AssessmentLayerTwoAResult)) .OfType() .Select(el => new EnumDisplayWrapper(el)) .ToArray(); DataGridViewControl.AddComboBoxColumn( nameof(WaveImpactAsphaltCoverFailureMechanismSectionResultRow.AssessmentLayerTwoA), RingtoetsCommonFormsResources.FailureMechanismResultView_DetailedAssessment_ColumnHeader, twoAResultDataSource, nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); DataGridViewControl.AddTextBoxColumn( nameof(WaveImpactAsphaltCoverFailureMechanismSectionResultRow.AssessmentLayerThree), RingtoetsCommonFormsResources.FailureMechanismResultView_TailorMadeAssessment_ColumnHeader); } private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex > SimpleAssessmentColumnIndex) { var simpleAssessmentResult = (SimpleAssessmentResultType) DataGridViewControl.GetCell(eventArgs.RowIndex, SimpleAssessmentColumnIndex).Value; if (FailureMechanismResultViewHelper.HasPassedSimpleAssessment(simpleAssessmentResult)) { DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } } }