// 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.GrassCoverErosionOutwards.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.GrassCoverErosionOutwards.Forms.Views { /// /// The view for a collection of . /// public class GrassCoverErosionOutwardsFailureMechanismResultView : FailureMechanismResultView { /// /// /// Creates a new instance of . /// public GrassCoverErosionOutwardsFailureMechanismResultView( IObservableEnumerable failureMechanismSectionResults, GrassCoverErosionOutwardsFailureMechanism failureMechanism) : base(failureMechanismSectionResults, failureMechanism) {} protected override GrassCoverErosionOutwardsFailureMechanismSectionResultRow CreateFailureMechanismSectionResultRow(GrassCoverErosionOutwardsFailureMechanismSectionResult sectionResult) { return new GrassCoverErosionOutwardsFailureMechanismSectionResultRow(sectionResult); } protected override void Dispose(bool disposing) { DataGridViewControl.CellFormatting -= OnCellFormatting; base.Dispose(disposing); } protected override void AddDataGridColumns() { DataGridViewControl.AddTextBoxColumn( nameof(GrassCoverErosionOutwardsFailureMechanismSectionResultRow.Name), RingtoetsCommonFormsResources.Section_DisplayName, true); EnumDisplayWrapper[] simpleAssessmentDataSource = Enum.GetValues(typeof(SimpleAssessmentResultType)) .OfType() .Select(sa => new EnumDisplayWrapper(sa)) .ToArray(); DataGridViewControl.AddComboBoxColumn( nameof(GrassCoverErosionOutwardsFailureMechanismSectionResultRow.SimpleAssessmentResult), RingtoetsCommonFormsResources.FailureMechanismResultView_SimpleAssessmentResult_DisplayName, simpleAssessmentDataSource, nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); EnumDisplayWrapper[] twoAResultDataSource = Enum.GetValues(typeof(AssessmentLayerTwoAResult)) .OfType() .Select(el => new EnumDisplayWrapper(el)) .ToArray(); DataGridViewControl.AddComboBoxColumn( nameof(GrassCoverErosionOutwardsFailureMechanismSectionResultRow.AssessmentLayerTwoA), RingtoetsCommonFormsResources.FailureMechanismResultView_DetailedAssessmentResult_DisplayName, twoAResultDataSource, nameof(EnumDisplayWrapper.Value), nameof(EnumDisplayWrapper.DisplayName)); DataGridViewControl.AddTextBoxColumn( nameof(GrassCoverErosionOutwardsFailureMechanismSectionResultRow.AssessmentLayerThree), RingtoetsCommonFormsResources.FailureMechanismResultView_TailorMadeAssessmentResult_DisplayName); } protected override void BindEvents() { base.BindEvents(); DataGridViewControl.CellFormatting += OnCellFormatting; } private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex > SimpleAssessmentColumnIndex) { SimpleAssessmentResultType simpleAssessmentResult = GetDataAtRow(eventArgs.RowIndex).SimpleAssessmentResult; if (FailureMechanismResultViewHelper.SimpleAssessmentIsSufficient(simpleAssessmentResult)) { DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } } }