Ejemplo n.º 1
0
        public ImportXlsBookForm(string filePath, DatabaseSchema schema, NotebookManager manager)
        {
            InitializeComponent();
            _filePath       = filePath;
            _databaseSchema = schema;
            _manager        = manager;

            _dockPanel = DockPanelUtil.CreateDockPanel();
            _dockPanel.DockLeftPortion = 300;
            _dockPanelContainer.Controls.Add(_dockPanel);

            _sheetsControl = new ImportXlsSheetsControl();
            {
                var dc = new UserControlDockContent("Workbook", _sheetsControl, DockAreas.DockLeft)
                {
                    CloseButtonVisible = false
                };
                dc.Show(_dockPanel, DockState.DockLeft);
            }

            _optionsControl = new ImportXlsSheetControl();
            {
                var dc = new UserControlDockContent("Worksheet", _optionsControl)
                {
                    CloseButtonVisible = false,
                    Icon = Properties.Resources.TableSheetIco
                };
                dc.Show(_dockPanel);
            }

            _sqlControl     = new SqlTextControl(readOnly: true);
            _sqlLoadControl = new LoadingContainerControl {
                ContainedControl = _sqlControl
            };
            {
                var dc = new UserControlDockContent("Import Script", _sqlLoadControl, DockAreas.DockBottom)
                {
                    CloseButtonVisible = false
                };
                dc.Show(_dockPanel, DockState.DockBottomAutoHide);
            }

            _outputPreviewControl     = new ImportPreviewControl();
            _outputPreviewLoadControl = new LoadingContainerControl {
                ContainedControl = _outputPreviewControl
            };
            {
                var dc = new UserControlDockContent("Preview", _outputPreviewLoadControl, DockAreas.DockBottom)
                {
                    CloseButtonVisible = false,
                    Icon = Properties.Resources.TableImportIco
                };
                dc.Show(_dockPanel, DockState.DockBottomAutoHide);
            }
        }
        public QueryDocumentControl(string name, NotebookManager manager, IWin32Window mainForm, Slot <bool> operationInProgress)
        {
            InitializeComponent();
            ItemName             = name;
            _manager             = manager;
            _notebook            = manager.Notebook;
            _mainForm            = mainForm;
            _operationInProgress = operationInProgress;
            _resultToolStrip.SetMenuAppearance();

            _grid.EnableDoubleBuffering();

            _textCtl = new SqlTextControl(false)
            {
                Dock    = DockStyle.Fill,
                Padding = new Padding(4, 0, 0, 0)
            };
            _sqlPanel.Controls.Add(_textCtl);

            // if this tool window has been pulled off into a floating window, then the MainForm's key handler won't
            // trigger on F5, so catch it here.
            _textCtl.Scintilla.KeyDown += async(sender, e) => {
                if (e.KeyCode == Keys.F5)
                {
                    await Execute();
                }
            };

            Load += (sender, e) => {
                string initialText = _manager.GetItemData(ItemName);
                if (initialText != null)
                {
                    _textCtl.SqlText = initialText;
                }

                _textCtl.SqlTextChanged += (sender2, e2) => _manager.SetDirty();

                ShowResult(0);
            };
        }
