Пример #1
0
        private void comboBoxEditSavedConnectionPostgres_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectedConnectionId = string.Empty;

            textEditAliasPostgres.Text    = string.Empty;
            textEditDatabasePostgres.Text = string.Empty;
            textEditHostOrIPPostgres.Text = string.Empty;
            textEditPasswordPostgres.Text = string.Empty;
            textEditPortPostgres.Text     = "5432";
            textEditUsernamePostgres.Text = string.Empty;


            var secili = DxHelper.GetSelectedItem(comboBoxEditSavedConnectionPostgres);

            if (secili.Value.ToString() != "-1")
            {
                var data = AppHelper.GetSavedConnections(true).FirstOrDefault(a => a.Id == secili.Value.ToString());
                if (data != null)
                {
                    textEditAliasPostgres.Text    = data.Alias;
                    textEditDatabasePostgres.Text = data.Database;
                    textEditHostOrIPPostgres.Text = data.HostOrIp;
                    textEditPasswordPostgres.Text = data.Password;
                    textEditPortPostgres.Text     = data.Port.ToString();
                    textEditUsernamePostgres.Text = data.Username;
                    _selectedConnectionId         = data.Id;
                }
            }
        }
Пример #2
0
        private void comboBoxEditSavedConnectionOracle_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectedConnectionId = string.Empty;

            textEditAliasPostgres.Text    = string.Empty;
            textEditHostOrIPPostgres.Text = string.Empty;
            textEditPasswordOracle.Text   = string.Empty;
            textEditUsernameOracle.Text   = string.Empty;


            var secili = DxHelper.GetSelectedItem(comboBoxEditSavedConnectionOracle);

            if (secili.Value.ToString() != "-1")
            {
                var data = AppHelper.GetSavedConnections(true).FirstOrDefault(a => a.Id == secili.Value.ToString());
                if (data != null)
                {
                    textEditAliasOracle.Text = data.Alias;
                    DxHelper.SetSelectedValue(comboBoxEditTnsNamesOracle, data.HostOrIp);
                    textEditUsernameOracle.Text = data.Username;
                    textEditPasswordOracle.Text = data.Password;
                    _selectedConnectionId       = data.Id;
                }
            }
        }
        private void comboBoxEditSavedConnection_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selected = DxHelper.GetSelectedItem(comboBoxEditSavedConnection);

            treeListTableList.DataSource = null;
            if (selected.Value.ToString() != "-1")
            {
                var list       = new List <DbTableModelItem>();
                var connection = AppHelper.GetSavedConnections().FirstOrDefault(a => a.Id == selected.Value.ToString());
                if (connection.DatabaseType == Models.DbType.Oracle)
                {
                    string _connectionString = "User Id=" + connection.Username + ";Password="******";Data Source=" + connection.HostOrIp + ";";
                    using (OracleConnection cnn = new OracleConnection(_connectionString))
                    {
                        cnn.Open();
                        OracleDataAdapter da = new OracleDataAdapter("Select table_name from user_tables where table_name like '%_GEO_%' order by table_name", cnn);
                        DataTable         dt = new DataTable();
                        da.Fill(dt);

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            list.Add(new DbTableModelItem()
                            {
                                Connection = connection,
                                IsOpen     = Program.mainForm.OpenedTables.Any(async => async.TableName == dt.Rows[i][0].ToString() && async.Connection.Id == connection.Id),
                                TableName  = dt.Rows[i][0].ToString()
                            });
                        }
                    }
                }
                treeListTableList.DataSource = list;
            }
        }
Пример #4
0
        private void simpleButtonConnect_Click(object sender, EventArgs e)
        {
            if (xtraTabControlMain.SelectedTabPageIndex == 0) // Postgresql
            {
                var model = new DbConnectionModel();
                model.Alias    = textEditAliasPostgres.Text.Trim();
                model.Database = textEditDatabasePostgres.Text.Trim();
                model.HostOrIp = textEditHostOrIPPostgres.Text.Trim();
                model.Password = textEditPasswordPostgres.Text.Trim();
                model.Port     = int.Parse(textEditPortPostgres.Text.Trim());
                model.Username = textEditUsernamePostgres.Text.Trim();

                string _connectionString = "Server = " + model.HostOrIp + "; Port = " + model.Port + "; Database = " + model.Database + "; User Id = " + model.Username + "; Password = "******";";
                try
                {
                    using (NpgsqlConnection cnn = new NpgsqlConnection(_connectionString))
                    {
                        cnn.Open();
                        NpgsqlDataAdapter da = new NpgsqlDataAdapter("Select 1", cnn);
                        DataTable         dt = new DataTable();
                        da.Fill(dt);

                        if (dt.Rows.Count > 0)
                        {
                            if (toggleSwitchSaveConnectionPostgres.IsOn)
                            {
                                if (!string.IsNullOrEmpty(_selectedConnectionId))
                                {
                                    AppHelper.RemoveConnection(_selectedConnectionId);
                                }
                                model.DatabaseType = Models.DbType.PostgreSQL;
                                AppHelper.SaveConnection(model);
                                this.Close();
                            }
                        }
                        else
                        {
                            XtraMessageBox.Show("Cannot connect to database. Please check");
                            this.DialogResult = DialogResult.None;
                        }
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show("Cannot connect to database. Please check");
                    this.DialogResult = DialogResult.None;
                }
            }
            else if (xtraTabControlMain.SelectedTabPageIndex == 1) // Oracle
            {
                var tns = DxHelper.GetSelectedItem(comboBoxEditTnsNamesOracle);
                if (tns.Value.ToString() != "-1")
                {
                    var model = new DbConnectionModel();
                    model.Alias    = textEditAliasOracle.Text.Trim();
                    model.HostOrIp = tns.Text.Trim();
                    model.Password = textEditPasswordOracle.Text.Trim();
                    model.Username = textEditUsernameOracle.Text.Trim();

                    string _connectionString = "User Id=" + model.Username + ";Password="******";Data Source=" + model.HostOrIp + ";";
                    try
                    {
                        using (OracleConnection cnn = new OracleConnection(_connectionString))
                        {
                            cnn.Open();
                            OracleDataAdapter da = new OracleDataAdapter("Select 1 from dual", cnn);
                            DataTable         dt = new DataTable();
                            da.Fill(dt);

                            if (dt.Rows.Count > 0)
                            {
                                if (toggleSwitchIsSaveConnectionOracle.IsOn)
                                {
                                    if (!string.IsNullOrEmpty(_selectedConnectionId))
                                    {
                                        AppHelper.RemoveConnection(_selectedConnectionId);
                                    }
                                    model.DatabaseType = Models.DbType.Oracle;
                                    AppHelper.SaveConnection(model);
                                    this.Close();
                                }
                            }
                            else
                            {
                                XtraMessageBox.Show("Cannot connect to database. Please check");
                                this.DialogResult = DialogResult.None;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        XtraMessageBox.Show("Cannot connect to database. Please check");
                        this.DialogResult = DialogResult.None;
                    }
                }
            }
        }