Beispiel #1
0
        /// <summary>
        /// Reset the avl filter operations given the property type.  This is called each time the control is configured by calling ResetFilterValues
        /// </summary>
        private void ConfigureFilterOptions()
        {
            FilterOperations.Clear();
            if (FilterColumnInfo.PropertyType != null)
            {
                if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "Starts With", " LIKE", "/Os.Controls;component/Images/StartsWith.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "Ends With", " LIKE", "/Os.Controls;component/Images/EndsWith.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "Contains", " LIKE", "/Os.Controls;component/Images/Contains.png"));
                }
                FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "Equals", "==", "/Os.Controls;component/Images/Equal.png"));
                //FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation, "Equals", "==", "/Os.Controls;component/Images/Equal.png"));


                if (TypeHelper.IsBool(FilterColumnInfo.PropertyType))
                {
                    CmbFilter.Visibility = Visibility.Visible;
                    DpFilter.Visibility  = Visibility.Collapsed;
                    TxtFilter.Visibility = Visibility.Collapsed;
                }

                if (TypeHelper.IsDateType(FilterColumnInfo.PropertyType) || TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    if (TypeHelper.IsDateType(FilterColumnInfo.PropertyType))
                    {
                        DpFilter.Visibility  = Visibility.Visible;
                        TxtFilter.Visibility = Visibility.Collapsed;
                        CmbFilter.Visibility = Visibility.Collapsed;
                    }

                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, "Greater Than", ">", "/Os.Controls;component/Images/GreaterThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, "Greater Than or Equal", ">=", "/Os.Controls;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "Less Than", "<", "/Os.Controls;component/Images/LessThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "Less Than or Equal", "<=", "/Os.Controls;component/Images/LessThanEqual.png"));
                }
                SelectedFilterOperation = FilterOperations[0];
            }
        }
Beispiel #2
0
        void ColumnFilterControl_Loaded(object sender, RoutedEventArgs e)
        {
            DataGridColumn       column    = null;
            DataGridColumnHeader colHeader = null;

            UIElement parent = (UIElement)VisualTreeHelper.GetParent(this);

            while (parent != null)
            {
                parent = (UIElement)VisualTreeHelper.GetParent(parent);
                if (colHeader == null)
                {
                    colHeader = parent as DataGridColumnHeader;
                }

                if (Grid == null)
                {
                    Grid = parent as ExDataGrid;
                }
            }

            if (colHeader != null)
            {
                column = colHeader.Column;
            }

            CanUserFilter         = Grid.CanUserFilter;
            CanUserFreeze         = Grid.CanUserFreeze;
            CanUserGroup          = Grid.CanUserGroup;
            CanUserSelectDistinct = Grid.CanUserSelectDistinct;


            if (column != null)
            {
                object oCanUserFilter = column.GetValue(ColumnConfiguration.CanUserFilterProperty);
                if (oCanUserFilter != null)
                {
                    CanUserFilter = (bool)oCanUserFilter;
                }

                object oCanUserFreeze = column.GetValue(ColumnConfiguration.CanUserFreezeProperty);
                if (oCanUserFreeze != null)
                {
                    CanUserFreeze = (bool)oCanUserFreeze;
                }

                object oCanUserGroup = column.GetValue(ColumnConfiguration.CanUserGroupProperty);
                if (oCanUserGroup != null)
                {
                    CanUserGroup = (bool)oCanUserGroup;
                }

                object oCanUserSelectDistinct = column.GetValue(ColumnConfiguration.CanUserSelectDistinctProperty);
                if (oCanUserSelectDistinct != null)
                {
                    CanUserSelectDistinct = (bool)oCanUserSelectDistinct;
                }
            }


            if (Grid.FilterType == null)
            {
                return;
            }

            FilterColumnInfo = new OptionColumnInfo(column, Grid.FilterType);

            Grid.RegisterOptionControl(this);

            FilterOperations.Clear();
            if (FilterColumnInfo.PropertyType != null)
            {
                FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "Equals", "/Capnode.Wpf;component/Images/Equal.png"));
                if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "Contains", "/Capnode.Wpf;component/Images/Contains.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "Starts With", "/Capnode.Wpf;component/Images/StartsWith.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "Ends With", "/Capnode.Wpf;component/Images/EndsWith.png"));
                }

                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "Not Equal", "/Capnode.Wpf;component/Images/NotEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, "Greater Than", "/Capnode.Wpf;component/Images/GreaterThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, "Greater Than or Equal", "/Capnode.Wpf;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "Less Than", "/Capnode.Wpf;component/Images/LessThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "Less Than or Equal", "/Capnode.Wpf;component/Images/LessThanEqual.png"));
                }

                SelectedFilterOperation = FilterOperations[0];
            }

            if (FilterColumnInfo != null && FilterColumnInfo.IsValid)
            {
                foreach (var i in DistinctPropertyValues.Where(i => i.IsChecked))
                {
                    i.IsChecked = false;
                }

                DistinctPropertyValues.Clear();
                FilterText = string.Empty;
                _boundColumnPropertyAccessor = null;

                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    CanUserSelectDistinct = false;
                    Visibility            = Visibility.Visible;
                }
                else if (!string.IsNullOrWhiteSpace(FilterColumnInfo.PropertyPath))
                {
                    Visibility = Visibility.Visible;
                    ParameterExpression arg        = linq.Expression.Parameter(typeof(object), "x");
                    linq.Expression     expr       = PropertyExpression(Grid.FilterType, FilterColumnInfo.PropertyPath, arg);
                    linq.Expression     conversion = linq.Expression.Convert(expr, typeof(object));
                    _boundColumnPropertyAccessor = linq.Expression.Lambda <Func <object, object> >(conversion, arg).Compile();
                }
                else
                {
                    Visibility = Visibility.Collapsed;
                }

                object oDefaultFilter = column.GetValue(ColumnConfiguration.DefaultFilterProperty);
                if (oDefaultFilter != null)
                {
                    FilterText = (string)oDefaultFilter;
                }
            }

            CalcControlVisibility();
        }
