/// <summary> /// Devuelve una lista ordenada y filtrada a partir de los datos de la lista /// actual, usando un criterio para fechas. /// </summary> /// <param name="criteria">Criterio para DateTime</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(DCriteria 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); switch (criteria.Operation) { case Operation.Less: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value < (DateTime)criteria.GetValue()) { 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) { DateTime value = (DateTime)prop.GetValue(item); if (value <= (DateTime)criteria.GetValue()) { 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) { DateTime value = (DateTime)prop.GetValue(item); if (value == (DateTime)criteria.GetValue()) { 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) { DateTime value = (DateTime)prop.GetValue(item); if (value >= (DateTime)criteria.GetValue()) { 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) { DateTime value = (DateTime)prop.GetValue(item); if (value > (DateTime)criteria.GetValue()) { sortedList.Add(item); } break; } } } } break; default: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value == (DateTime)criteria.GetValue()) { sortedList.Add(item); } break; } } } } break; } sortedList.ApplySort(sortProperty, sortDirection); return(sortedList); }
/// <summary> /// Devuelve una lista a partir de los datos de la lista actual, usando /// un criterio para fechas /// </summary> /// <param name="criteria">Filtro para DateTime</param> /// <returns>Lista</returns> public List <C> GetSubList(DCriteria 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.Less: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value < (DateTime)criteria.GetValue()) { list.Add(item); } break; } } } } break; case Operation.LessOrEqual: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value <= (DateTime)criteria.GetValue()) { 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) { DateTime value = (DateTime)prop.GetValue(item); if (value == (DateTime)criteria.GetValue()) { list.Add(item); } break; } } } } break; case Operation.GreaterOrEqual: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value >= (DateTime)criteria.GetValue()) { list.Add(item); } break; } } } } break; case Operation.Greater: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value > (DateTime)criteria.GetValue()) { list.Add(item); } break; } } } } break; default: { foreach (C item in Items) { foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(item)) { if (prop.Name == property.Name) { DateTime value = (DateTime)prop.GetValue(item); if (value == (DateTime)criteria.GetValue()) { list.Add(item); } break; } } } } break; } return(list); }