using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BusinessObjects.ReportEngine;
using CrystalDecisions.Enterprise;
using System.IO;
using System.Text.RegularExpressions;
/// <summary>
/// Class1 的摘要说明
/// </summary>
public class Class1
{
public delegate void SetPromptsHandler(IPrompts prompts);
public event SetPromptsHandler SetPrompt;
public Class1()
{ }
public string[] GetBOScript(int idocID, string user, string password, string cms, string auth)
{
string content = "";
string storageToken = "";
//
// TODO: 在此处添加构造函数逻辑
//
ReportEngines boReportEngines = null;
IDocumentInstance boIDocumentInstance = null;
int id = idocID;
//EnterpriseSession boEnterpriseSession = (EnterpriseSession)Session["EnterpriseSession"];
EnterpriseSession boEnterpriseSession = (new SessionMgr()).Logon(user, password, cms, auth);
boReportEngines = new ReportEngines(boEnterpriseSession.LogonTokenMgr.DefaultToken);
IReportEngine boIReportEngine = (IReportEngine)boReportEngines.getService(ReportEngineType.WI_ReportEngine);
boIDocumentInstance = boIReportEngine.OpenDocument(id);
boIDocumentInstance.Refresh();
// boIDocumentInstance.MustFillPassword not supported with RE.NET version when this sample created.
//if (boIDocumentInstance.MustFillPassword) {
// Session["ErrorMessage"] = "Context Prompts not supported in this sample.";
// Response.Redirect("ErrorPage.aspx");
//}
// Flag error for functionality not supported in this sample.
if (boIDocumentInstance.MustFillContextPrompts)
{
throw new Exception("111");
}
if (boIDocumentInstance.MustFillPrompts)
{
IPrompts prompts = boIDocumentInstance.GetPrompts();
this.SetPrompt(prompts);
boIDocumentInstance.SetPrompts();
}
if (boIDocumentInstance.MustFillPrompts)
{
throw new Exception("参数没有付全");
}
string reportID = boIDocumentInstance.Reports[0].ID;
IReport boIReport = boIDocumentInstance.Reports[reportID];
if (boIReport.PaginationMode != PaginationMode.Page)
boIReport.PaginationMode = PaginationMode.Page;
if (boIReport.ReportMode != ReportMode.Viewing)
((IDrillInfo)boIReport).EndDrill();
storageToken = boIDocumentInstance.StorageToken;
IHtmlView boIHtmlView = (IHtmlView)boIReport.GetView(OutputFormatType.Dhtml);
//boIHtmlView.UserAgent = Request.UserAgent;
StringWriter sw = new StringWriter();
boIHtmlView.WriteContent(sw);
content = sw.ToString();
Match htmlparts = Regex.Match(content, @"<head>(.*?)</head>.*<body(.*?)>(.*?)</body");
string headExtension = htmlparts.Groups[1].Captures[0].ToString();
string bodyAttributes = htmlparts.Groups[2].Captures[0].ToString();
content = htmlparts.Groups[3].Captures[0].ToString();
string[] result = new string[] { headExtension, bodyAttributes, content };
return result;
}
}
以上是我封装的类,通过这个类可以访问BO的报表,举个如何调用的例子:
Class1 class1 = new Class1();
class1.SetPrompt += new Class1.SetPromptsHandler(class1_SetPrompt);
ss = A;
string[] s = class1.GetBOScript(662, "administrator", "", "ws03r2entbase", "Enterprise");
headExtension = s[0];
bodyAttributes = s[1];
content = s[2];
void class1_SetPrompt(IPrompts prompts)
{
prompts[0].EnterValues(new string[] { "3" });
}
在asp中这样调用
<head runat="server">
<title>无标题页</title>
<%=headExtension %>
</head>
<body <%=bodyAttributes %>>
<form id="form1" runat="server">
<div>
<%=content %>
</div>
</form>
</body>
</html>
这样就可以用ASP调用BO的WEBI报表了!