AX2012/D365 SSRS报表开发

时间:2022-09-24 23:03:58

大家好,好久没有做SSRS报表了,近期刚好有做2张,就整理起来供初学者参考。

AX中SSRS报表开发的框架,父类非常多,这里跟大家简单分享2种比较常用的场景供大家使用。

1.简单的过滤字段,无特殊过滤lookup需要重载,只需要通过扩展类型实现下拉数据,无过滤条件信息联动需求;

即可以使用Contract直接作为参数,DP作为数据源,使用Controller进行调用。

以下代码为核心框架代码,边沿代码已拿掉。

临时表Tmp使用表类型:TempDB:

Controller类:

class ProdCostAnalysisController extends SrsReportRunController
{
    public static ProdCostAnalysisController construct()
    {
        return new ProdCostAnalysisController();
    }
    public static void main(Args _args)
    {
        ProdCostAnalysisController controller = ProdCostAnalysisController::construct();
        controller.parmReportName(ssrsReportStr(ProductionCostAnalysis, Report));
        controller.parmArgs(_args);
        controller.startOperation();
    }
}
Contract类:
[DataContractAttribute]
class ProdCostAnalysisContract
{
    TransDate   dateFrom;
    TransDate   dateTo;
    [DataMemberAttribute('dateFrom')]
    TransDate parmDateFrom(TransDate _dateFrom = dateFrom)
    {
        dateFrom = _dateFrom;
        return dateFrom;
    }
    [DataMemberAttribute('dateTo')]
    TransDate parmDateTo(TransDate _dateTo = dateTo)
    {
        dateTo = _dateTo;
        return dateTo;
    }
}
DP类:
[
    SRSReportParameterAttribute(classStr(ProdCostAnalysisContract)),
    SRSReportQueryAttribute(queryStr(ProdCostAnalysis))
]
class ProdCostAnalysisDP extends SrsReportDataProviderPreProcessTempDB
{
    ProdCostAnalysisTmp             prodCostAnalysisTmp;
    CostAnalysisCostGroupTmp   costAnalysisCostGroupTmp;
    BOMCostGroup                       bomCostGroup;
    void createReportData(ProdTable _prodTable, InventDim _inventDim)
    {     
       
    }
    [SRSReportDataSetAttribute(tableStr(ProdCostAnalysisTmp))]
    public ProdCostAnalysisTmp getProdCostAnalysisTmp()
    {
        select * from prodCostAnalysisTmp;
        return prodCostAnalysisTmp;
    }
    [SRSReportDataSetAttribute(tableStr(CostAnalysisCostGroupTmp))]
    public CostAnalysisCostGroupTmp getCostAnalysisCostGroupTmp()
    {
        select * from costAnalysisCostGroupTmp;
        return costAnalysisCostGroupTmp;
    }
    public void processReport()
    {
        ProdCostAnalysisContract   rdpContract;
        TransDate                            dateFrom;
        TransDate                            dateTo;
        rdpContract  = this.parmDataContract();
        dateFrom     = rdpContract.parmDateFrom();
        dateTo         = rdpContract.parmDateTo();
        Query                   query   = this.parmQuery();
        QueryBuildDataSource    qbds    = query.dataSourceTable(tableNum(ProdTable));
        QueryBuildRange         qbr          = qbds.addRange(fieldNum(ProdTable, SchedEnd));
        qbr.value(SysQuery::range(dateFrom, dateTo));
        QueryRun    queryRun    = new QueryRun(query);
        while (queryRun.next())
        {
            ProdTable       prodTable       = queryRun.get(tableNum(ProdTable));
            InventDim       inventDim       = queryRun.get(tableNum(InventDim));
            this.createReportData(prodTable, inventDim);
        }
    }
AX2012/D365 SSRS报表开发

AX2012/D365 SSRS报表开发

2.报表查询条件需要重载下拉,需要有联动处理过滤条件;

即可以使用Contract作为参数,绑定UIUIBuilder类,DP作为数据源,使用Controller进行调用。

以下代码为核心框架代码,边沿代码已拿掉。

临时表Tmp使用表类型:TempDB:

Controller类:

class PrintBarcodeController extends SrsReportRunController
{
    PrintBarCodeContract   contract;
    static void main(Args _args)
    {
        PrintBarcodeController controller = new PrintBarcodeController();
        controller.parmArgs(_args);
        controller.parmReportName(ssrsReportStr(PrintBarCode, Report));
        controller.parmShowDialog(true);
        controller.startOperation();
    }
    public void prePromptModifyContract()
    {      
        if (!this.parmArgs())
        {
            throw error(strFmt("@GLS221124", this.parmReportName()));
        }
        super();
        if(this.parmArgs().dataset())
        {
            switch (this.parmArgs().dataset())
            {
                case tableNum(WMSJournalTrans):
                    WMSJournalTrans wmsJournalTrans     = this.parmArgs().record() as WMSJournalTrans;
                    contract = this.parmReportContract().parmRdpContract() as PrintBarCodeContract;
                    contract.parmSourceTableId(wmsJournalTrans.TableId);
                    contract.parmSourceRecId(wmsJournalTrans.RecId);
                    break;
                case tableNum(ProdJournalBOM):
                    ProdJournalBOM prodJournalBOM       = this.parmArgs().record() as ProdJournalBOM;
                    contract = this.parmReportContract().parmRdpContract() as PrintBarCodeContract;
                    contract.parmSourceTableId(prodJournalBOM.TableId);
                    contract.parmSourceRecId(prodJournalBOM.RecId);
                    break;
            } 
        }     
    }
}
Contract类:
[
     DataContractAttribute,
     SysOperationContractProcessingAttribute(classStr(PrintBarCodeUIBuilder), SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)
]
class PrintBarCodeContract
{
    TableId     sourceTableId;
    RecId       sourceRecId;
    Integer     packagingQty, boxQty, innerQty;
   
