namespace HStation.WinFrmUI
|
{
|
public partial class SimulationCommonReportDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public SimulationCommonReportDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
}
|
|
private SimulationCommonReport _report1;
|
|
public void SetBindingData(SimulationPrintViewModel viewModel)
|
{
|
_report1 = new SimulationCommonReport();
|
_report1.SetBingdingData(viewModel);
|
|
// 生成报表文档
|
_report1.CreateDocument();
|
// 将报表文档加载到 DocumentViewer 中
|
documentViewer1.DocumentSource = _report1;
|
}
|
|
private void btnExportPDF_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
// 设置文件筛选器,只允许选择特定格式的文件
|
saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
|
saveFileDialog.Title = "选择保存路径";
|
|
// 显示对话框并获取用户选择的结果
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
{
|
string filePath = saveFileDialog.FileName;
|
|
try
|
{
|
_report1.ExportToPdf(filePath);
|
TipFormHelper.ShowSucceed("导出成功!");
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show($"导出报表时发生错误: {ex.Message}", "导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}
|
}
|
}
|
|
private void btnExportWord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
// 设置文件筛选器,只允许选择特定格式的文件
|
saveFileDialog.Filter = "Word Files (*.docx)|*.docx";
|
saveFileDialog.Title = "选择保存路径";
|
|
// 显示对话框并获取用户选择的结果
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
{
|
string filePath = saveFileDialog.FileName;
|
|
try
|
{
|
_report1.ExportToDocx(filePath);
|
TipFormHelper.ShowSucceed("导出成功!");
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show($"导出报表时发生错误: {ex.Message}", "导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}
|
}
|
}
|
}
|
}
|