ASP调用BO的WEBI开发的报表

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报表了!

 

 

 

 

 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值