public ImportColumnsControl()
        {
            InitializeComponent();

            _table = new DataTable();
            _table.Columns.Add(GridColumn.SourceName, typeof(string));
            _table.Columns.Add(GridColumn.TargetName, typeof(string));
            _table.Columns.Add(GridColumn.Conversion, typeof(string));
            _grid.AutoGenerateColumns = false;
            _grid.DataSource          = _table;
            _grid.CellValueChanged   += (sender, e) => Change.Notify();
            _grid.ApplyOneClickComboBoxFix();
            _grid.EnableDoubleBuffering();

            Bind.OnChange(new Slot[] { Change },
                          (sender, e) => ValidateGridInput());
        }
Exemple #2
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);
        }