ReportSource へのバインド(Crystal Reports Server または BusinessObjects Enterprise 11)
注 |
---|
このページでは、Crystal Reports for Visual Studio では使用できなかったが、アップグレード バージョンで使用可能になった機能について説明します。Crystal Reports for Visual Studio の詳細については、「Crystal Reports for Visual Studio について」を参照してください。アップグレード バージョンについての詳細情報は、「アップグレード オプション」を参照してください。 |
オブジェクト モデル
このレポートをバインドするシナリオでは CrystalReportViewer を使用しています(「CrystalReportViewer オブジェクト モデルによるレポートのバインド」を参照)。
レポートの場所
レポートには、BusinessObjects Enterprise Enterprise の Page Server からアクセスします。
説明
Crystal Reports Server または BusinessObjects Enterprise を使用すると、Enterprise フレームワークのサーバーからレポートを配布できます。Crystal Reports Server または BusinessObjects Enterprise に保存されているレポートは、ユーザーの目的に応じて、さまざまな時間にさまざまなサーバーから表示できます。Crystal Reports Server または BusinessObjects Enterprise で、可能な限り高度なパフォーマンスでレポートを表示する必要はあるものの、そのレポートについて重要なプログラム上の変更を行う必要がない場合は、ReportSource クラスを使用して Page Server から直接レポートを表示します。
ReportSource クラスは、オブジェクト モデルに関連付けられません。パラメータやデータベース設定を変更する場合は、CrystalReportViewer コントロールを備えた制限付きオブジェクト モデルを使用できます。ただし、より複雑なプログラムでレポートと対話する場合は、Crystal Reports Server または BusinessObjects Enterprise レポートをバインドする他のシナリオを使用してください。
注 |
---|
Crystal Reports Server または BusinessObjects Enterprise でさまざまなサーバーを使用するシナリオの比較については、「推奨されるシナリオの概要」の「Crystal Reports Server または BusinessObjects Enterprise で推奨されるバインドのシナリオ」を参照してください。 |
長所
- 最高速:Crystal Reports Server または BusinessObjects Enterprise からレポートを表示するための最高のパフォーマンスを提供します。
短所
- 制限されたオブジェクト モデル:データベース ログオンやパラメータ設定のプログラムによる変更は、CrystalReportViewer オブジェクト モデルに制限されます。Crystal Reports Server または BusinessObjects Enterprise を使用する他のシナリオについては、「推奨されるシナリオの概要」を参照してください。
- 使用制限:このシナリオは Crystal Enterprise バージョン 10、Crystal Reports Server または BusinessObjects Enterprise 11 でのみ使用できます。
CrystalReportViewer コントロールを Crystal Reports Server または BusinessObjects Enterprise Page Server から提供されるレポートにバインドする
- Crystal Reports Server または BusinessObjects Enterprise がインストールされ、正しく動作する。
- Crystal Reports Server または BusinessObjects Enterprise SDK(.NET アセンブリを含む)がインストールされ、正しく動作する。
注 Crystal Reports Server または BusinessObjects Enterprise を開発用のマシンにインストールしている場合、SDK はそのインストールに含まれます。
- Crystal Reports Server または BusinessObjects Enterprise サーバーを探し、その名前をメモします。この例では、サーバー名は"BOE01"です。
1. サーバー名を調べるには、\[マイ コンピュータ\]アイコンを右クリックして\[プロパティ\]を選択します。
2. [システムのプロパティ]ダイアログ ボックスで、\[コンピュータ名]タブをクリックします。
3. \[フル コンピュータ名\]フィールドの名前がコンピュータ名です。
- 公開ウィザードを使って Chart.rpt を Crystal Reports Server または BusinessObjects Enterprise サーバーに公開します。レポート ファイルは Feature Examples サブディレクトリにあります。「サンプル レポートのディレクトリ」を参照してください。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/w5dk7atd.alert_note(ja-jp,VS.90).gif" title="Note" alt="Note" class="note" />注</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>公開ウィザードの使用方法については、Crystal Reports Server または BusinessObjects Enterprise のユーザー マニュアルを参照してください。</p></td>
</tr>
</tbody>
</table>
次のアセンブリ参照をプロジェクトに追加します。
- CrystalDecisions.Enterprise.Framework
- CrystalDecisions.Enterprise.InfoStore
- CrystalDecisions.Enterprise.Viewing.ReportSource
- CrystalDecisions.ReportAppServer.Controllers
[表示]メニューから[コード]をクリックし、この Web フォームまたは Windows フォームの分離コード クラスを表示します。このクラスで、CrystalDecisions.Enterprise 名前空間に、Visual Basic の場合は "Imports" 文を、C# の場合は "using" 文を追加します。
Imports CrystalDecisions.Enterprise Imports CrystalDecisions.Enterprise.Viewing Imports CrystalDecisions.ReportAppServer.Controllers
using CrystalDecisions.Enterprise; using CrystalDecisions.Enterprise.Viewing; using CrystalDecisions.ReportAppServer.Controllers;
以上で、Crystal Reports Server または BusinessObjects Enterprise にログオンするためのコードを記述する準備が完了しました。
Crystal Reports Server または BusinessObjects Enterprise にログオンする
「プロジェクトの設定」で作成した 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 インスタンスとして取得します。
``` vb
Dim myEnterpriseSession As EnterpriseSession = mySessionMgr.Logon( _
"Administrator", "", serverName, "secEnterprise")
```
``` csharp
EnterpriseSession enterpriseSession = sessionMgr.Logon(
"Administrator", "", serverName, "secEnterprise");
```
EnterpriseSession の GetService メソッドを使って、InfoStore サービスを(EnterpriseService として)取得します。
Dim myEnterpriseService As EnterpriseService = _ myEnterpriseSession.GetService("InfoStore")
EnterpriseService enterpriseService = enterpriseSession.GetService("InfoStore");
InfoStore を宣言してインスタンス化し、取得した EnterpriseService に InfoStore へのパラメータとして渡します。
``` vb
Dim myInfoStore As InfoStore = New InfoStore(myEnterpriseService)
```
``` csharp
InfoStore infoStore = new InfoStore(enterpriseService);
```
これで Crystal Reports Server または BusinessObjects Enterprise から Hierarchical Grouping レポートを取得できるようになりました。
Crystal Reports Server または BusinessObjects Enterprise から Hierarchical Grouping レポートを取得する
- EnterpriseService インスタンスの値を Page Server レポート ファクトリー サービスに再度割り当てるために、“PSReportFactory”文字列を EnterpriseService の GetService() メソッドに渡します。
``` vb
myEnterpriseService = myEnterpriseSession.GetService("PSReportFactory")
```
``` csharp
enterpriseService = enterpriseSession.GetService("PSReportFactory");
```
EnterpriseService の Interface プロパティをオブジェクト変数として返します。
Dim psrfObject As Object = myEnterpriseService.Interface
Object psrfObject = enterpriseService.Interface;
PSReportFactory インスタンスにオブジェクト変数をキャストします。
Dim myPSReportFactory As PSReportFactory = CType(psrfObject, PSReportFactory)
PSReportFactory psReportFactory = (PSReportFactory)psrfObject;
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 インデックス クラスを取得します。
``` vb
Dim myInfoObjects As InfoObjects = myInfoStore.Query(queryString)
```
``` csharp
InfoObjects infoObjects = infoStore.Query(queryString);
```
InfoObjects インデックス クラスの最初の列から InfoObject を取得します。
Dim myInfoObject As InfoObject = myInfoObjects(1)
InfoObject infoObject = infoObjects[1];
PSReportFactory インスタンスの OpenReportSource() メソッドから ReportSource インスタンスを宣言および操作して、InfoObject の ID プロパティに渡します。
Dim myReportSource As ReportSource = myPSReportFactory.OpenReportSource(myInfoObject.ID)
ReportSource reportSource = psReportFactory.OpenReportSource(infoObject.ID);
ReportSource インスタンスを CrystalReportViewer コントロールの ReportSource プロパティにバインドします。
myCrystalReportViewer.ReportSource = myReportSource
crystalReportViewer.ReportSource = reportSource;
レポートを表示するには、プロジェクトをビルドおよび実行してください。
レポートは、レポートの ID に基づいて、Crystal Reports Server または BusinessObjects Enterprise 内の Page Server から表示されます。たとえば、DropDownList コントロールのレポートのリストから ID を選択するなど、別のメソッドを使用してレポート ID にアクセスする場合は、InfoStore を照会したり、InfoObject を生成したりすることによってレポート ID を取得する必要はありません。