private void showPreview() { fError.Text = ""; fError.Visible = false; fNext.Enabled = true; fPartial.Visible = false; char recordSeparator, fieldSeparator, textDelimiter; if (fCommaSeparatedValues.Checked) { recordSeparator = '\n'; fieldSeparator = ','; textDelimiter = '"'; } else if (fSemicolonSeparatedValues.Checked) { recordSeparator = '\n'; fieldSeparator = ';'; textDelimiter = '"'; } else if (fTabSeparatedValues.Checked) { recordSeparator = '\n'; fieldSeparator = '\t'; textDelimiter = '\0'; } else { recordSeparator = GetCharacter(fCustomRecordSeparator); fieldSeparator = GetCharacter(fCustomFieldSeparator); textDelimiter = GetCharacter(fCustomTextDelimiter); } Encoding encoding; switch (fEncodingSelect.SelectedIndex) { case 1: encoding = Encoding.GetEncoding("windows-1250"); break; case 2: encoding = Encoding.GetEncoding("windows-1252"); break; default: encoding = Encoding.UTF8; break; } string inputData=encoding.GetString(fileContent); if (recordSeparator == '\n') { inputData = inputData.Replace("\r\n", "\n"); } CsvParserResult csvParserResult; this.checkColumnsWidth = false; try { CsvParser csvParser = new CsvParser(inputData, recordSeparator, fieldSeparator, textDelimiter, fHasHeader.Checked); csvParserResult = csvParser.GetData(10); fDataPreview.DataSource = (DataTable)csvParserResult; foreach (DataGridViewColumn column in fDataPreview.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; column.MinimumWidth = 30; } AutoSizeColums(); } catch (InvalidOperationException) { csvParserResult = null; fDataPreview.DataSource = null; fError.Text = Language.GetString("import.manyColumnsError") + "."; fError.Visible = true; fNext.Enabled = false; } catch (CsvParserException e) { csvParserResult = null; fDataPreview.DataSource = null; fError.Text = Language.GetString("import.parseError")+".\n" + Language.GetString("import.reason") +": "+e.Message + "."; fError.Visible = true; fNext.Enabled = false; } if (csvParserResult != null && csvParserResult.IsPartial()) { fPartial.Visible = true; } this.checkColumnsWidth = true; this.fDataPreview_ColumnWidthChanged(null, null); }
private void fNext_Click(object sender, EventArgs e) { char recordSeparator, fieldSeparator, textDelimiter; if (fCommaSeparatedValues.Checked) { recordSeparator = '\n'; fieldSeparator = ','; textDelimiter = '"'; } else if (fSemicolonSeparatedValues.Checked) { recordSeparator = '\n'; fieldSeparator = ';'; textDelimiter = '"'; } else if (fTabSeparatedValues.Checked) { recordSeparator = '\n'; fieldSeparator = '\t'; textDelimiter = '\0'; } else { recordSeparator = GetCharacter(fCustomRecordSeparator); fieldSeparator = GetCharacter(fCustomFieldSeparator); textDelimiter = GetCharacter(fCustomTextDelimiter); } Encoding encoding; switch (fEncodingSelect.SelectedIndex) { case 1: encoding = Encoding.GetEncoding("windows-1250"); break; case 2: encoding = Encoding.GetEncoding("windows-1252"); break; default: encoding = Encoding.UTF8; break; } string inputData = encoding.GetString(fileContent); if (recordSeparator == '\n') { inputData = inputData.Replace("\r\n", "\n"); } try { CsvParser csvParser = new CsvParser(inputData, recordSeparator, fieldSeparator, textDelimiter, fHasHeader.Checked); Data = csvParser.GetData(); } catch (GeneralException) { Data = null; } this.Close(); }