• SSRS应用理解与实现


    SSRS应用与理解

    前言

    很多企业的管理系统,像ERP、CRM等,都会有统计报表或财务收据的部分。目前市面上应用的比较火的PC报表产品有FineReport、葡萄城、PowerBI,不过它们都是些成熟的可直接用的产品,今天介绍的是一套微软的报表服务以及工具SSRS(ReportingSerivces),它有很强的可扩展性,可以集成到自己的任何程序当中去,刚好我们公司用到了这项技术,所以写写自己的理解。

    什么叫SSRS

    官网定义:

    SQL Server Reporting Services (SSRS) 提供了一系列本地工具和服务,用于创建、部署和管理移动和分页报表。

    https://docs.microsoft.com/zh-cn/sql/reporting-services/create-deploy-and-manage-mobile-and-paginated-reports?view=sql-server-ver15)

    主要是工具和服务,说明产品本身已经很完善了,但我们可以基于它这一套做成自己的报表系统。

    SSRS成员介绍

    ReportBuilder

    报表生成器,可创建报表,连接报表服务器之后将报表上传至报表服务器数据库

    ReportViewer

    报表预览控件,支持本地模式和远程模式。项目引用后,根据所需要实现对应的属性方法后,控件统一执行渲染。

    SQL Server ReportingServices

    Windows服务,提供远程模式的报表渲染服务。在安装数据库功能中可勾选此项进行安装。SQL 2017及以后可以用独立工具安装此服务。

    Report Server Configuration Manager

    服务配置管理器,用来管理维护服务地址,端口,报表数据库等信息的操作界面工具。

    SSRS应用原理与架构

    1、报表生成器制作报表并通过ReportingService服务上传至报表服务器数据库。

    2、ReportViewer控件通过设置远程服务地址以及报表目录,参数,并通过ReportingServices服务从报表服务器数据库获取报表信息并执行。(或通过本地模式)

    ReportViewer控件使用方法

    前提是我们在项目中引用了Microsoft.ReportViewer.WebForms.dll 并在Aspx页面中定义了该控件

     <rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="386px" Width="1427px"></rsweb:ReportViewer>
    

    后台代码

      Microsoft.Reporting.WebForms.ReportViewer _ReportViewer;
     protected void Page_Load(object sender, EventArgs e)
     {
        _ReportViewer = this.ReportViewer1;
     }
    

    控件它本身有两种模式,一种是服务器模式,一种是本地模式。

    服务器模式需要依靠本地或服务器的ReportingServices服务,依赖服务进行报表的渲染。优点:耗服务端资源并且性能不错 缺点:部署复杂

    本地模式只需要用到控件本身,相关属性自己程序处理后赋值给控件即可。优点:部署简单,使用方便 缺点:大数据量的报表非常耗客户端浏览器的内存

      //服务器模式
      protected void Button2_Click(object sender, EventArgs e)
            {
                ReportViewer1.Reset();
                ReportViewer1.ProcessingMode = ProcessingMode.Remote;
                ReportViewer1.Visible = true;
    
                //引擎数据库中报表路径
                ReportViewer1.ServerReport.ReportPath = "/报表项目2/Report1";
    
                ReportViewer1.ServerReport.DisplayName = "示例报表";
                //ReportingService服务地址
                ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://wh-pc-tians66/ReportServer");
                //身份验证
                ReportViewer1.ShowCredentialPrompts = false;
                ReportViewer1.ServerReport.ReportServerCredentials = new MyCredentials("sa", "666666",null);
                //Export("EXCEL");
            }
    
        //本地模式
            protected void Button1_Click(object sender, EventArgs e)
            {
                    ReportViewer1.Reset();
                    ReportViewer1.ProcessingMode = ProcessingMode.Local;
                    ReportViewer1.Visible = true;
    
                    //报表预览指定以流的方式或路径方式
                    //ReportViewer1.LocalReport.LoadReportDefinition(stream);
                    ReportViewer1.LocalReport.ReportPath = @"F:\Demo\ReportViewer\rdl\Report1.rdl";
    
                    ReportViewer1.LocalReport.DisplayName = "示例报表";
                    ReportViewer1.LocalReport.DataSources.Clear();
    
    
                    //数据集结果
                    ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", GetDataTable()));
                    ReportViewer1.LocalReport.Refresh();
    
                    //Export("EXCEL");
                }
              
            }
    

    当页面加载完成或通过其他动作可以触发,ReportViewer的展示报表。

    报表文件解析

    通过制作器生成的报表,其本身是一种带了丰富的报表元素xml文件。微软定义为后缀名为RDL的XML文件,根据不同元素和节点构建完整报表文件。

    如:

    表格-Table

    矩形-Tablix

    文本框-Textbox

    单位-ReportUnitType

    可扩展部分

    本地模式:

    如果项目中只考虑本地模式,那么可扩展部分就是ReportViewer的控件集成,它也支持集成到.NET CORE项目中。并使用微软的ReportBuilder制作报表皆可,或自己操作XML文件生成简单报表。

    远程模式:

    如果项目中采用服务器模式,那么可扩展部分除了本地模式中的两部分外,还需要掌握自己程序与远程服务ReportingService进行交互的方法,它本身提供了Soap Api接口供调用。

    SOAP 在 Reporting Services 中的角色 - SQL Server Reporting Services (SSRS) |微软文档 (microsoft.com)

  • 相关阅读:
    ip地址查询python3小工具_V0.0.1
    安恒 堡垒机 明御®运维审计与风险控制系统 部署中遇到的问题
    zping ping包工具20180605.exe测试版
    zping ping包工具20180524.exe测试版
    XSS练习平台-XSS Challenges
    温暖而又美妙的语言
    无法连接仓库:Error performing git command: /usr/local/src/git-2.9.5 ls-remote -h https://gitee.com/skynetInfo/auto-webui HEAD
    jenkins安装方式及启动配置
    Can't open file '/opt/svn/path/db/txn-current-lock': Permission denied
    centos部署maven私服
  • 原文地址:https://www.cnblogs.com/morehappy/p/16160739.html
Copyright © 2020-2023  润新知