利用reporting services扩展开发报表,实现group的展开折叠功能
来源:互联网 发布:网络电视机排行榜 编辑:程序博客网 时间:2024/05/22 12:07
该功能的实现需要借助于reporting services的cache功能。当用户成功运行一个report后,该report就会被存储在server的cache中,直到用户的session结束才被自动清除。
1. 第一次运行report时,加载报表定义并获得该report的ExecutionID,并将其存储在session中
//load report definition
execInfo = res.LoadReportDefinition(rptDefinition, out warnings);
//store ExecutionID for later requests
Session[strExecutionID] = execInfo.ExecutionID;
2. 当点击报表上的加号或减号图标去展开折叠一个group时,将ToggleItemId并传给服务器。
a. 服务器用此前的ExecutionID获得在Cache的报表。
res.ExecutionHeaderValue.ExecutionID = (String)Session[strExecutionID];
b. 调用ToggleItem方法,告诉服务器要展开或折叠报表的哪个group。
resToggle = res.ToggleItem(strToggleItem);
c. 最后再调用Render方法并将报表输出到web页面
具体代码如下:
String strDevInfo = (strFormat == "HTML4.0" ? "<DeviceInfo><Toolbar>True</Toolbar><Section>0</Section><HTMLFragment>False</HTMLFragment></DeviceInfo>" : "");
String strExtension;
String strEncoding;
String strMimeType;
Warning[] warnings = null;
String[] strStreamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
ReportExecutionService res = new ReportExecutionService();
res.Credentials = System.Net.CredentialCache.DefaultCredentials;
res.Url = strRESUrl;
res.Timeout = System.Threading.Timeout.Infinite;
res.ExecutionHeaderValue = execHeader;
if ("" != strToggleItem && null != Session[strExecutionID])
{
res.ExecutionHeaderValue.ExecutionID = (String)Session[strExecutionID];
}
else
{
//load report definition
execInfo = res.LoadReportDefinition(rptDefinition, out warnings);
//store ExecutionID for later requests
Session[strExecutionID] = execInfo.ExecutionID;
}
Byte[] rptRefined = null;
Boolean resToggle = true;
try
{
if ("" != strToggleItem && null != Session[strExecutionID])
{
resToggle = res.ToggleItem(strToggleItem);
}
//execute the report
rptRefined = res.Render(strFormat, strDevInfo, out strExtension, out strMimeType, out strEncoding, out warnings, out strStreamIDs);
//flush any pending response
Response.Clear();
//set the HTTP headers for a HTML response
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
switch (strFormat)
{
case "PDF": HttpContext.Current.Response.ContentType = "application/pdf"; break;
case "EXCEL": HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; break;
case "Word": HttpContext.Current.Response.ContentType = "application/msword"; break;
default: HttpContext.Current.Response.ContentType = "text/html"; break;
}
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
//send the bytes array containing the report as a binary response
HttpContext.Current.Response.BinaryWrite(rptRefined);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
if (ex.Message != "Thread was being aborted.")
{
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "text/html";
HttpContext.Current.Response.Write("<html><body><h1>Error</h1><br><br>" + ex.Message + "</body></html>");
}
}
res.Dispose();
res = null;
附上获得ToggleItemID的js代码:
function js_showReport(evt, strId) {
var rptDiv = document.getElementById(strId);
rptDiv.getElementsByTagName("div")[0].style.display = "none";
rptDiv.getElementsByTagName("iframe")[0].style.display = "block";
var srcElem = window.event ? event.srcElement : evt.target;
if (window.event) {
srcElem.contentWindow.document.body.attachEvent("onmousedown", function(event) {
var AElem = event.srcElement;
while (AElem != null && (AElem.tagName != null && AElem.tagName.toUpperCase() != "A" || AElem.tagName == null)) {
AElem = AElem.parentNode;
}
if (AElem != null) {
if (AElem.href.indexOf("ShowHideToggle=") != -1) {
js_runReport(AElem.href.substr(AElem.href.indexOf("ShowHideToggle=") + 15), (strId == "divInStock" ? "InStock" : "InTransit"));
}
}
event.returnValue = false;
});
}
else {
srcElem.contentWindow.document.body.onmousedown = function(event) {
var AElem = event.target;
while (AElem != null && (AElem.tagName != null && AElem.tagName.toUpperCase() != "A" || AElem.tagName == null)) {
AElem = AElem.parentNode;
}
if (AElem != null) {
if (AElem.href.indexOf("ShowHideToggle=") != -1) {
js_runReport(AElem.href.substr(AElem.href.indexOf("ShowHideToggle=") + 15), (strId == "divInStock" ? "InStock" : "InTransit"));
}
}
event.returnValue = false;
}
}
}
- 利用reporting services扩展开发报表,实现group的展开折叠功能
- Reporting Services一个不错的报表工具
- 一个简单的 Reporting Services 报表示例
- jquery 实现列表点击折叠与展开的功能
- 利用 SQL Server Reporting Services 从应用程序生成用户友好的报表
- 利用 SQL Server Reporting Services 从应用程序生成用户友好的报表
- 利用 SQL Server Reporting Services 从应用程序生成用户友好的报表
- 利用 SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- 利用MS Reporting Services与C#生成报表
- 利用MS Reporting Services与C#生成报表
- 自己实现floatactionbutton展开折叠功能
- Java报表软件树形展开的折叠报表的制作
- PCA原理
- 在Eclipse 2.0中使用版本控制系统CVS
- C语言中的联合体union
- SQL Server删除用户时产生“数据库主体在该数据库中拥有架构,无法删除”的解决办法
- epoll的简单用法示例(程序还有bug,但只是为了示例epoll的用法就不改了)
- 利用reporting services扩展开发报表,实现group的展开折叠功能
- 请教
- 如何在spring框架中解决多数据源的问题
- Qt操作excel类
- MPEG2 TS小结
- VS2010正式版破解方法
- ConnectString
- ghost版xp如何安装IIs
- 使用union类型出现的程序结果不确定问题