    [
        DataMemberAttribute('SourceRecId'),
        SysOperationDisplayOrderAttribute('4')
    ]
    public RecId parmSourceRecId(RecId _sourceRecId = sourceRecId)
    {
        sourceRecId = _sourceRecId;
        return sourceRecId;
    }
    [
        DataMemberAttribute('SourceTableId'),
        SysOperationDisplayOrderAttribute('5')
    ]
    public TableId parmSourceTableId(TableId _sourceTableId = sourceTableId)
    {
        sourceTableId = _sourceTableId;
        return sourceTableId;
    }
    [
        DataMemberAttribute('PackagingQty'),
        SysOperationDisplayOrderAttribute('1'),
        SysOperationLabelAttribute(literalStr("@SYS50772"))
    ]
    public Integer parmPackagingQty(Integer _packagingQty = packagingQty)
    {
        packagingQty = _packagingQty;
        return packagingQty;
    }
    [
        DataMemberAttribute('BoxQty'),
        SysOperationDisplayOrderAttribute('2'),
        SysOperationLabelAttribute(literalStr("@KKC0338"))
    ]
    public Integer parmBoxQty(Integer _boxQty = boxQty)
    {
        boxQty = _boxQty;
        return boxQty;
    }
    [
        DataMemberAttribute('InnerQty'),
        SysOperationDisplayOrderAttribute('3'),
        SysOperationLabelAttribute(literalStr("@SYS50777"))
    ]
    public Integer parmInnerQty(Integer _innerQty = innerQty)
    {
        innerQty = _innerQty;
        return innerQty;
    }
}
UIBuilder类:
public class PrintBarCodeUIBuilder extends SrsReportDataContractExtendUIBuilder_CN
{
    DialogField             dialogpackagingQty;
    DialogField             dialogBoxQty;
    DialogField             dialogInnerQty, dialogTableId, dialogRecId;
    PrintBarCodeContract    contract;
    WMSJournalTrans         wmsJournalTrans;
    public void postBuild()
    {
        contract = this.dataContractObject() as PrintBarCodeContract;
        super();
        dialogTableId   = this.bindInfo().getDialogField(contract, methodstr(PrintBarCodeContract, parmSourceTableId));
        dialogTableId.visible(false);
        dialogRecId     = this.bindInfo().getDialogField(contract, methodstr(PrintBarCodeContract, parmSourceRecId));
        dialogRecId.visible(false);
        dialogpackagingQty  = this.bindInfo().getDialogField(contract, methodstr(PrintBarCodeContract, parmPackagingQty));
        dialogBoxQty        = this.bindInfo().getDialogField(contract, methodstr(PrintBarCodeContract, parmBoxQty));
        dialogBoxQty.allowEdit(false);
        dialogBoxQty.value(0);
        dialogInnerQty      = this.bindInfo().getDialogField(contract, methodstr(PrintBarCodeContract, parmInnerQty));
        dialogpackagingQty.registerOverrideMethod(methodstr(FormIntControl, modified), methodstr(PrintBarCodeUIBuilder, packagingQtyModified), this);
       
        if (contract.parmSourceTableId() == tableNum(WMSJournalTrans))
        {
            dialogInnerQty.visible(false);
            select firstonly wmsJournalTrans
                where wmsJournalTrans.RecId == contract.parmSourceRecId();
            dialogpackagingQty.value(InventTable::find(wmsJournalTrans.itemId).TaxPackagingQty);
            if (wmsJournalTrans.qty &&
                dialogpackagingQty.value())
            {
                dialogBoxQty.value(roundUp(wmsJournalTrans.qty / dialogpackagingQty.value(), 1));
            }
        }
        if (contract.parmSourceTableId() == tableNum(ProdJournalBOM))
        {
            dialogpackagingQty.visible(false);
            dialogBoxQty.visible(false);
            ProdJournalBOM  prodJournalBOM = ProdJournalBOM::findRecId(contract.parmSourceRecId());
            dialogInnerQty.value(prodJournalBOM.BOMConsump);
        }  
    }
    public boolean packagingQtyModified(FormIntControl _dialogpackagingQty)
    {
        if (_dialogpackagingQty.modified() && _dialogpackagingQty.value())
        {
            dialogBoxQty.value(roundUp(wmsJournalTrans.qty / dialogpackagingQty.value(), 1));
        }
        if (!_dialogpackagingQty.value())
        {
            dialogBoxQty.value(0);
        }
        return true;
    }
}
DP类
[
    SRSReportParameterAttribute(classStr(PrintBarCodeContract))
]
    class PrintBarCodeDP extends SrsReportDataProviderPreProcessTempDB
{
    BarcodeTmp            barCodePrintTmp;
    PrintBarCodeContract  contract;
    [SRSReportDataSetAttribute('BarcodeTmp')]
    public BarcodeTmp getBarcodeTmp()
    {
        select  * from barCodePrintTmp;
        return  barCodePrintTmp;
    }
    [SysEntryPointAttribute]
    public void processReport()
    {
        int i;
        contract = this.parmDataContract() as PrintBarCodeContract;
        if (contract.parmSourceTableId() == tableNum(WMSJournalTrans))
        {
            WMSJournalTrans     wmsJournalTrans;
            select firstonly wmsJournalTrans
                where wmsJournalTrans.RecId == contract.parmSourceRecId();
            for (i = 1; i <= contract.parmBoxQty(); i ++)
            {
                Barcode     barcode     = Barcode::construct(BarcodeType::Code128);
                InventDim   inventDim   = wmsJournalTrans.inventDim();
                barcodePrintTmp.clear();
                barcodePrintTmp.linenum         = i;
                barcodePrintTmp.BarCode         = "*" + wmsJournalTrans.ItemId +"*";
                barcode.string(true, barcodePrintTmp.BarCode);
                barcode.encode();
                barcodePrintTmp.BarCodeString   = barcode.barcodeStr();
                barcodePrintTmp.InventBatchId   = inventDim.InventBatchId;
                barcodePrintTmp.InventSerialId  = inventDim.inventSerialId;
                barcodePrintTmp.InventColorId   = inventDim.InventColorId;
                if (barcodePrintTmp.InventColorId)
                {
                    barcodePrintTmp.ColorIdVisable = 1;
                }
                else
                {
                    barcodePrintTmp.ColorIdVisable = 0;
                }
                barcodePrintTmp.UnitId          = InventTableModule::find(wmsJournalTrans.itemId, ModuleInventPurchSales::Invent).UnitId;
                if ((wmsJournalTrans.qty mod contract.parmPackagingQty()) == 0)
                {
                    barcodePrintTmp.InnerBoxNum = contract.parmPackagingQty();
                }
                else
                {
                    barcodePrintTmp.InnerBoxNum = (i < contract.parmBoxQty()) ? contract.parmPackagingQty() : (wmsJournalTrans.qty mod contract.parmPackagingQty());
                }
                barcodePrintTmp.InnerBoxQtyUnitId = strFmt('%1 %2', int2Str(barcodePrintTmp.InnerBoxNum), barcodePrintTmp.UnitId);
                barcodePrintTmp.ItemName              = InventTable::find(wmsJournalTrans.itemId).itemName();
                barcodePrintTmp.ItemGroupName    = InventItemGroup::find(wmsJournalTrans.inventTable().itemGroupId()).Name;
                barcodePrintTmp.insert();
            }
        }
        if (contract.parmSourceTableId() == tableNum(ProdJournalBOM))
        {
            ProdJournalBOM  prodJournalBOM  = ProdJournalBOM::findRecId(contract.parmSourceRecId());
            Barcode         barcode          = Barcode::construct(BarcodeType::Code128);
            InventDim       inventDim      = prodJournalBOM.inventDim();
            barcodePrintTmp.clear();
            barcodePrintTmp.linenum           = 1;
            barcodePrintTmp.BarCode          = "*" + prodJournalBOM.ItemId +"*";
            barcode.string(true, barcodePrintTmp.BarCode);
            barcode.encode();
            barcodePrintTmp.BarCodeString = barcode.barcodeStr();
            barcodePrintTmp.InventBatchId   = inventDim.InventBatchId;
            barcodePrintTmp.InventSerialId   = inventDim.inventSerialId;
            barcodePrintTmp.InventColorId   = inventDim.InventColorId;
            if (barcodePrintTmp.InventColorId)
            {
                barcodePrintTmp.ColorIdVisable = 1;
            }
            else
            {
                barcodePrintTmp.ColorIdVisable = 0;
            }
            barcodePrintTmp.UnitId          = prodJournalBOM.BOMUnitId;
            barcodePrintTmp.InnerBoxNum     = contract.parmInnerQty();
            barcodePrintTmp.InnerBoxQtyUnitId = strFmt('%1 %2', int2Str(barcodePrintTmp.InnerBoxNum), barcodePrintTmp.UnitId);
            barcodePrintTmp.ItemName        = InventTable::find(prodJournalBOM.itemId).itemName();
            barcodePrintTmp.ItemGroupName   = InventItemGroup::find(prodJournalBOM.inventTable().itemGroupId()).Name;
            barcodePrintTmp.insert();
        }
    }
}
AX2012/D365 SSRS报表开发

AX2012/D365 SSRS报表开发

AX2012/D365 SSRS报表开发

