找回密码
 立即注册

QQ登录

只需一步,快速开始

KearneyKang 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2022-3-17 11:09  /   查看:1485  /  回复:0
报表绑定的时候有时候需要动态绑定json数据源,在实际应用中json API 数据绑定的方式引用的非常多,那么Activereports是如何进行动态json数据源绑定的了。下面我们就来进行一个实际的操作。
1.首先打开报表进行数据源的选择,选择 JsonProvider,然后进行数据源的绑定



2、进行数据集的绑定

3、进行报表的设计,设计好报表之后保存报表文件

4、进行代码的集成,后端修改正式的数据源的API接口,这块的实际业务场景就是能够根据能够根据客户的实际业务场景切换数据API接口
后端代码(Core)

  1. namespace WebCore001
  2. {
  3.     public class Startup
  4.     {
  5.         public static string EmbeddedReportsPrefix = "WebCore001.Reports";      
  6.         string Path = "";
  7.         // This method gets called by the runtime. Use this method to add services to the container.
  8.         public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
  9.         {
  10.             string reportName = P;//报表名称;                          
  11.             PageReport rep = new PageReport();   
  12.             rep.Load(new FileInfo(@"" + Path +"/"+ "Reports/" + reportName));
  13.             //数据源连接字符串的修改
  14.             string connect = "jsondoc=http://jsonplaceholder.typicode.com/comments/";
  15.             rep.Report.DataSources[0].ConnectionProperties.ConnectString = connect;
  16.             //rep.Report.DataSources[0].ConnectionProperties.ConnectString = connect;
  17.             //数据集查询语句的修改      
  18.             return rep.Report;
  19.         }
  20.         public void ConfigureServices(IServiceCollection services)
  21.         {
  22.             services
  23.                 .AddLogging(config =>
  24.                 {
  25.                     // Disable the default logging configuration
  26.                     config.ClearProviders();

  27.                     // Enable logging for debug mode only
  28.                     if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development)
  29.                     {
  30.                         config.AddConsole();
  31.                     }
  32.                 })
  33.                 .AddReporting()
  34.                 .AddMvc(option => option.EnableEndpointRouting = false);
  35.         }

  36.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  37.         public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  38.         {
  39.             if (env.IsDevelopment())
  40.             {
  41.                 app.UseDeveloperExceptionPage();
  42.             }
  43.             Path = env.ContentRootPath;
  44.             app.UseReporting(settings =>
  45.             {
  46.                 settings.UseCompression = true;

  47.                 //settings.UseFileStore(new DirectoryInfo(@"D:\Demo\JS-Viewer\WebCore001\WebCore001\Reports"));      
  48.                 //settings.UseFileStore(new DirectoryInfo(String.Format(@"{0}.\Reports", path)));
  49.                 settings.UseCustomStore(GetReport);//使用该方法可以自定义进行属性的设置和调用         
  50.                 settings.UseCompression = true;

  51.             });

  52.             app.UseMvc();
  53.         }
  54.       
  55.     }
  56. }
复制代码
5、参考demo



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部