public void SetCollection(IActivateItems activator, IPersistableObjectCollection collection)
        {
            _collection = (IViewSQLAndResultsCollection)collection;

            CommonFunctionality.ClearToolStrip();

            btnExecuteSql.Image = activator.CoreIconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Execute);

            var overlayer = new IconOverlayProvider();

            btnResetSql.Image = overlayer.GetOverlay(FamFamFamIcons.text_align_left, OverlayKind.Problem);

            if (_autoComplete == null)
            {
                _autoComplete = new AutoCompleteProviderFactory(activator).Create(_collection.GetQuerySyntaxHelper());

                _collection.AdjustAutocomplete(_autoComplete);

                _autoComplete.RegisterForEvents(_scintilla);
            }

            SetItemActivator(activator);

            CommonFunctionality.Add(btnExecuteSql);
            CommonFunctionality.Add(btnResetSql);

            foreach (var c in _timeoutControls.GetControls())
            {
                CommonFunctionality.Add(c);
            }

            foreach (DatabaseEntity d in _collection.GetToolStripObjects())
            {
                CommonFunctionality.AddToMenu(new ExecuteCommandShow(activator, d, 0, true));
            }

            CommonFunctionality.Add(new ToolStripSeparator());
            CommonFunctionality.Add(_serverHeader);

            try
            {
                var dap = _collection.GetDataAccessPoint();
                _serverHeader.Text  = $"Server: {dap.Server} Database: {dap.Database}";
                _serverHeader.Image = _databaseTypeIconProvider.GetImage(dap.DatabaseType);
            }
            catch (Exception)
            {
                _serverHeader.Text = "Server:Unknown";
            }


            RefreshUIFromDatabase();
        }
        public void SetCollection(IActivateItems activator, IPersistableObjectCollection collection)
        {
            _collection = (IViewSQLAndResultsCollection)collection;

            CommonFunctionality.ClearToolStrip();

            btnExecuteSql.Image = activator.CoreIconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Execute);

            var overlayer = new IconOverlayProvider();

            btnResetSql.Image = overlayer.GetOverlay(FamFamFamIcons.text_align_left, OverlayKind.Problem);

            if (_scintilla == null)
            {
                // figure out what DBMS we are targetting
                var syntax = _collection.GetQuerySyntaxHelper();

                // Create the SQL editor for that language
                ScintillaTextEditorFactory factory = new ScintillaTextEditorFactory();
                _scintilla = factory.Create(null, SyntaxLanguage.SQL, syntax);
                splitContainer1.Panel1.Controls.Add(_scintilla);
                _scintilla.TextChanged += _scintilla_TextChanged;
                _scintilla.KeyUp       += ScintillaOnKeyUp;

                // Setup autocomplete menu for the DBMS language
                _autoComplete = new AutoCompleteProviderWin(syntax);
                _collection.AdjustAutocomplete(_autoComplete);
                _autoComplete.RegisterForEvents(_scintilla);
            }

            SetItemActivator(activator);

            CommonFunctionality.Add(btnExecuteSql);
            CommonFunctionality.Add(btnResetSql);

            foreach (var c in _timeoutControls.GetControls())
            {
                CommonFunctionality.Add(c);
            }

            foreach (DatabaseEntity d in _collection.GetToolStripObjects())
            {
                CommonFunctionality.AddToMenu(new ExecuteCommandShow(activator, d, 0, true));
            }

            CommonFunctionality.Add(new ToolStripSeparator());
            CommonFunctionality.Add(_serverHeader);

            try
            {
                var dap = _collection.GetDataAccessPoint();
                _serverHeader.Text  = $"Server: {dap.Server} Database: {dap.Database}";
                _serverHeader.Image = _databaseTypeIconProvider.GetImage(dap.DatabaseType);
            }
            catch (Exception)
            {
                _serverHeader.Text = "Server:Unknown";
            }


            RefreshUIFromDatabase();
        }
示例#3
0
        public ConsoleGuiSqlEditor(IBasicActivateItems activator, IViewSQLAndResultsCollection collection)
        {
            this.Activator   = activator;
            this._collection = collection;
            Modal            = true;
            ColorScheme      = ConsoleMainWindow.ColorScheme;

            // Tabs (query and results)
            TabView = new TabView()
            {
                Width = Dim.Fill(), Height = Dim.Fill(), Y = 1
            };

            textView = new SqlTextView()
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Fill(),
                Height = Dim.Fill(),
                Text   = _orignalSql = collection.GetSql().Replace("\r\n", "\n").Replace("\t", "    ")
            };

            textView.AllowsTab = false;

            TabView.AddTab(queryTab = new Tab("Query", textView), true);

            tableView = new TableView()
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            tableView.Style.AlwaysShowHeaders = true;
            tableView.CellActivated          += TableView_CellActivated;

            TabView.AddTab(resultTab = new Tab("Results", tableView), false);

            Add(TabView);

            // Buttons on top of control

            _btnRunOrCancel = new Button("Run")
            {
                X = 0,
                Y = 0,
            };

            _btnRunOrCancel.Clicked += () => RunOrCancel();
            Add(_btnRunOrCancel);

            var resetSql = new Button("Reset Sq_l")
            {
                X = Pos.Right(_btnRunOrCancel) + 1
            };

            resetSql.Clicked += () => ResetSql();
            Add(resetSql);

            var clearSql = new Button("Clear S_ql")
            {
                X = Pos.Right(resetSql) + 1,
            };

            clearSql.Clicked += () => ClearSql();
            Add(clearSql);

            var lblTimeout = new Label("Timeout:")
            {
                X = Pos.Right(clearSql) + 1,
            };

            Add(lblTimeout);

            var tbTimeout = new TextField(_timeout.ToString())
            {
                X     = Pos.Right(lblTimeout),
                Width = 5
            };

            tbTimeout.TextChanged += TbTimeout_TextChanged;

            Add(tbTimeout);

            var btnSave = new Button("Save")
            {
                X = Pos.Right(tbTimeout) + 1,
            };

            btnSave.Clicked += () => Save();
            Add(btnSave);

            var btnClose = new Button("Clos_e")
            {
                X = Pos.Right(btnSave) + 1,
            };


            btnClose.Clicked += () => {
                Application.RequestStop();
            };

            Add(btnClose);

            var auto = new AutoCompleteProvider(collection.GetQuerySyntaxHelper());

            collection.AdjustAutocomplete(auto);
            var bits = auto.Items.SelectMany(auto.GetBits).OrderBy(a => a).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();

            textView.Autocomplete.AllSuggestions = bits;
            textView.Autocomplete.MaxWidth       = 40;
        }