共用方式為


使用 ReportAppFactory.OpenDocument() 方法繫結至 Managed RAS 伺服器

Note附註

本頁說明的是在 Crystal Reports for Visual Studio 中沒有提供,但在升級版本中提供的功能。如需關於 Crystal Reports for Visual Studio 的詳細資訊,請參閱「何謂 Crystal Reports for Visual Studio?」。如需關於升級版本的詳細資訊,請參閱「升級選項」

物件模型

這個報表繫結案例使用 ReportClientDocument (請參閱「與 ReportClientDocument 物件模型 (RAS) 繫結的報表」)。

報表位置

已儲存在 Crystal Reports Server 或 BusinessObjects Enterprise 的伺服器上。

說明

這個報表繫結案例會直接存取 ReportClientDocument 物件模型。它會擷取 EnterpriseSession、ReportAppFactory 和 InfoObject。然後將 InfoObject 的 ID 屬性及整數 0 (Visual Basic 中的選擇性參數) 傳遞給 ReportAppFactory 的 OpenDocument() 方法,從 Crystal Reports Server 或 BusinessObjects Enterprise 傳回 ReportClientDocument 的執行個體。如需程式碼範例,請參閱下面<實作>一節。

優點

  • 提供與 ReportClientDocument 物件模型 (使用 CE9 (含) 以上版本內之 RAS) 中之報表進行互動的可行方法。
  • 因 Crystal Reports Server 或 BusinessObjects Enterprise 內 Managed RAS 伺服器報表引擎的卓越效能而產生顯著的效能增益。如需詳細資訊,請參閱「比較所有 Business Objects 報表解決方案之間的架構」
  • 維護所有會與 ReportDocument 物件模型報表互動的原始程式碼,而仍能透過 ReportDocument.ReportClientDocument 屬性提供基礎 ReportClientDocument 物件模型的完整存取。
    Note附註

    ReportClientDocument 物件模型允許您以程式設計方法建立或修改變更,並將變更儲存至報表定義檔案。如需詳細資訊,請參閱<架構>中的「ReportClientDocument 物件模型 (RAS)」

  • 直接存取 ReportClientDocument 物件模型。

缺點

使用 ReportAppFactory 的 OpenDocument 方法從 Crystal Reports Server 或 BusinessObjects Enterprise 將報表載入至 RAS 伺服器

  • 必須安裝 Crystal Reports Server 或 BusinessObjects Enterprise,並確認其正在運作。
  • 必須在開發電腦上安裝 Crystal Reports Server 或 BusinessObjects Enterprise SDK (包括 .NET 組件)。
    Note附註

    如果開發電腦上已經安裝了 Crystal Reports Server 或 BusinessObjects Enterprise,SDK 即包含在該安裝中。

  • 尋找並抄下 Crystal Reports Server 或 BusinessObjects Enterprise 伺服器名稱。這個範例所使用的伺服器名稱為「BOE01」。

這個程序只能與「專案設定」一節中建立的專案搭配使用。「專案設定」包含特定命名空間參考以及本程序所需的程式碼組態;您必須具備這個組態,否則將無法完成此程序。因此,在您開始本程序前,必須先遵循「專案設定」中的步驟進行。

  1. 使用發行精靈,將 Chart.rpt 發行至 Crystal Reports Server 或 BusinessObjects Enterprise 伺服器。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\36bhtx7w.alert_note(zh-tw,VS.90).gif" alt="Note" class="note" />附註</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>若要瞭解如何使用發行精靈,請參閱 Crystal Reports Server 或 BusinessObjects Enterprise 使用者說明文件。</p></td>
</tr>
</tbody>
</table>

如需範例報表的詳細資訊,請參閱[「範例報表的目錄」](ms225622\(v=vs.90\).md)。
  1. 將下列組件參考加入至專案:
