2016-02-15 34 views
0

根据报告参数,我想切换显示的字段。SSRS dynamicaly使用自定义代码选择字段/列

例如一个正常的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语句,我想引用“字段” -Collection并返回相应列的值。

我需要参考什么来达到上述目的?

回答

0

得到它在VB.NET工作,但不是在C#中。 (C#不会让我访问字段对象的方法..)

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