11/19/2023
创建
|
{
SmallImage = ImageResource.table_save;
}
/// <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);
}
}
}
}
}
}
|