--- tags: DevExpress --- # DevExpress Report Develop * `Angular` [document-viewer-integration-in-angular](https://docs.devexpress.com/XtraReports/119430/web-reporting/javascript-reporting/angular/document-viewer/quick-start/document-viewer-integration-in-angular) https://docs.devexpress.com/XtraReports/400292/web-reporting/javascript-reporting/angular/document-viewer/quick-start/document-viewer-client-side-configuration-angular * `ASP.NET MVC` [document-viewer-server-side-configuration-asp-net-mvc](https://docs.devexpress.com/XtraReports/118597/web-reporting/javascript-reporting/server-side-configuration/document-viewer/document-viewer-server-side-configuration-asp-net-mvc) # Angular package.json ``` npm i ``` 安裝缺少的元件 ::: danger LNS專案有異動的DevExtreme CSS會被還原,因此要注意需要undo該變更 ::: ![](https://i.imgur.com/PWG1O5Z.png) # MVC Report Project # 注意事項 * 列印PDF文件時,中文無法顯示問題: :::warning 中文預設字形在PDF上無法顯示,改為正黑體即可 ::: ### 列印時間 * 若不需要即時更新,調整Running Band:GroupHeader1 * 預設的時間會隨報表換頁更新 ![](https://i.imgur.com/44Xjr47.png) ### 參數的排序 ```csharp= this.Parameters.AddRange(new DevExpress.XtraReports.Parameters.Parameter[] { this.accessUser, this.queryEndDate, this.daysInMonth}); ``` * 若出現此畫面,需調整參數設置,因未給參數數值關係 ![](https://i.imgur.com/AbzSy3E.png) ![](https://i.imgur.com/0B28PUn.png) ![](https://i.imgur.com/RFscUnW.png) ### 中文在PDF列印時消失了 * 將字型改成**微軟正黑體** Microsoft JhengHei (原本為Arial) ## 表頭重複作法 * 不同銀行 換頁顯示 * 表頭設定方式 ![](https://i.imgur.com/mejF1Ki.png) * 明細設定方式 ![](https://i.imgur.com/ehQAr19.png) * 標題列每頁重複顯示 * ![](https://i.imgur.com/wvTvRIo.png) * 表頭每頁重複顯示: 放在TopMargin中 ## SubReport Before Print * report code behind ```csharp= private void xrSubreport1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { //XtraReport reportSource = ((XRSubreport)sender).ReportSource; //var record = GetCurrentRow(); //((ObjectDataSource)reportSource.DataSource).DataMember = ""; //((ObjectDataSource)reportSource.DataSource).DataSource = record; //(Report.DataSource as ObjectDataSource).DataSource = recibo; XtraReport report = new XtraReport(); //XRSubreport subReport = report.FindControl("xrSubreport1", true) as XRSubreport; //XtraReport reportSource = subReport.ReportSource as XtraReport; //(reportSource.DataSource as ObjectDataSource).DataSource = recibo; } ``` * design code behind ```csharp= this.xrSubreport1.BeforePrint += new System.Drawing.Printing.PrintEventHandler(this.xrSubreport1_BeforePrint); ``` ## SubReport assign data source ```csharp= jsonDataSource.JsonSource = new CustomJsonSource(JsonConvert.SerializeObject(dataSource)); jsonDataSource.Fill(); var subReportControl = (XRSubreport)report.FindControl("xrSubreport1", true); if (subReportControl != null) { XtraReport subReport = subReportControl.ReportSource; subReport.DataSource = jsonDataSource; } ``` * 增加一個GroupFooter,level max+1 * ![](https://i.imgur.com/QC2aWFU.png) * 從ToolBox中拉一個XRSubreport控制項,並指定報表的來源 ![](https://i.imgur.com/DVvJcCy.png) * 屬性CanShrink設定為true,避免該頁超出父頁面範圍 * ![](https://i.imgur.com/VOO6nfI.png) # Error Handling 報表內容錯誤時,發出錯誤訊息,讓前端顯示 ## 前端 ### html ```htmlembedded= (OnServerError)="onServerError($event)" ``` ### ts ```typescript= onServerError(event){ console.log(event); this.message = event.args.Error.errorThrown; notify(this.message, 'error', 3000); } ``` ## 後端 * 新建一類別處理錯誤訊息 ```csharp= using System; using System.IO; using System.ServiceModel; using DevExpress.XtraReports.Web.WebDocumentViewer; namespace THS.ERP.LNS.Reports.Handler { public class CustomWebDocumentViewerExceptionHandler:WebDocumentViewerExceptionHandler { public override string GetExceptionMessage(Exception ex) { //return ex.GetType().Name + " occurred." + ex.Message; return ex.Message; } } } ``` * Global.asax Application_Start() ```csharp= DevExpress.XtraReports.Web.WebDocumentViewer.DefaultWebDocumentViewerContainer. Register<IWebDocumentViewerExceptionHandler, CustomWebDocumentViewerExceptionHandler>(); ```