Changeset 11002 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs
- Timestamp:
- 06/11/14 15:43:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs
r10994 r11002 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Globalization; 26 using System.Linq; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core; … … 159 161 if (!IsInTransaction) 160 162 OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); 163 } 164 165 public override bool SetValue(string value, int columnIndex, int rowIndex) { 166 bool valid = false; 167 if (IsType<double>(columnIndex)) { 168 double val; 169 valid = double.TryParse(value, out val); 170 SetValueIfValid(columnIndex, rowIndex, valid, val); 171 } else if (IsType<string>(columnIndex)) { 172 valid = value != null; 173 SetValueIfValid(columnIndex, rowIndex, valid, value); 174 } else if (IsType<DateTime>(columnIndex)) { 175 DateTime date; 176 valid = DateTime.TryParse(value, out date); 177 SetValueIfValid(columnIndex, rowIndex, valid, date); 178 } else { 179 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 180 } 181 182 if (!IsInTransaction) 183 OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); 184 185 return valid; 186 } 187 188 public override bool Validate(string value, out string errorMessage, int columnIndex){ 189 if (columnIndex < 0 || columnIndex > VariableNames.Count()) { 190 throw new ArgumentOutOfRangeException("column index is out of range"); 191 } 192 193 bool valid = false; 194 errorMessage = string.Empty; 195 if (IsType<double>(columnIndex)) { 196 double val; 197 valid = double.TryParse(value, out val); 198 if (!valid) { 199 errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")"; 200 } 201 } else if (IsType<string>(columnIndex)) { 202 valid = value != null; 203 if (!valid) { 204 errorMessage = "Invalid Value (string must not be null)"; 205 } 206 } else if (IsType<DateTime>(columnIndex)) { 207 DateTime date; 208 valid = DateTime.TryParse(value, out date); 209 if (!valid) { 210 errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\""; 211 } 212 } else { 213 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 214 } 215 216 return valid; 217 } 218 219 private void SetValueIfValid<T>(int columnIndex, int rowIndex, bool valid, T value) { 220 if (valid) 221 SetCell<T>(columnIndex, rowIndex, value); 222 } 223 224 public override bool AreAllStringColumns(IEnumerable<int> columnIndices) { 225 return columnIndices.All(x => IsType<string>(x)); 226 } 227 228 public override void DeleteRowsWithIndices(IEnumerable<int> rows) { 229 foreach (int rowIndex in rows) { 230 DeleteRow(rowIndex); 231 } 161 232 } 162 233
Note: See TracChangeset
for help on using the changeset viewer.