Esempio n. 1
0
        /// <summary>The exec load database details.</summary>
        /// <returns>The exec load database details.</returns>
        private bool ExecLoadDatabaseDetails()
        {
            bool   populate   = false;
            string connection = string.Empty;
            bool   success    = false;

            try
            {
                _hostWindow.SetPointerState(Cursors.WaitCursor);
                if (_metaDataService == null)
                {
                    _metaDataService = DatabaseMetaDataService.Create(_services.Settings.ConnectionDefinition.ProviderName);
                }

                connection = _metaDataService.GetDescription();
                populate   = true;
            }
            catch (Exception exp)
            {
                string msg = string.Format(
                    "{0}\r\n\r\nCheck the connection and select 'Reset Database Connection'.",
                    exp.Message);
                _hostWindow.DisplaySimpleMessageBox(_hostWindow.Instance, msg, "DB Connection Error");
                _hostWindow.SetStatus(this, exp.Message);
            }
            finally
            {
                _hostWindow.SetPointerState(Cursors.Default);
            }

            if (populate)
            {
                try
                {
                    _hostWindow.SetPointerState(Cursors.WaitCursor);
                    _model = _metaDataService.GetDbObjectModel(_services.Settings.ConnectionDefinition.ConnectionString);
                }
                finally
                {
                    _hostWindow.SetPointerState(Cursors.Default);
                }

                BuildTreeFromDbModel(connection);
                _hostWindow.SetStatus(this, string.Empty);
                success = true;
            }
            else
            {
                _populated = false;
                DatabaseTreeView.CollapseAll();
            }

            return(success);
        }
Esempio n. 2
0
        /// <summary>The query background worker_ run worker completed.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void queryBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                _runner.BatchProgress -= RunnerBatchProgress;
                if (e.Error != null)
                {
                    // todo: improve!
                    _hostWindow.DisplaySimpleMessageBox(this, e.Error.Message, "Error");
                    SetStatus(e.Error.Message);
                }
                else
                {
                    _hostWindow.SetPointerState(Cursors.Default);
                    string message = CreateQueryCompleteMessage(_runner.Batch.StartTime, _runner.Batch.EndTime);
                    if (_runner.Exception != null)
                    {
                        message = "ERROR - " + message;
                    }

                    AddTables();
                    SetStatus(message);
                    txtQuery.Focus();
                }
            }
            finally
            {
                UseWaitCursor = false;
                lock (_syncLock)
                {
                    IsBusy = false;
                }
            }
        }
Esempio n. 3
0
        /// <summary>Execute the command.</summary>
        public override void Execute()
        {
            IHostWindow hostWindow = Services.HostWindow;
            string      tableName  = hostWindow.DatabaseInspector.RightClickedTableName;

            string caption = string.Format("Truncate '{0}' Table Confirmation", tableName);
            string msg     = string.Format("Delete all '{0}' data, are you sure?", tableName);

            if (tableName != null && MessageBox.Show(msg, caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                DbConnection dbConnection;
                DbCommand    cmd = null;

                try
                {
                    hostWindow.SetPointerState(Cursors.WaitCursor);
                    dbConnection    = Settings.GetOpenConnection();
                    cmd             = dbConnection.CreateCommand();
                    cmd.CommandText = "DELETE FROM " + tableName;
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    Services.PostMessage(SystemMessage.TableTruncated, tableName);
                }
                catch (DbException dbExp)
                {
                    hostWindow.DisplaySimpleMessageBox(null, dbExp.Message, "Error");
                }
                catch (InvalidOperationException invalidExp)
                {
                    hostWindow.DisplaySimpleMessageBox(null, invalidExp.Message, "Error");
                }
                finally
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }

                    hostWindow.SetPointerState(Cursors.Default);
                }
            }
        }