问题
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