Пример #1
0
        private async void loadFromDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormConnectToDatabase connectToDatabase = new FormConnectToDatabase();

            connectToDatabase.LoadForm();
            connectToDatabase.ShowDialog();
            if (connectToDatabase.Saved)
            {
                this._userControlDBForgeEditor.displayUserMessageSuccess("Loading database schema...");
                this._userControlDBForgeEditor.showSpinner();
                IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(connectToDatabase.Provider);
                sqlInterface.SetConnectionString(connectToDatabase.ConnectionString);
                DatabaseContainer databaseContainer = null;

                await Task.Run(() =>
                {
                    databaseContainer = sqlInterface.GetDatabaseStructure();
                });

                this._userControlDBForgeEditor.LoadProject(databaseContainer);
                this.ConnectionString = connectToDatabase.ConnectionString;
                this._userControlDBForgeEditor.displayUserMessageSuccess("Database schema loaded...");
                this._userControlDBForgeEditor.hideSpinner();
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (comboBoxDatabases.SelectedIndex > -1)
            {
                this.Saved    = true;
                this.Provider = comboBoxProvider.Text;
                IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(comboBoxProvider.SelectedItem.ToString());

                if (this.checkBoxWindowsAuth.Checked)
                {
                    this.ConnectionString = sqlInterface.CreateConnectionStringUsingWindowsAuthentication(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString());
                }
                else
                {
                    this.ConnectionString = sqlInterface.CreateConnectionString(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString(), textBoxUsername.Text, textBoxPassword.Text);
                }

                ConfigHelper.WriteAppSetting("DatabaseInstance", textBoxInstance.Text);
                ConfigHelper.WriteAppSetting("DatabaseUsername", textBoxUsername.Text);
                ConfigHelper.WriteAppSetting("DatabaseProvider", comboBoxProvider.SelectedItem?.ToString());
                this.Close();
            }
            else
            {
                SetUserMessage("Database not selected...", true);
            }
        }
        private async Task TestConnection()
        {
            progressSpinnerDefault.Visible = true;
            IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(comboBoxProvider.SelectedItem.ToString());

            if (checkBoxWindowsAuth.Checked)
            {
                this.ConnectionString = sqlInterface.CreateConnectionStringUsingWindowsAuthentication(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString());
            }
            else
            {
                this.ConnectionString = sqlInterface.CreateConnectionString(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString(), textBoxUsername.Text, textBoxPassword.Text);
            }

            sqlInterface.SetConnectionString(this.ConnectionString);
            if (await sqlInterface.TestConnectionAsync())
            {
                this.SetUserMessage("Connected!", false);
                await LoadDatabases();
            }
            else
            {
                this.SetUserMessage("Unable to Connect...", true);
            }
            progressSpinnerDefault.Visible = false;
        }
        private async Task LoadDatabases()
        {
            try
            {
                IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(comboBoxProvider.SelectedItem.ToString());
                if (this.checkBoxWindowsAuth.Checked)
                {
                    this.ConnectionString = sqlInterface.CreateConnectionStringUsingWindowsAuthentication(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString());
                }
                else
                {
                    this.ConnectionString = sqlInterface.CreateConnectionString(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString(), textBoxUsername.Text, textBoxPassword.Text);
                }

                progressSpinnerDefault.Visible = true;
                comboBoxDatabases.DataSource   = null;
                resetUserMessage();
                sqlInterface.SetConnectionString(this.ConnectionString);
                bool result = sqlInterface.TestConnection();
                if (result)
                {
                    SetUserMessage("Connected!", false);

                    comboBoxDatabases.DataSource = await Task <List <string> > .Run(() =>
                    {
                        List <string> databases = sqlInterface.GetDatabaseList();
                        databases.Sort();
                        return(databases);
                    });
                }
                else
                {
                    SetUserMessage("Unable to Connect...", true);
                }
            }
            catch (Exception ex)
            {
                SetUserMessage($"Unable to Connect...Error={ex.Message}", true);
            }
            finally
            {
                progressSpinnerDefault.Visible = false;
            }
        }
Пример #5
0
        private void loadControls()
        {
            Action loadTypes = () =>
            {
                comboBoxFieldType.Items.Clear();
                IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(this._provider);
                foreach (var item in sqlInterface.ColumnTypes)
                {
                    comboBoxFieldType.Items.Add(item);
                }
            };


            if (this.comboBoxFieldType.InvokeRequired)
            {
                this.comboBoxFieldType.Invoke(new MethodInvoker(delegate
                {
                    loadTypes();
                }));
            }
            else
            {
                loadTypes();
            }


            if (this.textBoxFieldName.InvokeRequired)
            {
                this.textBoxFieldName.Invoke(new MethodInvoker(delegate
                {
                    textBoxFieldName.Select();
                }));
            }
            else
            {
                textBoxFieldName.Select();
            }
        }