Microsoft Dynamics 365 - SQL Server Reporting Services
SQL Server Reporting Services
简称为SSRS,是微软推出的用于创建、部署和管理报表
内容概述
本次记录的是D365(Microsoft Dynamics 365的简称)中报表开发的教程,在本文中,D365开发者可以学习到的是:
- 创建报表的基本流程;
- 设计报表的基本流程。
创建报表
创建报表首先需要创建一些辅助类用于提取用于展示的数据
报表数据提取与填充
用于数据提取需要最基本的三个类,分别以:Contract、Controller和DP结尾。
Contract类
在X++中,Contract类是一种数据结构,可以理解为Java语言中的实体类,在Contract类中包含各成员变量以及各变量的获取修改方法。在Java语言中,成员变量使用getter、setter获取设置方法;而在X++语言中,使用parm方法对成员变量进行获取与修改,代码类比如下:
public class Student
{
private String name;
private Integer age;
public Student() {}
public Student(String name, int age)
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}
以下为X++中Contract类的写法:
[DataContractAttribute]
public class StudentContract
{
str name;
int age;
[DataMemberAttribute]
public str parmName(str _name = name)
{
name = _name;
return name;
}
[DataMemberAttribute]
public int parmName(int _age = age)
{
age = _age;
return age;
}
}
Contract类在SSRS中用于传递打印报表的参数,这些参数在为报表提取数据时,过滤指定的数据。
Controller类
Controller类是报表功能的入口,在该类中会初始化报表打印相关信息,如:使用哪个报表、使用哪一个设计以及报表参数的选择信息,Controller类需要继承SrsReportRunController系统类,这是系统报表开发框架的一个关键类,后面或许会有一篇文章用于讲解该类,基本的Controller类的编写如下:
public class ReportExampleController extends SrsReportRunController implements BatchRetryable
{
public ReportExampleController construct()
{
return new ReportExampleController();
}
public static void main(Args _args)
{
ReportExampleController controller = ReportExampleController::construct();
/*
ExampleReport为用于打印的具体报表对象,Report为该对象的具体设计,一个报表对象可以拥有多个设计
*/
controller.parmReportName(ssrsReportStr(ExampleReport, Report));
controller.parmDialogCaption("@SYS323601"); //设置参数选择对话框的caption
controller.parmArgs(_args);
controller.startOperation(); //开始数据的提取与填充
}
[Hookable(false)]
public boolean isRetryable()
{
return true;
}
}
DP类
DP类中会为临时表插入用于打印的数据,临时表获得一条记录后,便会立即填充在报表上,DP类的基本写法如下:
临时表只能用于数据的临时存储,即每一条数据填充至报表上后,便需要clear清理一次数据
//ReportExampleTmp为用于提取数据的临时表
[
SRSReportParameterAttribute(classStr(ReportExampleTmp))
]
public class ReportExampleDP
{
ReportExampleContract contract;
[SRSReportDataSetAttribute(tableStr(ReportExampleTmp))]
public ReportExampleTmp getReportExampleTmp()
{
ReportExampleTmp reportExampleTmp;
select reportExampleTmp;
return reportExampleTmp;
}
public void processReport()
{
SalesTable salesTable;
contract = this.parmDataContract() as ReportExampleContract;
/*
此时的contract对象中已经得到了前台获取的所有用于过滤的数据,例如我们已经知道前台获取的值为SalesTable的SalesId,我们
可以通过contract的来得到
*/
SalesId salesId = contract.parmSalesId();
ttsbegin;
while select salesTable
where salesTable.SalesId = salesId
{
reportExampleTmp.clear(); //每一次插入新的记录前,清空临时表数据
reportExampleTmp.field1 = salesTable.filed1;
//......这里将过滤好的SalesTable的相关数据插入到临时表
reportExampleTmp.insert(); //复制结束后,插入数据库
}
ttscommit;
/*
ttsbegin;
ttscommit;
即数据库中的事务,在这两行代码中的一切操作均作为一个事务
*/
}
}
ActionMenuItem
创建相应的MenuItem,关联对应的Controller类,将其放至于需求指定的菜单路径下。
更新日志
内容随时会更新:
2022年8月30日 第一版
浙公网安备 33010602011771号