VS2010 Report Designer : Formatting an int as (x)d, (y)h, (z)m in RDLC

北战南征 提交于 2019-12-12 02:50:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!