1.  CrystalDecisions.Enterprise.Framework
2.  CrystalDecisions.Enterprise.InfoStore
3.  CrystalDecisions.ReportAppServer.ClientDoc
  1. 在程式碼後置頁面頂端,加入 "Imports" [Visual Basic] 或 "using" [C#] 陳述式,匯入 CrystalDecisions.Enterprise 命名空間和 CrystalDecisions.ReportAppServer.ClientDoc 命名空間。
``` vb
Imports CrystalDecisions.Enterprise
Imports CrystalDecisions.ReportAppServer.ClientDoc
```

``` csharp
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportAppServer.ClientDoc;
```

您現在即可開始加入程式碼,藉以在 Crystal Reports Server 或 BusinessObjects Enterprise 內開啟 RAS 伺服器中的報表。
  1. 在您已於「專案設定」時建立的 ConfigureCrystalReports() 方法中,宣告 serverName 字串並將其設定為 Crystal Reports Server 或 BusinessObjects Enterprise 伺服器的名稱。
``` vb
Dim serverName As String = "BOE01"
```

``` csharp
string serverName = "BOE01";
```
  1. 宣告並產生 SessionMgr 類別的執行個體。
``` vb
Dim mySessionMgr As SessionMgr = New SessionMgr()
```

``` csharp
SessionMgr sessionMgr = new SessionMgr();
```
  1. 將使用者名稱 (Administrator)、密碼 (空白)、serverName 變數和登入類型 (secEnterprise) 傳遞給 SessionMgr 執行個體的 Logon 方法,且傳回值擷取為 EnterpriseSession 的執行個體。
``` vb
Dim myEnterpriseSession As EnterpriseSession = mySessionMgr.Logon(
_
"Administrator", "", serverName, "secEnterprise")
```

``` csharp
EnterpriseSession enterpriseSession = sessionMgr.Logon(
"Administrator", "", serverName, "secEnterprise");
```
  1. 透過 EnterpriseSession 的 GetService 方法,擷取 InfoStore 服務 (型別為 EnterpriseService)。
``` vb
Dim myEnterpriseService As EnterpriseService = _
myEnterpriseSession.GetService("InfoStore")
```

``` csharp
EnterpriseService enterpriseService =
enterpriseSession.GetService("InfoStore");
```
  1. 使用所擷取的 InfoStore 服務,宣告並產生 InfoStore 執行個體。
``` vb
Dim myInfoStore As InfoStore = New InfoStore(myEnterpriseService)
```

``` csharp
InfoStore infoStore = new InfoStore(enterpriseService);
```
  1. 將 "RASReportFactory" 字串傳遞給 EnterpriseSession 的 GetService() 方法,重新指派 EnterpriseService 執行個體的值。
``` vb
myEnterpriseService =
myEnterpriseSession.GetService("RASReportFactory")
```

``` csharp
enterpriseService =
enterpriseSession.GetService("RASReportFactory");
```
  1. 以物件變數型別傳回 EnterpriseService 的 Interface 屬性。
``` vb
Dim rrfObject As Object = myEnterpriseService.Interface
```

``` csharp
Object rrfObject = enterpriseService.Interface;
```
  1. 將物件變數轉型為 ReportAppFactory 執行個體。
``` vb
Dim myReportAppFactory As ReportAppFactory = CType(rrfObject,
ReportAppFactory)
```

``` csharp
ReportAppFactory reportAppFactory = (ReportAppFactory)rrfObject;
```
  1. 輸入以下查詢字串,向 Crystal Reports Server 或 BusinessObjects Enterprise 查詢報表。
``` vb
Dim queryString As String = "Select SI_ID, SI_NAME, SI_PARENTID
From CI_INFOOBJECTS " _
& "Where SI_PROGID='CrystalEnterprise.Report' "
_
& "And SI_NAME Like 'Chart'"
```

``` csharp
string queryString = "Select SI_ID, SI_NAME, SI_PARENTID From
CI_INFOOBJECTS "
+ "Where SI_PROGID='CrystalEnterprise.Report' "
+ "And SI_NAME Like 'Chart'";
```
  1. 將查詢字串傳遞給 InfoStore 的 Query 方法,擷取含有查詢結果的 InfoObjects 索引類別。
``` vb
Dim myInfoObjects As InfoObjects = myInfoStore.Query(queryString)
```

``` csharp
InfoObjects infoObjects = infoStore.Query(queryString);
```
  1. 從 InfoObjects 索引類別的第一欄擷取 InfoObject。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\36bhtx7w.alert_note(zh-tw,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];
```
  1. 宣告並產生 ReportClientDocument 執行個體。
``` vb
Dim myReportClientDocument As ReportClientDocument = New
ReportClientDocumentClass()
```

``` csharp
ReportClientDocument reportClientDocument = new
ReportClientDocumentClass();
```
  1. 將 InfoObject 的 ID 屬性及整數 0 (Visual Basic 可省略這個整數) 傳遞給 ReportAppFactory 執行個體的 OpenDocument 方法。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images\36bhtx7w.alert_note(zh-tw,VS.90).gif" alt="Note" class="note" />附註</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>如此即可從 Crystal Reports Server 或 BusinessObjects Enterprise 中的報表應用程式伺服器 (RAS) 開啟型別為 ReportClientDocument 執行個體的報表。</p></td>
</tr>
</tbody>
</table>

``` vb
myReportClientDocument =
myReportAppFactory.OpenDocument(myInfoObject.ID, 0)
```

``` csharp
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID,
0);
```
  1. 將 ReportClientDocument 執行個體繫結至 CrystalReportViewer 控制項。
``` vb
myCrystalReportViewer.ReportSource = myReportClientDocument
```

``` csharp
crystalReportViewer.ReportSource = reportClientDocument;
```
  1. 若要檢視報表,請建置並執行專案。

請參閱