Ejemplo n.º 1
0
        private void SqlServerOKBtn_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = DBUtils.CreateSqlServerConnection(
                server: SqlServerHostTextBox.Text,
                username: SqlServerUsernameTextBox.Text,
                password: SqlServerPasswordTextBox.Password,
                noDB: true);

            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed with error: " + ex.Message);
                return;
            }

            if (WindowsAuthenticationRadioBtn.IsChecked != null)
            {
                Properties.Settings.Default.sqlServerUseWindowsAuthentication = WindowsAuthenticationRadioBtn.IsChecked.Value;
            }
            Properties.Settings.Default.sqlServerHost     = SqlServerHostTextBox.Text;
            Properties.Settings.Default.sqlServerUsername = SqlServerUsernameTextBox.Text;
            Properties.Settings.Default.sqlServerPassword = DBUtils.Protect(SqlServerPasswordTextBox.Password);
            Properties.Settings.Default.databaseType      = "SqlServer";

            Properties.Settings.Default.Save();

            Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Simply drops the database.
        /// </summary>
        private async void ClearDataBtn_Click(object sender, RoutedEventArgs e)
        {
            MessageDialogResult res = await this.ShowMessageAsync(
                "Are you sure?",
                "You are about to delete all the data, are you sure?",
                MessageDialogStyle.AffirmativeAndNegative);

            if (res == MessageDialogResult.Negative)
            {
                return;
            }

            MessageDialogResult res2 = await this.ShowMessageAsync(
                "Are you absolutely sure?",
                "Checking twice to be safe, are you sure you want to delete everything?",
                MessageDialogStyle.AffirmativeAndNegative);

            if (res2 == MessageDialogResult.Negative)
            {
                return;
            }

            try
            {
                if (Properties.Settings.Default.databaseType.ToLower() == "mysql")
                {
                    _context.Database.ExecuteSqlCommand("DROP DATABASE qpas");
                }
                else
                {
                    //very hacky....
                    using (var sqlConnection = DBUtils.CreateSqlServerConnection("master"))
                    {
                        sqlConnection.Open();
                        SqlCommand sqlCmd = new SqlCommand("ALTER DATABASE qpas SET SINGLE_USER WITH ROLLBACK IMMEDIATE", sqlConnection);
                        sqlCmd.ExecuteNonQuery();

                        sqlCmd.CommandText = "DROP DATABASE qpas";
                        sqlCmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                this.ShowMessageAsync(
                    "Error",
                    "Could not clear data. Error: " + ex.Message).Forget();
                var logger = LogManager.GetCurrentClassLogger();
                logger.Log(LogLevel.Error, ex);
                return;
            }


            await this.ShowMessageAsync(
                "Done",
                "Data deleted. The application will now shut down.");

            Application.Current.Shutdown();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Simply drops the database.
        /// </summary>
        private async void ClearDataBtn_Click(object sender, RoutedEventArgs e)
        {
            MessageDialogResult res = await this.ShowMessageAsync(
                "Are you sure?",
                "You are about to delete all the data, are you sure?",
                MessageDialogStyle.AffirmativeAndNegative);

            if (res == MessageDialogResult.Negative)
            {
                return;
            }

            MessageDialogResult res2 = await this.ShowMessageAsync(
                "Are you absolutely sure?",
                "Checking twice to be safe, are you sure you want to delete everything?",
                MessageDialogStyle.AffirmativeAndNegative);

            if (res2 == MessageDialogResult.Negative)
            {
                return;
            }

            if (Properties.Settings.Default.databaseType == "MySQL")
            {
                _context.Database.ExecuteSqlCommand("DROP DATABASE qpas");
            }
            else
            {
                //very hacky....
                using (var sqlConnection = DBUtils.CreateSqlServerConnection("master"))
                {
                    sqlConnection.Open();
                    SqlCommand sqlCmd = new SqlCommand("ALTER DATABASE qpas SET SINGLE_USER WITH ROLLBACK IMMEDIATE", sqlConnection);
                    sqlCmd.ExecuteNonQuery();

                    sqlCmd.CommandText = "DROP DATABASE qpas";
                    sqlCmd.ExecuteNonQuery();
                }
            }


            await this.ShowMessageAsync(
                "Done",
                "Data deleted. The application will now shut down.");

            Application.Current.Shutdown();
        }
Ejemplo n.º 4
0
        private void SqlServerTestConnectionBtn_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection connection = DBUtils.CreateSqlServerConnection(
                server: SqlServerHostTextBox.Text,
                username: SqlServerUsernameTextBox.Text,
                password: SqlServerPasswordTextBox.Password,
                noDB: true);

            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed with error: " + ex.Message);
                return;
            }

            MessageBox.Show("Connection succeeded.");
            connection.Close();
        }