Exemplo n.º 1
0
    private void LoadPage()
    {
        try {
            var index = 1; // Start at 1 because the top divider is already in place.

            var pageRecord = (PageNotebookItemRecord)_manager.GetItemData(ItemName);
            if (pageRecord.Blocks.Count == 0)
            {
                // Empty page. By default let's add a query.
                QueryBlockControl queryBlock = new(_manager);
                InsertBlock(queryBlock, index++);

                DividerBlockControl bottomDivider = new();
                bottomDivider.AddBlock += Divider_AddPart;
                InsertBlock(bottomDivider, index++);

                queryBlock.StartEditing();
                BeginInvoke(new Action(() => {
                    queryBlock.QueryControl.TextControl.SqlFocus();
                }));

                return;
            }

            foreach (var block in pageRecord.Blocks)
            {
                BlockControl blockControl;
                switch (block)
                {
                case TextPageBlockRecord textBlock:
                    TextBlockControl textBlockControl = new();
                    textBlockControl.LoadFromRecord(textBlock);
                    blockControl = textBlockControl;
                    break;

                case QueryPageBlockRecord queryBlock:
                    QueryBlockControl queryBlockControl = new(_manager);
                    queryBlockControl.LoadFromRecord(queryBlock);
                    blockControl = queryBlockControl;
                    break;

                default:
                    throw new NotImplementedException();
                }

                InsertBlock(blockControl, index++);

                DividerBlockControl bottomDivider = new();
                bottomDivider.AddBlock += Divider_AddPart;
                InsertBlock(bottomDivider, index++);
            }

            OnSizeChanged(EventArgs.Empty);
        } catch (Exception ex) {
            Ui.ShowError(TopLevelControl, "Page Error", ex);
        }
    }
Exemplo n.º 2
0
    public QueryDocumentControl(string name, NotebookManager manager, IWin32Window mainForm)
    {
        InitializeComponent();
        ItemName = name;
        _manager = manager;

        var record = _manager.GetItemData(ItemName) as ScriptNotebookItemRecord;

        _queryControl      = new(manager, isPageContext : false, initialText : record?.Sql ?? "");
        _queryControl.Dock = DockStyle.Fill;
        _queryControl.TextControl.SqlTextChanged += (sender2, e2) => _manager.SetDirty();
        Controls.Add(_queryControl);
    }