Click here to Skip to main content
15,889,838 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.1K   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.Collections.Generic;

using Framework.Db;

namespace Framework.Metadata
{
  //---------------------------------------------------------------------------
  /// <summary>
  /// Represents a shortened description of the tab metadata.
  /// </summary>
  public class CxTabCustomizer: CxCustomizerBase, IxStorableInIdOrder
  {
    //-------------------------------------------------------------------------
    private CxFormCustomizer m_ParentCustomizer;
    private CxPanelCustomizerList m_PanelCustomizers;

    private CxWinTabMetadata m_Metadata;
    private CxTabCustomizerData m_CurrentData;
    private CxTabCustomizerData m_InitialData;
    //-------------------------------------------------------------------------
    /// <summary>
    /// The metadata object the customizer belongs to.
    /// </summary>
    public CxWinTabMetadata Metadata
    {
      get { return m_Metadata; }
      set { m_Metadata = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Current data snapshot, non-saved data.
    /// </summary>
    public CxTabCustomizerData CurrentData
    {
      get { return m_CurrentData; }
      set { m_CurrentData = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Initial data snapshot, the data which is actually applied to the application.
    /// </summary>
    public CxTabCustomizerData InitialData
    {
      get { return m_InitialData; }
      set { m_InitialData = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Logical parent customizer object.
    /// </summary>
    public CxFormCustomizer ParentCustomizer
    {
      get { return m_ParentCustomizer; }
      set { m_ParentCustomizer = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Identifier of the customizer.
    /// </summary>
    public string Id
    {
      get { return Metadata.Id; }
    }
    //-------------------------------------------------------------------------
    public CxPanelCustomizerList PanelCustomizers
    {
      get { return m_PanelCustomizers; }
      set { m_PanelCustomizers = value; }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Ctor.
    /// </summary>
    /// <param name="manager">customization manager</param>
    /// <param name="parentCustomizer">the parent customizer</param>
    /// <param name="tabMetadata">tab metadata</param>
    public CxTabCustomizer(
      CxCustomizationManager manager, CxFormCustomizer parentCustomizer, CxWinTabMetadata tabMetadata)
    {
      Manager = manager;
      Metadata = tabMetadata;
      ParentCustomizer = parentCustomizer;
      Context = manager.Context;

      PanelCustomizers = new CxPanelCustomizerList();
    }
    //-------------------------------------------------------------------------
    public void Initialize()
    {
      InitializePanelCustomizers();
      
      CurrentData = new CxTabCustomizerData(this);
      InitialData = CurrentData.Clone();
    }
    //-------------------------------------------------------------------------
    protected void InitializePanelCustomizers()
    {
      PanelCustomizers.Clear();
      foreach (CxWinPanelMetadata panel in Metadata.Panels)
      {
        CxPanelCustomizer panelCustomizer =
          new CxPanelCustomizer(Manager, this, panel);
        panelCustomizer.Initialize();
        PanelCustomizers.Add(panelCustomizer);
      }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Applies the customizer state to the metadata it belongs to.
    /// </summary>
    public override bool ApplyToMetadata()
    {
      bool isChanged = base.ApplyToMetadata();
      foreach (CxPanelCustomizer panelCustomizer in PanelCustomizers)
      {
        isChanged |= panelCustomizer.ApplyToMetadata();
      }
      return isChanged;
    }
    //-------------------------------------------------------------------------
    /// <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>
    /// Returns the caption of the metadata object being customized in the scope
    /// of the given language.
    /// </summary>
    /// <returns>caption string</returns>
    public string GetLanguageCaption()
    {
      if (CurrentData.LanguageCaptionMap.ContainsKey(Context.CurrentEntityUsage))
      {
        Dictionary<string, string> captions = CurrentData.LanguageCaptionMap[Context.CurrentEntityUsage];
        string localized;
        if (captions.TryGetValue(Context.CurrentLanguageCd, out localized))
        {
          return localized;
        }
      }
      return Metadata.GetCaption(Context.CurrentEntityUsage, Context.CurrentLanguageCd);
    }
    //-------------------------------------------------------------------------
    /// <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())
      {
        SaveLanguageCaptions(connection);
        InitialData = CurrentData.Clone();
      }
      foreach (CxPanelCustomizer panelCustomizer in PanelCustomizers)
      {
        panelCustomizer.Save(connection);
      }
    }
    //-------------------------------------------------------------------------
    /// <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<CxEntityUsageMetadata, Dictionary<string, string>> pair in CurrentData.LanguageCaptionMap)
        {
          foreach (KeyValuePair<string, string> langCaption in pair.Value)
          {
            string localizationObjectName =
              Context.CurrentEntityUsage.Id + "." +
              ParentCustomizer.Metadata.Id + "." + 
              Metadata.Id;
            multilanguage.SetLocalizedValue(
              connection,
              langCaption.Key,
              Metadata.LocalizationObjectTypeCode,
              "text",
              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();
      foreach (CxPanelCustomizer panelCustomizer in PanelCustomizers)
      {
        panelCustomizer.ResetToDefault();
      }
    }
    //-------------------------------------------------------------------------
  }
}

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