Click here to Skip to main content
15,891,473 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.Collections.Generic;

using Framework.Db;
using Framework.Utils;

namespace Framework.Metadata
{
  //---------------------------------------------------------------------------
  /// <summary>
  /// Represents a shortened description of the attribute metadata.
  /// </summary>
  public class CxAttributeCustomizer : CxCustomizerBase, IxStorableInIdOrder
  {
    //-------------------------------------------------------------------------
    private CxEntityUsageCustomizer m_ParentCustomizer;
    private CxAttributeCustomizerData m_CurrentData;
    private CxAttributeCustomizerData m_InitialData;
    private string m_Id;
    private CxAttributeMetadata m_Metadata;
    //-------------------------------------------------------------------------
    /// <summary>
    /// The metadata object the customizer belongs to.
    /// </summary>
    public CxAttributeMetadata Metadata
    {
      get { return m_Metadata ?? ParentCustomizer.Metadata.GetAttribute(Id); }
      set { m_Metadata = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Current data snapshot, non-saved data.
    /// </summary>
    public CxAttributeCustomizerData CurrentData
    {
      get { return m_CurrentData; }
      set { m_CurrentData = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Initial data snapshot, the data which is actually applied to the application.
    /// </summary>
    public CxAttributeCustomizerData InitialData
    {
      get { return m_InitialData; }
      set { m_InitialData = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Logical parent customizer object.
    /// </summary>
    public CxEntityUsageCustomizer ParentCustomizer
    {
      get { return m_ParentCustomizer; }
      set { m_ParentCustomizer = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Identifier of the customizer.
    /// </summary>
    public string Id
    {
      get { return m_Id; }
      set { m_Id = value; }
    }
    //-------------------------------------------------------------------------
    public CxAttributeCustomizer(
      CxEntityUsageCustomizer parentCustomizer, string attributeId)
    {
      Id = attributeId;
      ParentCustomizer = parentCustomizer;
      Context = ParentCustomizer.Context;
      Manager = ParentCustomizer.Manager;

      CurrentData = new CxAttributeCustomizerData(this);
      InitialData = CurrentData.Clone();
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Indicates whether the customizer has been modified somehow.
    /// </summary>
    /// <returns>true if modified, otherwise false</returns>
    public bool GetIsModified()
    {
      return !CurrentData.Compare(InitialData);
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Applies the customizer state to the metadata it belongs to.
    /// </summary>
    /// <returns>true if changes took place</returns>
    public override bool ApplyToMetadata()
    {
      bool isChanged = base.ApplyToMetadata();
      if (!CxText.Equals(Metadata.WinControlPlacement, CurrentData.WinControlPlacement) ||
          Metadata.FilterAdvanced != CurrentData.IsShownOnAdvancedFilterPanel ||
          Metadata.Nullable == CurrentData.IsRequired ||
          !CxText.Equals(Metadata.Default, CurrentData.DefaultValue) ||
          !CxText.Equals(Metadata.RowSourceId, CurrentData.RowSourceId))
      {
        if (!ParentCustomizer.Metadata.IsAttributeDefined(Metadata.Id))
        {
          Metadata = Metadata.ApplyToEntityUsage(ParentCustomizer.Metadata);
        }
        Metadata.WinControlPlacement = CurrentData.WinControlPlacement;
        Metadata.FilterAdvanced = CurrentData.IsShownOnAdvancedFilterPanel;
        Metadata.Nullable = !CurrentData.IsRequired;
        Metadata.Default = CurrentData.DefaultValue;
        Metadata.RowSourceId = CurrentData.RowSourceId;

        isChanged |= true;
      }
      return isChanged;
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Saves the changes done to the customizer into the database store.
    /// </summary>
    /// <param name="connection">connection to be used</param>
    public void Save(CxDbConnection connection)
    {
      if (GetIsModified())
      {
        // Not quite an effective way, but quite simple.
        // We store language caption in the same method.
        SaveLanguageCaptions(connection);

        InitialData = CurrentData.Clone();
      }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Saves the language captions into the multilanguage subsystem.
    /// </summary>
    /// <param name="connection">connection to be used</param>
    protected void SaveLanguageCaptions(CxDbConnection connection)
    {
      CxMultilanguage multilanguage = Metadata.Holder.Multilanguage;
      if (multilanguage != null)
      {
        foreach (KeyValuePair<string, string> langCaption in CurrentData.LanguageCaptionMap)
        {
          string localizationObjectName = ParentCustomizer.Metadata.Id + "." + Metadata.Id;
          multilanguage.SetLocalizedValue(
            connection,
            langCaption.Key,
            CxAttributeUsageMetadata.OBJECT_TYPE_ATTRIBUTE_USAGE,
            "caption",
            localizationObjectName,
            langCaption.Value);
        }
      }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
    /// </summary>
    /// <returns>
    /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
    /// </returns>
    /// <filterpriority>2</filterpriority>
    public override string ToString()
    {
      return !string.IsNullOrEmpty(Id) ? Id : base.ToString();
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Resets the customizer to the metadata object default values.
    /// </summary>
    public override void ResetToDefault()
    {
      base.ResetToDefault();

      CurrentData.WinControlPlacement = Metadata.GetInitialProperty("win_control_placement", false);
      CurrentData.IsShownOnAdvancedFilterPanel = CxBool.Parse(Metadata.GetInitialProperty("filter_advanced", false), false);
    }
    //-------------------------------------------------------------------------
  }
}

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