private void ExportWindow_Load(object sender, EventArgs e) { IQueryBatchProvider batchProvider = _services.HostWindow.ActiveChildForm as IQueryBatchProvider; if (batchProvider != null && batchProvider.Batch != null) { if (batchProvider.Batch.Queries.Count > 1) { BatchQuerySelectForm querySelectForm = new BatchQuerySelectForm(); querySelectForm.Fill(batchProvider.Batch); querySelectForm.ShowDialog(); if (querySelectForm.DialogResult == DialogResult.OK) { _dsExecutedData = querySelectForm.SelectedQuery.Result; } else { Close(); // user calncelled } return; } if (batchProvider.Batch.Queries.Count == 1) { _dsExecutedData = batchProvider.Batch.Queries[0].Result; return; } } MessageBox.Show("Couldn't find a result window, run a query or view a table to export the data."); Close(); }
/// <summary>Execute the command.</summary> public override void Execute() { IQueryBatchProvider batchProvider = HostWindow.ActiveChildForm as IQueryBatchProvider; if (batchProvider == null) { HostWindow.DisplaySimpleMessageBox(null, "No results to save as a 'DataSet'.", "Save Results as DataSet XML Error"); } else { DataSet ds = null; if (batchProvider.Batch != null) { if (batchProvider.Batch.Queries.Count > 1) { BatchQuerySelectForm querySelectForm = Services.Resolve <BatchQuerySelectForm>(); querySelectForm.Fill(batchProvider.Batch); querySelectForm.ShowDialog(); if (querySelectForm.DialogResult == DialogResult.OK) { ds = querySelectForm.SelectedQuery.Result; } } else if (batchProvider.Batch.Queries.Count == 1) { ds = batchProvider.Batch.Queries[0].Result; } } if (ds == null) { return; } using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Title = "Save Results as DataSet XML"; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); saveFileDialog.Filter = Properties.Settings.Default.XmlFileDialogFilter; if (saveFileDialog.ShowDialog(HostWindow.Instance) == DialogResult.OK) { ds.WriteXml(saveFileDialog.FileName, XmlWriteMode.WriteSchema); string msg = string.Format("Saved results to file: '{0}'", saveFileDialog.FileName); HostWindow.SetStatus(HostWindow.ActiveChildForm, msg); } } } }