 3.报表开发中经常需要多选传值,从Controller传值到DP类,这里也介绍一种简单的方法;

3.1在Controller类的方法prePromptModifyContract中加入如下代码:

SRSReportRunPermission          SRSRRPermission;

 SRSRRPermission = new SRSReportRunPermission();
 SRSRRPermission.assert();

 Contract.parmTmpTableDataRecId(SRSTmpTblMarshaller::sendTmpTblToDataProvider(BarCodeTmp));(合约类增加这个方法)

(

[
    DataMemberAttribute('TmpTblDataRecId')
]
public RecId parmTmpTableDataRecId(RecId _tmpTableDataRecId = tmpTableDataRecId)
{
    tmpTableDataRecId = _tmpTableDataRecId;
    return tmpTableDataRecId;
}

)
 SRSTmpTblMarshaller::sendTmpTblToDataProvider(BarCodeTmp);
 CodeAccessPermission::revertAssert();

3.2在DP类中加入如下代码获取数据对象集合:

new SRSReportRunPermission().assert();
BarCodeTmp = SRSTmpTblMarshaller::getTmpTbl(contract.parmTmpTableDataRecId());
SRSTmpTblMarshaller::deleteTmpTblData(contract.parmTmpTableDataRecId());
CodeAccessPermission::revertAssert();

AX2012/D365 SSRS报表开发的更多相关文章

