Ejemplo n.º 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string databaseType = comboDatabaseType.Text;
            DatabaseConfigFactory   configFactory   = new DatabaseConfigFactory();
            DatabaseConfig          config          = configFactory.Create(databaseType);
            SecurityDatabaseService databaseService = new SecurityDatabaseService();

            if (databaseType == "mssql")
            {
                MSSqlDatabaseConfig tempConfig = (MSSqlDatabaseConfig)config;
                tempConfig.DataSource     = txtMSSqlIP.Text.Trim();
                tempConfig.InitialCatelog = txtMSSqlDatabaseName.Text.Trim();
                tempConfig.UserID         = txtMSSqlUserID.Text.Trim();
                tempConfig.Password       = txtMSSqlPwd.Text.Trim();
                tempConfig.DatabasePath   = txtMSSqlDatabasePath.Text.Trim();
                try
                {
                    databaseService.CreateDatabase(tempConfig);
                }
                catch (Exception ex)
                {
                    customError.ShowError(ex.Message);
                }
            }
            else
            {
                SqliteDatabaseConfig tempConfig = (SqliteDatabaseConfig)config;
                tempConfig.DataSource = txtSqliteDatabaseName.Text.Trim();
                try
                {
                    databaseService.CreateDatabase(tempConfig);
                }
                catch (Exception ex)
                {
                    customError.ShowError(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
 public void CreateDataBase()
 {
     try
     {
         SecurityDatabaseService service     = new SecurityDatabaseService();
         MSSqlDatabaseConfig     mssqlConfig = new MSSqlDatabaseConfig();
         mssqlConfig.DataSource     = "172_17_0_13";
         mssqlConfig.InitialCatelog = "testSecurity";
         mssqlConfig.UserID         = "sa";
         mssqlConfig.Password       = "******";
         mssqlConfig.DatabasePath   = "C:\\renkf\\database";
         service.CreateDatabase(mssqlConfig);
         Assert.IsTrue(1 == 1, "MSSQL数据库创建成功");
         SqliteDatabaseConfig sqliteConfig = new SqliteDatabaseConfig();
         sqliteConfig.DataSource = "C:\\renkf\\database\\text.db";
         service.CreateDatabase(sqliteConfig);
         Assert.IsTrue(1 == 1, "Sqlite数据库创建成功");
     }
     catch (Exception ex)
     {
         Assert.IsTrue(1 == 0, ex.Message);
     }
 }