/// <summary> /// 配置 SQLite3 数据库引擎. /// </summary> /// <param name="connectionString">连接字符串.</param> public void UseSQLite3(string connectionString) { DbAccess dba = new Wunion.DataAdapter.Kernel.SQLite3.SqliteDbAccess(); dba.ConnectionString = connectionString; ParserAdapter adapter = new Wunion.DataAdapter.Kernel.SQLite3.CommandParser.SqliteParserAdapter(); SQLite3 = new DataEngine(dba, adapter); }
private void InitializeDataEngine() { if (string.IsNullOrEmpty(txt_connection.Text)) { MessageBox.Show(Language.GetString("NullDbConnection"), Language.GetString("MsgBoxErrorTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { DbAccess DBA; ParserAdapter parserAdapter; switch (cmb_databaseType.SelectedItem as string) { case "Microsoft SQL Server": DBA = new SqlServerDbAccess(); DBA.ConnectionString = txt_connection.Text.Trim(); parserAdapter = new SqlServerParserAdapter(); codeService = new GeneratorService(DBA, parserAdapter); codeService.DbContext = new SqlServerDbContext(codeService.DbEngine); break; case "SQLite3": DBA = new Wunion.DataAdapter.Kernel.SQLite3.SqliteDbAccess(); DBA.ConnectionString = txt_connection.Text.Trim(); parserAdapter = new Wunion.DataAdapter.Kernel.SQLite3.CommandParser.SqliteParserAdapter(); codeService = new GeneratorService(DBA, parserAdapter); codeService.DbContext = new SQLite3DbContext(codeService.DbEngine); break; case "PostgreSQL": DBA = new Wunion.DataAdapter.Kernel.PostgreSQL.NpgsqlDbAccess(); DBA.ConnectionString = txt_connection.Text.Trim(); parserAdapter = new Wunion.DataAdapter.Kernel.PostgreSQL.CommandParser.NpgsqlParserAdapter(); codeService = new GeneratorService(DBA, parserAdapter); codeService.DbContext = new PostgreSQLDbContext(codeService.DbEngine); break; case "MySQL": DBA = new Wunion.DataAdapter.Kernel.MySQL.MySqlDBAccess(); DBA.ConnectionString = txt_connection.Text.Trim(); parserAdapter = new Wunion.DataAdapter.Kernel.MySQL.CommandParser.MySqlParserAdapter(); codeService = new GeneratorService(DBA, parserAdapter); codeService.DbContext = new MySQLDbContext(codeService.DbEngine); break; } codeService.Language = Language; dataGridView1.DataSource = new List <TableInfoModel>(); dataGridView1.DataSource = codeService.AllTables.Distinct(p => p.tableName).ToList(); } catch (Exception Ex) { MessageBox.Show(Ex.Message, Language.GetString("MsgBoxErrorTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 执行 Connect 命令. /// </summary> /// <param name="parameters">命令的参数列表.</param> /// <param name="lang">命令输出的语言环境服务.</param> /// <returns></returns> public static GeneratorService Do(List <string> parameters, LanguageService lang) { if (parameters == null || parameters.Count < 2) { WriteInstructions(); return(null); } string connectionString = ParametersPathGetter.MergeOne(parameters, 1); GeneratorService service = null; DbAccess DBA; switch (parameters[0].ToLower()) { case "ms-sql": DBA = new Wunion.DataAdapter.Kernel.SQLServer.SqlServerDbAccess(); DBA.ConnectionString = connectionString; service = new GeneratorService(DBA, new Wunion.DataAdapter.Kernel.SQLServer.CommandParser.SqlServerParserAdapter()); service.DbContext = new SqlServerDbContext(service.DbEngine); break; case "sqlite": DBA = new Wunion.DataAdapter.Kernel.SQLite3.SqliteDbAccess(); DBA.ConnectionString = connectionString; service = new GeneratorService(DBA, new Wunion.DataAdapter.Kernel.SQLite3.CommandParser.SqliteParserAdapter()); service.DbContext = new SQLite3DbContext(service.DbEngine); break; case "postgresql": DBA = new Wunion.DataAdapter.Kernel.PostgreSQL.NpgsqlDbAccess(); DBA.ConnectionString = connectionString; service = new GeneratorService(DBA, new Wunion.DataAdapter.Kernel.PostgreSQL.CommandParser.NpgsqlParserAdapter()); service.DbContext = new PostgreSQLDbContext(service.DbEngine); break; case "mysql": DBA = new Wunion.DataAdapter.Kernel.MySQL.MySqlDBAccess(); DBA.ConnectionString = connectionString; service = new GeneratorService(DBA, new Wunion.DataAdapter.Kernel.MySQL.CommandParser.MySqlParserAdapter()); service.DbContext = new MySQLDbContext(service.DbEngine); break; } if (service != null) { try { List <TableInfoModel> lst = service.AllTables.Distinct(p => p.tableName).ToList(); Console.WriteLine(lang.GetString("DatabaseConnected")); } catch (Exception Ex) { Console.WriteLine(Ex.Message); } } return(service); }