Crystal Reprot provides a great convenience for our development report, but it cannot achieve data customization when Runtime is not perfect. But though we can't runtime custom data, we can also implement Runtime custom loading reports. To achieve a custom loading report, use the push mode report to generate. (I didn't tried it, which netizen wants to tell me :)) Review the operation of the push mode, in the step of generating the report, we choose a empty report. This time is generated in the solution (assuming this name), but we can also see a synonym of Report.cs in the program directory. This file is the key to our discussion. Let's take a look at what this file is. namespace WebApp_Crystal_Dynametic {using System; using System.ComponentModel; using CrystalDecisions.Shared; using CrystalDecisions.ReportSource; using CrystalDecisions.CrystalReports.Engine; public class Report: ReportClass {public Report () {} public override string ResourceName {get {return "Report . rpt ";}} ...
Will you see red highlights? When we push the data to the Report class How to bind the data to the appropriate report, it is based on this code! In this case, then if we can dynamically change its return value, you can dynamically load the report, let us try. Here is the code I have modified:
namespace WebApp_Crystal_Dynametic {using System; using System.ComponentModel; using CrystalDecisions.Shared; using CrystalDecisions.ReportSource; using CrystalDecisions.CrystalReports.Engine; public class Report: ReportClass {string resourcename = "Report.rpt"; public Report () {} public Override string resourceename {get {return resourceename;} set {resourceEName = value;}} ...
Ok, now we create a few different reports (all push mode), I added a few Button in the program, and different reports are loaded in different Button events, and the different data is pushed to the report. The program compiles run (Window Server 2003 VS.NET 2003).
This way we can add a new report file to the program without changing the source code without changing the source code.