Example #1
0
        private void SQLTestButton_Click(object sender, System.EventArgs e)
        {
            // Test the connection string
            // Attempt to open a connection to make sure we will work?
            BuildConnectionString();


//			SqlConnection myConnection = new SqlConnection(mConnectString);
//			try
//			{
//				myConnection.Open();
//			}
//			catch(Exception ex)

            if (!MOG_ControllerSystem.InitializeDatabase(mConnectString, "", ""))
            {
                //MOG_Report.ReportMessage("SQL Database", "Could not open SQL database!", MOGPromptButtons.OK);
                Utils.ShowMessageBoxExclamation("Couldn't connect to SQL database " + this.SQLDatabaseComboBox.Text + " on server " + SQLServerComboBox.Text, "Connection Failure");
                return;
            }

            //MOG_Report.ReportMessage("SQL Database", "Successfully connected to SQL database " + SQLServerComboBox.Text + "!",MOGPromptButtons.OK);
            Utils.ShowMessageBoxInfo("Successfully connected to SQL database " + this.SQLDatabaseComboBox.Text + " on server " + SQLServerComboBox.Text, "Connection Successful");

            // notify others that we clicked the Test button
            OnTestButtonClicked();
        }
Example #2
0
        private void SQLOkButton_Click(object sender, System.EventArgs e)
        {
            // Test the connection string
            // Attempt to open a connection to make sure we will work?
            BuildConnectionStringNoCatalog();
            string databaseName = this.SQLDatabaseComboBox.Text;

            // Is this a 'Create new' database
            if (this.SQLCreateDatabaseRadioButton.Checked)
            {
                try
                {
                    if (MOG.DATABASE.MOG_DBAPI.DatabaseExists(mConnectString, this.SQLDatabaseTextBox.Text) == false)
                    {
                        if (MOG_Prompt.PromptResponse("Create new Database?", "We will need to create this database to test this connection.\n\n\tDATABASE NAME: " + this.SQLDatabaseTextBox.Text + "\n\nIs it ok to proceed?", MOGPromptButtons.OKCancel) == MOGPromptResult.OK)
                        {
                            if (MOG.DATABASE.MOG_DBAPI.CreateDatabase(mConnectString, this.SQLDatabaseTextBox.Text))
                            {
                                databaseName = SQLDatabaseTextBox.Text;
                            }
                            else
                            {
                                if (MOG_Prompt.PromptResponse("Create Database", "Unable to create database! \n\nDo you want to continue and save these new settings?", MOGPromptButtons.YesNo) == MOGPromptResult.No)
                                {
                                    return;
                                }
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MOG_Prompt.PromptMessage("Create Database", "Unable to check or create database with the following message:\n\n" + ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.ERROR);
                    return;
                }
            }

            BuildConnectionString();

            if (!MOG_ControllerSystem.InitializeDatabase(mConnectString, "", ""))
            {
                MOG_Prompt.PromptResponse("Connection Failure", "Couldn't connect to SQL database " + databaseName + " on server " + SQLServerComboBox.Text);
                return;
            }

            // notify others that we clicked the OK button
            OnOKClicked();
        }
Example #3
0
        static public bool MOGGlobalSQLLogin()
        {
            // Attempt to get our SQL connection string
            string mConnectionString = "";

            MOG_Ini config = new MOG_Ini(MOG_Main.GetExecutablePath() + "\\MOG.ini");

            SQLConnectForm sql = new SQLConnectForm();

            if (sql.ShowDialog() == DialogResult.OK)
            {
                mConnectionString = sql.mConnectString;
                config.PutString("SQL", "ConnectionString", mConnectionString);
                config.Save();
                config = null;

                return(MOG_ControllerSystem.InitializeDatabase(mConnectionString, "", ""));
            }

            return(false);
        }
Example #4
0
        private void SQLTestButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                string OriginalConnectionString = MOG_ControllerSystem.GetDB() != null?MOG_ControllerSystem.GetDB().GetConnectionString() : "";

                // Test the connection string
                // Attempt to open a connection to make sure we will work?
                BuildConnectionStringNoCatalog();
                string databaseName = GetDatabaseName();


                // Is this a 'Create new' database
                if (this.SQLCreateDatabaseRadioButton.Checked)
                {
                    try
                    {
                        // Test to see if we can get to the server
                        if (MOG.DATABASE.MOG_DBAPI.TestServerConnection(mConnectString))
                        {
                            if (MOG.DATABASE.MOG_DBAPI.TestDatabaseConnection(mConnectString, this.SQLDatabaseTextBox.Text) == false)
                            {
                                if (MOG_Prompt.PromptResponse("Create new Database?", "We will need to create this database to test this connection.\n\n\tDATABASE NAME: " + this.SQLDatabaseTextBox.Text + "\n\nIs it ok to proceed?", MOGPromptButtons.OKCancel) == MOGPromptResult.OK)
                                {
                                    if (MOG.DATABASE.MOG_DBAPI.CreateDatabase(mConnectString, this.SQLDatabaseTextBox.Text))
                                    {
                                        databaseName = SQLDatabaseTextBox.Text;
                                    }
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MOG_Prompt.PromptMessage("Create Database", "Unable to access server: " + this.ServerName);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        MOG_Prompt.PromptMessage("Create Database", "Unable to check or create database with the following message:\n\n" + ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.ERROR);
                        return;
                    }
                }


                // Build the full connection string
                BuildConnectionString();

                try
                {
                    if (!MOG_ControllerSystem.InitializeDatabase(mConnectString, "", ""))
                    {
                        MOG_Prompt.PromptResponse("Connection Failure", "Couldn't connect to SQL database " + databaseName + " on server " + SQLServerComboBox.Text);
                        throw new Exception();
                    }
                    else
                    {
                        MOG_Prompt.PromptResponse("Connection Successful", "Successfully connected to SQL database " + databaseName + " on server " + SQLServerComboBox.Text);
                    }
                }
                catch
                {
                }
                finally
                {
                    if (OriginalConnectionString.Length > 0)
                    {
                        // Restore the original DBbase
                        mConnectString = OriginalConnectionString;
                        if (!MOG_ControllerSystem.InitializeDatabase(mConnectString, "", ""))
                        {
                            MOG_Prompt.PromptResponse("Connection Failure", "Couldn't restore to original SQL database (" + mConnectString + ")");
                        }
                    }
                }
            }
            catch (Exception outer)
            {
                MOG_Prompt.PromptMessage("Error", outer.Message, outer.StackTrace, MOG_ALERT_LEVEL.ERROR);
                return;
            }

            // notify others that we clicked the Test button
            OnTestButtonClicked();
        }
Example #5
0
        static public void MOGGlobalLaunchProjectLogin(string projectName, bool forceLogin)
        {
            // Launch the login dialog
            LoginForm login = new LoginForm(projectName);

            mainForm.Enabled = false;

Login:
            // Show the dialog
            if (login.ShowDialog(mainForm) == DialogResult.OK)
            {
                try
                {
                    // Login to the specified Project
                    if (guiProject.SetLoginProject(login.LoginProjectsComboBox.Text, login.LoginBranchesComboBox.Text))
                    {
                        // Set the login user
                        guiUser guiUsers = new guiUser(mainForm);
                        if ((string.Compare(login.LoginUsersComboBox.Text, "Choose Valid User", true) == 0) || (login.LoginUsersComboBox.Text.Length == 0))
                        {
                            MessageBox.Show("A valid user must be selected!", "Missing User");
                            goto Login;
                        }

                        if (guiUsers.SetLoginUser(login.LoginUsersComboBox.Text))
                        {
                            mainForm.Enabled = true;

                            // Disable the Change SQL Server menu item if the logged in user is not an administrator
                            MOGGlobalSetSQLConnectionMenuItemEnabled(login.LoginUsersComboBox.Text);
                            // Disable the Configure Project menu item if the logged in user is not an administrator
                            MOGGlobalSetToolsConfigureProjectMenuItemEnabled(login.LoginUsersComboBox.Text);
                            // Disable the Set MOG Repository menu item if the logged in user is not an administrator
                            MOGGlobalSetFileMOGRepositoryMenuItemEnabled(login.LoginUsersComboBox.Text);
                        }
                        else
                        {
                            MessageBox.Show("A valid user must be selected!", "Login Error");
                            goto Login;
                        }
                    }
                    else
                    {
                        MessageBox.Show("A valid project and branch must be selected!", "Login Error");
                        goto Login;
                    }
                }
                catch (Exception e)
                {
                    MOG_Report.ReportMessage("Login Project", e.Message, e.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.ERROR);
                    goto Login;
                }
            }
            else if (login.DialogResult == DialogResult.Cancel && forceLogin)
            {
                if (MessageBox.Show(mainForm, "Do you wish to exit MOG?", "Exit?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    mainForm.Close();
                    mainForm.Shutdown();
                }
                else
                {
                    goto Login;
                }
            }
            else
            {
                if (!MOG_ControllerProject.IsProject() || !MOG_ControllerProject.IsUser())
                {
                    MessageBox.Show("A valid project and user must be selected!", "Missing Project or User");
                    goto Login;
                }

                mainForm.Enabled = true;
            }

            // Always initialize our Database before leaving because the dialog loads projects that will leave us in a dirty state
            MOG_ControllerSystem.InitializeDatabase("", MOG_ControllerProject.GetProjectName(), MOG_ControllerProject.GetBranchName());
        }