// compare one row versus the filters public static bool Evaluate(RevisionDataFields items, RevisionFilters filters) { // scan through the list of filter tests to determine if // the provided information passes // return true if this item meets all of the criteria // return false if any part of this item does not meet the criteria if (filters == null || items == null) { throw new ArgumentNullException(); } if (filters.Count == 0 || items.Count == 0) { return(false); } bool result = false; // compare the data item referenced in the filter to the filter criteria // the filters are in a outer (data enum) order // each data item field could have multiple criteria filters // inner loop is an 'or' loop - that is, if any of the inner // filters are true, the whole inner filter is true. for conflicts // that is, filtering the same item in opposite ways (e.g. is true and is false) // a true will supersede a false // // the outer loop is the opposite // it is an 'and' loop - a single false and the data row fails foreach (KeyValuePair <DataItems.FilterEnum, RevisionFilters.Filters> kvpOuter in filters) { foreach (KeyValuePair <int, RevisionFilters.Criteria> kvpInner in kvpOuter.Value) { if (kvpInner.Value.CompareOpr == RevisionFilters.ECompareOps.ANY) { result = true; } else { // evaluate the actual revision data versus the test criteria result = Verify(items[kvpOuter.Key.DataIdx], kvpInner.Value); } if (result) { break; } } if (!result) { break; } } return(result); }
// from data manager's primary list, // select those records that match the // filter criteria public static bool Select(RevisionFilters filters) { if (_preSelected.Count == 0) { return(false); } // start with empty and add to this ClearSelected(); foreach (RevisionDataFields kvp in _preSelected) { if (RevisionSelect.Evaluate(kvp, filters)) { _selected.Add(kvp); } } return(_selected.Count != 0); }