void ColumnOptionControl_Loaded(object sender, RoutedEventArgs e)
        {
            //Check the Grid for Building commmands and Visibility
            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;
            }

            FilterColumnInfo = new OptionColumnInfo(column, Grid);

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

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

            Grid.RegisterColumnOptionControl(this);
            ResetVisibility();
        }
Exemple #2
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ColumnInfo info = cbColumns.SelectedItem as ColumnInfo;

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

            FilterColumnInfo = new OptionColumnInfo(info.DataGridColumn, FilterSelectedItem.Grid);
            FilterSelectedItem.FilterOperations.Clear();
            if (FilterColumnInfo.PropertyType != null)
            {
                if (FilterColumnInfo.PropertyConvertType != null)
                {
                    if (TypeHelper.IsStringType(FilterColumnInfo.PropertyConvertType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "等于", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "包含", "/Jib.WPF.Controls;component/Images/Contains.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "开始于", "/Jib.WPF.Controls;component/Images/StartsWith.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "结束于", "/Jib.WPF.Controls;component/Images/EndsWith.png"));
                        CalcControlVisibility(ColumnType.String);
                    }
                    if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyConvertType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                        CalcControlVisibility(ColumnType.Num);
                    }
                    if (TypeHelper.IsBoolType(FilterColumnInfo.PropertyConvertType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        CalcControlVisibility(ColumnType.Bool);
                    }
                    if (TypeHelper.IsDateTimeType(FilterColumnInfo.PropertyConvertType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                        CalcControlVisibility(ColumnType.Date);
                    }
                }
                else
                {
                    if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "等于", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "包含", "/Jib.WPF.Controls;component/Images/Contains.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "开始于", "/Jib.WPF.Controls;component/Images/StartsWith.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "结束于", "/Jib.WPF.Controls;component/Images/EndsWith.png"));
                        CalcControlVisibility(ColumnType.String);
                    }
                    if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                        CalcControlVisibility(ColumnType.Num);
                    }
                    if (TypeHelper.IsBoolType(FilterColumnInfo.PropertyType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        CalcControlVisibility(ColumnType.Bool);
                    }
                    if (TypeHelper.IsDateTimeType(FilterColumnInfo.PropertyType))
                    {
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                        FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                        CalcControlVisibility(ColumnType.Date);
                    }
                }
            }
            if (FilterColumnInfo != null && FilterColumnInfo.IsValid)
            {
                FilterSelectedItem.BoolPropertyValues.Clear();
                _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));
                    }

                    ParameterExpression arg = System.Linq.Expressions.Expression.Parameter(typeof(object), "x");
                    Type type = FilterSelectedItem.Grid.FilterType;
                    System.Linq.Expressions.Expression expr = System.Linq.Expressions.Expression.Convert(arg, type);

                    expr = System.Linq.Expressions.Expression.Property(expr, type, FilterColumnInfo.PropertyPath);
                    if (!string.IsNullOrWhiteSpace(FilterColumnInfo.StringPath))
                    {
                        System.Reflection.PropertyInfo propInfo2 = FilterSelectedItem.Grid.FilterType.GetProperty(FilterColumnInfo.PropertyPath);
                        expr = System.Linq.Expressions.Expression.Property(expr, propInfo2.PropertyType, FilterColumnInfo.StringPath);
                    }
                    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)
                    {
                        List <object> result = new List <object>();
                        foreach (var i in FilterSelectedItem.Grid.ItemsSource)
                        {
                            AllSelectedPropertyChanged selectedModel = i as AllSelectedPropertyChanged;
                            object value = _boundColumnPropertyAccessor(selectedModel);
                            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");
                            }
                        }

                        //foreach (var item in result)
                        //{
                        //    FilterSelectedItem.ColumnValue = item.ToString() + ",";
                        //}
                        //if (!string.IsNullOrWhiteSpace(FilterSelectedItem.ColumnValue))
                        //{
                        //    FilterSelectedItem.ColumnValue = FilterSelectedItem.ColumnValue.Remove(FilterSelectedItem.ColumnValue.Length - 1);
                        //}
                    }
                }
            }
        }
Exemple #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 DataGridExtend;
                }
            }

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

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

            if (column != null)
            {
                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);

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