namespace HStation.WinFrmUI
|
{
|
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
|
{
|
public XtraForm1()
|
{
|
InitializeComponent();
|
this.Load += Form1_Load;
|
}
|
|
private XtraReport1 _report1;
|
|
public void SetBindingData(SimulationPrintViewModel viewModel)
|
{
|
_report1 = new XtraReport1();
|
_report1.SetBingdingData(viewModel);
|
|
// 生成报表文档
|
_report1.CreateDocument();
|
// 将报表文档加载到 DocumentViewer 中
|
documentViewer1.DocumentSource = _report1;
|
}
|
|
private void Form1_Load(object sender, EventArgs e)
|
{
|
/* XtraReport1 report = new XtraReport1();
|
// 生成报表文档
|
report.CreateDocument();
|
|
// 将报表文档加载到 DocumentViewer 中
|
documentViewer1.DocumentSource = report;*/
|
}
|
|
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);
|
}
|
}
|
}
|
}
|
}
|