示例#1
0
        private bool DoConnect(IWin32Window owner)
        {
            bool   successfulConnect = false;
            Action action            = () => {
                using (var connection = CreateConnection(_builder)) {
                    connection.Open();
                    ReadTableNames(connection);
                }
            };

            using (var f = new WaitForm("SQL Notebook", $"Accessing {ProductName}...", action)) {
                f.ShowDialog(owner);
                if (f.ResultException == null)
                {
                    successfulConnect = true;
                }
                else
                {
                    MessageForm.ShowError(owner,
                                          "Connection Error",
                                          $"The connection to {ProductName} failed.",
                                          f.ResultException.Message);
                }
            }
            return(successfulConnect);
        }
示例#2
0
        public MainForm(string filePath, bool isNew)
        {
            InitializeComponent();

            _menuStrip.SetMenuAppearance();
            _menuStrip.Items.Insert(0, _searchTxt = new CueToolStripTextBox {
                Alignment   = ToolStripItemAlignment.Right,
                CueText     = "Search Help",
                ToolTipText = "Search the built-in documentation (Ctrl+H)",
                AutoSize    = false,
                Margin      = new Padding(0, 0, 5, 0)
            });
            _searchTxt.InnerTextBox.KeyDown += (sender, e) => {
                if (e.KeyCode == Keys.Enter)
                {
                    e.Handled          = true;
                    e.SuppressKeyPress = true;
                    var text = _searchTxt.Text;
                    OpenHelp("/search?q=" + System.Net.WebUtility.UrlEncode(text));
                    _searchTxt.Text = "";
                }
            };

            if (isNew)
            {
                _notebook = new Notebook(filePath, isNew);
            }
            else
            {
                var f = new WaitForm("SQL Notebook", $"Opening notebook \"{Path.GetFileNameWithoutExtension(filePath)}\"", () => {
                    _notebook = new Notebook(filePath, isNew);
                });
                using (f) {
                    f.StartPosition = FormStartPosition.CenterScreen;
                    f.ShowDialog();
                    if (f.ResultException != null)
                    {
                        throw f.ResultException;
                    }
                }
            }
            _isNew     = isNew;
            _manager   = new NotebookManager(_notebook, _isTransactionOpen);
            _importer  = new Importer(_manager, this);
            _dockPanel = new DockPanel {
                Dock  = DockStyle.Fill,
                Theme = new VS2012LightTheme {
                    ToolStripRenderer = new MenuRenderer()
                },
                DocumentStyle          = DocumentStyle.DockingWindow,
                DefaultFloatWindowSize = new Size(700, 700),
                ShowDocumentIcon       = true,
                DockLeftPortion        = 250
            };
            _toolStripContainer.ContentPanel.Controls.Add(_dockPanel);

            _contentsPane = new UserControlDockContent("Table of Contents",
                                                       _explorer = new ExplorerControl(_manager, this, _operationInProgress),
                                                       DockAreas.DockLeft | DockAreas.DockRight);
            _contentsPane.CloseButtonVisible = false;
            _contentsPane.Show(_dockPanel, DockState.DockLeft);

            _manager.NotebookItemOpenRequest  += Manager_NotebookItemOpenRequest;
            _manager.NotebookItemCloseRequest += Manager_NotebookItemCloseRequest;
            _manager.NotebookItemsSaveRequest += Manager_NotebookItemsSaveRequest;
            _manager.NotebookDirty            += (sender, e) => SetDirty();
            _manager.NotebookItemRename       += Manager_NotebookItemRename;
            _manager.StatusUpdate             += Manager_StatusUpdate;
            _manager.HandleHotkeyRequest      += Manager_HandleHotkeyRequest;

            // show a progressbar in the taskbar button and the statusbar when a operation is in progress
            _operationInProgress.Change += (oldValue, newValue) => {
                if (!oldValue && newValue)
                {
                    this.BeginTaskbarProgress();
                    _statusLbl.Visible = true;

                    // this restarts the statusbar progress marquee from the beginning
                    _statusProgressbar.Style   = ProgressBarStyle.Continuous;
                    _statusProgressbar.Style   = ProgressBarStyle.Marquee;
                    _statusProgressbar.Visible = true;

                    _cancelLnk.IsLink  = true;
                    _cancelLnk.Text    = "Cancel";
                    _cancelLnk.Visible = true;
                }
                else if (oldValue && !newValue)
                {
                    _notebook.EndUserCancel();
                    this.EndTaskbarProgress();
                    _statusProgressbar.Visible = false;
                    _statusLbl.Visible         = false;
                    _cancelLnk.Visible         = false;
                }
            };

            Slot.Bind(
                () => BeginInvoke(new MethodInvoker(() =>
                                                    _importMnu.Enabled = _saveAsMnu.Enabled = !_operationInProgress && !_isTransactionOpen
                                                    )),
                _operationInProgress, _isTransactionOpen);
            Slot.Bind(
                () => BeginInvoke(new MethodInvoker(() =>
                                                    _exportMnu.Enabled = !_operationInProgress
                                                    )),
                _operationInProgress);
            Slot.Bind(
                () => BeginInvoke(new MethodInvoker(() =>
                                                    _saveBtn.Enabled = _saveMnu.Enabled = !_operationInProgress && _isDirty && !_isTransactionOpen
                                                    )),
                _operationInProgress, _isDirty, _isTransactionOpen);
            _isDirty.Change += (a, b) => SetTitle();
            Slot.Bind(
                () => BeginInvoke(new MethodInvoker(() =>
                                                    _openTransactionLbl.Visible = _isTransactionOpen
                                                    )),
                _isTransactionOpen);

            if (isNew)
            {
                switch (Settings.Default.AutoCreateInNewNotebooks)
                {
                case 1:     // New note
                    Load += (sender, e) => {
                        var name = _manager.NewNote();
                        OpenItem(new NotebookItem(NotebookItemType.Note, name));
                        _isDirty.Value = false;
                    };
                    break;

                case 2:     // New console
                    Load += (sender, e) => {
                        var name = _manager.NewConsole();
                        OpenItem(new NotebookItem(NotebookItemType.Console, name));
                        _isDirty.Value = false;
                    };
                    break;

                case 3:     // New script
                    Load += (sender, e) => {
                        var name = _manager.NewScript();
                        OpenItem(new NotebookItem(NotebookItemType.Script, name));
                        _isDirty.Value = false;
                    };
                    break;
                }
            }

            Load += async(sender, e) => {
                _manager.Rescan();

                var updateAvailable = await IsUpdateAvailable();

                if (updateAvailable)
                {
                    _appUpdateLbl.Visible = true;
                }
            };
            SetTitle();
        }