private void RollBack() { try { string sysScriptPath1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Scripts\\Sys_BGT_DB\\1BGT_Sys_DB_Script_DELETE.sql"; DBHandler dbMan = new DBHandler(Config.GetSysDBConnectionString()); string sysDBQuery = File.ReadAllText(sysScriptPath1); sysDBQuery = sysDBQuery.Replace("AOXX", ProjectDBName.ToUpper()); sysDBQuery = sysDBQuery.Replace("SuperUserIDXX", TeamleadUserID); sysDBQuery = sysDBQuery.Replace("GuestUserIDXX", GuestUserID); dbMan.ExecuteNonQuery(sysDBQuery); //delete the project db if (!_dbInstall.DeleteDB(Config.GetSuperConnectionString(), ProjectDBName.ToUpper())) { //ErrorMsg = string.Format("Can not delete database: {0}. Please delete the database manually and run installer again.", ProjectDBName); } } catch (Exception ex) { LogWrite(ex.Message.ToString()); } }
private void btnInstall_Click(object sender, EventArgs e) { if (ValidateInfo()) { pbDBInstall.Select(); btnInstall.Visible = false; btnBack.Visible = false; lblWaitingtxt.Visible = true; pbDBInstall.Visible = true; Application.DoEvents(); Thread.Sleep(1000); if (CreateNg) { pbDBInstall.Maximum = 11; } try { string superDBConnectionString = Config.GetSuperConnectionString(); string sysDBConnectionString = Config.GetSysDBConnectionString(); string projectDBConnectionString = Config.GetProjectDBConnectionString(ProjectDBName); string changeOwnerConnectionString = Config.GetChangeOwnerConnectionString(ProjectDBName); //create role DataTable dtRole = _dbInstall.CheckRoleExist(superDBConnectionString, ProjectDBName.ToUpper()); if (dtRole.Rows.Count <= 0) { _dbInstall.CreateRole(superDBConnectionString, ProjectDBName.ToUpper()); } ProgressBarUpdate(); LogWrite("User Role Installed."); //create database bool createDb = true; DataTable dtDB = _dbInstall.CheckDatabaseExist(superDBConnectionString, ProjectDBName.ToUpper()); if (dtDB.Rows.Count > 0) { if (Config.Host == "37.34.53.43") { MessageBox.Show("Database already exist"); pbDBInstall.Value = 0; pbDBInstall.Visible = false; lblWaitingtxt.Visible = false; btnInstall.Visible = true; btnBack.Visible = true; return; } if (MessageBox.Show("Database already exist. Sure to replace it?", "Replace", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { if (!_dbInstall.DeleteDB(Config.GetSuperConnectionString(), ProjectDBName.ToUpper())) { success = false; ErrorMsg = string.Format("Can not delete database: {0}. Please delete the database manually and run installer again.", ProjectDBName); OpenSummaryWindow(); return; } } else { createDb = false; } } if (createDb) { _dbInstall.CreateDatabase(superDBConnectionString, ProjectDBName.ToUpper(), Config.TemplateDBName); } ProgressBarUpdate(); LogWrite("Database Created."); //chnage owner _dbInstall.ChangeOwner(changeOwnerConnectionString, ProjectDBName.ToUpper()); ProgressBarUpdate(); LogWrite("Owner is changed."); using (NpgsqlConnection pgConn = new NpgsqlConnection(sysDBConnectionString)) { pgConn.Open(); using (NpgsqlTransaction tran = pgConn.BeginTransaction()) { // Sys _dbInstall.Sys_Delete_Prev_Data(sysDBConnectionString, "Sys_BGT_DB\\1BGT_Sys_DB_Script_DELETE.sql", ProjectDBName, sysSuperUserId, TeamleadUserID, GuestUserID); ProgressBarUpdate(); LogWrite("Sys table is clean."); _dbInstall.Sys_Install_Role_Independent_Data(sysDBConnectionString, "Sys_BGT_DB\\2BGT_Sys_DB_Script_Role_Independend_Entry-Reports.sql", ProjectDBName, Config.Port); LogWrite("Sys Role independent entry-reports data installed."); ProgressBarUpdate(); _dbInstall.Sys_Install_Role_Independent_Data(sysDBConnectionString, "Sys_BGT_DB\\3BGT_Sys_DB_Script_Role_Independend-Report_Functions.sql", ProjectDBName, Config.Port); LogWrite("Role independent report functions installed."); ProgressBarUpdate(); _dbInstall.Sys_Install_Role_Independent_Data(sysDBConnectionString, "Sys_BGT_DB\\4BGT_Sys_DB_Script_Role_Independend-Metadata.sql", ProjectDBName, Config.Port); ProgressBarUpdate(); LogWrite("Role independent metadata installed."); _dbInstall.Sys_Install_SuperRole(sysDBConnectionString, "Sys_BGT_DB\\5BGT_Sys_DB_Script_SUPER.sql", ProjectDBName, sysSuperUserName, sysSuperUserId, sysSuperUserPassword); LogWrite("Super Role Installed."); _dbInstall.Sys_Install_TeamleadRole(sysDBConnectionString, "Sys_BGT_DB\\5BGT_Sys_DB_Script_Teamlead.sql", ProjectDBName, TeamleadUserName, TeamleadUserID, TeamleadUserPassword); LogWrite("Teamlead Role Installed."); _dbInstall.Sys_Install_GuestRole(sysDBConnectionString, "Sys_BGT_DB\\5BGT_Sys_DB_Script_Guest.sql", ProjectDBName, GuestUserName, GuestUserID, GuestUserPassword); LogWrite("Guest Role Installed."); //dsah-board entry _dbInstall.Sys_Install_Role_Independent_Data(sysDBConnectionString, "Sys_BGT_DB\\6BGT_Sys_DB_Script_Dashboard.sql", ProjectDBName, Config.Port); LogWrite("Dashboard installed."); ProgressBarUpdate(); tran.Commit(); pgConn.Clone(); } } // Project _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\1Tables.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date); _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\2Tables_Index.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date); _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\3Tables_Trigger.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date); _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\4Tables_values.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date, Bronhouder, ApplicationName, Administration, ReferencePrefix, IdentificationPrefix, MsgToelichting); _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\5Functions.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date); _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\6Views.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date); _dbInstall.Install_ProjectData(projectDBConnectionString, "AOXX_DB\\7GT_Views.sql", ProjectDBName, Organization, MethodIndex, MethodName, Precision, Date); ProgressBarUpdate(); LogWrite("Project data installed."); //run ned graphics db script if (CreateNg) { using (NpgsqlConnection pgConn = new NpgsqlConnection(sysDBConnectionString)) { pgConn.Open(); using (NpgsqlTransaction tran = pgConn.BeginTransaction()) { _dbInstall.Install_NedGraphics_Sys(sysDBConnectionString, "NG\\NedGraphics_ChaloIS_SYS_TABLES_SuperUser.sql", ProjectDBName, Config.Port); ProgressBarUpdate(); LogWrite("Ned Graphics Sys data installed."); _dbInstall.Install_NedGraphics_Projects(projectDBConnectionString, "NG\\NedGraphics_Script.sql", ProjectDBName); ProgressBarUpdate(); LogWrite("Ned Graphics Project data installed."); tran.Commit(); pgConn.Close(); } } } success = true; LogWrite("Installation is successful."); } catch (Exception ex) { LogWrite(ex.Message.ToString()); success = false; ErrorMsg = ex.Message; RollBack(); } OpenSummaryWindow(); pbDBInstall.Value = 0; } }