예제 #1
0
    public ImportPreviewControl(DataTable table)
    {
        InitializeComponent();

        Controls.Add(_grid = DataGridViewUtil.NewDataGridView());
        _grid.Dock         = DockStyle.Fill;
        _grid.DataSource   = table;
        _grid.AutoSizeColumns(this.Scaled(500));

        Disposed += delegate {
            table.Dispose();
        };
    }
예제 #2
0
    public TableDocumentControl(NotebookManager manager, string tableName)
    {
        InitializeComponent();
        _manager   = manager;
        _tableName = tableName;
        _toolStrip.SetMenuAppearance();

        _grid      = DataGridViewUtil.NewDataGridView(contextMenu: true);
        _grid.Dock = DockStyle.Fill;
        _tablePanel.Controls.Add(_grid);

        Ui ui = new(this, false);

        ui.Init(_scriptBtn, Resources.script_go, Resources.script_go32);
    }
    public DatabaseImportCustomQueryForm(IImportSession session, string targetName, string sql)
    {
        InitializeComponent();
        _session = session;

        _sqlTextControl = new(false) { Dock = DockStyle.Fill };
        _sqlPanel.Controls.Add(_sqlTextControl);
        _sqlTextControl.SqlText = sql;

        _grid      = DataGridViewUtil.NewDataGridView();
        _grid.Dock = DockStyle.Fill;
        _previewPanel.Controls.Add(_grid);

        Ui ui = new(this, 120, 40);

        ui.Init(_table);
        ui.InitHeader(_importLabel);
        ui.Init(_importFlow);
        ui.Pad(_importFlow);
        ui.MarginBottom(_importFlow);
        ui.Init(_targetNameLabel);
        ui.Init(_targetNameText, 50);
        ui.Init(_splitter, 0.5);
        ui.Init(_sqlTable);
        ui.InitHeader(_sqlLabel);
        ui.Init(_previewToolStrip);
        ui.Init(_executeButton, Resources.ControlPlayBlue, Resources.control_play_blue32);
        ui.Init(_sqlPanel);
        ui.Init(_previewTable);
        ui.InitHeader(_previewLabel);
        ui.Init(_previewPanel);
        ui.Init(_buttonFlow);
        ui.MarginTop(_buttonFlow);
        ui.Init(_okButton);
        ui.Init(_cancelButton);

        _targetNameText.Text        = targetName;
        _sqlTextControl.F5KeyPress += delegate { Execute(); };
        Shown += delegate { _sqlTextControl.SqlFocus(); };
    }
