【问题标题】:FastReport open source object data sourceFastReport 开源对象数据源
【发布时间】:2020-07-23 15:23:48
【问题描述】:

我尝试使用 FastReport 开源来根据我将提供给报告的数据构建报告。

我在演示中找到了我想要的 (https://github.com/FastReports/FastReport/tree/master/Demos/OpenSource/DataFromBusinessObject/DataFromBusinessObject)

在这个演示中,我在报告文件中看到使用了BusinessObjectDataSource,这似乎是我想要使用的。

但是,我看不到在社区设计器中添加此类源的方法。我需要手动添加所有这些吗?或者有没有办法生成所需的标记?我在他们的网站上找不到解决方案。

【问题讨论】:

    标签: fastreport


    【解决方案1】:

    我找到了一种方法,像这样手动制作所需的 xml:

    <BusinessObjectDataSource Name="Invoices" ReferenceName="Invoices" Enabled="true">
      <Column Name="Reference" DataType="System.String"/>
      <Column Name="Date" DataType="System.String"/>
      <Column Name="CompanyName" DataType="System.String"/>
      <Column Name="InvoiceEmail" DataType="System.String"/>
      <Column Name="VAT" DataType="System.String"/>
      <Column Name="Street" DataType="System.String"/>
      <Column Name="Number" DataType="System.String"/>
      <Column Name="City" DataType="System.String"/>
      <Column Name="ZipCode" DataType="System.String"/>
      <Column Name="Country" DataType="System.String"/>
      <Column Name="TotalPrice" DataType="System.Decimal"/>
      <Column Name="VATValue" DataType="System.Decimal"/>
      <Column Name="VATPercentage" DataType="System.Decimal"/>
      <Column Name="VATComment" DataType="System.String"/>
    </BusinessObjectDataSource>
    

    唯一的缺点是,如果我的对象发生变化,我需要更新它(但至少它正在工作!)

    【讨论】:

      【解决方案2】:

      我找到了一种方法来生成一个带有从业务对象生成的字段的空报告。 您只需创建一个空的报表对象,在其 Dictionary 属性上调用“RegisterBusinessObject()”,然后保存报表本身:

      var report = new Report();
      report.Dictionary.RegisterBusinessObject(
                    new List<Invoice>(), // a (empty) list of objects
                    "Invoices",          // name of dataset
                    2,                   // depth of navigation into properties
                    true                 // enable data source
             );
      report.save(@"invoiceReport.frx");
      

      如果您的对象发生更改,您仍然需要更新报告描述,但至少您不必手动编写代码!

      【讨论】:

      • 谢谢,下次我要报告的时候会检查这个:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多