Click here to Skip to main content
15,896,118 members
Articles / Web Development / ASP.NET

Using Silverlight in Enterprise: RAD of User Friendly Database Access

Rate me:
Please Sign up or sign in to vote.
4.81/5 (19 votes)
31 Jul 2009CPOL8 min read 58.2K   7K   80  
This article introduces FulcrumWeb RAD Framework - A Silverlight UI Engine to build user friendly database driven applications
/********************************************************************
 *  FulcrumWeb RAD Framework - Fulcrum of your business             *
 *  Copyright (c) 2002-2009 FulcrumWeb, ALL RIGHTS RESERVED         *
 *                                                                  *
 *  THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      *
 *  FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        *
 *  COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       *
 *  AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  *
 *  AND PERMISSION FROM FULCRUMWEB. CONSULT THE END USER LICENSE    *
 *  AGREEMENT FOR INFORMATION ON ADDITIONAL RESTRICTIONS.           *
 ********************************************************************/

using System;
using System.ComponentModel;
using System.Data;
using System.Collections;

namespace Framework.Db
{
  //----------------------------------------------------------------------------
  /// <summary>
  /// Represents a property based upon a data-column, 
  /// to read data-rows properly.
  /// </summary>
  public class CxColumnPropertyDescriptor : PropertyDescriptor
  {
    //----------------------------------------------------------------------------
    private DataColumn m_Column;
    //----------------------------------------------------------------------------
    
    #region Properties
    //----------------------------------------------------------------------------
    /// <summary>
    /// A data-column that holds a description of the property.
    /// </summary>
    public DataColumn Column
    {
      get { return m_Column; }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// A type of the object to be examined by this property descriptor.
    /// </summary>
    public override Type ComponentType
    {
      get { return typeof(DataRow); }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets a value indicating whether the member is browsable, 
    /// as specified in the System.ComponentModel.BrowsableAttribute.
    /// </summary>
    public override bool IsBrowsable
    {
      get { return ((m_Column.ColumnMapping != MappingType.Hidden) && base.IsBrowsable); }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets a value indicating whether this property is read-only.
    /// </summary>
    public override bool IsReadOnly
    {
      get { return m_Column.ReadOnly; }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// A type of the property.
    /// </summary>
    public override Type PropertyType
    {
      get { return m_Column.DataType; }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets the collection of attributes for this member.
    /// </summary>
    public override AttributeCollection Attributes
    {
      get
      {
        if (typeof(IList).IsAssignableFrom(PropertyType))
        {
          Attribute[] array = new Attribute[base.Attributes.Count + 1];
          base.Attributes.CopyTo(array, 0);
          array[array.Length - 1] = new ListBindableAttribute(false);
          return new AttributeCollection(array);
        }
        return base.Attributes;
      }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets the name that can be displayed in a window, 
    /// such as a Properties window.
    /// </summary>
    public override string DisplayName
    {
      get { return Column.Caption; }
    }
    //----------------------------------------------------------------------------
    public override string Name
    {
      get
      {
        return Column.ColumnName;
      }
    }
    #endregion

    #region Ctors
    //----------------------------------------------------------------------------
    /// <summary>
    /// Ctor.
    /// </summary>
    /// <param name="dataColumn"></param>
    public CxColumnPropertyDescriptor(DataColumn dataColumn)
      : base(dataColumn.ColumnName, null)
    {
      m_Column = dataColumn;
    }
    //----------------------------------------------------------------------------
    #endregion

    #region Methods
    //----------------------------------------------------------------------------
    /// <summary>
    /// Checks if the value is not reset yet.
    /// </summary>
    /// <param name="rowObj"></param>
    /// <returns></returns>
    public override bool CanResetValue(object rowObj)
    {
      DataRow row = (DataRow)rowObj;
      object value = row[m_Column.ColumnName];
      return value != DBNull.Value && value != null;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Checks if the current property descriptor describes the same
    /// data property as the given one.
    /// </summary>
    /// <param name="other">a property descriptor to compare with</param>
    /// <returns>true if equals</returns>
    public override bool Equals(object other)
    {
      if (other is CxColumnPropertyDescriptor)
      {
        CxColumnPropertyDescriptor descriptor = (CxColumnPropertyDescriptor)other;
        return (descriptor.Column == Column);
      }
      return false;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Returns a hashcode for the property descriptor.
    /// </summary>
    /// <returns>a hash code</returns>
    public override int GetHashCode()
    {
      return Column.GetHashCode();
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets the property's value from the given data-row.
    /// </summary>
    /// <param name="rowObj">a row object</param>
    /// <returns>a value of the property</returns>
    public override object GetValue(object rowObj)
    {
      DataRow row = (DataRow)rowObj;
      return row[m_Column.ColumnName];
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Sets a value in the given data-row object to its reset state.
    /// </summary>
    /// <param name="rowObj">a data-row to be changed</param>
    public override void ResetValue(object rowObj)
    {
      DataRow row = (DataRow)rowObj;
      row[m_Column.ColumnName] = DBNull.Value;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Sets a value in the given data-row object.
    /// </summary>
    /// <param name="rowObj">a data-row to be changed</param>
    /// <param name="value">a value to be set</param>
    public override void SetValue(object rowObj, object value)
    {
      DataRow row = (DataRow)rowObj;
      row[m_Column.ColumnName] = value;
      OnValueChanged(rowObj, EventArgs.Empty);
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Determines a value indicating whether the value of this 
    /// property needs to be persisted.
    /// </summary>
    /// <param name="rowObj">a data-row that should be examined 
    /// for persistence</param>
    /// <returns>true if the property should be persisted; otherwise false</returns>
    public override bool ShouldSerializeValue(object rowObj)
    {
      return false;
    }
    //----------------------------------------------------------------------------
    #endregion
  }

}

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)


Written By
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions