Multi-language report in C#

浪子不回头ぞ 提交于 2019-12-13 06:23:22

问题


I'm writing reporting application in C# (local reports). I've made report patterns (rdlc files) and now I'm trying to make them autotranslating due to localization of user. I've managed to make a single translation (translation of one field, but there are many of them) with resource file, but this requires parameter to every textbox I use in report :

ReportParameter p = new ReportParameter("Report1Parameter3", GlobalStrings.FieldText);
this.reportViewer1.LocalReport.SetParameters(p);

Is there any way to make it more "direct" than using additional parameter for every text field?


回答1:


I think you should put all field to your dataset, and process translate before bind data for every user.




回答2:


This has been the solution in my desktop application. Let's say you have a separate resource file stored in the same folder of your application and named Resources.dll created with a resx file named Reports.resx with Public access

Step 1

Set permissions for local report (this should be repeated after every reset)

<YourReportViewer>.LocalReport.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted))

Step 2

In your rdlc report add following code (under report properties or manually edit rdlc file adding the code under <Report>/<Code> tag)

Private Shared Resources As Type = Reflection.Assembly.LoadFile(IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources.dll")).GetType("Resources.Reports")

Default Public ReadOnly Property Item(name As String) As String
    Get
        Return Resources.GetProperty(name, Reflection.BindingFlags.Static Or Reflection.BindingFlags.Public).GetValue(Nothing).ToString()
    End Get
End Property

Step 3

In your report you can reference strings in resources using an expression like this:

=Code!<NameOfYourResource>


来源:https://stackoverflow.com/questions/19653228/multi-language-report-in-c-sharp

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