绑定到转换为 Report 实例的 InfoObject
注意 |
---|
本页描述了在 Crystal Reports for Visual Studio 中未提供但在升级版本中提供的功能。若需更多有关 Crystal Reports for Visual Studio 的信息,请参见“什么是 Crystal Reports for Visual Studio?”有关升级版本的更多信息,请参见“升级选项”。 |
对象模型
此报表绑定方案使用 InfoObject(请参见“通过 InfoObject 对象模型进行报表绑定 (BOE)”)。
报表的位置
存储在 Crystal Reports Server 或 BusinessObjects Enterprise 中的某个服务器上。
说明
InfoObject 对象模型随 Crystal Reports Server 或 BusinessObjects Enterprise 一同提供。它将系统中的所有 Enterprise 对象(报表、用户、组、服务器、服务器组、文件夹)视为可以通过编程方式与之进行交互的信息对象。该对象模型中的所有信息对象都由具有相同名称的相应类表示。这些类是从 InfoObject 继承的。
若要使用此对象模型绑定报表,可以从 Crystal Reports Server 或 BusinessObjects Enterprise 中检索一个将包装为 InfoObject 实例的报表。若要绑定到此 InfoObject 实例,请将此 InfoObject 实例赋给 CrystalReportViewer 控件的 ReportSource 属性。
优点
- 可用于调度报表在特定时间运行,并使用特定的参数以输出到 FTP、SMTP、磁盘或打印机目标。
缺点
- 作为显示报表的方法使用时,不如使用 RAS 服务器或页面服务器时的速度快。
- 如果要在运行时以编程方式修改报表,则必须使用“通过 ReportClientDocument 对象模型进行报表绑定(RAS)” 中的绑定方案之一与 RAS 服务器进行交互。
- 如果希望速度最快并且只需显示报表,则最好使用“绑定到 ReportSource(Crystal Reports Server 或 BusinessObjects Enterprise 11)” 中的报表绑定方案访问用于报表绑定的页面服务器。
绑定到包装为 InfoObject 并强制转换为 Report 的报表
- 必须安装 Crystal Reports Server 或 BusinessObjects Enterprise,并且经验证可以正常工作。
- 必须在开发计算机上安装 Crystal Reports Server 或 BusinessObjects Enterprise SDK(包括 .NET 程序集)。
注意 若已在开发计算机上安装 Crystal Reports Server 或 BusinessObjects Enterprise,则在此安装中已包含 SDK。
- 找到并记录 Crystal Reports Server 或 BusinessObjects Enterprise 服务器的名称。对于此示例,服务器名称为“BOE01”。
注意 |
---|
此过程仅适用于已通过“项目设置”创建的项目。“项目设置”包含此过程需要的特定命名空间引用和代码配置。如果没有该配置,将无法完成此过程。因此,在开始此过程之前,必须首先执行“项目设置”中的步骤。 |
- 使用发布向导将 Chart.rpt 发布到 Crystal Reports Server 或 BusinessObjects Enterprise 服务器。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>若需了解如何使用发布向导,请参见 Crystal Reports Server 或 BusinessObjects Enterprise 用户文档。</p>
<p>有关示例报表的信息,请参见<a href="ms225622(v=vs.90).md">“示例报表目录”</a>。</p></td>
</tr>
</tbody>
</table>
将以下程序集引用添加到项目中:
- CrystalDecisions.Enterprise.Framework
- CrystalDecisions.Enterprise.InfoStore
- CrystalDecisions.Enterprise.Desktop.Report
在代码隐藏页的顶部,为 CrystalDecisions.Enterprise 命名空间和 CrystalDecisions.Enterprise.Desktop 命名空间添加一条 "Imports" [Visual Basic] 或 "using" [C#] 语句。
``` vb
Imports CrystalDecisions.Enterprise
Imports CrystalDecisions.Enterprise.Desktop
```
``` csharp
using CrystalDecisions.Enterprise;
using CrystalDecisions.Enterprise.Desktop;
```
现在已准备就绪,可以添加相应的代码,以便绑定到包含 Crystal Reports Server 或 BusinessObjects Enterprise 中某个报表的 InfoObject 实例。
在 ConfigureCrystalReports() 方法(在“项目设置”中创建)中,声明 serverName 字符串,并将其设置为 Crystal Reports Server 或 BusinessObjects Enterprise 服务器的名称。
Dim serverName As String = "BOE01"
string serverName = "BOE01";
声明并实例化 SessionMgr 类。
Dim mySessionMgr As SessionMgr = New SessionMgr()
SessionMgr sessionMgr = new SessionMgr();
将用户名(Administrator)、密码(空白)、serverName 变量和登录类型(secEnterprise)传递给该 SessionMgr 实例的 Logon 方法,从而获得一个 EnterpriseSession 实例。
Dim myEnterpriseSession As EnterpriseSession = mySessionMgr.Logon( _ "Administrator", "", serverName, "secEnterprise")
EnterpriseSession enterpriseSession = sessionMgr.Logon( "Administrator", "", serverName, "secEnterprise");
从 EnterpriseSession 的 GetService 方法中获取 InfoStore 服务(作为 EnterpriseService)。
Dim myEnterpriseService As EnterpriseService = _ myEnterpriseSession.GetService("InfoStore")
EnterpriseService enterpriseService = enterpriseSession.GetService("InfoStore");
使用获得的 InfoStore 服务声明并实例化 InfoStore。
Dim myInfoStore As InfoStore = New InfoStore(myEnterpriseService)
InfoStore infoStore = new InfoStore(enterpriseService);
输入下列查询字符串以向 Crystal Reports Server 或 BusinessObjects Enterprise 查询报表。
Dim queryString As String = "Select SI_ID, SI_NAME, SI_PARENTID From CI_INFOOBJECTS " _ & "Where SI_PROGID='CrystalEnterprise.Report' " _ & "And SI_NAME Like 'Chart'"
string queryString = "Select SI_ID, SI_NAME, SI_PARENTID From CI_INFOOBJECTS " + "Where SI_PROGID='CrystalEnterprise.Report' " + "And SI_NAME Like 'Chart'";
通过将查询字符串传递到 InfoStore 的 Query 方法获取包含查询结果的 InfoObjects 索引类。
Dim myInfoObjects As InfoObjects = myInfoStore.Query(queryString)
InfoObjects infoObjects = infoStore.Query(queryString);
从该 InfoObject 索引类的第一列中获取 InfoObjects
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>InfoObjects 索引类的索引从 1 开始,而不是从 0 开始。</p></td>
</tr>
</tbody>
</table>
``` vb
Dim myInfoObject As InfoObject = myInfoObjects(1)
```
``` csharp
InfoObject infoObject = infoObjects[1];
```
声明 Report 实例并将 InfoObject 强制转换为 Report。
Dim myReport As Report = CType(myInfoObject, Report)
Report report = (Report)infoObject;
将 EnterpriseLogon 控件的 CrystalReportViewer 属性设置为 EnterpriseSession 实例。
myCrystalReportViewer.EnterpriseLogon = myEnterpriseSession
crystalReportViewer.EnterpriseLogon = enterpriseSession;
将 Report 实例绑定到 CrystalReportViewer 控件。
myCrystalReportViewer.ReportSource = myReport
crystalReportViewer.ReportSource = report;