Esempio n. 1
0
        private void RunSql(string sql)
        {
            using (var connection = ConnectionService.GetConnection(server, database))
            {
                connection.Open();

                NpgsqlCommand     command     = new NpgsqlCommand(sql, connection);
                NpgsqlDataAdapter adapter     = new NpgsqlDataAdapter(command);
                DataSet           queryResult = new DataSet();

                try
                {
                    adapter.Fill(queryResult);
                    if (queryResult.Tables.Count > 0)
                    {
                        dgvSqlResult.DataSource = queryResult.Tables[0];
                        tcResults.SelectedTab   = tpSqlResult;
                        txtSqlError.Text        = String.Empty;
                    }
                }
                catch (NpgsqlException e)
                {
                    txtSqlError.Text      = e.Message;
                    tcResults.SelectedTab = tpError;
                    txtSqlError.Select(0, 0);
                }
            }
        }
Esempio n. 2
0
        public void ShowTable(TreeNode node)
        {
            DataTable     table  = (DataTable)node.Tag;
            TreeNode      dbNode = GetSelectedDBNode(node);
            Database      db     = (Database)dbNode.Tag;
            Server        server = (Server)dbNode.Parent.Tag;
            List <Column> columns;

            using (NpgsqlConnection connection = ConnectionService.GetConnection(server, db))
            {
                connection.Open();
                DatabaseService.fetchTableByName(connection, table);
                columns = DatabaseService.fetchTableColumns(connection, table.DataSet.DataSetName, table.TableName);
                table.ExtendedProperties[Database.TABLE_PROPERTY_COLUMNS] = columns;
            }


            // dehilight image of previous opened table
            if (openedTableNode != null)
            {
                openedTableNode.ImageKey         = IMAGE_KEY_TABLE;
                openedTableNode.SelectedImageKey = IMAGE_KEY_TABLE;
            }
            // hilight image of selected table
            openedTableNode                  = node;
            openedTableNode.ImageKey         = IMAGE_KEY_TABLE_OPEN;
            openedTableNode.SelectedImageKey = IMAGE_KEY_TABLE_OPEN;

            if (TableOpened != null)
            {
                TableOpened(table);
            }
        }
Esempio n. 3
0
        private void OpenDatabase(TreeNode dbNode)
        {
            Database db     = (Database)dbNode.Tag;
            Server   server = (Server)dbNode.Parent.Tag;

            using (NpgsqlConnection connection = ConnectionService.GetConnection(server, db))
            {
                try
                {
                    connection.Open();
                }
                catch (NpgsqlException e)
                {
                    MessageBox.Show(e.Message, String.Format("Error {0}", e.ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                db.Schemas = DatabaseService.fetchAllSchemasWithTables(connection);
            }

            FillTreeViewWithTables(dbNode);


            dbNode.ImageKey         = IMAGE_KEY_DATABASE_CONNECTED;
            dbNode.SelectedImageKey = IMAGE_KEY_DATABASE_CONNECTED;
            db.IsOpen = true;

            if (DatabaseOpened != null)
            {
                DatabaseOpened();
            }
        }
Esempio n. 4
0
 private void FillDatabaseList()
 {
     using (var connection = ConnectionService.GetConnection(server, database))
     {
         connection.Open();
         cmbDatabase.DataSource         = DatabaseService.fetchDbNames(connection);
         ctrlConnectionStatus.BackColor = COLOR_SUCCESS;
     }
 }
Esempio n. 5
0
 private void btnTestConnection_Click(object sender, EventArgs e)
 {
     if (ValidateChildren(ValidationConstraints.Enabled))
     {
         try
         {
             using (var connection = ConnectionService.GetConnection(server, database))
             {
                 connection.Open();
                 ctrlConnectionStatus.BackColor = COLOR_SUCCESS;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Information);
             ctrlConnectionStatus.BackColor = COLOR_FAIL;
         }
     }
 }