사용자 지정 보고서 항목 런타임 구성 요소 만들기

사용자 지정 보고서 항목 런타임 구성 요소는 CLS 규격 언어를 사용하여 Microsoft .NET Framework 구성 요소로 구현되며 런타임에 보고서 처리기에 의해 호출됩니다. 사용자 지정 보고서 항목의 해당 디자인 타임 구성 요소를 수정하여 디자인 환경에서 런타임 구성 요소의 속성을 정의합니다.

완전히 구현된 사용자 지정 보고서 항목의 샘플은 SQL Server Reporting Services 제품 샘플을 참조 하세요.

정의 및 인스턴스 개체

사용자 지정 보고서 항목을 구현하기 전에 정의 개체와 인스턴스 개체차이점을 이해하는 것이 중요합니다. 정의 개체는 사용자 지정 보고서 항목의 RDL 표현을 제공하는 반면 인스턴스 개체는 평가된 버전의 정의 개체입니다. 보고서의 각 항목에 대한 정의 개체는 하나뿐입니다. 식을 포함하는 정의 개체의 속성에 액세스하면 평가되지 않은 식 문자열이 표시됩니다. 인스턴스 개체는 평가된 버전의 정의 개체를 포함하며 항목의 정의 개체와 일대다 관계를 가질 수 있습니다. 예를 들어 보고서에 Tablix 세부 정보 행이 포함된 CustomReportItem 데이터 영역이 있는 경우 정의 개체는 하나만 있지만 데이터 영역의 각 행에 대한 인스턴스 개체가 있습니다.

ICustomReportItem 인터페이스 구현

CustomReportItem 런타임 구성 요소를 만들려면 Microsoft.ReportingServices.ProcessingCore.dll에 정의된 인터페이스를 구현 ICustomReportItem 해야 합니다.

namespace Microsoft.ReportingServices.OnDemandReportRendering  
{  
    public interface ICustomReportItem  
    {  
        void GenerateReportItemDefinition(CustomReportItem customReportItem);  
void EvaluateReportItemInstance(CustomReportItem customReportItem);  
    }  
}  

인터페이스를 구현한 ICustomReportItem 후에는 다음과 같은 두 개의 메서드 스텁이 GenerateReportItemDefinitionEvaluateReportItemInstance생성됩니다. 이 GenerateReportItemDefinition 메서드는 먼저 호출되며 정의 속성을 설정하고 항목을 렌더링하는 데 사용되는 정의 및 인스턴스 속성을 모두 포함하는 개체를 만드는 Image 데 사용됩니다. EvaluateReportItemInstance 이 메서드는 정의 개체를 평가한 후 호출되며 항목을 렌더링하는 데 사용할 인스턴스 개체를 제공합니다.

다음 예제 구현에서는 컨트롤의 이름을 이미지로 렌더링하는 사용자 지정 보고서 항목을 보여 줍니다.

namespace Microsoft.Samples.ReportingServices  
{  
    using System;  
    using System.Collections.Generic;  
    using System.Collections.Specialized;  
    using System.Drawing.Imaging;  
    using System.IO;  
    using System.Text;  
    using Microsoft.ReportingServices.OnDemandReportRendering;  
  
    public class PolygonsCustomReportItem : ICustomReportItem  
    {  
        #region ICustomReportItem Members  
  
        public void GenerateReportItemDefinition(CustomReportItem cri)  
        {  
            // Create the Image object that will be   
            // used to render the custom report item  
            cri.CreateCriImageDefinition();  
            Image polygonImage = (Image)cri.GeneratedReportItem;  
        }  
  
        public void EvaluateReportItemInstance(CustomReportItem cri)  
        {  
            // Get the Image definition  
            Image polygonImage = (Image)cri.GeneratedReportItem;  
  
            // Create the image for the custom report item  
            polygonImage.ImageInstance.ImageData = DrawImage(cri);  
        }  
  
        #endregion  
  
        /// <summary>  
        /// Creates an image of the CustomReportItem's name  
        /// </summary>  
        private byte[] DrawImage(CustomReportItem customReportItem)  
        {  
            int width = 1;          // pixels  
            int height = 1;         // pixels  
            int resolution = 75;    // dpi  
  
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height);  
            bitmap.SetResolution(resolution, resolution);  
  
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);  
            graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;  
  
            // Get the Font for the Text  
            System.Drawing.Font font = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace,  
                12, System.Drawing.FontStyle.Regular);  
  
            // Get the Brush for drawing the Text  
            System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen);  
  
            // Get the measurements for the image  
            System.Drawing.SizeF maxStringSize = graphics.MeasureString(customReportItem.Name, font);  
            width = (int)(maxStringSize.Width + 2 * font.GetHeight(resolution));  
            height = (int)(maxStringSize.Height + 2 * font.GetHeight(resolution));  
  
            bitmap.Dispose();  
            bitmap = new System.Drawing.Bitmap(width, height);  
            bitmap.SetResolution(resolution, resolution);  
  
            graphics.Dispose();  
            graphics = System.Drawing.Graphics.FromImage(bitmap);  
            graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;  
  
            // Draw the text  
            graphics.DrawString(customReportItem.Name, font, brush, font.GetHeight(resolution),   
                font.GetHeight(resolution));  
  
            // Create the byte array of the image data  
            MemoryStream memoryStream = new MemoryStream();  
            bitmap.Save(memoryStream, ImageFormat.Bmp);  
            memoryStream.Position = 0;  
            byte[] imageData = new byte[memoryStream.Length];  
            memoryStream.Read(imageData, 0, imageData.Length);  
  
            return imageData;  
        }  
    }  
}  

사용자 지정 보고서 항목 아키텍처
사용자 지정 보고서 항목 디자인 타임 구성 요소 만들기
사용자 지정 보고서 항목 클래스 라이브러리
방법: 사용자 지정 보고서 항목 배포