Click here to Skip to main content
15,894,630 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.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

using Framework.Silverlight.Client.AppServer;

namespace Framework.Silverlight.Client
{
  /// <summary>
  /// Represents command.
  /// </summary>
  public class CxCommand : INotifyPropertyChanged
  {
    public event PropertyChangedEventHandler PropertyChanged;
    private string m_Id;
    private bool m_IsEnabled;
    private bool m_IsEntityInstanceRequired;
    private Visibility m_IsVisibleInContext = Visibility.Visible;
    public event DxCommandClickHandler CommandClick;
    private readonly string m_HandlerClassId;
    private readonly bool m_IsMultiple;
    private readonly bool m_IsHandlerBatch;
    private readonly string m_ConfirmationText;
    private bool m_CanRunOnServer = true;
    public string EntityUsageId { get; private set; }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Initializes a new instance of the CxCommand class.
    /// </summary>
    /// <param name="commandMetadata">Command metadata from server.</param>
    public CxCommand(CxClientCommandMetadata commandMetadata)
    {
      Id = commandMetadata.Id;
      Text = commandMetadata.Text;
      IsEntityInstanceRequired = commandMetadata.IsEntityInstanceRequired;
      m_HandlerClassId = commandMetadata.SlHandlerClassId;
      m_IsMultiple = commandMetadata.IsMultiple;
      m_IsHandlerBatch = commandMetadata.IsHandlerBatch;
      m_ConfirmationText = commandMetadata.ConfirmationText;
      IsVisible = commandMetadata.Visible;
      HasServerHandler = commandMetadata.HasServerHandler;
      EntityUsageId = commandMetadata.EntityUsageId;
      if (!string.IsNullOrEmpty(commandMetadata.ImageId))
      {
        CxClientImageMetadata imageMetadata = CxAppContext.Instance.ImagesMetadata[commandMetadata.ImageId.ToUpper()];
        IxImageProvider imageProvider =
            (IxImageProvider) CxTypeActivator.CreateInstance(imageMetadata.ProviderClassId);
        BitmapImage bmp = new BitmapImage(new Uri(imageProvider[imageMetadata.ImageIndex], UriKind.RelativeOrAbsolute));
        ImageSource = bmp;
      }
      IsEnabled = commandMetadata.IsEnabled;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Initializes a new instance of the CxCommand class.
    /// </summary>
    /// <param name="commandId">Id of the appropriated command.</param>
    public CxCommand(string commandId)
    {
      Id = commandId;
      HasServerHandler = true;
      m_IsHandlerBatch = false;
      m_IsMultiple = false;
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Initializes a new instance of the CxCommand class.
    /// </summary>
    /// <param name="commandId">Id of the appropriated command.</param>
    /// <param name="handlerClassId">ID of the C# class implementing IxCommandHandler interface used to perform the command.</param>
    public CxCommand(string commandId, string handlerClassId )
    {
      Id = commandId;
      HasServerHandler = true;
      m_IsHandlerBatch = false;
      m_IsMultiple = false;
      m_HandlerClassId = handlerClassId;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets or sets the image source of command image.
    /// </summary>
    public ImageSource ImageSource { get; set; }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Unique ID of the command.
    /// </summary>
    public string Id
    {
      get { return m_Id; }
      set
      {
        if (m_Id != value)
        {
          m_Id = value;
          OnPropertyChanged(new PropertyChangedEventArgs("Id"));
        }

      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Command caption displayed to user.
    /// </summary>
    public string Text { get; set; }

    //----------------------------------------------------------------------------
    /// <summary>
    /// True if command requires selected entity instance to be executed for.
    /// </summary>
    public bool IsEntityInstanceRequired
    {
      get { return m_IsEntityInstanceRequired; }
      set
      {
        m_IsEntityInstanceRequired = value;
        m_IsEnabled = m_IsEntityInstanceRequired ? false : true;
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets or sets a value indicating whether the command are displayed.
    /// </summary>
    public bool IsVisible{get; set;}

    //----------------------------------------------------------------------------
    /// <summary>
    /// Visibility of the command.
    /// </summary>
    public Visibility IsVisibleInContext
    {
      get { return m_IsVisibleInContext; }
      set
      {
        if (m_IsVisibleInContext != value)
        {
          m_IsVisibleInContext = value;
          OnPropertyChanged(new PropertyChangedEventArgs("IsVisibleInContext"));
        }
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// True if command is accessible.
    /// </summary>
    public bool IsEnabled
    {
      get { return m_IsEnabled; }
      set
      {
        if (m_IsEnabled != value)
        {
          m_IsEnabled = value;
          OnPropertyChanged(new PropertyChangedEventArgs("IsEnabled"));
        }
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Executes command.
    /// </summary>
    public void Execute()
    {
      OnCommandClick(new CxCommandClickEventArgs(Id));
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Need for Silverlight binding.
    /// </summary>
    public string Click
    {
      get { return string.Empty; }
      set
      {
        OnCommandClick(new CxCommandClickEventArgs(Id));
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Need for Silverlight binding.
    /// </summary>
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
    {
      if (PropertyChanged != null)
      {
        PropertyChanged(this, e);
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Raises the CommandClick event.
    /// </summary>
    protected virtual void OnCommandClick(CxCommandClickEventArgs e)
    {
      if (CommandClick != null)
      {
        CommandClick(this, e);
      }
    }

    //---------------------------------------------------------------------------
    /// <summary>
    /// ID of the C# class implementing IxCommandHandler interface used to perform the command.
    /// </summary>
    public string HandlerClassId
    {
      get { return m_HandlerClassId; }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// True if command can be applied to multiple entities selected in a grid.
    /// </summary>
    public bool IsMultiple
    {
      get { return m_IsMultiple; }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// True for batch commands (single handler method is called for all selected entities). Can be used in a combination with sl_handler_class_id only.
    /// </summary>
    public bool IsHandlerBatch
    {
      get { return m_IsHandlerBatch; }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Confirmation text to be displayed before command execution.
    /// </summary>
    public string ConfirmationText
    {
      get { return m_ConfirmationText; }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets the value, that defines, that command has handlers on server.
    /// </summary>
    public bool HasServerHandler { get; set; }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Gets the value, that defines, can it command run on server.
    /// </summary>
    public bool CanRunOnServer
    {
      get { return m_CanRunOnServer; }
      set { m_CanRunOnServer = value; }
    }
  }

}

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