private void ExecuteButton_Click(object sender, EventArgs e)
        {
            IDbConnection conn = null;

            try
            {
                MainApplicationSettings.DBInfo dbInfo = (MainApplicationSettings.DBInfo)((ItemValue)DBConnectionComboBox.SelectedItem).key;

                _currentConnectionString = dbInfo.GetOracleConnectionString();

                this._provider = new DataProvider(_currentConnectionString, ProviderType.Oracle);

                conn = _provider.OpenConnection();

                string[] SQLStatements = _textArea.Text.Split(';');

                _provider.ExecuteNonQueryMultiple(SQLStatements);

                FillTableListComboBox(ref NewTableComboBox, true);

                NewTableComboBox.Enabled = true;
                NewTableLabel.Enabled    = true;
                MessageBox.Show("Execution completed succesfully", "Executed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
            finally
            {
                _provider.CloseConnection(conn);
            }
        }
        private DataTable GetTableData(string tableName)
        {
            IDbConnection conn    = null;
            IDbCommand    comm    = null;
            IDataAdapter  adapter = null;

            try
            {
                MainApplicationSettings.DBInfo dbInfo = (MainApplicationSettings.DBInfo)((ItemValue)DBConnectionComboBox.SelectedItem).key;

                _currentConnectionString = dbInfo.GetOracleConnectionString();

                this._provider = new DataProvider(_currentConnectionString, ProviderType.Oracle);


                conn = _provider.OpenConnection();


                string SQLStatement = null;
                SQLStatement = "select * from " + tableName;

                comm = new OracleCommand(SQLStatement, (OracleConnection)conn);

                adapter = new OracleDataAdapter();
                ((OracleDataAdapter)adapter).SelectCommand = (OracleCommand)comm;

                DataSet dataset = new DataSet();
                dataset.Locale = System.Globalization.CultureInfo.InvariantCulture;
                adapter.Fill(dataset);

                return(dataset.Tables[0]);
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
                return(null);
            }
            finally
            {
                _provider.CloseConnection(conn);
            }
        }
Ejemplo n.º 3
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                MainApplicationSettings.DBInfo dbInfo = new MainApplicationSettings.DBInfo();
                if (DBConnectionNameTextBox.Text.Trim() != "")
                {
                    if (_tmp_settings.DBConnections.Count > 0)
                    {
                        var existingDbNames = from dbnames in _tmp_settings.DBConnections
                                              where dbnames.DBConnectionName == DBConnectionNameTextBox.Text
                                              select dbnames;
                        if (existingDbNames.Count() > 0 && _newDbConnection)
                        {
                            MessageBox.Show("Sorry, a DB connection " + DBConnectionNameTextBox.Text + " already exist.", "Database connection name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                    dbInfo.DBConnectionName = DBConnectionNameTextBox.Text;
                }
                else
                {
                    MessageBox.Show("Please, insert a Database connection name", "Database connection name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                dbInfo.UserName = DBUserNameTextBox.Text;
                dbInfo.Pwd      = DBPasswordTextBox.Text;
                dbInfo.TSNName  = OracleTNSTextBox.Text;
                dbInfo.DBType   = ProviderType.Oracle;
                dbInfo.ID       = dbInfo.DBConnectionName.GetHashCode();

                _tmp_settings.DBConnections.Add(dbInfo);
                SaveDBConnButton.Enabled = false;
                _newDbConnection         = false;
                MessageBox.Show("DBConnection added. Please, to apply this change permanently, click main Save button to close this Settings module", "Removed", MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
        }
        private void FillTableListComboBox(ref ComboBox listToBeFilled, bool alreadyExisting)
        {
            IDbConnection conn = null;
            IDbCommand    comm = null;
            IDataReader   rdr  = null;

            try
            {
                List <string> actualList = new List <string>();

                MainApplicationSettings.DBInfo dbInfo = (MainApplicationSettings.DBInfo)((ItemValue)DBConnectionComboBox.SelectedItem).key;
                _currentConnectionString = dbInfo.GetOracleConnectionString();

                this._provider = new DataProvider(_currentConnectionString, ProviderType.Oracle);


                conn = _provider.OpenConnection();


                string SQLStatement = null;
                SQLStatement = "SELECT table_name FROM all_tables where owner =\'" + dbInfo.UserName.ToUpper() + "\' order by table_name";

                comm = new OracleCommand(SQLStatement, (OracleConnection)conn);
                rdr  = comm.ExecuteReader(System.Data.CommandBehavior.Default);
                if (rdr == null)
                {
                    return;
                }

                while (rdr.Read())
                {
                    string tmpString = rdr[0].ToString();
                    actualList.Add(tmpString);

                    if (!alreadyExisting)
                    {
                        listToBeFilled.Items.Add(tmpString);
                        _previousLoadedTable.Add(tmpString);
                    }
                    else
                    {
                        if (!_previousLoadedTable.Contains(tmpString))
                        {
                            listToBeFilled.Items.Add(tmpString);
                        }
                    }
                }

                _previousLoadedTable.Clear();
                _previousLoadedTable = actualList;
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                _provider.CloseConnection(conn);
            }
        }