[AX]AX2012 从代码运行SSRS报表

在AX中SSRS除了从menu item运行,还可以从X++类运行,和AX3的runbasereport类类似,AX2012提供了SrsReportRunController、SrsReportDataContract、SrsReportRdlDataContract 、SrsReportDataContractUIBuilder、SrsPrintDestinationSettings 等类来运行SSRS报表,下面是一个运行vend.report报表结果保存到pdf文件的例子(转自http://axinternals.blogspot.com/2011/11/running-report-via-code-in-ax2012.html):

static void RunSSRSReport(Args _args)
{
    SrsReportRunController  reportRunController;
    Map                     queryContracts;
    MapEnumerator           mapEnum;
    Query                   query;
    QueryBuildRange         range;
    ;

    // Create the report run controller
    reportRunController = new SrsReportRunController();
    reportRunController.parmReportName('Vend.Report');
    reportRunController.parmLoadFromSysLastValue(false);

    // NB call to parmLoadFromSysLastValue must occur before any reference to
    // parmReportContract, otherwise the previous values (query ranges etc)
    // are defaulted in.

    // Set printer settings (print to file, format, filename, etc).
    reportRunController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    reportRunController.parmReportContract().parmPrintSettings().overwriteFile(true);
    reportRunController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    reportRunController.parmReportContract().parmPrintSettings().fileName('c:\\test.pdf');

    // Find/enumerate queries in the contract. The return from parmQueryContracts is
    // a map of type <ParameterName,Query(class)>

    queryContracts = reportRunController.parmReportContract().parmQueryContracts();
    mapEnum = queryContracts.getEnumerator();
    while(mapEnum.moveNext())
    {
        // Get the query and update the datasource as required
        query = mapEnum.currentValue();
        range = SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(VendTable)),fieldNum(VendTable,AccountNum));
        range.value('1*');
    }

    // Run the report
    reportRunController.runReport();

}

除了可以直接使用SrsReportRunController,AX也提供了很多它的扩展类,比如SrsPrintMgmtFormLetterController,从它扩展了类GiroPrintMgmtFormLetterController,而具体很多打印invoice的类比如SalesInvoiceController又继承自GiroPrintMgmtFormLetterController,使用这个类可以打印一组Invoice journal,具体如何使用可以参看系统自带的报表比如SalesInvoice。

微软就报表编程模型提供了一份白皮书,这里下载:http://www.microsoft.com/en-us/download/details.aspx?id=27725

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值