Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs
===================================================================
diff -u -r3a6559edf6580a3c02e963c5ea2ee12f4bfec247 -r71df8711592b93a889d1064548a2a0071b7eef19
--- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision 3a6559edf6580a3c02e963c5ea2ee12f4bfec247)
+++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision 71df8711592b93a889d1064548a2a0071b7eef19)
@@ -161,10 +161,11 @@
///
/// The of the column.
/// The of the column.
+ /// Indicates whether the column is read-only or not.
/// The of the column.
/// is also used to create the .
/// The format is "column_.
- public void AddCheckBoxColumn(string dataPropertyName, string headerText, DataGridViewAutoSizeColumnMode autoSizeMode = DataGridViewAutoSizeColumnMode.AllCells)
+ public void AddCheckBoxColumn(string dataPropertyName, string headerText, bool readOnly = false, DataGridViewAutoSizeColumnMode autoSizeMode = DataGridViewAutoSizeColumnMode.AllCells)
{
dataGridView.Columns.Add(new DataGridViewCheckBoxColumn
{
@@ -173,6 +174,7 @@
Name = string.Format(CultureInfo.InvariantCulture,
"column_{0}",
dataPropertyName),
+ ReadOnly = readOnly,
AutoSizeMode = autoSizeMode
});
}
Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs
===================================================================
diff -u -r3a6559edf6580a3c02e963c5ea2ee12f4bfec247 -r71df8711592b93a889d1064548a2a0071b7eef19
--- Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision 3a6559edf6580a3c02e963c5ea2ee12f4bfec247)
+++ Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision 71df8711592b93a889d1064548a2a0071b7eef19)
@@ -251,7 +251,7 @@
DataGridViewTextBoxColumn columnData = (DataGridViewTextBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
Assert.AreEqual(readOnly, columnData.ReadOnly);
Assert.AreEqual(DataGridViewAutoSizeColumnMode.AllCells, columnData.AutoSizeMode);
@@ -291,7 +291,7 @@
DataGridViewTextBoxColumn columnData = (DataGridViewTextBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
Assert.AreEqual(readOnly, columnData.ReadOnly);
Assert.AreEqual(autoSizeMode, columnData.AutoSizeMode);
@@ -326,14 +326,51 @@
DataGridViewCheckBoxColumn columnData = (DataGridViewCheckBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
+ Assert.IsFalse(columnData.ReadOnly);
Assert.AreEqual(DataGridViewAutoSizeColumnMode.AllCells, columnData.AutoSizeMode);
Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, columnData.HeaderCell.Style.Alignment);
}
}
[Test]
+ public void AddCheckboxColumn_ReadOnlySet_AddsColumnToDataGridViewWithReadOnlyTrue()
+ {
+ // Setup
+ using (var form = new Form())
+ using (var control = new DataGridViewControl())
+ {
+ var propertyName = "PropertyName";
+ var headerText = "HeaderText";
+
+ form.Controls.Add(control);
+ form.Show();
+
+ var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
+
+ var autoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
+
+ // Precondition
+ Assert.AreEqual(0, dataGridView.ColumnCount);
+
+ // Call
+ control.AddCheckBoxColumn(propertyName, headerText, true, autoSizeMode);
+
+ // Assert
+ Assert.AreEqual(1, dataGridView.ColumnCount);
+
+ DataGridViewCheckBoxColumn columnData = (DataGridViewCheckBoxColumn) dataGridView.Columns[0];
+ Assert.AreEqual(propertyName, columnData.DataPropertyName);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
+ Assert.AreEqual(headerText, columnData.HeaderText);
+ Assert.IsTrue(columnData.ReadOnly);
+ Assert.AreEqual(autoSizeMode, columnData.AutoSizeMode);
+ Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, columnData.HeaderCell.Style.Alignment);
+ }
+ }
+
+ [Test]
public void AddCheckboxColumn_AutoSizeModeSet_AddsColumnToDataGridViewWithAutoSizeMode()
{
// Setup
@@ -354,15 +391,16 @@
Assert.AreEqual(0, dataGridView.ColumnCount);
// Call
- control.AddCheckBoxColumn(propertyName, headerText, autoSizeMode);
+ control.AddCheckBoxColumn(propertyName, headerText, false, autoSizeMode);
// Assert
Assert.AreEqual(1, dataGridView.ColumnCount);
DataGridViewCheckBoxColumn columnData = (DataGridViewCheckBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
+ Assert.IsFalse(columnData.ReadOnly);
Assert.AreEqual(autoSizeMode, columnData.AutoSizeMode);
Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, columnData.HeaderCell.Style.Alignment);
}
@@ -396,7 +434,7 @@
DataGridViewComboBoxColumn columnData = (DataGridViewComboBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
Assert.IsNull(columnData.DataSource);
Assert.AreEqual(string.Empty, columnData.ValueMember);
@@ -432,7 +470,7 @@
DataGridViewComboBoxColumn columnData = (DataGridViewComboBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
Assert.IsNull(columnData.DataSource);
Assert.AreEqual(string.Empty, columnData.ValueMember);
@@ -479,7 +517,7 @@
DataGridViewComboBoxColumn columnData = (DataGridViewComboBoxColumn) dataGridView.Columns[0];
Assert.AreEqual(propertyName, columnData.DataPropertyName);
- Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name);
+ Assert.AreEqual($"column_{propertyName}", columnData.Name);
Assert.AreEqual(headerText, columnData.HeaderText);
Assert.AreSame(dataSource, columnData.DataSource);
Assert.AreEqual("Value", columnData.ValueMember);
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj
===================================================================
diff -u -rdc682a1792664507e869ee5ecda02a9cff5426ea -r71df8711592b93a889d1064548a2a0071b7eef19
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision dc682a1792664507e869ee5ecda02a9cff5426ea)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 71df8711592b93a889d1064548a2a0071b7eef19)
@@ -123,6 +123,9 @@
PipingFailureMechanismView.cs
+
+ UserControl
+
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingSoilLayerTable.cs
===================================================================
diff -u
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingSoilLayerTable.cs (revision 0)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingSoilLayerTable.cs (revision 71df8711592b93a889d1064548a2a0071b7eef19)
@@ -0,0 +1,61 @@
+// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic;
+using Core.Common.Controls.DataGrid;
+using Ringtoets.Piping.Primitives;
+
+namespace Ringtoets.Piping.Forms.Views
+{
+ public class PipingSoilLayerTable : DataGridViewControl
+ {
+ public PipingSoilLayerTable()
+ {
+ AddColumns();
+ }
+
+ public void SetData(IEnumerable layers)
+ {
+ if (layers == null)
+ {
+ throw new ArgumentNullException(nameof(layers));
+ }
+
+ SetDataSource(layers);
+ }
+
+ private void AddColumns()
+ {
+ AddTextBoxColumn(nameof(PipingSoilLayer.MaterialName), "Naam", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.Color), "Kleur", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.Top), "Topniveau [m+NAP]", true);
+ AddCheckBoxColumn(nameof(PipingSoilLayer.IsAquifer), "Is aquifer", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.PermeabilityMean), "Doorlatendheid (verwachtingswaarde) [m/s]", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.PermeabilityDeviation), "Doorlatendheid (standaardafwijking) [m/s]", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.DiameterD70Mean), "d70 (verwachtingswaarde) [m]", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.DiameterD70Deviation), "d70 (standaardafwijking) [m]", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.BelowPhreaticLevelMean), "Verzadigd gewicht (verwachtingswaarde) [kn/m³]", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.BelowPhreaticLevelDeviation), "Verzadigd gewicht (standaardafwijking) [kn/m³]", true);
+ AddTextBoxColumn(nameof(PipingSoilLayer.BelowPhreaticLevelShift), "Verzadigd gewicht (verschuiving) [kn/m³]", true);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj
===================================================================
diff -u -rdc682a1792664507e869ee5ecda02a9cff5426ea -r71df8711592b93a889d1064548a2a0071b7eef19
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision dc682a1792664507e869ee5ecda02a9cff5426ea)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 71df8711592b93a889d1064548a2a0071b7eef19)
@@ -102,6 +102,7 @@
+
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingSoilLayerTableTest.cs
===================================================================
diff -u
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingSoilLayerTableTest.cs (revision 0)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingSoilLayerTableTest.cs (revision 71df8711592b93a889d1064548a2a0071b7eef19)
@@ -0,0 +1,196 @@
+// Copyright (C) Stichting Deltares 2016. 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.Drawing;
+using System.Windows.Forms;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Piping.Forms.Views;
+using Ringtoets.Piping.Primitives;
+
+namespace Ringtoets.Piping.Forms.Test.Views
+{
+ [TestFixture]
+ public class PipingSoilLayerTableTest
+ {
+ private const int nameColumnIndex = 0;
+ private const int colorColumnIndex = 1;
+ private const int topColumnIndex = 2;
+ private const int isAquiferColumnIndex = 3;
+ private const int permeabilityMeanColumnIndex = 4;
+ private const int permeabilityDeviationColumnIndex = 5;
+ private const int d70MeanColumnIndex = 6;
+ private const int d70DeviationColumnIndex = 7;
+ private const int belowPhreaticLevelWeightMeanColumnIndex = 8;
+ private const int belowPhreaticLevelWeightDeviationColumnIndex = 9;
+ private const int belowPhreaticLevelWeightShiftColumnIndex = 10;
+
+ [Test]
+ public void Constructor_InitializesWithColumns()
+ {
+ // Call
+ var table = new PipingSoilLayerTable();
+
+ // Assert
+ var nameColumn = table.GetColumnFromIndex(nameColumnIndex);
+ Assert.AreEqual("Naam", nameColumn.HeaderText);
+ var colorColumn = table.GetColumnFromIndex(colorColumnIndex);
+ Assert.AreEqual("Kleur", colorColumn.HeaderText);
+ var topColumn = table.GetColumnFromIndex(topColumnIndex);
+ Assert.AreEqual("Topniveau [m+NAP]", topColumn.HeaderText);
+ var isAquiferColumn = table.GetColumnFromIndex(isAquiferColumnIndex);
+ Assert.AreEqual("Is aquifer", isAquiferColumn.HeaderText);
+ var permeabilityMeanColumn = table.GetColumnFromIndex(permeabilityMeanColumnIndex);
+ Assert.AreEqual("Doorlatendheid (verwachtingswaarde) [m/s]", permeabilityMeanColumn.HeaderText);
+ var permeabilityDeviationColumn = table.GetColumnFromIndex(permeabilityDeviationColumnIndex);
+ Assert.AreEqual("Doorlatendheid (standaardafwijking) [m/s]", permeabilityDeviationColumn.HeaderText);
+ var d70MeanColumn = table.GetColumnFromIndex(d70MeanColumnIndex);
+ Assert.AreEqual("d70 (verwachtingswaarde) [m]", d70MeanColumn.HeaderText);
+ var d70DeviationColumn = table.GetColumnFromIndex(d70DeviationColumnIndex);
+ Assert.AreEqual("d70 (standaardafwijking) [m]", d70DeviationColumn.HeaderText);
+ var belowPhreaticLevelWeightMeanColumn = table.GetColumnFromIndex(belowPhreaticLevelWeightMeanColumnIndex);
+ Assert.AreEqual("Verzadigd gewicht (verwachtingswaarde) [kn/m³]", belowPhreaticLevelWeightMeanColumn.HeaderText);
+ var belowPhreaticLevelWeightDeviationColumn = table.GetColumnFromIndex(belowPhreaticLevelWeightDeviationColumnIndex);
+ Assert.AreEqual("Verzadigd gewicht (standaardafwijking) [kn/m³]", belowPhreaticLevelWeightDeviationColumn.HeaderText);
+ var belowPhreaticLevelWeightShiftColumn = table.GetColumnFromIndex(belowPhreaticLevelWeightShiftColumnIndex);
+ Assert.AreEqual("Verzadigd gewicht (verschuiving) [kn/m³]", belowPhreaticLevelWeightShiftColumn.HeaderText);
+
+ Assert.Throws(() => table.GetColumnFromIndex(belowPhreaticLevelWeightShiftColumnIndex+1));
+
+ Assert.IsEmpty(table.Rows);
+ }
+
+ [Test]
+ public void SetData_WithNullData_ThrowsArgumentNullException()
+ {
+ // Setup
+ var table = new PipingSoilLayerTable();
+
+ // Call
+ TestDelegate test = () => table.SetData(null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("layers", paramName);
+ }
+
+ [Test]
+ public void SetData_NoDataSet_SetNewData()
+ {
+ // Setup
+ var table = new PipingSoilLayerTable();
+ var layers = new[]
+ {
+ new PipingSoilLayer(2.5),
+ new PipingSoilLayer(2.3),
+ new PipingSoilLayer(1.1)
+ };
+
+ // Call
+ table.SetData(layers);
+
+ // Assert
+ Assert.AreEqual(3, table.Rows.Count);
+ }
+
+ [Test]
+ public void SetData_WithDataSet_ClearDataAndAddNewData()
+ {
+ // Setup
+ var table = new PipingSoilLayerTable();
+ var layers = new[]
+ {
+ new PipingSoilLayer(2.5),
+ new PipingSoilLayer(2.3),
+ new PipingSoilLayer(1.1)
+ };
+ table.SetData(new[]
+ {
+ new PipingSoilLayer(1.0)
+ });
+
+ // Call
+ table.SetData(layers);
+
+ // Assert
+ Assert.AreEqual(3, table.Rows.Count);
+ }
+
+ [Test]
+ public void SetData_WithData_ExpectedValuesInTable()
+ {
+ // Setup
+ var table = new PipingSoilLayerTable();
+ var layers = new[]
+ {
+ CreatePipingSoilLayer(),
+ CreatePipingSoilLayer(),
+ CreatePipingSoilLayer()
+ };
+ table.SetData(new[]
+ {
+ new PipingSoilLayer(1.0)
+ });
+
+ // Call
+ table.SetData(layers);
+
+ // Assert
+ Assert.AreEqual(3, table.Rows.Count);
+ for (int i = 0; i < table.Rows.Count; i++)
+ {
+ DataGridViewRow tableRow = table.Rows[i];
+ Assert.NotNull(tableRow);
+ Assert.AreEqual(layers[i].MaterialName, tableRow.Cells[nameColumnIndex].Value);
+ Assert.AreEqual(layers[i].Color, tableRow.Cells[colorColumnIndex].Value);
+ Assert.AreEqual(layers[i].Top, tableRow.Cells[topColumnIndex].Value);
+ Assert.AreEqual(layers[i].IsAquifer, tableRow.Cells[isAquiferColumnIndex].Value);
+ Assert.AreEqual(layers[i].PermeabilityMean, tableRow.Cells[permeabilityMeanColumnIndex].Value);
+ Assert.AreEqual(layers[i].PermeabilityDeviation, tableRow.Cells[permeabilityDeviationColumnIndex].Value);
+ Assert.AreEqual(layers[i].DiameterD70Mean, tableRow.Cells[d70MeanColumnIndex].Value);
+ Assert.AreEqual(layers[i].DiameterD70Deviation, tableRow.Cells[d70DeviationColumnIndex].Value);
+ Assert.AreEqual(layers[i].BelowPhreaticLevelMean, tableRow.Cells[belowPhreaticLevelWeightMeanColumnIndex].Value);
+ Assert.AreEqual(layers[i].BelowPhreaticLevelDeviation, tableRow.Cells[belowPhreaticLevelWeightDeviationColumnIndex].Value);
+ Assert.AreEqual(layers[i].BelowPhreaticLevelShift, tableRow.Cells[belowPhreaticLevelWeightShiftColumnIndex].Value);
+ }
+ }
+
+ private PipingSoilLayer CreatePipingSoilLayer()
+ {
+ var random = new Random();
+
+ return new PipingSoilLayer(random.NextDouble())
+ {
+ MaterialName = $"{random.NextDouble()}",
+ Color = Color.FromKnownColor(random.NextEnumValue()),
+ IsAquifer = random.NextBoolean(),
+ PermeabilityMean = random.NextRoundedDouble(),
+ PermeabilityDeviation = random.NextRoundedDouble(),
+ DiameterD70Mean = random.NextRoundedDouble(),
+ DiameterD70Deviation = random.NextRoundedDouble(),
+ BelowPhreaticLevelMean = random.NextRoundedDouble(),
+ BelowPhreaticLevelDeviation = random.NextRoundedDouble(),
+ BelowPhreaticLevelShift = random.NextRoundedDouble(),
+ };
+ }
+ }
+}
\ No newline at end of file