예제 #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);
            }
        }