10K*_*KY4 9 c# asp.net-mvc crystal-reports-2010
我在复选框列表中有多个Crystal Reports,因此用户可以同时打印/显示多个报表.
目前我正在使用会话传递reportdocument,但大多数时候会话值在分配给crystal报表之前被替换,因此多个报表包含相同的数据.我在每个循环上应用了3秒的延迟,但不是可靠的解决方案.此外,图像不会显示在报告中.
这有什么优雅的技巧吗?
要么
什么是Session变量的替代品?
jQuery的:
$.each(chkBoxarr, function (index, value) {
var w = window.open();
$.ajax({
type: "POST",
url: "PrintReports",
traditional: true,
data: { id: value},
datatype: "json",
success: function (data) {
w.document.write(data);
},
error: function () {
alert("Error");
}
});
});
Run Code Online (Sandbox Code Playgroud)
控制器:
public ActionResult PrintReports(id)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
HttpContext.Session["rpt"] = rpt;
return Redirect("~/Viewer.aspx");
}
Run Code Online (Sandbox Code Playgroud)
Viewer.aspx.cs
Page_Init(object sender, EventArgs e)
{
var rpt = System.Web.HttpContext.Current.Session["rpt"];
CrystalReportViewer1.ReportSource = (ReportDocument)rpt;
}
Run Code Online (Sandbox Code Playgroud)
JavaScript:
$.each(chkBoxarr, function (index, value) {
$.ajax({
url: "PrintReports",
type: 'GET',
data: { id: value},
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
if (data.success) {
var URL = 'Viewer.aspx?type=' + data.URL;
window.open(URL);
}
else {
alert(data.message);
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
控制器:
public ActionResult PrintReports(id)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
string guid = Guid.NewGuid().ToString();
Session[guid] = rpt;
return Json(new { success = true, URL = guid }, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
查看器.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ReportName = Request.QueryString["type"].ToString();
ReportDocument doc = new ReportDocument();
doc = (ReportDocument)Session[ReportName];
if (doc == null)
Response.Write("<H2>Nothing Found; No Report name found</H2>");
CrystalReportViewer1.ReportSource = doc;
}
Run Code Online (Sandbox Code Playgroud)
没有会话:
$.each(chkBoxarr, function (index, value) {
var URL = 'Viewer.aspx?id=' + value;
window.open(URL);
});
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rpt = new ReportDocument();
rpt.Load("~/ReportFileName.rpt");
CrystalReportViewer1.ReportSource = rpt;
}
Run Code Online (Sandbox Code Playgroud)
对于显示图像,在 Viewer.aspx 所在的文件夹中添加一个 aspx 文件 CrystalImageHandler.aspx。还添加
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
Run Code Online (Sandbox Code Playgroud)
在Weconfig中...版本号取决于您的crystalreport版本
| 归档时间: |
|
| 查看次数: |
1128 次 |
| 最近记录: |