Changeset 8877 for trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.cs
- Timestamp:
- 11/07/12 16:28:33 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views
-
Property
svn:mergeinfo
set to
/branches/DataAnalysisCSVImport/HeuristicLab.Problems.Instances.DataAnalysis.Views merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/DataAnalysisImportTypeDialog.cs
r8693 r8877 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.ComponentModel; 25 using System.Globalization; 26 using System.Linq; 22 27 using System.Windows.Forms; 28 using HeuristicLab.Core.Views; 29 using HeuristicLab.Problems.DataAnalysis; 23 30 24 31 namespace HeuristicLab.Problems.Instances.DataAnalysis.Views { 25 32 public partial class DataAnalysisImportTypeDialog : Form { 33 34 public static readonly BindingList<KeyValuePair<DateTimeFormatInfo, string>> dateTimeFormats = new BindingList<KeyValuePair<DateTimeFormatInfo, string>>{ 35 new KeyValuePair<DateTimeFormatInfo, string>(DateTimeFormatInfo.GetInstance(new CultureInfo("de-DE")), "dd/mm/yyyy hh:MM:ss" ), 36 new KeyValuePair<DateTimeFormatInfo, string>(DateTimeFormatInfo.InvariantInfo, "mm/dd/yyyy hh:MM:ss" ), 37 new KeyValuePair<DateTimeFormatInfo, string>(DateTimeFormatInfo.InvariantInfo, "yyyy/mm/dd hh:MM:ss" ), 38 new KeyValuePair<DateTimeFormatInfo, string>(DateTimeFormatInfo.InvariantInfo, "mm/yyyy/dd hh:MM:ss" ) 39 }; 40 41 public static readonly BindingList<KeyValuePair<char, string>> POSSIBLE_SEPARATORS = new BindingList<KeyValuePair<char, string>>{ 42 new KeyValuePair<char, string>(',', ", (Comma)" ), 43 new KeyValuePair<char, string>(';', "; (Semicolon)" ), 44 new KeyValuePair<char, string>('\t', "\\t (Tab)") 45 }; 46 47 public static readonly BindingList<KeyValuePair<NumberFormatInfo, string>> POSSIBLE_DECIMAL_SEPARATORS = new BindingList<KeyValuePair<NumberFormatInfo, string>>{ 48 new KeyValuePair<NumberFormatInfo, string>(NumberFormatInfo.InvariantInfo, ". (Period)" ), 49 new KeyValuePair<NumberFormatInfo, string>(NumberFormatInfo.GetInstance(new CultureInfo("de-DE")), ", (Comma)" ) 50 }; 26 51 27 52 public string Path { … … 38 63 } 39 64 65 public DataAnalysisCSVFormat CSVFormat { 66 get { 67 return new DataAnalysisCSVFormat() { 68 Separator = (char)SeparatorComboBox.SelectedValue, 69 NumberFormatInfo = (NumberFormatInfo)DecimalSeparatorComboBox.SelectedValue, 70 DateTimeFormatInfo = (DateTimeFormatInfo)DateTimeFormatComboBox.SelectedValue 71 }; 72 } 73 } 74 40 75 public DataAnalysisImportTypeDialog() { 41 76 InitializeComponent(); 77 ToolTip.SetToolTip(SeparatorInfoLabel, (string)SeparatorInfoLabel.Tag); 78 ToolTip.SetToolTip(DecimalSeparatorInfoLabel, (string)DecimalSeparatorInfoLabel.Tag); 79 ToolTip.SetToolTip(DateTimeFormatInfoLabel, (string)DateTimeFormatInfoLabel.Tag); 80 ToolTip.SetToolTip(ShuffelInfoLabel, (string)ShuffelInfoLabel.Tag); 81 82 SeparatorComboBox.DataSource = POSSIBLE_SEPARATORS; 83 SeparatorComboBox.ValueMember = "Key"; 84 SeparatorComboBox.DisplayMember = "Value"; 85 DecimalSeparatorComboBox.DataSource = POSSIBLE_DECIMAL_SEPARATORS; 86 DecimalSeparatorComboBox.ValueMember = "Key"; 87 DecimalSeparatorComboBox.DisplayMember = "Value"; 88 DateTimeFormatComboBox.DataSource = dateTimeFormats; 89 DateTimeFormatComboBox.ValueMember = "Key"; 90 DateTimeFormatComboBox.DisplayMember = "Value"; 42 91 } 43 92 … … 47 96 } 48 97 49 private void openFileButton_Click(object sender, System.EventArgs e) { 50 if (openFileDialog.ShowDialog(this) == DialogResult.OK) { 51 ProblemTextBox.Text = openFileDialog.FileName; 98 protected virtual void OpenFileButtonClick(object sender, System.EventArgs e) { 99 if (openFileDialog.ShowDialog(this) != DialogResult.OK) return; 100 101 ProblemTextBox.Text = openFileDialog.FileName; 102 ParseCSVFile(); 103 } 104 105 protected virtual void CSVFormatComboBoxSelectionChangeCommitted(object sender, EventArgs e) { 106 if (string.IsNullOrEmpty(ProblemTextBox.Text)) return; 107 108 ParseCSVFile(); 109 } 110 111 protected void ParseCSVFile() { 112 PreviewDatasetMatrix.Content = null; 113 try { 114 TableFileParser csvParser = new TableFileParser(); 115 csvParser.Parse(ProblemTextBox.Text, 116 (NumberFormatInfo)DecimalSeparatorComboBox.SelectedValue, 117 (DateTimeFormatInfo)DateTimeFormatComboBox.SelectedValue, 118 (char)SeparatorComboBox.SelectedValue); 119 IEnumerable<string> variableNamesWithType = GetVariableNamesWithType(csvParser); 120 PreviewDatasetMatrix.Content = new Dataset(variableNamesWithType, csvParser.Values); 121 122 CheckAdditionalConstraints(csvParser); 123 124 ErrorTextBox.Text = String.Empty; 125 ErrorTextBox.Visible = false; 52 126 OkButton.Enabled = true; 127 } 128 catch (Exception ex) { 129 OkButton.Enabled = false; 130 ErrorTextBox.Text = ex.Message; 131 ErrorTextBox.Visible = true; 132 } 133 } 134 135 protected virtual void CheckAdditionalConstraints(TableFileParser csvParser) { 136 if (!csvParser.Values.Any(x => x is List<double>)) { 137 throw new ArgumentException("No double column could be found!"); 138 } 139 } 140 141 private IEnumerable<string> GetVariableNamesWithType(TableFileParser csvParser) { 142 IList<string> variableNamesWithType = csvParser.VariableNames.ToList(); 143 for (int i = 0; i < csvParser.Values.Count; i++) { 144 if (csvParser.Values[i] is List<double>) { 145 variableNamesWithType[i] += " (Double)"; 146 } else if (csvParser.Values[i] is List<string>) { 147 variableNamesWithType[i] += " (String)"; 148 } else if (csvParser.Values[i] is List<DateTime>) { 149 variableNamesWithType[i] += " (DateTime)"; 150 } else { 151 throw new ArgumentException("The variable values must be of type List<double>, List<string> or List<DateTime>"); 152 } 153 } 154 return variableNamesWithType; 155 } 156 157 protected void ControlToolTip_DoubleClick(object sender, EventArgs e) { 158 Control control = sender as Control; 159 if (control != null) { 160 using (TextDialog dialog = new TextDialog(control.Name, (string)control.Tag, true)) { 161 dialog.ShowDialog(this); 162 } 53 163 } 54 164 }
Note: See TracChangeset
for help on using the changeset viewer.