Esempio n. 1
0
    private void OkBtn_Click(object sender, EventArgs e)
    {
        string sql;

        try {
            sql = _session.GenerateSql(GetSelectedTables(), _methodLinkRad.Checked);
        } catch (Exception ex) {
            Ui.ShowError(this, "Error", ex);
            return;
        }

        var text = $"Importing from database...";

        WaitForm.GoWithCancel(this, "Import", text, out var success, cancel => {
            SqlUtil.WithCancellableTransaction(_manager.Notebook, () => {
                _manager.ExecuteScript(sql);
            }, cancel);
        });
        _manager.Rescan();
        _manager.SetDirty();
        if (!success)
        {
            return;
        }

        DialogResult = DialogResult.OK;
        Close();
    }
Esempio n. 2
0
    private void Execute()
    {
        var sql = _inputText.SqlText.Trim();

        if (string.IsNullOrWhiteSpace(sql))
        {
            return;
        }

        using var output = WaitForm.GoWithCancel(TopLevelControl, "Console", "Executing...", out var success, cancel => {
            return(SqlUtil.WithCancellation(_manager.Notebook, () => {
                using var status = WaitStatus.StartRows("Script output");
                return _manager.ExecuteScript(sql, onRow: status.IncrementRows);
            }, cancel));
        });
        _manager.SetDirty();
        _manager.Rescan();
        if (!success)
        {
            return;
        }

        _inputText.SqlText = "";
        Log(sql, output);
        TakeFocus();
    }
Esempio n. 3
0
    private void ExecuteAllButton_Click(object sender, EventArgs e)
    {
        AcceptAll();

        _manager.CommitOpenEditors();

        List <Action> uiThreadActions    = new();
        var           queryBlockControls = _flow.Controls.OfType <QueryBlockControl>().ToList();

        WaitForm.Go(TopLevelControl, "Page Execution", "Executing all queries...", out _, () => {
            foreach (var queryBlockControl in queryBlockControls)
            {
                var output = queryBlockControl.ExecuteOnWorkerThread();
                uiThreadActions.Add(() => {
                    queryBlockControl.Output?.Dispose();
                    queryBlockControl.Output = output;
                    queryBlockControl.Invalidate();
                });
            }
        });

        foreach (var action in uiThreadActions)
        {
            action();
        }
        OnSizeChanged(EventArgs.Empty);

        _manager.SetDirty();
        _manager.Rescan();
    }
Esempio n. 4
0
    private void SaveBtn_Click(object sender, EventArgs e)
    {
        if (_list.SelectedIndices.Count != 1)
        {
            return;
        }
        var          lvi  = _list.SelectedItems[0];
        var          type = (NotebookItemType)Enum.Parse(typeof(NotebookItemType), lvi.Group.Name);
        NotebookItem item = new(type, lvi.Text);

        using SaveFileDialog saveFileDialog = new() {
                  AddExtension                 = true,
                  AutoUpgradeEnabled           = true,
                  CheckPathExists              = true,
                  DefaultExt                   = ".csv",
                  Filter                       = "CSV files|*.csv",
                  OverwritePrompt              = true,
                  SupportMultiDottedExtensions = true,
                  Title         = "Save CSV As",
                  ValidateNames = true
              };
        if (saveFileDialog.ShowDialog(this) != DialogResult.OK)
        {
            return;
        }
        var filePath = saveFileDialog.FileName;

        var typeKeyword =
            type switch {
            NotebookItemType.Script => "SCRIPT",
            NotebookItemType.Table => "TABLE",
            NotebookItemType.View => "TABLE",
            _ => throw new InvalidOperationException("Unrecognzied notebook item type.")
        };
        var sql =
            $"EXPORT CSV {filePath.SingleQuote()} " +
            $"FROM {typeKeyword} {item.Name.DoubleQuote()} " +
            $"OPTIONS (TRUNCATE_EXISTING_FILE: 1);";

        WaitForm.GoWithCancel(this, "Export", "Exporting to file...", out var success, cancel => {
            SqlUtil.WithCancellableTransaction(_manager.Notebook, () => {
                _manager.ExecuteScriptNoOutput(sql);
            }, cancel);
        });
        _manager.Rescan();
        _manager.SetDirty();
        if (!success)
        {
            return;
        }

        Process.Start(new ProcessStartInfo {
            FileName  = "explorer.exe",
            Arguments = $"/e, /select, \"{filePath}\""
        });
        Close();
    }
Esempio n. 5
0
    public ExplorerControl(NotebookManager manager, IWin32Window mainForm)
    {
        InitializeComponent();
        _mainForm = mainForm;
        _manager  = manager;
        _manager.NotebookChange += (sender, e) => HandleNotebookChange(e);
        _contextMenuStrip.SetMenuAppearance();
        _toolStrip.SetMenuAppearance();
        _toolStrip.Padding   = new(this.Scaled(1), 0, 0, 0);
        _toolStrip.BackColor = SystemColors.Window;

        ImageList imageList = new() {
            ColorDepth = ColorDepth.Depth32Bit,
            ImageSize  = new(this.Scaled(16), this.Scaled(16)),
        };

        // Same order as the ICON_* constants.
        // ICON_PAGE
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.page, Resources.page32, dispose: false));
        // ICON_SCRIPT
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.script, Ui.ShiftImage(Resources.script32, 0, 1), dispose: false));
        // ICON_TABLE
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.table, Resources.table32, dispose: false));
        // ICON_VIEW
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.filter, Resources.filter32, dispose: false));
        // ICON_LINKED_TABLE
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.link, Resources.link32, dispose: false));
        // ICON_KEY
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.key, Resources.key32, dispose: false));
        // ICON_COLUMN
        imageList.Images.Add(Ui.GetScaledIcon(this, Resources.bullet_white, Resources.bullet_white32, dispose: false));

        _tree = new ExplorerTreeView {
            BorderStyle      = BorderStyle.None,
            ContextMenuStrip = _contextMenuStrip,
            Dock             = DockStyle.Fill,
            FullRowSelect    = true,
            LabelEdit        = true,
            ShowRootLines    = true,
        };
        _tree.ImageList             = imageList;
        _tree.TreeViewNodeSorter    = new ExplorerNodeComparer();
        _tree.AfterLabelEdit       += Tree_AfterLabelEdit;
        _tree.BeforeExpand         += Tree_BeforeExpand;
        _tree.BeforeLabelEdit      += Tree_BeforeLabelEdit;
        _tree.KeyDown              += Tree_KeyDown;
        _tree.NodeMouseClick       += Tree_NodeMouseClick;
        _tree.NodeMouseDoubleClick += Tree_NodeMouseDoubleClick;
        _tree.EnableDoubleBuffering();
        _toolStripContainer.ContentPanel.Controls.Add(_tree);

        Ui      ui             = new(this, false);
        Padding buttonPadding  = new(this.Scaled(2));
        var     newPageImage16 = Ui.SuperimposePlusSymbol(Resources.page);
        var     newPageImage32 = Ui.SuperimposePlusSymbol(Resources.page32);

        ui.Init(_toolbarNewPageButton, newPageImage16, newPageImage32);
        var newScriptImage16 = Ui.SuperimposePlusSymbol(Resources.script);
        var newScriptImage32 = Ui.SuperimposePlusSymbol(Ui.ShiftImage(Resources.script32, 0, 1));

        ui.Init(_toolbarNewScriptButton, newScriptImage16, newScriptImage32);

        _tree.GotFocus += (sender, e) => {
            _manager.CommitOpenEditors();
            _manager.Rescan(notebookItemsOnly: true);
        };
    }