我有一份报告我在SSRS中建立。我有一个文本框,它使用报告底部的自定义代码(不在页脚中)。这是使用中的功能:
=Code.WinnerTextBox(First(Fields!WinnerName.Value, "FightDetails" ),First(Fields!Blue_Corner.Value, "Judge1"),First(Fields!Red_Corner.Value,"Judge1"),First(Fields!FightDecisionCode.Value, "FightDetails" ),First(Fields!DecisionTypeName.Value, "FightDetails" ),First(Fields!FightDecisionRoundNo.Value, "FightDetails" ), First(Fields!FightDecisionTime.Value,"FightDetails" ),First(Fields!SubmissionTypeName.Value, "FightDetails" ))
以下是使用中的自定义代码:
Public Class CalculateTotals
Dim public redTotal AS Integer
Dim public redRoundTotal AS Integer
Dim public blueTotal AS Integer
Dim public blueRoundTotal AS Integer
Public Function AddRedTotal(ByVal RedCornerDeduction AS Integer, ByVal RedCornerPoints AS Integer) AS Integer
redRoundTotal = RedCornerPoints - RedCornerDeduction
redTotal = redTotal + redRoundTotal
return redRoundTotal
End Function
Public Function GetFinalRed()
return redTotal
End Function
Public Function AddBlueTotal(ByVal BlueCornerDeduction AS Integer, ByVal BlueCornerPoints AS Integer) AS Integer
blueRoundTotal = blueCornerPoints - blueCornerDeduction
blueTotal = blueTotal + blueRoundTotal
return blueRoundTotal
End Function
Public Function GetFinalBlue()
return blueTotal
End Function
Public Function GetLeaderName(ByVal RedName AS String, ByVal BlueName AS String) AS String
IF GetFinalBlue() > GetFinalRed() Then
return BlueName
ElseIf GetFinalRed() > GetFinalBlue() Then
return RedName
ElseIf GetFinalRed() = GetFinalBlue() Then
return "Draw"
Else
return "Something is very wrong with the data"
End If
End Function
End Class
Dim Public Judge1 AS CalculateTotals = New CalculateTotals()
Dim Public Judge2 AS CalculateTotals = New CalculateTotals()
Dim Public Judge3 AS CalculateTotals = New CalculateTotals()
Dim Public red AS Integer
Dim Public blue AS Integer
Dim Public leader AS String
Public Function GetRed() AS Integer
red = Judge1.GetFinalRed() + Judge2.GetFinalRed() + Judge3.GetFinalRed()
return red
End Function
Public Function GetBlue() AS Integer
blue = Judge1.GetFinalBlue()+Judge2.GetFinalBlue()+Judge3.GetFinalBlue()
return blue
End Function
Public Function WinnerTextBox(ByVal Winner As String, ByVal BlueCorner As String, ByVal RedCorner As String, ByVal DecisionCode As Integer, ByVal DecisionType As String, ByVal DecisionRound As Integer, ByVal FightDecisionTime As String, ByVal SubmissionType As String) As String
Dim ReturnString As String
If (GetBlue() = GetRed()) Or (DecisionCode = 10) Or (DecisionCode = 11) Or (DecisionCode = 12) Then
ReturnString = "Draw: " & CStr(GetBlue()) & "-" & CStr(GetRed()) & " (" & DecisionType & ")"
ElseIf (Winner Is Nothing) Then
If (GetBlue() > GetRed()) Then
ReturnString = "Leader: " & BlueCorner & CStr(GetBlue()) & "-" & CStr(GetRed())
Else
ReturnString = "Leader: " & RedCorner & CStr(GetRed()) & "-" & CStr(GetBlue())
End If
ElseIf (DecisionCode = 1) Then
ReturnString = "Winner: " & Winner & " By " & DecisionType & " In Round " & CStr(DecisionRound) & " At " & FightDecisionTime
ElseIf (DecisionCode = 9) Then
ReturnString = "Winner: " & Winner & " By " & DecisionType & " " & SubmissionType & " In Round " & CStr(DecisionRound) & " At " & FightDecisionTime
ElseIf Winner = BlueCorner Then
ReturnString = "Winner (" & CStr(GetBlue()) & "-" & CStr(GetRed()) & "): " & Winner & " By " & DecisionType & " In Round " & CStr(DecisionRound) & " At " & FightDecisionTime
ElseIf Winner = RedCorner Then
ReturnString = "Winner (" & CStr(GetRed()) & "-" & CStr(GetBlue()) & "): " & Winner & " By " & DecisionType & " In Round " & CStr(DecisionRound) & " At " & FightDecisionTime
End If
Return ReturnString
现在,当报表运行时,它在屏幕上呈现绝对正确,但是当它导出为PDF或打印时,文本框会呈现以下文本:
平局:0-0(敲门)
这让我相信打印报告的过程导致自定义代码以某种方式再次尝试运行,并且没有数据,因此返回此信息。有没有办法防止这种情况发生?那是怎么回事?如果是这样,你能帮我理解为什么它会在打印时重新渲染吗?另外,有关如何正确打印的任何建议吗?
答案 0 :(得分:0)
刚出现类似问题(我认为)。我们运行了更简单的代码来获得运行总计。使用打印,打印预览或导出为PDF就像在Tablix上运行两次一样。我们的修复是创建另一个初始化函数。我会尝试这样的事情;
Public function Initialize()
redTotal = 0
redRoundTotal =0
blueTotal =0
blueRoundTotal =0
end function
出于我们的目的,我们必须在tablix中添加另一行,并将text = code.initialize放在新行的文本框中。我尝试将它放在整个页面上,在页眉和页脚中,到处都是,并且它唯一可以工作的地方是它是否位于使用运行总计的Tablix的最后。
如果你在文本框中使用这个代码,不知道在哪里放这个,也许有办法在同一个文本框中添加多个代码调用???