- Timestamp:
- 03/05/15 14:37:02 (10 years ago)
- Location:
- branches/HeuristicLab.DatasetRefactor/sources
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r12031 r12141 177 177 <Compile Include="Interfaces\IDataPreprocessorStarter.cs" /> 178 178 <Compile Include="MenuItems\ShrinkDataAnalysisRunsMenuItem.cs" /> 179 <Compile Include="ModifiableDatasetView.cs"> 180 <SubType>UserControl</SubType> 181 </Compile> 182 <Compile Include="ModifiableDatasetView.Designer.cs"> 183 <DependentUpon>ModifiableDatasetView.cs</DependentUpon> 184 </Compile> 179 185 <Compile Include="Plugin.cs" /> 180 186 <Compile Include="ProblemDataView.cs"> -
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r12031 r12141 222 222 return variableValues[variableNames[columnIndex]][rowIndex].ToString(); 223 223 } 224 public boolSetValue(string value, int rowIndex, int columnIndex) {224 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 225 225 throw new NotSupportedException(); 226 226 } 227 public boolValidate(string value, out string errorMessage) {227 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 228 228 throw new NotSupportedException(); 229 229 } -
branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r12032 r12141 28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Data; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 … … 33 34 [Item("ModifiableDataset", "Represents a dataset containing data that should be analyzed, which can be modified by adding or replacing variables and values.")] 34 35 [StorableClass] 35 public class ModifiableDataset : Dataset {36 public class ModifiableDataset : Dataset, IStringConvertibleMatrix { 36 37 [StorableConstructor] 37 38 private ModifiableDataset(bool deserializing) : base(deserializing) { } … … 99 100 } 100 101 101 public void ChangeVariableValue(object value, string variableName, int row) {102 public void SetVariableValue(object value, string variableName, int row) { 102 103 IList list; 103 104 variableValues.TryGetValue(variableName, out list); … … 106 107 if (row < 0 || list.Count < row) 107 108 throw new ArgumentOutOfRangeException("Invalid row value"); 109 if (GetVariableType(variableName) != value.GetType()) 110 throw new ArgumentException("The type of the provided value does not match the variable type."); 111 108 112 list[row] = value; 109 113 } … … 116 120 return list[0].GetType(); 117 121 } 122 123 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 124 var variableName = variableNames[columnIndex]; 125 // if value represents a double 126 double dv; 127 if (double.TryParse(value, out dv)) { 128 SetVariableValue(dv, variableName, rowIndex); 129 return true; 130 } 131 // if value represents a DateTime object 132 DateTime dt; 133 if (DateTime.TryParse(value, out dt)) { 134 SetVariableValue(dt, variableName, rowIndex); 135 return true; 136 } 137 // if value is simply a string 138 SetVariableValue(value, variableName, rowIndex); 139 return true; 140 } 141 142 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 143 return ValidateValue(value, out errorMessage); 144 } 145 146 private static bool ValidateValue(string value, out string errorMessage) { 147 double dv; 148 if (double.TryParse(value, out dv)) { 149 errorMessage = string.Empty; 150 return true; 151 } 152 DateTime dt; 153 if (DateTime.TryParse(value, out dt)) { 154 errorMessage = string.Empty; 155 return true; 156 } 157 errorMessage = "Value could not be validated. Please ensure that the value is either a string, a double, or a DateTime value."; 158 return false; 159 } 118 160 } 119 161 }
Note: See TracChangeset
for help on using the changeset viewer.