Esempio n. 1
0
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria, string sortProperty, ListSortDirection sortDirection)
        {
            SortedBindingList <C> sortedList = GetSortedSubList(criteria);

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Esempio n. 2
0
        /// <summary>
        /// Devuelve un elemento a partir de los datos de la lista actual
        /// </summary>
        /// <param name="criteria">Filtro</param>
        /// <returns>Objeto C</returns>
        public virtual C GetItem(FCriteria criteria)
        {
            if (Items.Count == 0)
            {
                return(default(C));
            }

            PropertyDescriptor property = TypeDescriptor.GetProperties(Items[0]).Find(criteria.GetProperty(), false);

            foreach (C item in Items)
            {
                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                {
                    if (prop.Name == property.Name)
                    {
                        object value = prop.GetValue(item);

                        switch (criteria.Operation)
                        {
                        case Operation.Equal:
                            if (value.ToString().ToLower().Equals(criteria.GetValue().ToString().ToLower()))
                            {
                                return(item);
                            }
                            break;

                        default:
                            if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                            {
                                return(item);
                            }
                            break;
                        }
                    }
                }
            }

            return(default(C));
        }
Esempio n. 3
0
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria, List <string> properties_list)
        {
            List <C> list = new List <C>();
            SortedBindingList <C> sortedList = new SortedBindingList <C>(list);

            if (Items.Count == 0)
            {
                return(sortedList);
            }

            PropertyDescriptor property = null;

            if (criteria.GetProperty() != null)
            {
                property = TypeDescriptor.GetProperties(Items[0]).Find(criteria.GetProperty(), false);
            }
            else
            {
                property = null;
            }

            Type type = typeof(C);

            System.Reflection.PropertyInfo prop = null;

            switch (criteria.Operation)
            {
            case Operation.Equal:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (value.ToString().ToLower().Equals(criteria.GetValue().ToString().ToLower()))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (value.ToString().ToLower().Equals(criteria.GetValue().ToString().ToLower()))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;

            case Operation.StartsWith:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (value.ToString().ToLower().StartsWith(criteria.GetValue().ToString().ToLower()))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (value.ToString().ToLower().StartsWith(criteria.GetValue().ToString().ToLower()))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;

            case Operation.Less:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (criteria.Less(value))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (criteria.Less(value))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;

            case Operation.LessOrEqual:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (criteria.LessOrEqual(value))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (criteria.LessOrEqual(value))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;

            case Operation.Greater:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (criteria.Greater(value))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (criteria.Greater(value))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;

            case Operation.GreaterOrEqual:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (criteria.GreaterOrEqual(value))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (criteria.GreaterOrEqual(value))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;

            case Operation.Contains:
            default:
            {
                foreach (C item in Items)
                {
                    foreach (string propName in properties_list)
                    {
                        prop = type.GetProperty(propName);

                        if (prop == null)
                        {
                            continue;
                        }

                        //Buscamos en una propiedad en concreto
                        if (property != null)
                        {
                            if (prop.Name == property.Name)
                            {
                                object value = prop.GetValue(item, null);
                                if (value == null)
                                {
                                    break;
                                }
                                if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                                {
                                    sortedList.Add(item);
                                }
                                break;
                            }
                        }
                        //Buscamos en todas las propiedades de la lista
                        else
                        {
                            object value = prop.GetValue(item, null);
                            if (value == null)
                            {
                                continue;
                            }
                            if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                            {
                                sortedList.Add(item);
                                break;
                            }
                        }
                    }
                }
            } break;
            }

            return(sortedList);
        }
Esempio n. 4
0
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria)
        {
            List <C> list = new List <C>();

            SortedBindingList <C> sortedList = new SortedBindingList <C>(list);

            if (Items.Count == 0)
            {
                return(sortedList);
            }

            PropertyDescriptor property = TypeDescriptor.GetProperties(Items[0]).Find(criteria.GetProperty(), false);

            switch (criteria.Operation)
            {
            case Operation.StartsWith:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (value.ToString().ToLower().StartsWith(criteria.GetValue().ToString().ToLower()))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.Equal:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (criteria.Equal(value))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.Less:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (criteria.Less(value))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.LessOrEqual:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (criteria.LessOrEqual(value))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.Greater:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (criteria.Greater(value))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            case Operation.GreaterOrEqual:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (criteria.GreaterOrEqual(value))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            default:
            {
                foreach (C item in Items)
                {
                    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item))
                    {
                        if (prop.Name == property.Name)
                        {
                            object value = prop.GetValue(item);
                            if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                            {
                                sortedList.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;
            }

            return(sortedList);
        }