async Task GetFile(ImportedFileType typeFile) { MakeTextBoxResultShow(); txtbResultShow.ReadOnly = true; EnabledInterface(false); string filePath = null; using (OpenFileDialog ofd = new OpenFileDialog()) { if (typeFile == ImportedFileType.Text) { filePath = ofd.OpenFileDialogReturnPath(Properties.Resources.DialogTextFile, "Выберите для импорта текстовый файл с данными и резделителями:"); } else if (typeFile == ImportedFileType.Excel) { filePath = ofd.OpenFileDialogReturnPath(Properties.Resources.DialogExcelFile, "Выберите для импорта Excel файл с данными. Первая строчка должна содержать названия колонок:"); } } if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath)) { await ImportFileIntoLocalDB(filePath, typeFile); await Task.Run(() => ShowMessage("Готово!")); } else { AddLineAtTextBoxResultShow($"Файл '{filePath}' пустой или не выбран"); } HideTextBoxResultShow(); EnabledInterface(true); }
private ISQLConnectionSettings CheckSQLiteDB(ISQLConnectionSettings tmpSettings) { ISQLConnectionSettings newSettings = new SQLConnectionSettings(tmpSettings); using (OpenFileDialog ofd = new OpenFileDialog()) { newSettings.Database = ofd.OpenFileDialogReturnPath(); newSettings.Name = "currentDB"; if (!string.IsNullOrWhiteSpace(newSettings.Database)) { newSettings = CheckSchemaSQLite(newSettings); } else { DialogResult dialog = MessageBox.Show("Create new DB?", "DB is empty!", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { newSettings.Database = "MainDB.db"; SQLiteDBOperations connector = new SQLiteDBOperations(newSettings); connector.TryMakeLocalDB(); newSettings = CheckSchemaSQLite(newSettings); } } } return(newSettings); }
private ISQLConnectionSettings CheckSQLiteDB() { string db = null; using (OpenFileDialog ofd = new OpenFileDialog()) { db = ofd.OpenFileDialogReturnPath(Properties.Resources.DialogDbFile, "Выберите файл с БД SQLite:"); } ISQLConnectionSettings newSettings = new SQLConnectionSettings { Database = db, ProviderName = SQLProvider.SQLite }; if (!string.IsNullOrWhiteSpace(newSettings.Database) && File.Exists(newSettings.Database)) { DbSchema schemaDb = null; try { schemaDb = DbSchema.LoadDB(newSettings.Database); IList <string> tablesDb = schemaDb.Tables.Select(tbl => tbl.Value.TableName).ToList(); if (tablesDb?.Count > 0) { newSettings.Table = tablesDb[0]; cmbDataBases.DataSource = new List <string> { newSettings.Database }; cmbTables.DataSource = tablesDb; tbResultShow.AppendLine("The inputed data are correct."); } } catch (Exception e) { newSettings = null; tbResultShow.AppendLine($"Ошибка в БД: {e.Message}"); tbResultShow.AppendLine($"{e}"); } finally { if (schemaDb?.Tables?.Count == 0) { newSettings = null; tbResultShow.AppendLine("Подключенная база данных пустая или же в ней отсутствуют какие-либо таблицы с данными!"); tbResultShow.AppendLine("Предварительно создайте базу данных, таблицы и импортируйте/добавьте в них данные..."); tbResultShow.AppendLine("Заблокирован функционал по получению данных из таблиц..."); } } } return(newSettings); }