private void RebuildFilter() { this.FilterDescriptors.BeginUpdate(); for (int index = this.FilterDescriptors.Count - 1; index >= 0; --index) { FilterDescriptor filterDescriptor = this.FilterDescriptors[index]; filterDescriptor.PropertyChanged -= new PropertyChangedEventHandler(this.FilterExpression_PropertyChanged); this.FilterDescriptors.Remove(filterDescriptor); } this.FilterDescriptors.Clear(); FilterDescriptorCollection filterDescriptors = this.FilterDescriptors; if (this.predicates.Count > 0) { filterDescriptors.LogicalOperator = GridViewHelper.GetLogicalOperator(this.predicates[0].BinaryOperator); } List <FilterPredicate> validPredicates = this.GetValidPredicates(); for (int index = 0; index < validPredicates.Count; ++index) { object[] predicateValues = this.GetPredicateValues(validPredicates[index]); FilterOperator filterOperator = GridViewHelper.GetFilterOperator(validPredicates[index].Function); if (filterOperator != FilterOperator.None) { FilterDescriptor filterDescriptor = new FilterDescriptor(this.PropertyName, filterOperator, predicateValues[0]); filterDescriptor.PropertyChanged += new PropertyChangedEventHandler(this.FilterExpression_PropertyChanged); filterDescriptors.Add(filterDescriptor); } else { CompositeFilterDescriptor.DescriptorType type = CompositeFilterDescriptor.DescriptorType.Between; if (this.predicates[index].Function == GridKnownFunction.NotBetween) { type = CompositeFilterDescriptor.DescriptorType.NotBetween; } CompositeFilterDescriptor descriptor = CompositeFilterDescriptor.CreateDescriptor(type, this.PropertyName, predicateValues[0], predicateValues[1]); descriptor.PropertyChanged += new PropertyChangedEventHandler(this.FilterExpression_PropertyChanged); filterDescriptors.Add((FilterDescriptor)descriptor); } if (this.IsComposite(validPredicates.Count - index, validPredicates)) { CompositeFilterDescriptor filterDescriptor = new CompositeFilterDescriptor(); filterDescriptor.PropertyChanged += new PropertyChangedEventHandler(this.FilterExpression_PropertyChanged); filterDescriptor.LogicalOperator = GridViewHelper.GetLogicalOperator(validPredicates[index + 2].BinaryOperator); filterDescriptors.Add((FilterDescriptor)filterDescriptor); filterDescriptors = filterDescriptor.FilterDescriptors; } } this.FilterDescriptors.EndUpdate(); }
//private void Parse(string expression) //{ // ExpressionNode root = ExpressionParser.Parse(expression, false); // //validate name nodes // this.BeginUpdate(); // this.Clear(); // Stack<ExpressionNode> nodeStack = new Stack<ExpressionNode>(); // nodeStack.Push(root); // Stack<FilterExpressionCollection> collectionStack = new Stack<FilterExpressionCollection>(); // collectionStack.Push(this); // while (nodeStack.Count > 0) // { // ExpressionNode current = nodeStack.Pop(); // FilterExpressionCollection expressions = collectionStack.Pop(); // UnaryOpNode unaryNode = current as UnaryOpNode; // if (unaryNode != null) // { // if (unaryNode.Op == Operator.Noop) // { // nodeStack.Push(((UnaryOpNode)current).Right); // collectionStack.Push(expressions); // continue; // } // } // BinaryOpNode binaryNode = current as BinaryOpNode; // if (binaryNode != null) // { // if (this.IsPredicate(binaryNode)) // { // FilterExpression filterExpression = new FilterExpression(); // expressions.Add(filterExpression); // continue; // } // nodeStack.Push(binaryNode.Right); // FilterExpressionCollection collection = expressions; // if(!this.IsPredicate(binaryNode.Right)) // { // CompositeFilterExpression compositeExpression = new CompositeFilterExpression(); // expressions.Add(compositeExpression); // collection = compositeExpression.FilterExpressions; // } // collectionStack.Push(collection); // nodeStack.Push(binaryNode.Left); // collection = expressions; // if (!this.IsPredicate(binaryNode.Left)) // { // CompositeFilterExpression compositeExpression = new CompositeFilterExpression(); // compositeExpression.BinaryOperator = (binaryNode.Op == Operator.And) ? FilterExpression.BinaryOperation.AND : FilterExpression.BinaryOperation.OR; // expressions.Add(compositeExpression); // collection = compositeExpression.FilterExpressions; // } // collectionStack.Push(collection); // } // } // this.EndUpdate(); //} //private bool IsPredicate(ExpressionNode node) //{ // while (node is UnaryOpNode) // { // node = ((UnaryOpNode)node).Right; // } // BinaryOpNode binaryNode = node as BinaryOpNode; // if (binaryNode == null) // { // return false; // } // if (binaryNode.Left is NameNode || binaryNode.Right is NameNode) // { // return true; // } // return false; //} private void Parse(string expression) { ExpressionNode root = ExpressionParser.Parse(expression, false); //validate name nodes this.BeginUpdate(); this.Clear(); Stack <ExpressionNode> nodeStack = new Stack <ExpressionNode>(); nodeStack.Push(root); Stack <FilterDescriptorCollection> collectionStack = new Stack <FilterDescriptorCollection>(); collectionStack.Push(this); while (nodeStack.Count > 0) { ExpressionNode current = nodeStack.Pop(); FilterDescriptorCollection expressions = collectionStack.Pop(); UnaryOpNode unaryNode = current as UnaryOpNode; if (unaryNode != null) { if (unaryNode.Op == Operator.Noop) { nodeStack.Push(((UnaryOpNode)current).Right); collectionStack.Push(expressions); continue; } } BinaryOpNode binaryNode = current as BinaryOpNode; if (binaryNode != null) { if (this.IsPredicate(binaryNode)) { FilterDescriptor filterDescriptor = this.CreateFilterDescriptor(binaryNode); expressions.Add(filterDescriptor); continue; } nodeStack.Push(binaryNode.Right); FilterDescriptorCollection collection = expressions; if (!this.IsPredicate(binaryNode.Right)) { CompositeFilterDescriptor compositeExpression = new CompositeFilterDescriptor(); expressions.Add(compositeExpression); collection = compositeExpression.FilterDescriptors; } collectionStack.Push(collection); nodeStack.Push(binaryNode.Left); collection = expressions; if (!this.IsPredicate(binaryNode.Left)) { CompositeFilterDescriptor compositeExpression = new CompositeFilterDescriptor(); compositeExpression.LogicalOperator = (binaryNode.Op == Operator.And) ? FilterLogicalOperator.And : FilterLogicalOperator.Or; expressions.Add(compositeExpression); collection = compositeExpression.FilterDescriptors; } collectionStack.Push(collection); } } this.EndUpdate(); }
public CompositeFilterDescriptor() { this.filters = new FilterDescriptorCollection(); }
public CompositeFilterDescriptor() { this.filters = new FilterDescriptorCollection(); this.filters.CollectionChanged += new NotifyCollectionChangedEventHandler(this.filters_CollectionChanged); }
private void Parse(string expression) { ExpressionNode binaryNode1 = ExpressionParser.Parse(expression, false); this.BeginUpdate(); this.Clear(); Stack <ExpressionNode> expressionNodeStack = new Stack <ExpressionNode>(); expressionNodeStack.Push(binaryNode1); Stack <FilterDescriptorCollection> descriptorCollectionStack = new Stack <FilterDescriptorCollection>(); descriptorCollectionStack.Push(this); this.LogicalOperator = this.GetCompositeFilterDescriptorLogicalOperator(binaryNode1); bool flag = false; while (expressionNodeStack.Count > 0) { ExpressionNode expressionNode = expressionNodeStack.Pop(); FilterDescriptorCollection descriptorCollection1 = descriptorCollectionStack.Pop(); UnaryOpNode unaryOpNode = expressionNode as UnaryOpNode; if (unaryOpNode != null) { if (unaryOpNode.Op == Operator.Noop) { expressionNodeStack.Push(((UnaryOpNode)expressionNode).Right); descriptorCollectionStack.Push(descriptorCollection1); continue; } if (unaryOpNode.Op == Operator.Not) { expressionNodeStack.Push(((UnaryOpNode)expressionNode).Right); flag = true; descriptorCollectionStack.Push(descriptorCollection1); continue; } } BinaryOpNode binaryNode2 = expressionNode as BinaryOpNode; if (binaryNode2 != null) { if (this.IsPredicate((ExpressionNode)binaryNode2)) { FilterDescriptor filterDescriptor = this.CreateFilterDescriptor(binaryNode2); if (flag) { filterDescriptor.Operator = this.GetNegativeOperator(filterDescriptor.Operator); flag = false; } descriptorCollection1.Add(filterDescriptor); } else { expressionNodeStack.Push(binaryNode2.Right); FilterDescriptorCollection descriptorCollection2 = descriptorCollection1; if (!this.IsPredicate(binaryNode2.Right)) { CompositeFilterDescriptor filterDescriptor = new CompositeFilterDescriptor(); filterDescriptor.LogicalOperator = this.GetCompositeFilterDescriptorLogicalOperator(binaryNode2.Right); descriptorCollection1.Add((FilterDescriptor)filterDescriptor); descriptorCollection2 = filterDescriptor.FilterDescriptors; } descriptorCollectionStack.Push(descriptorCollection2); expressionNodeStack.Push(binaryNode2.Left); FilterDescriptorCollection descriptorCollection3 = descriptorCollection1; if (!this.IsPredicate(binaryNode2.Left)) { CompositeFilterDescriptor filterDescriptor = new CompositeFilterDescriptor(); filterDescriptor.LogicalOperator = this.GetCompositeFilterDescriptorLogicalOperator(binaryNode2.Left); descriptorCollection1.Add((FilterDescriptor)filterDescriptor); descriptorCollection3 = filterDescriptor.FilterDescriptors; } descriptorCollectionStack.Push(descriptorCollection3); } } } this.EndUpdate(); }