Beispiel #3
0
        void ColumnFilterControl_Loaded(object sender, RoutedEventArgs e)
        {
            DataGridColumn       column    = null;
            DataGridColumnHeader colHeader = null;

            UIElement parent = (UIElement)VisualTreeHelper.GetParent(this);

            while (parent != null)
            {
                parent = (UIElement)VisualTreeHelper.GetParent(parent);
                if (colHeader == null)
                {
                    colHeader = parent as DataGridColumnHeader;
                }

                if (Grid == null)
                {
                    Grid = parent as JibGrid;
                }
            }

            if (colHeader != null)
            {
                column = colHeader.Column;
            }

            CanUserFilter         = Grid.CanUserFilter;
            CanUserFreeze         = Grid.CanUserFreeze;
            CanUserGroup          = Grid.CanUserGroup;
            CanUserSelectDistinct = Grid.CanUserSelectDistinct;


            if (column != null)
            {
                object oCanUserFilter = column.GetValue(ColumnConfiguration.CanUserFilterProperty);
                if (oCanUserFilter != null)
                {
                    CanUserFilter = (bool)oCanUserFilter;
                }

                object oCanUserFreeze = column.GetValue(ColumnConfiguration.CanUserFreezeProperty);
                if (oCanUserFreeze != null)
                {
                    CanUserFreeze = (bool)oCanUserFreeze;
                }

                object oCanUserGroup = column.GetValue(ColumnConfiguration.CanUserGroupProperty);
                if (oCanUserGroup != null)
                {
                    CanUserGroup = (bool)oCanUserGroup;
                }

                object oCanUserSelectDistinct = column.GetValue(ColumnConfiguration.CanUserSelectDistinctProperty);
                if (oCanUserSelectDistinct != null)
                {
                    CanUserSelectDistinct = (bool)oCanUserSelectDistinct;
                }
            }


            if (Grid.FilterType == null)
            {
                return;
            }

            FilterColumnInfo = new OptionColumnInfo(column, Grid.FilterType);

            Grid.RegisterOptionControl(this);

            FilterOperations.Clear();
            if (FilterColumnInfo.PropertyType != null)
            {
                if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "Contains", "/Jib.WPF.Controls;component/Images/Contains.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "Starts With", "/Jib.WPF.Controls;component/Images/StartsWith.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "Ends With", "/Jib.WPF.Controls;component/Images/EndsWith.png"));
                }
                FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "Equals", "/Jib.WPF.Controls;component/Images/Equal.png"));
                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, "Greater Than", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, "Greater Than or Equal", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "Less Than", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "Greater Than or Equal", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "Not Equal", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                }
                SelectedFilterOperation = FilterOperations[0];
            }

            if (FilterColumnInfo != null && FilterColumnInfo.IsValid)
            {
                foreach (var i in DistinctPropertyValues.Where(i => i.IsChecked))
                {
                    i.IsChecked = false;
                }
                DistinctPropertyValues.Clear();
                FilterText = string.Empty;
                _boundColumnPropertyAccessor = null;

                if (!string.IsNullOrWhiteSpace(FilterColumnInfo.PropertyPath))
                {
                    if (FilterColumnInfo.PropertyPath.Contains('.'))
                    {
                        throw new ArgumentException(string.Format("This version of the grid does not support a nested property path such as '{0}'.  Please make a first-level property for filtering and bind to that.", FilterColumnInfo.PropertyPath));
                    }

                    this.Visibility = System.Windows.Visibility.Visible;
                    ParameterExpression arg = System.Linq.Expressions.Expression.Parameter(typeof(object), "x");
                    System.Linq.Expressions.Expression expr = System.Linq.Expressions.Expression.Convert(arg, Grid.FilterType);
                    expr = System.Linq.Expressions.Expression.Property(expr, Grid.FilterType, FilterColumnInfo.PropertyPath);
                    System.Linq.Expressions.Expression conversion = System.Linq.Expressions.Expression.Convert(expr, typeof(object));
                    _boundColumnPropertyAccessor = System.Linq.Expressions.Expression.Lambda <Func <object, object> >(conversion, arg).Compile();
                }
                else
                {
                    this.Visibility = System.Windows.Visibility.Collapsed;
                }
                object oDefaultFilter = column.GetValue(ColumnConfiguration.DefaultFilterProperty);
                if (oDefaultFilter != null)
                {
                    FilterText = (string)oDefaultFilter;
                }
            }

            CalcControlVisibility();
        }
        void ColumnFilterControl_Loaded(object sender, RoutedEventArgs e)
        {
            DataGridColumn       column    = null;
            DataGridColumnHeader colHeader = null;

            UIElement parent = (UIElement)VisualTreeHelper.GetParent(this);

            while (parent != null)
            {
                parent = (UIElement)VisualTreeHelper.GetParent(parent);
                if (colHeader == null)
                {
                    colHeader = parent as DataGridColumnHeader;
                }

                if (Grid == null)
                {
                    Grid = parent as DataGridExtend;
                }
            }

            if (colHeader != null)
            {
                column = colHeader.Column;
            }

            CanUserFreeze         = Grid.CanUserFreeze;
            CanUserGroup          = Grid.CanUserGroup;
            CanUserSelectDistinct = Grid.CanUserSelectDistinct;

            FilterColumnInfo = new OptionColumnInfo(column, Grid);

            if (column != null)
            {
                object oCanUserFreeze = column.GetValue(ColumnConfiguration.CanUserFreezeProperty);
                if (oCanUserFreeze != null)
                {
                    CanUserFreeze = (bool)oCanUserFreeze;
                    Grid.FreezeColumn(FilterColumnInfo.Column);
                }


                object oCanUserGroup = column.GetValue(ColumnConfiguration.CanUserGroupProperty);
                if (oCanUserGroup != null)
                {
                    CanUserGroup = (bool)oCanUserGroup;
                    if (!string.IsNullOrWhiteSpace(FilterColumnInfo.PropertyPath))
                    {
                        Grid.AddGroup(FilterColumnInfo.PropertyPath);
                    }
                }


                object oCanUserSelectDistinct = column.GetValue(ColumnConfiguration.CanUserSelectDistinctProperty);
                if (oCanUserSelectDistinct != null)
                {
                    CanUserSelectDistinct = (bool)oCanUserSelectDistinct;
                }
            }
            if (Grid.FilterType == null)
            {
                return;
            }



            Grid.RegisterOptionControl(this);

            FilterOperations.Clear();
            if (FilterColumnInfo.PropertyType != null)
            {
                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType) && TypeHelper.IsStringType(FilterColumnInfo.PropertyConvertType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                    CalcControlVisibility(ColumnType.ConvertString);
                }
                else
                {
                    if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType) || TypeHelper.IsStringType(FilterColumnInfo.PropertyConvertType))
                    {
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "Contains", "/Jib.WPF.Controls;component/Images/Contains.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "Starts With", "/Jib.WPF.Controls;component/Images/StartsWith.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "Ends With", "/Jib.WPF.Controls;component/Images/EndsWith.png"));
                        CalcControlVisibility(ColumnType.String);
                    }
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                    if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                    {
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                        CalcControlVisibility(ColumnType.Num);
                    }
                    if (TypeHelper.IsBoolType(FilterColumnInfo.PropertyType) || TypeHelper.IsBoolType(FilterColumnInfo.PropertyConvertType))
                    {
                        CalcControlVisibility(ColumnType.Bool);
                    }
                    if (TypeHelper.IsDateTimeType(FilterColumnInfo.PropertyType))
                    {
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                        CalcControlVisibility(ColumnType.Date);
                    }
                }

                if (FilterOperations.Count > 0)
                {
                    SelectedFilterOperation = FilterOperations[0];
                }
            }

            if (FilterColumnInfo != null && FilterColumnInfo.IsValid)
            {
                foreach (var i in DistinctPropertyValues.Where(i => i.IsChecked))
                {
                    i.IsChecked = false;
                }
                DistinctPropertyValues.Clear();
                FilterText = string.Empty;
                _boundColumnPropertyAccessor = null;

                if (!string.IsNullOrWhiteSpace(FilterColumnInfo.PropertyPath))
                {
                    if (FilterColumnInfo.PropertyPath.Contains('.'))
                    {
                        throw new ArgumentException(string.Format("This version of the grid does not support a nested property path such as '{0}'.  Please make a first-level property for filtering and bind to that.", FilterColumnInfo.PropertyPath));
                    }

                    this.Visibility = System.Windows.Visibility.Visible;
                    ParameterExpression arg = System.Linq.Expressions.Expression.Parameter(typeof(object), "x");
                    System.Linq.Expressions.Expression expr = System.Linq.Expressions.Expression.Convert(arg, Grid.FilterType);
                    expr = System.Linq.Expressions.Expression.Property(expr, Grid.FilterType, FilterColumnInfo.PropertyPath);
                    System.Linq.Expressions.Expression conversion = System.Linq.Expressions.Expression.Convert(expr, typeof(object));
                    _boundColumnPropertyAccessor = System.Linq.Expressions.Expression.Lambda <Func <object, object> >(conversion, arg).Compile();

                    if (_boundColumnPropertyAccessor != null)
                    {
                        if (DistinctPropertyValues.Count == 0)
                        {
                            //List<object> result = new List<object>();
                            //foreach (var i in Grid.ItemsSource)
                            //{
                            //    object value = _boundColumnPropertyAccessor(i);
                            //    if (value != null)
                            //    {
                            //        if (result.Where(o => o.ToString() == value.ToString()).Count() == 0)
                            //            result.Add(value);
                            //    }
                            //    else if (FilterColumnInfo.PropertyType == typeof(bool?) && FilterColumnInfo.IsSpecialState)
                            //    {
                            //        if (result.Where(o => o == value).Count() == 0)
                            //            result.Add(value);
                            //    }

                            //}
                            //try
                            //{
                            //    result.Sort();
                            //}
                            //catch
                            //{
                            //    if (System.Diagnostics.Debugger.IsLogging())
                            //        System.Diagnostics.Debugger.Log(0, "Warning", "There is no default compare set for the object type");
                            //}

                            //if (result.Count > 0)
                            //{
                            //    StringBuilder sb = new StringBuilder();
                            //    foreach (var obj in result)
                            //    {
                            //        var item = new CheckboxComboItem()
                            //        {
                            //            Description = GetFormattedValue(obj),
                            //            Tag = obj,
                            //            IsChecked = true
                            //        };
                            //        item.PropertyChanged += new PropertyChangedEventHandler(filter_PropertyChanged);
                            //        DistinctPropertyValues.Add(item);
                            //        sb.AppendFormat("{0}{1}", sb.Length > 0 ? "," : "",item.Description );
                            //    }

                            //    FilterText = sb.ToString();
                            //}
                            //else
                            //{
                            //    FilterText = string.Empty;
                            //}
                        }
                    }
                }
                else
                {
                    this.Visibility = System.Windows.Visibility.Collapsed;
                }
                object oDefaultFilter = column.GetValue(ColumnConfiguration.DefaultFilterProperty);
                if (oDefaultFilter != null)
                {
                    FilterText = (string)oDefaultFilter;
                }
            }
        }