From bb7165071ee890cfac760dbb15cd921e6f6e3096 Mon Sep 17 00:00:00 2001 From: duheng <2784771470@qq.com> Date: 星期三, 19 二月 2025 10:46:10 +0800 Subject: [PATCH] 报表优化 --- WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/13-print/99-test/XtraForm1.cs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 54 insertions(+), 4 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/13-print/99-test/XtraForm1.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/13-print/99-test/XtraForm1.cs index 3b42608..2d520e1 100644 --- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/13-print/99-test/XtraForm1.cs +++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/13-print/99-test/XtraForm1.cs @@ -8,15 +8,17 @@ this.Load += Form1_Load; } + private XtraReport1 _report1; + public void SetBindingData(SimulationPrintViewModel viewModel) { - XtraReport1 report = new XtraReport1(); - report.SetBingdingData(viewModel); + _report1 = new XtraReport1(); + _report1.SetBingdingData(viewModel); // 鐢熸垚鎶ヨ〃鏂囨。 - report.CreateDocument(); + _report1.CreateDocument(); // 灏嗘姤琛ㄦ枃妗e姞杞藉埌 DocumentViewer 涓� - documentViewer1.DocumentSource = report; + documentViewer1.DocumentSource = _report1; } private void Form1_Load(object sender, EventArgs e) @@ -28,5 +30,53 @@ // 灏嗘姤琛ㄦ枃妗e姞杞藉埌 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); + } + } + } } } \ No newline at end of file -- Gitblit v1.9.3