问题
I'm returning a int from my database which denotes time in minutes.
i.e. if the column's value is 10, it means 10 minutes. If it's 199, it means its 3 hours and 19 minutes.
I then group my results, and calculate a SUM(Fields!TotalTime.Value).
How can I format this int in the following format : (x)d, (y)h, (z)m, where
d = days
h = hours
m = minutes
using the built-in functions? Or, can I somehow write my own function, like a WPF Converter? Because I'm grouping in the report, I cannot return an already formatted value from the database.
回答1:
It is actually possible to do a custom converter.
When in report designer, right-click the report, and click report properties. Under the Code tab, you can specify code specifically being used in the report. Create your converter function there. In my case :
Public Function GenerateTimeString(ByVal minutes As Integer) As String
Dim returnString As String = ""
If minutes = 0 Then
returnString = "0m"
Else
Dim ts As TimeSpan = TimeSpan.FromMinutes(minutes)
If ts.Days <> 0 Then
returnString = returnString & ts.Days & "d,"
End If
returnString = returnString & ts.Hours & "d," & ts.Minutes & "m"
End If
Return returnString
End Function
Then, call it in your columns with :
=Code.GenerateTimeString(Sum(Fields!TotalTime.Value))
来源:https://stackoverflow.com/questions/9195521/vs2010-report-designer-formatting-an-int-as-xd-yh-zm-in-rdlc