Ejemplo n.º 3
0
        }                                                      // the ultimate result of this forum

        public ImportCsvForm(string filePath, DatabaseSchema schema, NotebookManager manager)
        {
            InitializeComponent();
            _filePath       = filePath;
            _databaseSchema = schema;
            _manager        = manager;

            _dockPanel = new DockPanel {
                Dock          = DockStyle.Fill,
                DocumentStyle = DocumentStyle.DockingWindow,
                Theme         = new VS2012LightTheme {
                    ShowWindowListButton    = false,
                    ShowAutoHideButton      = false,
                    ForceActiveCaptionColor = true
                },
                DockTopPortion            = 0.5,
                AllowEndUserDocking       = false,
                AllowEndUserNestedDocking = false,
                ShowDocumentIcon          = true
            };
            _dockPanelContainer.Controls.Add(_dockPanel);

            _optionsControl = new ImportCsvOptionsControl(schema)
            {
                Dock = DockStyle.Fill
            };
            {
                var dc = new UserControlDockContent("Import Options", _optionsControl, DockAreas.DockTop)
                {
                    CloseButtonVisible = false
                };
                dc.Show(_dockPanel, DockState.DockTop);
            }

            _columnsControl = new ImportColumnsControl {
                Dock = DockStyle.Fill
            };
            _columnsLoadControl = new LoadingContainerControl {
                ContainedControl = _columnsControl
            };
            {
                var dc = new UserControlDockContent("Columns", _columnsLoadControl, DockAreas.Float | DockAreas.DockTop)
                {
                    CloseButtonVisible = false
                };
                dc.Show(_dockPanel, new Rectangle(-50000, -50000, 100, 100)); // hide brief flash of this floating window
                dc.DockHandler.FloatPane.DockTo(_dockPanel.DockWindows[DockState.DockTop]);
                dc.DockAreas = DockAreas.DockTop;
            }

            DockContent inputPreviewDc;

            _inputPreviewControl = new ImportTextFilePreviewControl {
                Dock = DockStyle.Fill
            };
            _inputPreviewLoadControl = new LoadingContainerControl {
                ContainedControl = _inputPreviewControl
            };
            {
                var dc = new UserControlDockContent("Original File", _inputPreviewLoadControl)
                {
                    CloseButton        = false,
                    CloseButtonVisible = false,
                    ControlBox         = false,
                    Icon = Properties.Resources.PageWhiteTextIco
                };
                dc.Show(_dockPanel);
                inputPreviewDc = dc;
            }

            _sqlControl = new SqlTextControl(readOnly: true)
            {
                Dock = DockStyle.Fill
            };
            _sqlLoadControl = new LoadingContainerControl {
                ContainedControl = _sqlControl
            };
            {
                var dc = new UserControlDockContent("Import Script", _sqlLoadControl)
                {
                    CloseButton        = false,
                    CloseButtonVisible = false,
                    ControlBox         = false,
                    Icon = Properties.Resources.ScriptIco
                };
                dc.Show(_dockPanel);
            }

            _outputPreviewControl = new ImportPreviewControl {
                Dock = DockStyle.Fill
            };
            _outputPreviewLoadControl = new LoadingContainerControl {
                ContainedControl = _outputPreviewControl
            };
            {
                var dc = new UserControlDockContent("Preview", _outputPreviewLoadControl)
                {
                    CloseButton        = false,
                    CloseButtonVisible = false,
                    ControlBox         = false,
                    Icon = Properties.Resources.TableImportIco
                };
                dc.Show(_dockPanel);
            }

            inputPreviewDc.Activate(); // select "Original File" tab initially

            Load += async(sender, e) => {
                ValidateOptions();
                await UpdateControls(inputChange : true);
            };

            var o = _optionsControl;

            Bind.OnChange(new Slot[] { o.TargetTableName },
                          async(sender, e) => {
                ValidateOptions();
                await UpdateControls(columnsChange: true);
            });
            Bind.OnChange(new Slot[] { o.FileEncoding },
                          async(sender, e) => await UpdateControls(inputChange: true));
            Bind.OnChange(new Slot[] { o.IfTableExists, o.SkipLines, o.HasColumnHeaders },
                          async(sender, e) => await UpdateControls(columnsChange: true));
            Bind.OnChange(new Slot[] { o.IfConversionFails, _columnsControl.Change, _optionsError, _columnsError,
                                       _inputPreviewError },
                          async(sender, e) => await UpdateScriptAndOutputPreview());
            Bind.BindAny(new[] { _columnsLoadControl.IsOverlayVisible, _inputPreviewLoadControl.IsOverlayVisible,
                                 _outputPreviewLoadControl.IsOverlayVisible, _sqlLoadControl.IsOverlayVisible },
                         x => _okBtn.Enabled = !x);

            Text = $"Import {Path.GetFileName(_filePath)}";
            o.TargetTableName.Value = Path.GetFileNameWithoutExtension(_filePath);
        }