  1. &lbrack;AX2012&rsqb;在SSRS报表中获取从Menuitem传入的记录

    在较早版本的AX中我们运行一个报表时会用到类RunBaseReport,从它扩展一个子类,再由它运行报表,一个典型的Axapta3中的例子: class ReportProdInfo extends ...

  2. SSRS 报表开发小技巧

    说明: 开发工具为: SQL Server Data Tools (英文版)     开发环境为: SQL Server 2012 (英文版) 一. 饼图数据外部显示 首先我们来看3张效果图:  内部 ...

  3. WIN8 Metro UI 风格下的微软报表开发与设计 Metro UI SSRS - BIWORK

    开篇介绍 作为 BI 系统前端展现的报表,其重要性不言而喻,我们对于一个好的报表的要求也无非主要包含以下几点: 1. 数据完整和正确,数据质量没有问题 2. 友好的清晰的界面,整洁美观,有得体的格式 ...

  4. 【Reporting Services 报表开发】— 交互式报表

    我们知道,界面是人与系统间的对话方式,当使用者面对的是冷冰冰的界面,不但会造成使用者对于系统的热情减低,也会因为不便而产生诸多抱怨.尤其像报表时企业内几乎每日都会使用到的工具,因此,如何让使用者可以再 ...

  5. &lbrack;AX2012 R3&rsqb;在SSRS报表中使用QR二维码