예제 #4
0
    public DatabaseImportTablesForm(NotebookManager manager, IImportSession session)
    {
        InitializeComponent();
        _manager = manager;
        _session = session;

        _dataTable = GetTables(session);

        // Source grid
        _srcGrid = DataGridViewUtil.NewDataGridView(
            autoGenerateColumns: false, allowSort: false, userColors: false, columnHeadersVisible: false);
        _srcGrid.Dock            = DockStyle.Fill;
        _srcGrid.CellBorderStyle = DataGridViewCellBorderStyle.None;
        _srcGrid.SelectionMode   = DataGridViewSelectionMode.FullRowSelect;
        _srcPanel.Controls.Add(_srcGrid);
        DataGridViewTextBoxColumn srcNameColumn = new() {
            AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, DataPropertyName = "display_name"
        };

        _srcGrid.Columns.Add(srcNameColumn);
        _srcView                   = _dataTable.AsDataView();
        _srcView.RowFilter         = "to_be_imported = 0";
        _srcView.Sort              = "display_name";
        _srcGrid.DataSource        = _srcView;
        _srcGrid.SelectionChanged += SrcGrid_SelectionChanged;

        // Destination grid
        _dstGrid = DataGridViewUtil.NewDataGridView(
            autoGenerateColumns: false, allowSort: false, userColors: false, columnHeadersVisible: false);
        _dstGrid.Dock            = DockStyle.Fill;
        _dstGrid.CellBorderStyle = DataGridViewCellBorderStyle.None;
        _dstGrid.SelectionMode   = DataGridViewSelectionMode.FullRowSelect;
        _dstPanel.Controls.Add(_dstGrid);
        DataGridViewTextBoxColumn dstColumn = new() {
            AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, DataPropertyName = "display_name"
        };

        _dstGrid.Columns.Add(dstColumn);
        var dstView = _dataTable.AsDataView();

        dstView.RowFilter          = "to_be_imported = 1";
        dstView.Sort               = "display_name";
        _dstGrid.DataSource        = dstView;
        _dstGrid.SelectionChanged += DstGrid_SelectionChanged;

        EnableDisableButtons();

        Ui ui = new(this, 140, 35);

        ui.Init(_selectionTable);
        ui.InitHeader(_srcLabel);
        ui.Init(_srcToolStrip);
        ui.Init(_addQueryButton,
                Ui.SuperimposePlusSymbol(Resources.table), Ui.SuperimposePlusSymbol(Resources.table32));
        ui.MarginRight(_addQueryButton);
        ui.Init(_srcFilterText);
        _srcFilterText.TextBox.SetCueText("Search");
        ui.Init(_srcFilterClearButton, Resources.filter_clear, Resources.filter_clear32);
        ui.Init(_srcPanel);

        ui.InitHeader(_middleLabel);
        ui.Init(_selectionButtonsFlow);
        ui.Pad(_selectionButtonsFlow);
        ui.Init(_addButton);
        ui.Init(_removeButton);
        _addButton.AutoSize = false;
        _addButton.Size     = _removeButton.Size;

        ui.InitHeader(_dstLabel);
        ui.Init(_dstToolStrip);
        ui.Init(_editTableButton, Resources.table_edit, Resources.table_edit32);
        ui.Init(_dstPanel);

        ui.InitHeader(_methodLabel);
        ui.MarginTop(_methodLabel);
        ui.Init(_methodFlow);
        ui.Pad(_methodFlow);
        ui.Init(_methodCopyRad);
        ui.Init(_methodLinkRad);

        ui.Init(_buttonFlow2);
        ui.MarginTop(_buttonFlow2);
        ui.Init(_viewSqlButton);
        ui.Init(_buttonFlow);
        ui.MarginTop(_buttonFlow);
        ui.Init(_okBtn);
        ui.Init(_cancelBtn);
    }

    private void DstGrid_SelectionChanged(object sender, EventArgs e)
    {
        _editTableButton.Enabled = _dstGrid.SelectedRows.Count == 1;;
        _removeButton.Enabled    = _dstGrid.SelectedRows.Count > 0;
    }
