// 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 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
{
///
/// Class for displaying as a row in a grid view.
///
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.
/// The property values required to create an instance of
/// .
/// Thrown when any parameter is null.
/// Thrown when
/// is a valid value, but unsupported.
internal 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
{
return SectionResult.SimpleAssessmentResult;
}
set
{
SectionResult.SimpleAssessmentResult = value;
UpdateInternalData();
}
}
///
/// 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 FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayname(simpleAssemblyCategoryGroup);
}
}
///
/// Gets the tailor made assembly category group.
///
public string TailorMadeAssemblyCategoryGroup
{
get
{
return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayname(tailorMadeAssemblyCategoryGroup);
}
}
///
/// Gets the combined assembly category group.
///
public string CombinedAssemblyCategoryGroup
{
get
{
return FailureMechanismSectionAssemblyCategoryGroupHelper.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();
}
}
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 = TechnicalInnovationFailureMechanismAssemblyFactory.AssembleSimpleAssessment(SectionResult);
}
catch (AssemblyException e)
{
simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None;
ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.Message;
}
}
private void TryGetTailorMadeAssemblyCategoryGroup()
{
try
{
tailorMadeAssemblyCategoryGroup = TechnicalInnovationFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(SectionResult);
}
catch (AssemblyException e)
{
tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None;
ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.Message;
}
}
private void TryGetCombinedAssemblyCategoryGroup()
{
try
{
combinedAssemblyCategoryGroup = TechnicalInnovationFailureMechanismAssemblyFactory.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; }
}
}
}