ningshuxia
2025-03-24 7b8ae93d47186c442ff890a1a83d108f115924c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);
                }
            }
        }
    }
}