diff --git a/DataTableConverter/Assisstant/DatabaseHelper.cs b/DataTableConverter/Assisstant/DatabaseHelper.cs index 4d0bbb7..11a8444 100644 --- a/DataTableConverter/Assisstant/DatabaseHelper.cs +++ b/DataTableConverter/Assisstant/DatabaseHelper.cs @@ -1599,11 +1599,10 @@ internal Dictionary GroupCountOfColumn(string columnName, string t internal void SplitTableOnRowValue(Dictionary dict, string column, string tableName) { - SQLiteConnection connection = GetConnection(tableName); Dictionary aliasColumnMapping = GetAliasColumnMapping(tableName); string headerString = GetHeaderString(aliasColumnMapping.Keys); string valueString = GetValueString(aliasColumnMapping.Count); - using (SQLiteCommand command = connection.CreateCommand()) + using (SQLiteCommand command = GetConnection(tableName).CreateCommand()) { CreateIndexOn(tableName, column, null, false); command.CommandText = $"SELECT {headerString} from [{tableName}] where [{column}] = ? COLLATE CASESENSITIVE"; diff --git a/DataTableConverter/Assisstant/ErrorHelper.cs b/DataTableConverter/Assisstant/ErrorHelper.cs index 621f53f..f48b5fd 100644 --- a/DataTableConverter/Assisstant/ErrorHelper.cs +++ b/DataTableConverter/Assisstant/ErrorHelper.cs @@ -16,6 +16,11 @@ internal static void LogMessage(Exception exception, Form mainForm, bool showMes { ShowError($"Die Datei {path.FileName} kann nicht gefunden werden", mainForm); } + else if(exception is FileLoadException ex) + { + ShowError($"Die Datei {ex.FileName} kann nicht geladen werden\nWird sie von einem anderen Prozess verwendet?", mainForm); + LogMessage(exception.ToString(), mainForm, false); + } else { LogMessage(exception.ToString(), mainForm, showMessage); @@ -26,7 +31,7 @@ internal static void LogMessage(string text, Form mainForm, bool showMessage = t { try { - File.AppendAllText(path, $"{Environment.NewLine}{DateTime.Today}; Version:{FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion} {Environment.NewLine}{text}{Environment.NewLine}"); + File.AppendAllText(path, $"{Environment.NewLine}{DateTime.Now}; Version:{FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion} {Environment.NewLine}{text}{Environment.NewLine}"); if (showMessage) { ShowError(ErrorMessage, mainForm); diff --git a/DataTableConverter/Assisstant/ImportHelper.cs b/DataTableConverter/Assisstant/ImportHelper.cs index d82e006..7948114 100644 --- a/DataTableConverter/Assisstant/ImportHelper.cs +++ b/DataTableConverter/Assisstant/ImportHelper.cs @@ -661,7 +661,7 @@ private string GetFormattedValue(object value, string formatString, int formatIn internal void OpenExcel(string path, ProgressBar progressBar, Form mainForm, string tableName, ref string password) { - using (var stream = File.Open(path, FileMode.Open, FileAccess.Read)) + using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { // Auto-detect format, supports: // - Binary Excel files (2.0-2003 format; *.xls) diff --git a/DataTableConverter/Properties/AssemblyInfo.cs b/DataTableConverter/Properties/AssemblyInfo.cs index 2c55761..0d87500 100644 --- a/DataTableConverter/Properties/AssemblyInfo.cs +++ b/DataTableConverter/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.16.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.17.0")] \ No newline at end of file diff --git a/DataTableConverter/View/Form1.cs b/DataTableConverter/View/Form1.cs index 35d4ca5..8dd55ab 100644 --- a/DataTableConverter/View/Form1.cs +++ b/DataTableConverter/View/Form1.cs @@ -661,34 +661,42 @@ private void LoadData(bool readjustColumnWidth = true, bool preventLoading = fal void load() { - if (readjustColumnWidth) - { - ColumnWidths.Clear(); - } - else + try { - SaveWidthOfDataGridViewColumns(); - } - MaxPages = Math.Ceiling(DatabaseHelper.GetRowCount(TableName) / Properties.Settings.Default.MaxRows); - SetPage(); - CheckAllowToAddRows(); + if (readjustColumnWidth) + { + ColumnWidths.Clear(); + } + else + { + SaveWidthOfDataGridViewColumns(); + } + MaxPages = Math.Ceiling(DatabaseHelper.GetRowCount(TableName) / Properties.Settings.Default.MaxRows); + SetPage(); + CheckAllowToAddRows(); + + int scrollBarHorizontal = dgTable.HorizontalScrollingOffset; + if (!preventLoading) + { + DataTable table = DatabaseHelper.GetData(SortingOrder, OrderType, (int)((Page - 1) * Properties.Settings.Default.MaxRows), TableName); + + dgTable.RowsAdded -= dgTable_RowsAdded; + dgTable.DataSource = null; //else readded columns are at the wrong index + dgTable.DataSource = table; + dgTable.Columns[0].Visible = false; + dgTable.RowsAdded += dgTable_RowsAdded; + SetRowCount(DatabaseHelper.GetRowCount(TableName)); + } + RestoreDataGridSortMode(); + SetWidth(); - int scrollBarHorizontal = dgTable.HorizontalScrollingOffset; - if (!preventLoading) + dgTable.HorizontalScrollingOffset = scrollBarHorizontal; + } + catch(OutOfMemoryException) { - DataTable table = DatabaseHelper.GetData(SortingOrder, OrderType, (int)((Page - 1) * Properties.Settings.Default.MaxRows), TableName); - - dgTable.RowsAdded -= dgTable_RowsAdded; - dgTable.DataSource = null; //else readded columns are at the wrong index - dgTable.DataSource = table; - dgTable.Columns[0].Visible = false; - dgTable.RowsAdded += dgTable_RowsAdded; - SetRowCount(DatabaseHelper.GetRowCount(TableName)); + ErrorHelper.LogMessage("Es können nicht so viele Zeilen gelesen werden. Bitte reduzieren sie die maximal geladenen Zeilen pro Seite in den Einstellungen", this); + GC.Collect(); } - RestoreDataGridSortMode(); - SetWidth(); - - dgTable.HorizontalScrollingOffset = scrollBarHorizontal; } }