报表绑定的时候有时候需要动态绑定json数据源,在实际应用中json API 数据绑定的方式引用的非常多,那么Activereports是如何进行动态json数据源绑定的了。下面我们就来进行一个实际的操作。
1.首先打开报表进行数据源的选择,选择 JsonProvider,然后进行数据源的绑定
2、进行数据集的绑定
3、进行报表的设计,设计好报表之后保存报表文件
4、进行代码的集成,后端修改正式的数据源的API接口,这块的实际业务场景就是能够根据能够根据客户的实际业务场景切换数据API接口
后端代码(Core)
- namespace WebCore001
- {
- public class Startup
- {
- public static string EmbeddedReportsPrefix = "WebCore001.Reports";
- string Path = "";
- // This method gets called by the runtime. Use this method to add services to the container.
- public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
- {
- string reportName = P;//报表名称;
- PageReport rep = new PageReport();
- rep.Load(new FileInfo(@"" + Path +"/"+ "Reports/" + reportName));
- //数据源连接字符串的修改
- string connect = "jsondoc=http://jsonplaceholder.typicode.com/comments/";
- rep.Report.DataSources[0].ConnectionProperties.ConnectString = connect;
- //rep.Report.DataSources[0].ConnectionProperties.ConnectString = connect;
- //数据集查询语句的修改
- return rep.Report;
- }
- public void ConfigureServices(IServiceCollection services)
- {
- services
- .AddLogging(config =>
- {
- // Disable the default logging configuration
- config.ClearProviders();
- // Enable logging for debug mode only
- if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development)
- {
- config.AddConsole();
- }
- })
- .AddReporting()
- .AddMvc(option => option.EnableEndpointRouting = false);
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- Path = env.ContentRootPath;
- app.UseReporting(settings =>
- {
- settings.UseCompression = true;
- //settings.UseFileStore(new DirectoryInfo(@"D:\Demo\JS-Viewer\WebCore001\WebCore001\Reports"));
- //settings.UseFileStore(new DirectoryInfo(String.Format(@"{0}.\Reports", path)));
- settings.UseCustomStore(GetReport);//使用该方法可以自定义进行属性的设置和调用
- settings.UseCompression = true;
- });
- app.UseMvc();
- }
-
- }
- }
复制代码 5、参考demo
|