Ejemplo n.º 1
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);
            }
        }
        /// <summary>
        /// 配置 MySQL 数据库引擎.
        /// </summary>
        /// <param name="connectionString">连接字符串.</param>
        /// <param name="connectionPool">连接池数量(0 表示禁用).</param>
        public void UseMySql(string connectionString, int connectionPool = 0)
        {
            DbAccess dba = new Wunion.DataAdapter.Kernel.MySQL.MySqlDBAccess();

            dba.ConnectionString = connectionString;
            ParserAdapter adapter = new Wunion.DataAdapter.Kernel.MySQL.CommandParser.MySqlParserAdapter();

            MySql = new DataEngine(dba, adapter);
            SetConnectionPool(MySql, connectionString, connectionPool);
        }