SSRS 动态 select field/column 使用自定义代码
SSRS dynamicaly select field/column using custom code
根据报告参数,我想切换显示的字段。
例如一个正常的 RS 表达式看起来像这样
= IIF(Parameters!ReportTypesREPORTTYPEID.Label = 1, Fields!CLIENTGROUP.Value
, IIF(Parameters!ReportTypesREPORTTYPEID.Label = 2, Fields!COSTUNITNUMBER.Value
... etc..
)))
因为我在多个地方(以及多个变体)需要此代码,所以我想将它移到 .NET class 库中。
我已经完成了引用 class 函数的基本设置:
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 和 return 相应列的值。
实现以上需要参考什么?
可以在 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
根据报告参数,我想切换显示的字段。
例如一个正常的 RS 表达式看起来像这样
= IIF(Parameters!ReportTypesREPORTTYPEID.Label = 1, Fields!CLIENTGROUP.Value
, IIF(Parameters!ReportTypesREPORTTYPEID.Label = 2, Fields!COSTUNITNUMBER.Value
... etc..
)))
因为我在多个地方(以及多个变体)需要此代码,所以我想将它移到 .NET class 库中。
我已经完成了引用 class 函数的基本设置:
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 和 return 相应列的值。
实现以上需要参考什么?
可以在 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