SSRS使用自定义代码动态选择字段/列

时间:2016-02-15 08:20:00

标签: reporting-services ssrs-2012

根据报告参数,我想切换显示的字段。

e.g。正常的RS表达式看起来像这样

= IIF(Parameters!ReportTypesREPORTTYPEID.Label = 1, Fields!CLIENTGROUP.Value
, IIF(Parameters!ReportTypesREPORTTYPEID.Label = 2, Fields!COSTUNITNUMBER.Value
... etc.. 
)))

由于我需要在多个地方(以及多种变体)中使用此代码,因此我想将其移至.NET类库。

我已经使用基本设置来引用类函数:

using System;
using System.Security;
using System.Data.SqlClient;

namespace Reporting_RS_Lib
{
    public class Functions
    {
        public static int GetReportType(int reportTypeId)
        {
            if (reportTypeId == 0) // will be a case statment
            {
                return 1;
            }
            else {
                return 2;
            }
        }
    }
}

在if语句中,我想引用" Fields" -Collection并返回相应列的值。

我需要参考什么来实现上述目标?

1 个答案:

答案 0 :(得分:0)

让它在VB.NET中工作,但不在C#中工作。 (C#不允许我访问fields对象的方法..)

Imports Microsoft.ReportingServices.ReportProcessing.ReportObjectModel
' 
' Deployment 
' copy dll to C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\bin
' add the following to C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\rssrvpolicy.config
' 
'<CodeGroup
'           class="VBFuncs"
'           version="1"
'           PermissionSetName="FullTrust"
'           Name="VBFuncs"
'           Description="Reporting extensions.. ">
'          <IMembershipCondition
'               class="VBFuncs"
'               version="1"
'               Url="C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\bin\CIDB_Reporting_RS_LibVB.dll"
'       />
'   </CodeGroup>   


Public Class VBFuncs

    Public Function ByReportType(ByVal fieldCollection As Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Fields, ByVal reportTypeId As Integer) As Object
        Dim fieldName As String = "unkown"
        Dim value As String
        Try
            Select Case reportTypeId
                Case 1
                    fieldName = "Client_Group_ID"
                Case 2
                    fieldName = "Contract_Number"
                Case Else
                    fieldName = "Unkown"
            End Select
            value = fieldCollection(fieldName).Value
        Catch ex As Exception
            Return "Unkown/ or not found reportType " & reportTypeId & " " & fieldName
        End Try
        Return value
    End Function
End Class