大家好,好久没有做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);
        }
    }

 

 

 

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

 

 

 

 

 

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

版权声明:本文为alfred-cn原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/alfred-cn/p/SSRS.html