• AX2012/D365 SSRS报表开发


    以下3种报表的实现方式供大家参考。

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

    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);
            }
        }

    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("BoxQty"))
        ]
        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();
            }
        }
    }

     

     

     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();

  • 相关阅读:
    在jQuery中.bind() .live() .delegate() .on()的区别
    jquery小结测试题
    揭秘子类构造函数执行过程
    过滤器
    实现AJAX的基本步骤
    AJAX 原生态
    java工程师需要学什么
    Java进阶之路
    git入门大全
    轻松学JVM
  • 原文地址:https://www.cnblogs.com/alfred-cn/p/SSRS.html
Copyright © 2020-2023  润新知