/// <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);
        }
示例#2
0
        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);
            }
        }