Click here to Skip to main content
15,891,253 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.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
using System.Linq;
using Framework.Silverlight.Client.AppServer;
using Liquid;

namespace Framework.Silverlight.Client
{
  /// <summary>
  /// Represents the main page control.(main application window) 
  /// </summary>
  public partial class CxMainPage
  {
    
    public event EventHandler ApplicationStarting;
    private readonly CxAppContext m_Context;
    private CxEntityMarks m_EntityMarks;
    private CxEntityMark m_SelectedEntityMark;
    private IEnumerable<CxClientSectionMetadata> m_Sections;
    //----------------------------------------------------------------------------
    /// <summary>
    /// Initializes a new instance of the CxMainPage class.
    /// </summary
    public CxMainPage()
    {
      InitializeComponent();
      dialogPlaceHolder.RootUi = this;
      m_Context = CxAppContext.Instance;
      m_Context.UiThreadDispatcher = Dispatcher;
      m_Context.NavigationChanged += m_context_NavigationChanged;
      m_Context.WorkspaceListChanged += new EventHandler(m_Context_WorkspaceListChanged);

      CxAppContext.Instance.FrameContainer = m_frameHolder;

      CxAppContext.Instance.RootDialogContainer = dialogPlaceHolder;

      toolBox.SelectedSectionChanged += m_toolBox_SelectedSectionChanged;
      Loaded += Page_Loaded;

      toolBox.DataContext = m_Context;
      m_historyTree.DataContext = m_Context;

      m_Context.HintsCanvas = hintsCanvas;
      m_Context.RootWaitingControl = this; 
    }
  
    //-----------------------------------------------------------------------------------
    /// <summary>
    /// Handles SizeChanged event.
    /// </summary>
    private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
    {
      MeasureSplitter();
      CalculatesSpinner();
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Measures splitter position.
    /// </summary>
    private void MeasureSplitter()
    {
      clmToolBox.Width = new GridLength(ActualWidth * 18 / 100);
      clmToolBox.MaxWidth = ActualWidth * 95 / 100;
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles Loaded event.
    /// </summary>
    private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
    {
      MeasureSplitter();
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Saves static metadata, such as static rowsources, 
    /// assemblies metadata, classes metadata etc. in memory. 
    /// </summary>
    /// <param name="portal">CxPortalMetadata with static metadata.</param>
    private void SaveStaticMetadata(CxClientPortalMetadata portal)
    {
      if (portal == null)
      {
        return;
      }

      m_Context.StaticRowSources.Clear();
      m_Context.StaticRowSources.AddRange(portal.StaticRowsources);

      m_Context.AssembliesMetadata.Clear();
      foreach (CxClientAssemblyMetadata assembly in portal.Assemblies)
      {
        m_Context.AssembliesMetadata.Add(assembly.Id, assembly);
      }

      m_Context.ClassesMetadata.Clear();
      foreach (CxClientClassMetadata classMetadata in portal.Classes)
      {
        m_Context.ClassesMetadata.Add(classMetadata.Id, classMetadata);
      }

      m_Context.LayoutMetadata.Clear();
      foreach (CxLayoutElement frameMetadata in portal.Frames)
      {
        m_Context.LayoutMetadata.Add(frameMetadata.Id, frameMetadata);
      }

      m_Context.ImagesMetadata.Clear();
      foreach (CxClientImageMetadata imageMetadata in portal.Images)
      {
        m_Context.ImagesMetadata.Add(imageMetadata.Id, imageMetadata);
      }

      CxAppContext.Instance.Assemblies.Clear();
      CxAppContext.Instance.Assemblies["APP.SILVERLIGHT.CLIENT"] = CxAppContext.Instance.MainAssembly;
      foreach (KeyValuePair<string, byte[]> pair in portal.AssembliesData)
      {
        using (MemoryStream ms = new MemoryStream())
        {
          ms.Write(pair.Value, 0, pair.Value.Length);
          AssemblyPart assemblyPart = new AssemblyPart();
          Assembly assembly = assemblyPart.Load(ms);
          CxAppContext.Instance.Assemblies.Add(pair.Key, assembly);
        }
      }

    }

   
    //-------------------------------------------------------------------------
    /// <summary>
    /// Handler raised when the search text box gets a focus.
    /// </summary>
    private void tbSearch_GotFocus(object sender, RoutedEventArgs e)
    {
      // Imitating "smart" textbox.
      if (tbSearch.Text == "Global Search")
      {
        tbSearch.Text = string.Empty;
        tbSearch.Foreground = new SolidColorBrush(Colors.Black);
      }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Handler raised when the search text box looses its focus.
    /// </summary>
    private void tbSearch_LostFocus(object sender, RoutedEventArgs e)
    {
      // Imitating "smart" textbox.
      if (string.IsNullOrEmpty(tbSearch.Text.Trim()))
      {
        tbSearch.Text = "Global Search";
        tbSearch.Foreground = new SolidColorBrush(Colors.LightGray);
      }
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Initializes main menu: items, images, etc. 
    /// </summary>
    private void InitMainMenu()
    {
      IxImageProvider imageProvider = (IxImageProvider)CxTypeActivator.CreateInstance(m_Context.DefaultImageProviderClassId);
      btnRefresh.Image.Source = new BitmapImage(new Uri(imageProvider[701], UriKind.RelativeOrAbsolute));
      btnHistory.Image.Source = new BitmapImage(new Uri(imageProvider[702], UriKind.RelativeOrAbsolute));
      btnFavorites.Image.Source = new BitmapImage(new Uri(imageProvider[703], UriKind.RelativeOrAbsolute));
      btnSiteMap.Image.Source = new BitmapImage(new Uri(imageProvider[704], UriKind.RelativeOrAbsolute));
    }
    
    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles MouseLeftButtonUp event.
    /// </summary>
    private void btnRefresh_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
      m_Context.RefreshActiveFrame();
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Handles Click event.
    /// </summary>
    private void CxGlassButton_Click(object sender, EventArgs e)
    {
      m_Menu.Show();
    }
    //-------------------------------------------------------------------------
    /// <summary>
    /// Handles MouseDown event.
    /// </summary>
    private void MainPage_MouseDown(object sender, MouseButtonEventArgs e)
    {
      if (dialogPlaceHolder.DialogLoaded != true)
      {
        m_Menu.Hide();
      }
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles KeyDown event.
    /// </summary>
    private void tbSearch_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {
      if (e.Key == Key.Enter)
        throw new ExUnderConstructionException();
    }
    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles MouseLeave event.
    /// </summary>
    private void UserControl_MouseLeave(object sender, MouseEventArgs e)
    {
      CancelScrollingDrag(this);
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Try to cancel scrolling in scroll bars.
    /// (workaround, related on Silverlight 2.0 bug with scroll bars when Windowless="true")
    /// </summary>
    /// <param name="root"></param>
    private void CancelScrollingDrag(DependencyObject root)
    {
      int childCount = VisualTreeHelper.GetChildrenCount(root);

      for(int i = 0; i < childCount; i++)
      {
        DependencyObject child = VisualTreeHelper.GetChild(root, i);
        Thumb thumb = child as Thumb;
        if (thumb != null)
        {
          thumb.CancelDrag();
        }
        else
        {
          CancelScrollingDrag(child);
        }
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles MouseLeftButtonDown event.
    /// </summary>
    private void vSplitter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      HtmlPage.Window.Invoke("HideAllFrames");
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles MouseLeftButtonUp event.
    /// </summary>
    private void vSplitter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
      HtmlPage.Window.Invoke("ShowAllFrames");
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles CxDialogPlaceHolder.PopupDialogLoaded event. 
    /// </summary>
    void dialogPlaceHolder_PopupDialogLoaded(object sender, EventArgs e)
    {
      hintsCanvas.Children.Clear();
    }
   
    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles clickCollector.MouseLeftButtonDown event
    /// </summary>
    private void clickCollector_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      HideFavoritesList();
      HideHistoryList();
      HideSiteMap();
    }
      
    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles 'Logout' button click.
    /// </summary>
    private void btnLogout_MouseLeftDown(object sender, MouseButtonEventArgs e)
    {
      CxAppContext.Instance.Logout();
    }

  

   

  

   
  }
}

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