コード例 #1
0
        /// <summary>The run template.</summary>
        public void RunTemplate()
        {
            TemplateModel  templateModel  = _services.Resolve <TemplateModel>();
            TemplateResult templateResult = null;

            txtErrors.Clear();

            try
            {
                string[] lines = AllText.Replace("\r", string.Empty).Split('\n');
                string   text;
                Dictionary <string, object> items = new Dictionary <string, object>();
                items[TemplateModel.Extension] = templateModel.InferExtensionFromFilename(FileName, items);
                text           = templateModel.PreProcessTemplate(lines, GetValue, items);
                templateResult = templateModel.ProcessTemplate(text, items);
            }
            catch (TemplateException exp)
            {
                _hostWindow.DisplaySimpleMessageBox(this, exp.Message, "Template Error");

// todo - try to get the line number and move cursor?...
                txtErrors.Text = exp.Message;
            }

            if (templateResult != null)
            {
                // display in new window
                IFileEditorResolver resolver = _services.Resolve <IFileEditorResolver>();
                IEditor             editor   = _services.Resolve <IEditor>(resolver.ResolveEditorNameByExtension(templateResult.Extension));
                editor.AllText = templateResult.Text;
                editor.SetSyntax(templateResult.SyntaxName);
                _hostWindow.DisplayDockedForm(editor as DockContent);
            }
        }
コード例 #2
0
        /// <summary>The tool strip button test_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void toolStripButtonTest_Click(object sender, EventArgs e)
        {
            // do a standalone raw connection test
            Exception exp = QueryRunner.TestDbConnection(ProviderName, ConnectionString);

            if (exp == null)
            {
                string msg = string.Format(Resources.Connected_to_0_successfully, ConnectionName);
                _hostWindow.DisplaySimpleMessageBox(this, msg, Resources.Connection_Successful);
            }
            else
            {
                string msg = string.Format(Resources.Failed_connecting_to_0_1_2, ConnectionName, Environment.NewLine, exp.Message);
                _hostWindow.DisplaySimpleMessageBox(this, msg, Resources.Connection_Failed);
            }
        }
コード例 #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);
                }
            }
        }
コード例 #4
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);
        }
コード例 #5
0
        /// <summary>The tool strip button test_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void toolStripButtonTest_Click(object sender, EventArgs e)
        {
            // do a standalone raw connection test
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            if (definition != null)
            {
                Exception exp = QueryRunner.TestDbConnection(definition.ProviderName, definition.ConnectionString);
                if (exp == null)
                {
                    string msg = string.Format("Connected to '{0}' successfully.", definition.Name);
                    _hostWindow.DisplaySimpleMessageBox(this, msg, "Connection Successful");
                }
                else
                {
                    string msg = string.Format("Failed connecting to '{0}'.{1}{2}", definition.Name, Environment.NewLine, exp.Message);
                    _hostWindow.DisplaySimpleMessageBox(this, msg, "Connection Failed");
                }
            }
        }
コード例 #6
0
ファイル: QueryForm.cs プロジェクト: shuicheng9/sap_interface
        /// <summary>The execute query.</summary>
        /// <param name="sql">The sql.</param>
        public void ExecuteQuery(string sql)
        {
            if (IsBusy)
            {
                _hostWindow.DisplaySimpleMessageBox(this, "Please wait for the current operation to complete.", "Busy");
                return;
            }

            if (_settings.ConnectionDefinition == null)
            {
                _hostWindow.DisplaySimpleMessageBox(this, "Please select a connection.", "Select a Connection");
                return;
            }

            lock (_syncLock)
            {
                IsBusy = true;
            }

            _runner       = QueryRunner.Create(_settings.ProviderFactory, _settings.ConnectionDefinition.ConnectionString, _settings.EnableQueryBatching, _settings.CommandTimeout);
            UseWaitCursor = true;
            queryBackgroundWorker.RunWorkerAsync(sql);
        }