gpt4 book ai didi

reporting-services - 报告服务 : Business object data source with parent-child-grandchild

转载 作者:行者123 更新时间:2023-12-04 07:56:06 26 4
gpt4 key购买 nike

如何使用 POCO/自定义业务对象创建具有父子孙关系的报表?

public class Invoice
{
public List<Account> Accounts { get; set; }
}

public class Account
{
public List<LineItem> LineItems { get; set; }
}

public void GenerateReport()
{
var localReport = new LocalReport();
localReport.LoadReportDefinition(GetEmbeddedResource("Invoice.rdlc"));
localReport.DataSources.Add(new ReportDataSource("InvoiceDataset", new List<Invoice> { invoices }));
}

最好在子报表上使用表和列表控件。具有本地处理功能的 Reporting Services v10(.rdlc 文件)。

最佳答案

发票.rdlc

  • 添加名为 InvoiceDataset 的数据集(从报告数据工具窗口)
  • 添加一个列表控件(因为报表必须绑定(bind)到发票列表,即使该列表将只包含一个元素)
  • 在列表控件中添加发票级别字段,如客户名称
  • 在 List 控件中添加一个指向 Account.rdlc 的 Subreport 控件,其名称为“Account”,参数为 InvoiceId

  • Account.rdlc
  • 添加名为 AccountDataset 的数据集(来自“报告数据”工具窗口)
  • 添加 InvoiceId 参数以匹配 Invoice.rdlc 子报表控件中指定的参数
  • 添加列表控件
  • 在 List 控件中添加 Account-level 字段,例如 Account Number
  • 在 List 控件中添加一个指向 LineItem.rdlc 的子报表,其中包含两个参数:InvoiceId 和 AccountId

  • LineItem.rdlc
  • 添加名为 LineItemDataset 的数据集(从报表数据工具窗口)
  • 添加 InvoiceId 和 AccountId 参数以匹配 Account.rdlc 子报表控件中指定的参数
  • 添加列表控件
  • 在列表控件中添加行项目级别的字段,如描述、数量、价格

  • 将此报告生成为 pdf 格式:
    public byte[] GenerateInvoicePdf(Invoice invoice)
    {
    var localReport = new LocalReport();

    localReport.LoadReportDefinition(GetEmbeddedResource("Invoice.rdlc"));
    localReport.LoadSubreportDefinition("Account", GetEmbeddedResource("Account.rdlc"));
    localReport.LoadSubreportDefinition("LineItem", GetEmbeddedResource("LineItem.rdlc"));
    var datasource = new List<Invoice> {invoice};
    localReport.DataSources.Add(new ReportDataSource("InvoiceDataset", datasource));
    localReport.SubreportProcessing +=
    (o, args) =>
    {
    if (args.ReportPath == "Account")
    {
    var invoiceId = long.Parse(args.Parameters["InvoiceId"].Values[0]);
    var invoice = datasource.First(x => x.InvoiceId == invoiceId);
    args.DataSources.Add(new ReportDataSource("AccountDataset", invoice.Accounts));
    }
    else if (args.ReportPath == "LineItem")
    {
    var invoiceId = long.Parse(args.Parameters["InvoiceId"].Values[0]);
    var accountId = long.Parse(args.Parameters["AccountId"].Values[0]);
    var invoice = datasource.First(x => x.InvoiceId == invoiceId);
    var account = invoice.Accounts.First(x => x.AccountId == accountId);
    args.DataSources.Add(new ReportDataSource("LineItemDataset", account.LineItems));
    }
    };
    return localReport.Render("pdf");
    }

    关于reporting-services - 报告服务 : Business object data source with parent-child-grandchild,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9269798/

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