예제 #5
0
    private void Log(string sql, ScriptOutput output)
    {
        var maxColWidth = Ui.XWidth(50, this);

        _outputFlow.SuspendLayout();
        while (_outputFlow.Controls.Count > MAX_HISTORY)
        {
            _outputFlow.Controls.RemoveAt(0);
        }

        if (!string.IsNullOrWhiteSpace(sql))
        {
            Label label = new() {
                AutoSize = true,
                Text     = sql,
                Margin   = _outputSqlMargin,
                Cursor   = Cursors.Hand,
            };

            void OptionsUpdated()
            {
                var opt = UserOptions.Instance;

                label.Font = opt.GetCodeFont();
                var colors = opt.GetColors();

                label.BackColor = colors[UserOptionsColor.GRID_BACKGROUND];
                label.ForeColor = colors[UserOptionsColor.GRID_PLAIN];
            }

            OptionsUpdated();
            UserOptions.OnUpdate(label, OptionsUpdated);

            label.MouseUp += (sender, e) => {
                if (e.Button == MouseButtons.Left)
                {
                    _inputText.SqlText = sql;
                    TakeFocus();
                }
            };
            _outputFlow.Controls.Add(label);
        }

        if ((output.TextOutput?.Count ?? 0) > 0)
        {
            var   text  = string.Join(Environment.NewLine, output.TextOutput);
            Label label = new() {
                AutoSize         = true,
                Text             = text,
                Margin           = _outputTableMargin,
                ContextMenuStrip = _contextMenuStrip
            };

            void OptionsUpdated()
            {
                var opt = UserOptions.Instance;

                label.Font = opt.GetDataTableFont();
                var colors = opt.GetColors();

                label.BackColor = colors[UserOptionsColor.GRID_BACKGROUND];
                label.ForeColor = colors[UserOptionsColor.GRID_PLAIN];
            }

            OptionsUpdated();
            UserOptions.OnUpdate(label, OptionsUpdated);

            _outputFlow.Controls.Add(label);
        }

        if (output.ScalarResult != null)
        {
            Label label = new() {
                AutoSize = true,
                Text     = output.ScalarResult.ToString(),
                Margin   = _outputTableMargin,
            };

            void OptionsUpdated()
            {
                var opt = UserOptions.Instance;

                label.Font = opt.GetDataTableFont();
                var colors = opt.GetColors();

                label.BackColor = colors[UserOptionsColor.GRID_BACKGROUND];
                label.ForeColor = colors[UserOptionsColor.GRID_PLAIN];
            };
            OptionsUpdated();
            UserOptions.OnUpdate(label, OptionsUpdated);

            _outputFlow.Controls.Add(label);
        }

        foreach (var simpleDataTable in output.DataTables)
        {
            Label label = new() {
                AutoSize = true,
                Text     = simpleDataTable.FullCount > MAX_GRID_ROWS
                    ? $"{simpleDataTable.FullCount:#,##0} row{(simpleDataTable.FullCount == 1 ? "" : "s")} ({MAX_GRID_ROWS:#,##0} shown)"
                    : $"{simpleDataTable.FullCount:#,##0} row{(simpleDataTable.FullCount == 1 ? "" : "s")}",
                Margin = _outputCountMargin,
            };

            void OptionsUpdated()
            {
                var opt = UserOptions.Instance;

                label.Font = opt.GetDataTableFont();
                var colors = opt.GetColors();

                label.BackColor = colors[UserOptionsColor.GRID_BACKGROUND];
                label.ForeColor = colors[UserOptionsColor.GRID_PLAIN];
            };
            OptionsUpdated();
            UserOptions.OnUpdate(label, OptionsUpdated);

            _outputFlow.Controls.Add(label);

            var grid = DataGridViewUtil.NewDataGridView(allowColumnResize: false, allowSort: false);
            grid.Margin           = _outputTableMargin;
            grid.ContextMenuStrip = _contextMenuStrip;
            grid.ScrollBars       = ScrollBars.None;
            _outputFlow.Controls.Add(grid);
            grid.DataSource = simpleDataTable.ToDataTable(MAX_GRID_ROWS);
            grid.ClearSelection();

            // Why do I need BeginInvoke() for autosize to work properly?
            BeginInvoke(new Action(() => {
                grid.AutoSizeColumns(maxColWidth);
                grid.Size = new(
                    grid.Columns.OfType <DataGridViewColumn>().Sum(x => x.Width),
                    grid.ColumnHeadersHeight + grid.Rows.OfType <DataGridViewRow>().Sum(x => x.Height));
            }));
        }

        _outputFlow.Controls.Add(new Panel {
            Size     = _spacerSize,
            AutoSize = false
        });

        _outputFlow.ResumeLayout(true);

        if (_outputPanel.AutoScrollPosition.X != 0)
        {
            _outputPanel.AutoScrollPosition = new(0, _outputPanel.AutoScrollPosition.Y);
        }
        _outputPanel.ScrollControlIntoView(_outputFlow.Controls[_outputFlow.Controls.Count - 1]);
    }