    AX2012是自带生成QR二维码的类,可以很方便的用在SSRS报表中,下面演示如何在RDP的报表中使用二维码,首先从定义临时表开始: 字段URL是要用于二维码的字符串,QrCode是container ...

  6. Dynamics AX 2012 R2 SSRS报表在VS2010中预览没有数据

    今天,Reinhard 在VS中制作SSRS报表,预览的时候发现显示不出数据. 仔细检查了数据处理环节和临时表里的数据,都发现没有问题. 用同事的账号登陆同样的开发环境,发现他的账号可以在VS中预览到 ...

  7. 【Reporting Services 报表开发】— 表达式

    一.常用的SSRS原始函数可以打开文本框的表达式中看到,如图1 图1 如下为SSRS中设计报表时常用的运算函数: 运算符/函数 说明 + 前后位数字则为加法,前后为字符串则为链接符号 - 数值减法 * ...

  8. &lbrack;译&rsqb;SSRS 报表版本控制

    问题 如今商务智能应用广泛,对我们的商业愈加重要. 对新报表和的各种需求不断攀升. 自 SQL Server 2008 R2的 Reporting Services (SSRS) 开始,微软视图为减轻 ...

  9. SSRS报表服务随笔&lpar;rdl报表服务&rpar;-创建一个简单的报表

    这段时间一直在敲rdl报表,在国内的不这么留在,在国外的话,还是挺流行的,国内的话,这方面的资料很少很少,也踏过不少坑 先从SSRS了解起,SSRS全称 SQL Server Reporting Se ...

随机推荐

  1. Java中的DatagramPacket与DatagramSocket的初步&lpar;转&rpar;

    1.基本概念: a.DatagramPacket与DatagramSocket位于java.net包中 b.DatagramPacket表示存放数据的数据报,DatagramSocket表示接受或发送 ...

  2. FMS之Multi-point publishing技术

    采用该技术,能large-scale你的直播系统,结构如图所示: A. Live Video B. Server 1 (New York City)  C. Server 2 (Chicago) an ...

  3. 原生JS实现全选,反选

    无样式,比较丑 <!DOCTYPE html><html><head><meta charset="UTF-8"><title ...

  4. Pandas的index属性

    我们在统计数据的长度或者个数,不用统计去专门获取数值,而是用index这个数据获取即可,DataFrame的index直接就是最前面的索引号,如果要统计列的个数,使用DataFrame.colums获 ...

  5. Eclipse&sol;MyEclipse连接Hadoop集群出现:Unable to &period;&period;&period; &period;&period;&period; org&period;apache&period;hadoop&period;security&period;AccessControlExceptiom&colon;Permission denied问题

    问题详细如下: 解决办法: <property> <name>dfs.premissions</name> <value>false</value ...

  6. ecahrt 扇形(半扇形)

    var data = [{ "name": "1", "value": 54 }, { "name": "2& ...

  7. LOG收集系统&lpar;一&rpar;:原日志至收集

    Date: 20140207Auth: Jin 设置一个LOG收集系统1. 收集原生(不解析,不压缩)的业务日志和WEB日志(NGINX,PHP)2. 提供给开发,测试直接阅读和下载 需求分析原生日志 ...

  8. Selenium2&plus;python自动化53-unittest批量执行(discover)【转载】

    前言 我们在写用例的时候,单个脚本的用例好执行,那么多个脚本的时候,如何批量执行呢?这时候就需要用到unittet里面的discover方法来加载用例了. 加载用例后,用unittest里面的Text ...

  9. FBX导入错误 :ImportFBX Errors&colon;

    原地址:http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html Unity3D吐槽1--FBX导入 Unity3d ...

  10. 利用python的numpy创建矩阵并对其赋值

    创建一个3X3的矩阵并对其赋值: x = numpy.array([[1,2,3],[4,5,6],[7,8,9]]) print x print x.shape 运行结果: [[ ] [ ] [ ] ...