[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

 

 

posted @ 2012-08-27 11:31  断水流  阅读(1287)  评论(0编辑  收藏  举报