Example #1
0
        /// <summary>
        /// Devuelve una lista a partir de los datos de la lista actual
        /// </summary>
        /// <param name="criteria">Filtro</param>
        /// <returns>Lista</returns>
        public virtual List <C> GetSubList(FCriteria criteria)
        {
            List <C> list = new List <C>();

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

            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);
                        if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                        {
                            list.Add(item);
                        }
                    }
                }
            }

            return(list);
        }
Example #2
0
        /// <summary>
        /// Devuelve una lista ordenada y filtrada a partir de los datos de la lista
        /// actual
        /// </summary>
        /// <param name="criteria">Filtro</param>
        /// <param name="sortProperty">Campo de ordenación</param>
        /// <param name="sortDirection">Sentido de ordenación</param>
        /// <returns>Lista ordenada</returns>
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria,
                                                      string sortProperty,
                                                      ListSortDirection sortDirection)
        {
            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);

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

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Example #3
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);
                        if (value.ToString().ToLower().Contains(criteria.GetValue().ToString().ToLower()))
                        {
                            return(item);
                        }
                    }
                }
            }

            return(default(C));
        }
Example #4
0
        /// <summary>
        /// Función que realiza el filtrado de los formularios Localize
        /// cuando se busca por campos que no pertenecen a la tabla
        /// </summary>
        /// <param name="sublist"></param>
        /// <param name="lista"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public static List <C> GetFilteredList(T lista, IList sublist, string property)
        {
            List <C> rlist = new List <C>();

            //T rlist = DataPortal.Create<T>();
            PropertyDescriptor prop, prop2;

            foreach (object item in sublist)
            {
                prop = TypeDescriptor.GetProperties(item).Find("Oid", true);

                FCriteria criteria = new FCriteria <long>(property, (long)prop.GetValue(item));

                List <C> list = null;

                list = GetSubList(lista, criteria);

                if (list.Count > 0)
                {
                    foreach (C dom in list)
                    {
                        prop2 = TypeDescriptor.GetProperties(dom).Find(property, true);
                        if ((long)prop2.GetValue(dom) == (long)prop.GetValue(item))
                        {
                            rlist.Add(dom);
                        }
                    }
                }
            }

            return(rlist);
        }
Example #5
0
        public SortedBindingList <C> GetSortedSubList(FCriteria criteria, string sortProperty, ListSortDirection sortDirection)
        {
            SortedBindingList <C> sortedList = GetSortedSubList(criteria);

            sortedList.ApplySort(sortProperty, sortDirection);
            return(sortedList);
        }
Example #6
0
        public virtual C GetItem(FCriteria criteria)
        {
            if (Items.Count == 0)
            {
                return(default(C));
            }

            PropertyDescriptor prop = TypeDescriptor.GetProperties(Items[0]).Find(criteria.GetProperty(), false);
            int pos = FindCore(prop, criteria.GetValue());

            if (pos != -1)
            {
                return(Items[pos]);
            }

            return(default(C));
        }
Example #7
0
        /// <summary>
        /// Devuelve una lista a partir de los datos de la lista actual
        /// </summary>
        /// <param name="criteria">Filtro (Insensitive)</param>
        /// <returns>Lista</returns>
        public List <C> GetSubList(FCriteria criteria)
        {
            List <C> list = new List <C>();

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

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

            switch (criteria.Operation)
            {
            case Operation.Contains:
            {
                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()))
                            {
                                list.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 (value.ToString().ToLower().Equals(criteria.GetValue().ToString().ToLower()))
                            {
                                list.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;

            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()))
                            {
                                list.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()))
                            {
                                list.Add(item);
                            }
                            break;
                        }
                    }
                }
            } break;
            }

            return(list);
        }
Example #8
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);
        }