Click here to Skip to main content
15,896,310 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 System.Windows;
using System.Windows.Controls;
using Framework.Silverlight.Client.AppServer;

namespace Framework.Silverlight.Client
{
  /// <summary>
  /// Provides base features for layout building.
  /// </summary>
  public abstract class CxLayoutBuilder
  {
    //-------------------------------------------------------------------------
    protected CxAutoLayoutFrame m_rootFrame;
    //----------------------------------------------------------------------------
    /// <summary>
    /// Initializes a new instance of the CxLayoutBuilder class.
    /// </summary>
    /// <param name="rootFrame">Root frame (CxAutoLayoutFrame or one of inheritors)</param>
    protected CxLayoutBuilder(CxAutoLayoutFrame rootFrame)
    {
      m_rootFrame = rootFrame;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Returns one of inheritors from CxLayoutBuilder depends on given string.
    /// </summary>
    protected CxLayoutBuilder GetBuilder(string type)
    {
      switch (type)
      {
        case "frame":
          return new CxFrameBuilder(m_rootFrame);
        case "panel":
          return new CxPanelBuilder(m_rootFrame);
        case "tab_control":
          return new CxTabControlBuilder(m_rootFrame);
        case "tab":
          return new CxTabBuilder(m_rootFrame);
        case "hint":
          return new CxHintBuilder(m_rootFrame);

        default:
          throw new ExApplicationException("The Layout Builder for layout " +
              "element '{0}' is not defined.", type);
      }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Gets type of suppoted Layout element.
    /// </summary>
    public abstract string TargetType { get; }
    //---------------------------------------------------------------------------
    /// <summary>
    /// Gets UI element for layuot.
    /// </summary>
    /// <param name="element">CxLayoutElement to create UI element.</param>
    /// <param name="entityUsage">CxEntityUsage from frame.</param>
    /// <param name="entity">CxBaseEntity from frame.</param>
    /// <param name="openMode">Frame open mode.</param>
    /// <returns>Greated UI element.</returns>
    public abstract FrameworkElement GetUiElement(
        CxLayoutElement element,
        CxEntityUsage entityUsage,
        CxBaseEntity entity,
        NxOpenMode openMode);
    //----------------------------------------------------------------------------
    /// <summary>
    /// Initializes for layout.
    /// </summary>
    /// <param name="grid">Grid that need to initialize.</param>
    /// <param name="element">CxLayoutElement to grid initialize.</param>
    protected void InitLayoutGrid(Grid grid, CxLayoutElement element)
    {
      int rowsCount = element.RowsCount > 0 ? element.RowsCount : 1;
      int columnsCount = element.ColumnsCount > 0 ? element.ColumnsCount : 1;
      IList<object> rowsHeightList = ParseGridLengthArray(element.RowsHeight);
      IList<object> columnsWidthList = ParseGridLengthArray(element.ColumnsWidth);

      for (int i = 0; i < rowsCount; i++)
      {
        RowDefinition rowDefinition = new RowDefinition 
        {
          Height = new GridLength(1, GridUnitType.Star)
        };

        if ((rowsHeightList.Count - 1) >= i && rowsHeightList[i] is GridUnitType)
        {
          rowDefinition.Height = new GridLength(1, (GridUnitType) rowsHeightList[i]);
        }
        if ((rowsHeightList.Count - 1) >= i && rowsHeightList[i] is double)
        {
          rowDefinition.Height = new GridLength((double) rowsHeightList[i], GridUnitType.Pixel);
        }
        grid.RowDefinitions.Add(rowDefinition);
      }
      for (int i = 0; i < columnsCount; i++)
      {
        ColumnDefinition columnDefinition = new ColumnDefinition 
        {
          Width = new GridLength(1, GridUnitType.Star)
        };

        if ((columnsWidthList.Count - 1) >= i && columnsWidthList[i] is GridUnitType)
        {
          columnDefinition.Width = new GridLength(1, (GridUnitType) columnsWidthList[i]);
        }
        if ((columnsWidthList.Count - 1) >= i && columnsWidthList[i] is double)
        {
          columnDefinition.Width = new GridLength((double) columnsWidthList[i], GridUnitType.Pixel);
        }
        grid.ColumnDefinitions.Add(columnDefinition);
      }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Creates and initializes grid for layout.
    /// </summary>
    /// <param name="element">CxLayoutElement to grid initialize.</param>
    /// <returns>Created grid.</returns>
    protected virtual Grid GetLayoutGrid(CxLayoutElement element)
    {
      Grid grid = new Grid();
     
      InitLayoutGrid(grid, element);

      return grid;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Parses grid length data from layuot markup.
    /// </summary>
    /// <param name="markup">layuot markup to parse.</param>
    /// <returns>List of standard WPF grid length objects. </returns>
    private IList<object> ParseGridLengthArray(string markup)
    {
      List<object> valuesAsObj = new List<object>();

      if (string.IsNullOrEmpty(markup))
      {
        return valuesAsObj;
      }

      string[] values = markup.Split(new[] { ',' });
      foreach (string s in values)
      {
        string lowerVal = s.Replace(" ", string.Empty);
        lowerVal = lowerVal.ToLower();

        switch (lowerVal)
        {
          case "auto":
            valuesAsObj.Add(GridUnitType.Auto);
            break;
          case "*":
            valuesAsObj.Add(GridUnitType.Star);
            break;
          default:
            try
            {
              valuesAsObj.Add(Convert.ToDouble(lowerVal));
            }
            catch (Exception ex)
            {
              throw new ExApplicationException(ex,
                  "Invalid parameter in string of columns size definitions: '{0}'",
                  lowerVal);
            }
            break;
        }
      }
      return valuesAsObj;
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Sets rows and columns count in given FrameworkElement.
    /// </summary>
    protected virtual void SetRowAndColumn(
        FrameworkElement uiElement,
        CxLayoutElement layoutElement)
    {
      uiElement.SetValue(Grid.RowProperty, layoutElement.Row);
      uiElement.SetValue(Grid.ColumnProperty, layoutElement.Column);

      uiElement.SetValue(Grid.RowSpanProperty, layoutElement.RowSpan);
      uiElement.SetValue(Grid.ColumnSpanProperty, layoutElement.ColumnSpan);
    }
    //-------------------------------------------------------------------------
  
  }
}

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