AX2012/D365 SSRS报表开发
大家好,好久没有做SSRS报表了,近期刚好有做2张,就整理起来供初学者参考。
AX中SSRS报表开发的框架,父类非常多,这里跟大家简单分享2种比较常用的场景供大家使用。
1.简单的过滤字段,无特殊过滤lookup需要重载,只需要通过扩展类型实现下拉数据,无过滤条件信息联动需求;
即可以使用Contract直接作为参数,DP作为数据源,使用Controller进行调用。
以下代码为核心框架代码,边沿代码已拿掉。
临时表Tmp使用表类型:TempDB:
Controller类:
{
public static ProdCostAnalysisController construct()
{
return new ProdCostAnalysisController();
}
{
ProdCostAnalysisController controller = ProdCostAnalysisController::construct();
controller.parmReportName(ssrsReportStr(ProductionCostAnalysis, Report));
controller.parmArgs(_args);
controller.startOperation();
}
class ProdCostAnalysisContract
{
TransDate dateFrom;
TransDate dateTo;
TransDate parmDateFrom(TransDate _dateFrom = dateFrom)
{
dateFrom = _dateFrom;
}
TransDate parmDateTo(TransDate _dateTo = dateTo)
{
dateTo = _dateTo;
}
SRSReportParameterAttribute(classStr(ProdCostAnalysisContract)),
SRSReportQueryAttribute(queryStr(ProdCostAnalysis))
]
class ProdCostAnalysisDP extends SrsReportDataProviderPreProcessTempDB
{
ProdCostAnalysisTmp prodCostAnalysisTmp;
CostAnalysisCostGroupTmp costAnalysisCostGroupTmp;
BOMCostGroup bomCostGroup;
{
}
public ProdCostAnalysisTmp getProdCostAnalysisTmp()
{
select * from prodCostAnalysisTmp;
}
public CostAnalysisCostGroupTmp getCostAnalysisCostGroupTmp()
{
select * from costAnalysisCostGroupTmp;
}
{
ProdCostAnalysisContract rdpContract;
TransDate dateFrom;
TransDate dateTo;
dateFrom = rdpContract.parmDateFrom();
dateTo = rdpContract.parmDateTo();
QueryBuildDataSource qbds = query.dataSourceTable(tableNum(ProdTable));
QueryBuildRange qbr = qbds.addRange(fieldNum(ProdTable, SchedEnd));
QueryRun queryRun = new QueryRun(query);
{
ProdTable prodTable = queryRun.get(tableNum(ProdTable));
InventDim inventDim = queryRun.get(tableNum(InventDim));
this.createReportData(prodTable, inventDim);
}
}
2.报表查询条件需要重载下拉,需要有联动处理过滤条件;
即可以使用Contract作为参数,绑定UIUIBuilder类,DP作为数据源,使用Controller进行调用。
以下代码为核心框架代码,边沿代码已拿掉。
临时表Tmp使用表类型:TempDB:
Controller类:
{
PrintBarCodeContract contract;
{
PrintBarcodeController controller = new PrintBarcodeController();
controller.parmArgs(_args);
controller.parmReportName(ssrsReportStr(PrintBarCode, Report));
controller.parmShowDialog(true);
controller.startOperation();
}
{
if (!this.parmArgs())
{
throw error(strFmt(“@GLS221124”, this.parmReportName()));
}
super();
{
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;
ProdJournalBOM prodJournalBOM = this.parmArgs().record() as ProdJournalBOM;
contract = this.parmReportContract().parmRdpContract() as PrintBarCodeContract;
contract.parmSourceTableId(prodJournalBOM.TableId);
contract.parmSourceRecId(prodJournalBOM.RecId);
break;
}
}
}
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;
}
DataMemberAttribute(‘SourceTableId’),
SysOperationDisplayOrderAttribute(‘5’)
]
public TableId parmSourceTableId(TableId _sourceTableId = sourceTableId)
{
sourceTableId = _sourceTableId;
}
DataMemberAttribute(‘PackagingQty’),
SysOperationDisplayOrderAttribute(‘1’),
SysOperationLabelAttribute(literalStr(“@SYS50772”))
]
public Integer parmPackagingQty(Integer _packagingQty = packagingQty)
{
packagingQty = _packagingQty;
}
DataMemberAttribute(‘BoxQty’),
SysOperationDisplayOrderAttribute(‘2’),
SysOperationLabelAttribute(literalStr(“@KKC0338”))
]
public Integer parmBoxQty(Integer _boxQty = boxQty)
{
boxQty = _boxQty;
}
DataMemberAttribute(‘InnerQty’),
SysOperationDisplayOrderAttribute(‘3’),
SysOperationLabelAttribute(literalStr(“@SYS50777”))
]
public Integer parmInnerQty(Integer _innerQty = innerQty)
{
innerQty = _innerQty;
}
{
DialogField dialogpackagingQty;
DialogField dialogBoxQty;
DialogField dialogInnerQty, dialogTableId, dialogRecId;
PrintBarCodeContract contract;
WMSJournalTrans wmsJournalTrans;
{
contract = this.dataContractObject() as PrintBarCodeContract;
super();
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);
}
}
{
if (_dialogpackagingQty.modified() && _dialogpackagingQty.value())
{
dialogBoxQty.value(roundUp(wmsJournalTrans.qty / dialogpackagingQty.value(), 1));
}
if (!_dialogpackagingQty.value())
{
dialogBoxQty.value(0);
}
return true;
}
SRSReportParameterAttribute(classStr(PrintBarCodeContract))
]
class PrintBarCodeDP extends SrsReportDataProviderPreProcessTempDB
{
BarcodeTmp barCodePrintTmp;
PrintBarCodeContract contract;
public BarcodeTmp getBarcodeTmp()
{
select * from barCodePrintTmp;
}
public void processReport()
{
int i;
contract = this.parmDataContract() as PrintBarCodeContract;
{
WMSJournalTrans wmsJournalTrans;
where wmsJournalTrans.RecId == contract.parmSourceRecId();
{
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;
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();