Click here to Skip to main content
15,892,072 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 1 – Southwind Entities

Rate me:
Please Sign up or sign in to vote.
4.50/5 (12 votes)
14 Nov 2012LGPL315 min read 41.4K   2K   52  
Tutorial focused in writing the entities using Signum Framework, a Win/Web LINQ-enabled framework for writing data-centric applications.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using Signum.Utilities;

namespace Signum.Windows
{
    /// <summary>
    /// Interaction logic for SelectorWindow.xaml
    /// </summary>
    public partial class SelectorWindow : Window
    {
        public class ElementInfo
        {
            public object Element { get; set; }
            public ImageSource Image { get; set; }
            public string Text { get; set; }
        }

        public static readonly DependencyProperty TypesProperty =
            DependencyProperty.Register("Elements", typeof(ElementInfo[]), typeof(SelectorWindow), new UIPropertyMetadata(null));
        public ElementInfo[] Elements
        {
            get { return (ElementInfo[])GetValue(TypesProperty); }
            set { SetValue(TypesProperty, value); }
        }

        public static readonly DependencyProperty SelectedElementProperty =
            DependencyProperty.Register("SelectedElement", typeof(object), typeof(SelectorWindow), new UIPropertyMetadata(null));
        public object SelectedElement
        {
            get { return (object)GetValue(SelectedElementProperty); }
            set { SetValue(SelectedElementProperty, value); }
        }


        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register("Message", typeof(string), typeof(SelectorWindow), new UIPropertyMetadata(null));
        public string Message
        {
            get { return (string)GetValue(MessageProperty); }
            set { SetValue(MessageProperty, value); }
        }

        public static bool ShowDialog<T>(T[] elements, Func<T, ImageSource> relatedImage, Func<T, string> relatedText, out T selectedElement)
        {
            return ShowDialog<T>(elements, relatedImage, relatedText, out selectedElement, Signum.Windows.Properties.Resources.SelectAnElement, Signum.Windows.Properties.Resources.SelectAnElement, null);
        }

        public static bool ShowDialog<T>(T[] elements, Func<T, ImageSource> relatedImage, Func<T, string> relatedText, out T selectedElement, string title, string message, Window owner)
        {
            if (relatedImage == null)
                relatedImage = o => null;
            if (relatedText == null)
                relatedText = o => o.ToString();
            SelectorWindow w = new SelectorWindow(){
                Owner = owner,
                Title = title,
                Message = message,
                Elements = elements.Select(e => new ElementInfo() 
                {
                    Element = e,
                    Image = relatedImage(e),
                    Text = relatedText(e)
                }).ToArray()};
            bool res = w.ShowDialog() ?? false;
            if (res)
                selectedElement = (T)w.SelectedElement;
            else
                selectedElement = default(T);
            return res;
        }

        public SelectorWindow()
        {
            InitializeComponent();

            this.Message = Signum.Windows.Properties.Resources.SelectAnElement;
        }

        private void ToggleButton_Checked(object sender, RoutedEventArgs e)
        {
            SelectedElement = ((ElementInfo)((ToggleButton)sender).DataContext).Element;
            DialogResult = true;
            Close();
        }
    }
}

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 GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions