次の方法で共有


カスタム レポート アイテムの実行時コンポーネントの作成

新規 : 2005 年 12 月 5 日

カスタム レポート アイテムの実行時コンポーネントは、任意の CLS 準拠の言語を使用して Microsoft .NET Framework コンポーネントとして実装され、実行時にレポート プロセッサによって呼び出されます。実行時コンポーネントに対するプロパティは、カスタム レポート アイテムの対応するデザイン時コンポーネントを使用してデザイン環境で設定されます。

レポート処理エンジンが実行時にレポート定義内に CustomReportItem 要素を見つけると、実行時コンポーネントは CustomReportItem オブジェクトを読み込み、渡します。次に、実行時コンポーネントは CustomReportItem オブジェクトのプロパティを使用して、レポートの一部として表示するためにレポート処理エンジンによって使用される標準の ReportItem オブジェクトを作成します。

ms345254.note(ja-jp,SQL.90).gif重要 :
現在サポートされているレポート アイテムの種類は、Image のみです。

カスタム実行時コンポーネント クラスのインスタンスは、対応する CustomReportItem の種類の任意のインスタンスを含む各レポートの実行中に 1 つ作成されます。レポートで発生する CustomReportItem の一致する各インスタンスについて、実行時コンポーネント クラスの CustomItem プロパティが設定され、Process メソッドが呼び出されます。

ms345254.note(ja-jp,SQL.90).gif重要 :
レポート サーバーはマルチスレッドであるため、ICustomReportItem を実装するクラスは、静的なメンバ変数を使用しないようにする必要があります。

処理エンジンが実行時コンポーネントのインスタンス化を試行しているときにエラーが発生した場合、カスタム レポート アイテムは表示されません。実行時コンポーネントがインスタンス化された後に発生したエラー (CustomItem プロパティの設定中、Process メソッドの呼び出し中、または NULL であるか無効なコンテンツを持つ RenderItem プロパティを返している間の例外など) によって、レポート全体の実行が失敗します。

実行時コンポーネントの実装

カスタム レポート アイテムの実行時コンポーネントのメイン クラスは、ICustomReportItem インターフェイスを実装します。ICustomReportItem インターフェイスは次のように定義されます。

namespace Microsoft.ReportingServices.ReportRendering
{
    public interface ICustomReportItem
    {
        Action Action { get; }
        CustomReportItem CustomItem { set; }
        ReportItem RenderItem { get; }

        ChangeType Process();
    }
}

ICustomReportItem 実装の最も重要なメンバは、Process メソッドと RenderItem プロパティです。

レポート アイテムを処理し、返す

デザイン時コンポーネントを使用してカスタム レポート アイテムに設定したプロパティは、レポートの実行時に、レポート処理エンジンによって実行時コンポーネントに渡されます。これらのプロパティにアクセスするには、ICustomReportItem 実装の CustomItem プロパティを使用します。式である任意の CustomReportItem プロパティは、実行時コントロールに渡される前に、レポート処理エンジンによって評価されます。

レポートの実行時に、レポート処理エンジンは、実行時コントロールの Process メソッドを呼び出します。Process メソッドを使用して、CustomItem プロパティに含まれるデータを解析し、表示されたイメージを RenderItem プロパティに配置できます。その後、レポート処理エンジンは、レポートの RenderItem プロパティに含まれているイメージを表示できます。

次のコード例は、Process メソッドを実装する方法を示しています。

public ChangeType Process()
{
    int dpi = 96;
    int imageWidth = (int)(m_CustomReportItem.Width.ToInches() * dpi);
    int imageHeight = (int)(m_CustomReportItem.Height.ToInches() * dpi);
    Bitmap image = new Bitmap(imageWidth, imageHeight);
    Graphics graphics = Graphics.FromImage(image);
    Color backgroundColor = ((ReportColor)m_CustomReportItem.Style["BackgroundColor"]).ToColor();
    if (backgroundColor == Color.Transparent)
        backgroundColor = Color.White;
    graphics.Clear(backgroundColor);
    int maxX = (int)LookupCustomProperty(m_CustomReportItem.CustomProperties, "poly:MaxX", 100);
    int maxY = (int)LookupCustomProperty(m_CustomReportItem.CustomProperties, "poly:MaxY", 100);
    int minX = (int)LookupCustomProperty(m_CustomReportItem.CustomProperties, "poly:MinX", 0);
    int minY = (int)LookupCustomProperty(m_CustomReportItem.CustomProperties, "poly:MinY", 0);
    float scaleX = imageWidth / (float)(maxX - minX);
    float scaleY = imageHeight / (float)(maxY - minY);
    string proportional = 
(string)LookupCustomProperty(m_CustomReportItem.CustomProperties, 
"poly:Proportional", bool.FalseString);
    if ((string)proportional == bool.TrueString)
    {
        if (scaleX > scaleY)
            scaleX = scaleY;
        else
            scaleY = scaleX;
    }
    string transString =
 (string)LookupCustomProperty(m_CustomReportItem.CustomProperties,
 "poly:Translucent", "Opaque");
    int translucency = 255;
    switch (transString)
    {
        case "Opaque": translucency = 255; break;
        case "Translucent": translucency = 128; break;
        case "Transparent": translucency = 32; break;
    }
    DataMemberCollection shapes =
 m_CustomReportItem.CustomData.DataRowGroupings[0];
    m_ImageMap = new ImageMapAreasCollection();
    int row = 0;
    for (int i = 0; i < shapes.Count; i++)
    {
        DataMember shape = shapes[i];
        string colorname = (string)LookupCustomProperty(shape.CustomProperties, "poly:Color",
 "Black");
        ReportColor rptColor = new ReportColor(colorname);
        Color color = Color.FromArgb(translucency, rptColor.ToColor());
        Brush brush = new SolidBrush(color);
        DataMemberCollection points = shape.Children[0];
        string hyperlink = (string)LookupCustomProperty(shape.CustomProperties, "poly:Hyperlink",
 "");
        ImageMapArea imageMapArea = new ImageMapArea();
        float[] coordinates = new float[points.Count * 2];
        Point[] drawpoints;
        drawpoints = new Point[points.Count];
        for (int j = 0; j < points.Count; j++)
        {
            DataCell point = m_CustomReportItem.CustomData.DataCells[row, 0];
            int x = 0;
            int y = 0;
            for (int val = 0; val < point.DataValues.Count; val++)
            {
                string name = point.DataValues[val].Name;
                object value = point.DataValues[val].Value;
                int intvalue = 0;
                if (value.GetType() == typeof(int))
                {
                    intvalue = (int)value;
                }
                else if (value.GetType() == typeof(double))
                {
                    intvalue = (int)((double)value);
                }
                if (name == "X")
                    x = (int)((intvalue - minX) * scaleX);
                else if (name == "Y")
                    y = (int)((intvalue - minY) * scaleY);
            }
            drawpoints[j] = new Point(x, y);
            coordinates[j * 2] = 100 * x / imageWidth;
            coordinates[j * 2 + 1] = 100 * y / imageHeight;
            row = row + 1;
        }
        if (hyperlink != "")
        {
            imageMapArea.SetCoordinates(ImageMapArea.ImageMapAreaShape.Polygon, 
coordinates);
            Action action = new Action();
            action.SetHyperlinkAction(hyperlink);
            if (imageMapArea.ActionInfo == null)
                imageMapArea.ActionInfo = new ActionInfo();
            if (imageMapArea.ActionInfo.Actions == null)
                imageMapArea.ActionInfo.Actions = new ActionCollection();
            imageMapArea.ActionInfo.Actions.Add(action);
            m_ImageMap.Add(imageMapArea);
        }
        graphics.FillPolygon(brush, drawpoints);
    }
    m_PolygonImage = new Microsoft.ReportingServices.ReportRendering.Image(
   m_CustomReportItem.Name, m_CustomReportItem.ID);
    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    image.Save(stream, ImageFormat.Bmp);
    m_PolygonImage.ImageData = new byte[stream.Length];
    stream.Seek(0, System.IO.SeekOrigin.Begin);
    stream.Read(m_PolygonImage.ImageData, 0, (int)stream.Length);
    
    m_PolygonImage.MIMEType = "image/bmp";
    
    if (m_ImageMap.Count > 0)
        m_PolygonImage.ImageMap = m_ImageMap;

   return ChangeType.None;
}

RenderItem プロパティの制限

レポートのカスタム レポート アイテムがページのヘッダーまたはフッター、あるいは詳細グループに配置された場合、または RepeatWith プロパティが定義されている場合、RenderItem はデータ領域ではなくなる可能性があります。

すべてのカスタム レポート アイテムは、名前、位置、サイズ、共有スタイルのプロパティなど、カスタム コントロールの最初のインスタンスと同じ共有プロパティ値を持つ必要があります。共有されないプロパティ値は、インスタンスごとに異なる可能性があります。UniqueName プロパティは、同じカスタム レポート アイテムのすべてのインスタンスで一意である必要があります。

CustomReportItem の以下のプロパティは、RenderItem の対応するプロパティをオーバーライドします。TopLeftHiddenBookmark、および Label プロパティです。

参照

概念

カスタム レポート アイテムのアーキテクチャ
カスタム レポート アイテムのデザイン時コンポーネントの作成
カスタム レポート アイテムのクラス ライブラリ
カスタム レポート アイテムの配置

その他の技術情報

カスタム レポート アイテムのサンプル

ヘルプおよび情報

SQL Server 2005 の参考資料の入手