예제 #1
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var sel = cbProvider.SelectedItem;

                switch (sel)
                {
                case ConnectionProvider.MsSql:
                    var conInfo = new MsSqlConnectionInfo()
                    {
                        Server            = txtServer.Text,
                        Port              = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text),
                        TrustedConnection = chkIntegratedSecurity.IsChecked.Value,
                        Username          = txtUsername.Text,
                        Password          = txtPassword.Password,
                        Database          = cbDatabase.Text
                    };

                    Sql = new MsSqlService();
                    Sql.Build(conInfo);
                    Sql.TestConnect();
                    break;

                case ConnectionProvider.PostgreSql:
                    var npgInfo = new NpgConnectionInfo
                    {
                        Server            = txtServer.Text,
                        Port              = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text),
                        TrustedConnection = chkIntegratedSecurity.IsChecked.Value,
                        Username          = txtUsername.Text,
                        Password          = txtPassword.Password,
                        Database          = cbDatabase.Text
                    };

                    Sql = new NpgService();
                    Sql.Build(npgInfo);
                    Sql.TestConnect();
                    break;

                case ConnectionProvider.MySql:

                    if (chkIntegratedSecurity.IsChecked == true)
                    {
                        throw new InvalidOperationException("Integrated Security doesnt supported by MySql Server");
                    }

                    var myInfo = new MySqlConnectionInfo
                    {
                        Server   = txtServer.Text,
                        Port     = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text),
                        Username = txtUsername.Text,
                        Password = txtPassword.Password,
                        Database = cbDatabase.Text
                    };

                    Sql = new MySqlService();
                    Sql.Build(myInfo);
                    Sql.TestConnect();
                    break;
                }

                DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void cbDatabase_DropDownOpened(object sender, EventArgs e)
        {
            cbDatabase.ItemsSource = new List <string> {
                "<Loading databases>"
            };
            var sel = Enum.Parse <ConnectionProvider>(cbProvider.SelectedItem.ToString());

            try
            {
                switch (sel)
                {
                case ConnectionProvider.MsSql:
                    var conInfo = new MsSqlConnectionInfo
                    {
                        Server            = txtServer.Text,
                        Port              = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text),
                        TrustedConnection = chkIntegratedSecurity.IsChecked.Value,
                        Username          = txtUsername.Text,
                        Password          = txtPassword.Password
                    };

                    var mssql = new MsSqlService();
                    cbDatabase.ItemsSource = mssql.LoadDatabase(conInfo);
                    break;

                case ConnectionProvider.PostgreSql:
                    var npgInfo = new NpgConnectionInfo
                    {
                        Server            = txtServer.Text,
                        Port              = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text),
                        TrustedConnection = chkIntegratedSecurity.IsChecked.Value,
                        Username          = txtUsername.Text,
                        Password          = txtPassword.Password
                    };

                    var npgsql = new NpgService();
                    cbDatabase.ItemsSource = npgsql.LoadDatabase(npgInfo);
                    break;

                case ConnectionProvider.MySql:

                    if (chkIntegratedSecurity.IsChecked == true)
                    {
                        throw new InvalidOperationException("Integrated Security doesnt supported by MySql Server");
                    }

                    var myInfo = new MySqlConnectionInfo
                    {
                        Server   = txtServer.Text,
                        Port     = Convert.ToInt32(string.IsNullOrWhiteSpace(txtPort.Text) ? "-1" : txtPort.Text),
                        Username = txtUsername.Text,
                        Password = txtPassword.Password
                    };

                    var mysql = new MySqlService();
                    cbDatabase.ItemsSource = mysql.LoadDatabase(myInfo);
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }