阿泰的软件实用主义

水晶报表/BOE

博客园 首页 新随笔 联系 订阅 管理
  213 Posts :: 10 Stories :: 4072 Comments :: 43 Trackbacks

公告

本例为答疑所用,代码原样摘自官方示例

x:\Program Files\CrystalTutorialSampleCodeProjects\CS_Web_RDObjMod_DBLogonSubrpt\CS_Web_RDObjMod_DBLogonSubrpt

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 CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class _Default : System.Web.UI.Page 
{
    
private ReportDocument northwindCustomersReport;

    
private void ConfigureCrystalReports()
    {
        northwindCustomersReport 
= new ReportDocument();
        
string reportPath = Server.MapPath("NorthwindCustomers.rpt");
        northwindCustomersReport.Load(reportPath);

        ConnectionInfo connectionInfo 
= new ConnectionInfo();
        connectionInfo.ServerName 
= "ENXP-50701E";
        connectionInfo.DatabaseName 
= "Northwind";
        connectionInfo.IntegratedSecurity 
= true;
        SetDBLogonForReport(connectionInfo, northwindCustomersReport);

        SetDBLogonForSubreports(connectionInfo, northwindCustomersReport);

        crystalReportViewer.ReportSource 
= northwindCustomersReport;
    }

    
private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }

    
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
    {
        Tables tables 
= reportDocument.Database.Tables;
        
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            TableLogOnInfo tableLogonInfo 
= table.LogOnInfo;
            tableLogonInfo.ConnectionInfo 
= connectionInfo;
            table.ApplyLogOnInfo(tableLogonInfo);
        }
    }

    
private void SetDBLogonForSubreports(ConnectionInfo connectionInfo, ReportDocument reportDocument)
    {
        Sections sections 
= reportDocument.ReportDefinition.Sections;
        
foreach (Section section in sections)
        {
            ReportObjects reportObjects 
= section.ReportObjects;
            
foreach (ReportObject reportObject in reportObjects)
            {
                
if (reportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    SubreportObject subreportObject 
= (SubreportObject)reportObject;
                    ReportDocument subReportDocument 
= subreportObject.OpenSubreport(subreportObject.SubreportName);
                    SetDBLogonForReport(connectionInfo, subReportDocument);
                }
            }
        }
    }
}

 

posted on 2009-08-11 00:50 阿泰 阅读(680) 评论(0) 编辑 收藏
(评论功能已被博主禁用)