Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Integrate Reporting Services with Silverlight and RIA Services

, 28 Jul 2010 CPOL
Integrate Reporting Services with your Silverlight Line-of-Business applications.
ReportingServicesDemo.zip
ReportingServicesDemo
ReportingServicesDemo
Assets
Resources
Bin
Controls
Generated_Code
Models
Shared
Helpers
Libs
System.Windows.Controls.Data.DataForm.Toolkit.dll
Models
Properties
DataSources
ReportingServicesDemo.Web.ADWLTDomainContext.datasource
ReportingServicesDemo.Web.UserRegistrationContext.datasource
ReportingServicesDemo.csproj.user
Views
Login
Web
Resources
ReportingServicesDemo.Web
ADWLTModel.edmx
App_Data
bin
ClientBin
ReportingServicesDemo.xap
DemoReport.rdlc
Models
Shared
Properties
ReportingServicesDemo.Web.csproj.user
Resources
Services
namespace ReportingServicesDemo.Controls
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using ReportingServicesDemo.Web;

    /// <summary>
    /// Enhances <see cref="DataForm" /> functionality by using a <see cref="PasswordBox" /> 
    /// control for password fields and exposing a <see cref="CustomDataForm.Fields"/> collection 
    /// to allow runtime access to <see cref="DataForm" /> fields.
    /// </summary>
    public class CustomDataForm : DataForm
    {
        private Dictionary<string, DataField> fields = new Dictionary<string, DataField>();

        /// <summary>
        /// Returns a <c>Dictionary&lt;string,DataField&gt;</c> containing all the
        /// <see cref="DataField" /> controls being displayed keyed by the
        /// property name to which each field is bound.
        /// </summary>
        public Dictionary<string, DataField> Fields
        {
            get { return this.fields; }
        }

        /// <summary>
        /// Extends <see cref="DataForm.OnAutoGeneratingField" /> by replacing <see cref="TextBox"/>es with <see cref="PasswordBox"/>es
        /// whenever applicable
        /// </summary>
        protected override void OnAutoGeneratingField(DataFormAutoGeneratingFieldEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            // Get metadata about the property being defined
            PropertyInfo propertyInfo = this.CurrentItem.GetType().GetProperty(e.PropertyName);

            // Do the password field replacement if that is the case
            if (e.Field.Content is TextBox && this.IsPasswordProperty(propertyInfo))
            {
                e.Field.ReplaceTextBox(new PasswordBox(), PasswordBox.PasswordProperty);
            }

            // Keep this newly generated field accessible through the Fields property
            this.fields[e.PropertyName] = e.Field;

            // Call base implementation (which will call other event listeners)
            base.OnAutoGeneratingField(e);
        }

        /// <param name="propertyInfo">The entity property being analyzed</param>
        /// <summary>
        /// Returns whether the given property should be represented by a <see cref="PasswordBox" /> or not.
        /// The default implementation will simply use a naming convention and returns true if the
        /// property contains the word "Password".
        /// </summary>
        protected virtual bool IsPasswordProperty(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            // Suggestion: to handle more complex scenarios, allow an entity to override
            // this mechanism by using the System.ComponentModel.DataAnnotations.UIHintAttribute 
            return propertyInfo.Name.IndexOf("Password", StringComparison.OrdinalIgnoreCase) != -1;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ernesto Herrera
Web Developer Sigo S.A.
Venezuela Venezuela
Ernesto Herrera is a Senior Developer, Architect with more than 12 years experience, actually working with Silverlight Line-of-Bussiness Applications, he holds a MCTS Web Application 2.0 Certification, and have a wide experience with sql server since the 6.5 version, on his free time he likes to play tennis with his wife,kids and friends, also enjoy playing Wii with his sons, he works at Sigo S.A., a retail business located at Margarita Island, Venezuela.
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 28 Jul 2010
Article Copyright 2010 by Ernesto Herrera
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid