public ImportPreviewForm(IImportSession session) { InitializeComponent(); // hide the "This file has a header row" checkbox for non-CSV sources _csvHeaderChk.Visible = false; _tablesGrp.Height += (_tablesGrp.Top - _csvHeaderChk.Top); _tablesGrp.Top = _csvHeaderChk.Top; // always copy instead of link for file sources if (session is IFileImportSession) { _methodGrp.Enabled = false; _methodCopyRad.Checked = true; } _sourceTableNames = session.TableNames; _targetTableNames = new List <string>(session.TableNames); foreach (var tableName in _sourceTableNames) { int index = _listBox.Items.Add(tableName); // if there's only one table, then check it. if there are multiple, then uncheck by default. _listBox.SetItemChecked(index, session.TableNames.Count == 1); } EnableDisableButtons(); }
public DatabaseConnectionForm(string title, DbConnectionStringBuilder builder, IImportSession session) { InitializeComponent(); _builder = builder; _session = session; Ui ui = new(this, 75, 30); ui.Init(_table); ui.Init(_tabs); ui.Init(_basicTable); ui.Pad(_basicTable); ui.Init(_addressLabel); ui.Init(_serverTxt); ui.Init(_databaseLabel); ui.MarginTop(_databaseLabel); ui.Init(_databaseTxt); ui.Init(_usernameLabel); ui.MarginTop(_usernameLabel); ui.Init(_usernameTxt); ui.Init(_passwordLabel); ui.MarginTop(_passwordLabel); ui.Init(_passwordTxt); ui.Init(_windowsAuthChk); ui.MarginTop(_windowsAuthChk); ui.Init(_propertyGrid); ui.Init(_buttonFlow1); ui.MarginTop(_buttonFlow1); ui.Init(_clearButton); ui.Init(_buttonFlow2); ui.MarginTop(_buttonFlow2); ui.Init(_okBtn); ui.Init(_cancelBtn); if (builder is not SqlConnectionStringBuilder) { _windowsAuthChk.Visible = false; } if (builder is MySqlConnectionStringBuilder) { _databaseLabel.Text = "&Schema name:"; } _propertyGrid.SelectedObject = builder; Text = title; UpdateBasicOptionsUi(_session.GetBasicOptions(builder)); // populate basic options with info from builder Load += delegate { _serverTxt.Select(); }; }
private static DataTable GetTables(IImportSession session) { DataTable dt = new(); dt.Columns.Add("source_table", typeof(SourceTable)); dt.Columns.Add("display_name", typeof(string)); dt.Columns.Add("to_be_imported", typeof(bool)); dt.BeginLoadData(); foreach (var(schema, table) in session.TableNames) { var sourceTable = SourceTable.FromTable(schema, table); dt.LoadDataRow(new object[] { sourceTable, sourceTable.DisplayText, false }, true); } dt.EndLoadData(); return(dt); }
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(); }; }
public object Deserialize(IImportSession session) { return Deserialize(); }
private async Task DoCommonImport(IImportSession session) { IReadOnlyList <ImportPreviewForm.SelectedTable> selectedTables = null; bool csvHasHeaderRow = false, copyData = false; using (var frm = new ImportPreviewForm(session)) { if (frm.ShowDialog(_owner) != DialogResult.OK) { return; } selectedTables = frm.SelectedTables; csvHasHeaderRow = frm.CsvHasHeaderRow; copyData = frm.CopyData; } var fileSession = session as IFileImportSession; var dbSession = session as IDatabaseImportSession; if (fileSession != null) { fileSession.FileHasHeaderRow = csvHasHeaderRow; } Action import = () => { _notebook.Invoke(() => { _notebook.Execute("BEGIN"); try { if (dbSession != null) { DoDatabaseImport(selectedTables, copyData, dbSession); } else if (fileSession != null) { DoDatabaseImport(selectedTables, fileSession); } else { throw new InvalidOperationException("Unexpected session type."); } _notebook.Execute("COMMIT"); session.AddToRecentlyUsed(); } catch { try { _notebook.Execute("ROLLBACK"); } catch { } throw; } }); }; _manager.PushStatus("Importing the selected tables..."); Exception exception = null; await Task.Run(() => { try { import(); } catch (Exception ex) { exception = ex; } }); _manager.PopStatus(); _manager.Rescan(); if (exception == null) { _manager.SetDirty(); } else { MessageForm.ShowError(_owner, "Import Error", "The import failed.", exception.Message); } }
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; }
public object Deserialize(IImportSession session) { System.Type t = System.Type.GetType(session.FullAssemblyTypeName); return ImportFileTSV.DeserializeItem(t, SerializedData); }