Aracılığıyla paylaş


Özel rapor madde çalışma zamanı bileşeni oluşturma

The custom report item run-time component is implemented as a Microsoft .NET Framework component using any CLS-compliant language, and is called by the report processor at run time.Run - özelliklerini tanımladığınızsaat değiştirerek özel rapor öğesi tasarım ortamında bileşeni, karşılık gelen tasarım -saat bileşeni.

Tam olarak uygulanan özel rapor öğesi örnek için bkz: SQL Server Reporting Services ürün örnekleri.

Tanım ve örnek nesneleri

Özel rapor öğesi uygulamadan önce arasındaki farkı anlamak önemli olduğunu tanımı nesnelerinin ve örnek nesneleri.Örnek nesneleri tanım nesnelerin Değerlendirilmiş sürümlerini olduğu yerde tanım nesneleri özel rapor öğesi rdl gösterimini sağlar.Rapordaki her öğe için tek bir tanım nesnesi vardır.İfadeler içeren bir tanım nesnesi özellikleri erişirken, unevaluated ifadesi elde edersiniz dize.Örnek nesneleri tanım nesneleri Değerlendirilmiş sürümlerinde vardır ve öğe tanımı nesnesi ile bir-çok ilişkisi olabilir.Örneğin, bir rapor varsa, bir Tablix veri bölgesi içeren bir CustomReportItem örnek olan bir nesne için her satırda olacaktır ama bir ayrıntı satırda olacak tek bir tanım nesnesiveri bölge.

ICustomReportItem arabirimini uygulayan

Oluşturmak için bir CustomReportItem run -saat uygulamak için gereksinim duyduğunuz bileşeni ICustomReportItem Microsoft.ReportingServices.ProcessingCore.dll içinde tanımlanan arabirim:

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

Uyguladıysanız, sonra ICustomReportItem arabirim, iki yöntem sizin için yer tutucular oluşturulur: GenerateReportItemDefinitionand EvaluateReportItemInstance.The GenerateReportItemDefinition method is called first and is used for setting definition properties and creating the Image object that will contain both the definition and instance properties that are used for rendering the item.The EvaluateReportItemInstance method is called after the definition objects have been evaluated, and it provides the instance objects that will be used for rendering the item.

Aşağıdaki örnek olarak bir resim denetiminin adını işleyen bir özel rapor öğesi uygulamasıdır.

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;
        }
    }
}