private void Execute() { var sql = _inputText.SqlText.Trim(); if (string.IsNullOrWhiteSpace(sql)) { return; } using var output = WaitForm.GoWithCancel(TopLevelControl, "Console", "Executing...", out var success, cancel => { return(SqlUtil.WithCancellation(_manager.Notebook, () => { using var status = WaitStatus.StartRows("Script output"); return _manager.ExecuteScript(sql, onRow: status.IncrementRows); }, cancel)); }); _manager.SetDirty(); _manager.Rescan(); if (!success) { return; } _inputText.SqlText = ""; Log(sql, output); TakeFocus(); }
private void OkBtn_Click(object sender, EventArgs e) { string sql; try { sql = _session.GenerateSql(GetSelectedTables(), _methodLinkRad.Checked); } catch (Exception ex) { Ui.ShowError(this, "Error", ex); return; } var text = $"Importing from database..."; WaitForm.GoWithCancel(this, "Import", text, out var success, cancel => { SqlUtil.WithCancellableTransaction(_manager.Notebook, () => { _manager.ExecuteScript(sql); }, cancel); }); _manager.Rescan(); _manager.SetDirty(); if (!success) { return; } DialogResult = DialogResult.OK; Close(); }
private void SaveBtn_Click(object sender, EventArgs e) { if (_list.SelectedIndices.Count != 1) { return; } var lvi = _list.SelectedItems[0]; var type = (NotebookItemType)Enum.Parse(typeof(NotebookItemType), lvi.Group.Name); NotebookItem item = new(type, lvi.Text); using SaveFileDialog saveFileDialog = new() { AddExtension = true, AutoUpgradeEnabled = true, CheckPathExists = true, DefaultExt = ".csv", Filter = "CSV files|*.csv", OverwritePrompt = true, SupportMultiDottedExtensions = true, Title = "Save CSV As", ValidateNames = true }; if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { return; } var filePath = saveFileDialog.FileName; var typeKeyword = type switch { NotebookItemType.Script => "SCRIPT", NotebookItemType.Table => "TABLE", NotebookItemType.View => "TABLE", _ => throw new InvalidOperationException("Unrecognzied notebook item type.") }; var sql = $"EXPORT CSV {filePath.SingleQuote()} " + $"FROM {typeKeyword} {item.Name.DoubleQuote()} " + $"OPTIONS (TRUNCATE_EXISTING_FILE: 1);"; WaitForm.GoWithCancel(this, "Export", "Exporting to file...", out var success, cancel => { SqlUtil.WithCancellableTransaction(_manager.Notebook, () => { _manager.ExecuteScriptNoOutput(sql); }, cancel); }); _manager.Rescan(); _manager.SetDirty(); if (!success) { return; } Process.Start(new ProcessStartInfo { FileName = "explorer.exe", Arguments = $"/e, /select, \"{filePath}\"" }); Close(); }
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); }
private void Block_Dirty(object sender, EventArgs e) { _manager.SetDirty(); }