gpt4 book ai didi

vb.net - 报表查看器 - 具有嵌套列表对象的对象

转载 作者:行者123 更新时间:2023-12-01 15:07:41 25 4
gpt4 key购买 nike

我有一个现有的类结构,希望/需要将其用作使用 vb 和 2005 的一系列报告的数据源,(尽管我们几乎准备好转移到 2010 年,所以如果这能解决这个问题今天搬家!)

使用 gotreportviewer sample对于嵌套对象,我添加了一个 reportmanager 类,公开了一个 getdata 方法,该方法填充了我的所有数据并返回了一个列表(对象)。数据在那里并且在数据绑定(bind)点是正确的,我可以添加和引用顶级属性,但是无论我尝试什么语法我都无法引用嵌套类/列表中的字段。我收到各种消息,从输出字段中的“#Error”到什么都没有,再到无法编译。

我的类结构大致是这样的简短形式:

Assembly0  
Class ReportManager
TheData as List(Of Object)
New() 'that populates TheData from the class structure below
GetData() as List(of Object)

Assembly1
Class Test
aProperty1 as String
aProperty2 as Int
aProperty3 as String
aProperty4 as String
aProperty4 as List(of aType1)

Assembly2
Class AaType1
aProperty1 as String
aProperty2 as Int
aProperty3 as String
aProperty4 as String
aProperty4 as List(of aType2)
aProperty4 as List(of aType3)
aProperty4 as String

Assembly3
Class aType2
aProperty1 as Boolean
aProperty1 as String
you get the idea

and so on.....

在我的主应用中

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
' Create an instance of our ReportManager Class
Try
' trust assemblies used in get data
ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(Assembly.GetExecutingAssembly().Evidence)
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("assy1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234")
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("assy2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234")
' etc through ALL dependant assemblies

' create datamanager, that will populate its TheData property
Dim reportMan As Data.Reporting.Manager = New Data.Reporting.Manager(18) ' test id sent

' this is the method from the gotreportviewer sample, which only allows you to reference top level properties, regardless of syntax used. i.e. =Fields!Prop.Value.SubProp
' doesnt work
'ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DummyDataSource", reportMan.GetData))
'Me.ReportingDataBindingSource.DataSource = reportMan.GetData


' this is the only method I have found that allows me to reference an objects nested property and its fields.....?
Data = reportMan.GetData()
Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Data_Reporting_ReportingData", Data))

' fortnatley there is only ever one test in the list, HOWEVER there will be 4 specimens and n stages below that and so on..
Dim SpecimenData As SpecimenList = Data(0).Specimens
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Tests_Specimen", SpecimenData))

' so this method is no good either. currently only a test its just returning the first specimen.
'Dim StageData As Tests.Stages = Data(0).Specimens(0).Stages
'Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Tests_Specimen", SpecimenData))

' render report
Me.ReportViewer1.RefreshReport()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

结束子

我在网上/谷歌上找到的修复:

  • 您必须添加“ExecuteReportInCurrentAppDomain”,这样做没有区别。

  • 你必须添加程序集:AllowPartiallyTrustedCallers() 到 AssemblyInfo.vb,没有区别。

  • 你必须强烈命名你的依赖程序集,这样做并且它确实摆脱了关于在报告的“代码”属性中进行的调用的错误(用于本地化)。

  • 已尝试 =Fields!Property.Value.SubProperty 语法,但它不起作用!无论我尝试什么变化。

    ' 在 rdlc 中 - 此语法适用于顶级属性
    =Sum(Fields!TestVersion.Value, "Data_Reporting_ReportingData")

    ' 在上面的代码中使用替代方法列表是可行的
    =First(Fields!Index.Value, "Tests_Specimen")

    ' 但这些不是它的子属性
    =First(Fields!Specimens.Value.Index, "Data_Reporting_ReportingData")
    =Fields!Specimens.Value.Index
    =Fields!Specimens.Value.Index.Value

    这是否意味着我别无选择,只能创建类似Dim SpecimenData As Tests.SpecimenList = Data(0).Specimens 每个嵌套对象?同样出于明显的原因,我宁愿不必展平整个数据结构,因为它很大。

我已经尝试了所有我能找到的关于这个的东西,没有太多东西,所有东西都指向同样的三四篇文章/博客帖子,这些文章/博客帖子对我不起作用,他们的样本未经修改就可以工作,但是当适用于嵌套列表或继承列表类型的嵌套对象。

有没有人有使用带有嵌套列表的对象的实际工作的示例代码?因为除了最简单的场景之外,我找不到任何在线工作。即一个程序集或一个代码文件或无嵌套列表或简单/ native 类型。

这是我一周中最精彩的部分!我现在秃顶,压力很大,请帮忙。

没有人能推荐一个支持这种东西的第三方供应商吗? Crystal 吗?鹅卵石?

为文字墙道歉...马特玛

最佳答案

我正在寻找几乎相同的东西,除了我有具有其他对象属性的对象,没有对象列表,无论如何,你问过 Crystal Reports 是否做这种事情,是的,它做,做起来有点困难,但确实如此。

我不知道为什么现在很难用这种想法工作。因为我们一直在使用持久性框架,比如 Entity Framework 和其他框架,所以,你用持久性做一个 hell 般的工作,当你去报告时,如果你想轻松工作,你需要回到你的数据库模型! 太浪费时间了!

我刚刚发现,可以在报表查看器中执行此操作,但它在 visual studio 2010 中有问题,它已在 SP1 中修复,但您需要设置所有用作可序列化的嵌套对象

请阅读:http://wraithnath.blogspot.com.br/2011/04/reportviewer-object-datasource-nested.html

关于vb.net - 报表查看器 - 具有嵌套列表对象的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3118737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com