Click here to Skip to main content
15,885,985 members
Articles / Web Development / ASP.NET

Signum Framework Principles

Rate me:
Please Sign up or sign in to vote.
4.74/5 (27 votes)
25 Jul 2011CPOL18 min read 98.9K   1.1K   86  
Explains the philosophy behind Signum Framework, an ORM with a full LINQ Provider that encourages an entities-first approach.
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.ComponentModel;
using System.Linq;
using System.Collections.ObjectModel;
using Signum.Entities;
using System.Windows.Input;
using System.Collections.Generic;
using System.Globalization;
using Signum.Utilities;
using Signum.Entities.DynamicQuery;
using Signum.Entities.Reflection;

namespace Signum.Windows
{
	public partial class FilterBuilder
	{  
        ObservableCollection<FilterOptions> filters;
        public ObservableCollection<FilterOptions> Filters
        {
            get { return filters; }
            set
            {
                filters = value;
                lvFilters.ItemsSource = filters;
            }
        }

        List<Column> columns;
        public List<Column> Columns
        {
            get { return columns; }
            set
            {
                columns = value;
                cbFilters.ItemsSource = value;
            }
        }

        public FilterBuilder()
        {
            this.InitializeComponent();
        }

        private void btCreate_Click(object sender, RoutedEventArgs e)
        {
            if (cbFilters.SelectedItem == null)
            {
                MessageBox.Show(Properties.Resources.NoFilterSelected);
                return;
            }

            Column c = (Column)cbFilters.SelectedItem;
            FilterType ft = FilterOperationsUtils.GetFilterType(c.Type);
            FilterOptions f = new FilterOptions
            {
                Column = c,
                Operation =  FilterOperationsUtils.FilterOperations[ft].First(),
                Value = null,
            };

            filters.Add(f); 
        }

        private void ComboBox_Loaded(object sender, RoutedEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            FilterOptions f = (FilterOptions)cb.DataContext;
            FilterType ft = FilterOperationsUtils.GetFilterType(f.Column.Type);
            cb.ItemsSource = FilterOperationsUtils.FilterOperations[ft];
            cb.IsEnabled = !f.Frozen;
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            Grid g = (Grid)sender;
            Common.SetCurrentWindow(g, this.FindCurrentWindow());
            FilterOptions f = (FilterOptions)g.DataContext;

            Common.SetIsReadOnly(g, f.Frozen); 

            Type type = f.Column.Type;
            if (typeof(Lazy).IsAssignableFrom(type) || typeof(IdentifiableEntity).IsAssignableFrom(type))
            {
                Type cleanType = typeof(Lazy).IsAssignableFrom(type) ? Reflector.ExtractLazy(type) : type;
                if (Reflector.IsLowPopulation(cleanType))
                {
                    EntityCombo ec = new EntityCombo { EntityType = type, LoadDataTrigger = LoadDataTrigger.OnLoad, Style = (Style)FindResource("toolTip") };
                    ec.SetBinding(EntityCombo.EntityProperty, new Binding
                    {
                        Path = new PropertyPath(FilterOptions.RealValueProperty),
                        NotifyOnValidationError = true,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                    });
                    g.Children.Add(ec);
                }
                else
                {
                    EntityLine el = new EntityLine { EntityType = type, Create = false, HideAutoCompleteOnLostFocus = false };
                    el.SetBinding(EntityLine.EntityProperty, new Binding
                    {
                        Path = new PropertyPath(FilterOptions.RealValueProperty),
                        NotifyOnValidationError = true,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true
                    });
                    g.Children.Add(el);
                }
            }
            else
            {
                ValueLine vl = new ValueLine() { ValueType = type };
                vl.SetBinding(ValueLine.ValueProperty, new Binding
                {
                    Path = new PropertyPath("RealValue"),
                    NotifyOnValidationError = true,
                    ValidatesOnDataErrors = true,
                    ValidatesOnExceptions = true,
                });
                g.Children.Add(vl);
            }
        }

        private void btRemove_Click(object sender, RoutedEventArgs e)
        {
            RemoveFilters();
        }

        private void RemoveFilters()
        {
            var toRemove = lvFilters.SelectedItems.Cast<FilterOptions>().ToList();
            foreach (var f in toRemove)
            {
                filters.Remove(f);
            }
        }

        private void lvFilters_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                RemoveFilters();
            }
        }
	}
}

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
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