Click here to Skip to main content
15,885,869 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   81  
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;

namespace Framework.Silverlight.Client 
{
  /// <summary>
  /// Dialog that shows when application performs files uploading.
  /// </summary>
  public class CxUploadDialog : CxDialog
  {
    private readonly CxUploadPanel m_UploadPanel = new CxUploadPanel();
    private long m_FileLenght;
    string strFileLenght = "";
    public event EventHandler CancelUpload;
    //----------------------------------------------------------------------------
    /// <summary>
    /// Default .ctor
    /// </summary>
    public CxUploadDialog()
    {
      Buttons = NxDialogButtons.Custom;
      HoldSizePercent = 40;
      IsFixedSize = true;
      Width = 500;
      m_UploadPanel.SetValue(Grid.RowProperty, 1);
      LayoutRoot.Children.Add(m_UploadPanel);
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Creates custom buttons set.
    /// Dialog calls to this method if DefaultButton property set as 'Custom'.
    /// </summary>
    /// <returns>Created list of dialog buttons.</returns>
    protected override List<Button> CreateCustomButtons()
    {
      List<Button> btns = base.CreateCustomButtons();

      CxDialogButton btnCancel = new CxDialogButton();
      btnCancel.DialogResult = NxDialogResult.Cancel;
      btnCancel.Content = "Cancel";
      btns.Add(btnCancel);
      btnCancel.Click += btnCancel_Click;
      return btns;
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Handles Click event.
    /// </summary>
    void btnCancel_Click(object sender, RoutedEventArgs e)
    {
      if(CancelUpload != null)
      {
        CancelUpload(this, EventArgs.Empty);
      }
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Sets progress bar position.
    /// </summary>
    /// <param name="fileLength">Length of whole file.</param>
    /// <param name="bytesUploaded">Already uploaded bytes count.</param>
    /// <param name="percentUploaded">Already uploaded bytes in percents.</param>
    /// <param name="speed"></param>
    public void SetProgress(long fileLength, long bytesUploaded, double percentUploaded, float speed)
    { 
      m_UploadPanel.PersentValue = percentUploaded;
      m_UploadPanel.PersentText = string.Concat(percentUploaded, "%");
      if (m_FileLenght != fileLength)
      {
        m_FileLenght = fileLength;
        strFileLenght = GetFileSizeAsString(fileLength);
      }
      m_UploadPanel.UploadedBytesText = string.Format(
        "Uploaded: {0} from {1}", GetFileSizeAsString(bytesUploaded), strFileLenght);
      m_UploadPanel.UpoadSpeedText = string.Concat("Upload speed kb/s: ", speed);
    }

    //----------------------------------------------------------------------------
    /// <summary>
    /// Converts and returns given file size in suitable for users string format.
    /// </summary>
    /// <param name="size">File size to convert.</param>
    /// <returns>Converted file size.</returns>
    public static string GetFileSizeAsString(long size)
    {
      double s = size;
      string[] format = new [] { "{0} bytes", "{0} KB", "{0} MB", "{0} GB", "{0} TB", "{0} PB", "{0} EB", "{0} ZB", "{0} YB" };
      int i = 0;
      while (i < format.Length - 1 && s >= 1024)
      {
        s = (100 * s / 1024) / 100.0;
        i++;
      }
      return string.Format(format[i], s.ToString("###,###,##0.##"));
    }
  }
}

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