/// <summary> /// increase the key position depending on the logical Operator /// </summary> /// <param name="ctx"></param> /// <returns></returns> public uint incIncreaseKeyNo(SelectConditionsContext ctx) { // increase only if the last operator was an AND/ANDALSO if (ctx.logicalOperator_2() != null) { // if there is an AND or ANDALSO if (ctx.logicalOperator_2().Last().Operator.Token.ToUint == Token.AND || ctx.logicalOperator_2().Last().Operator.Token.ToUint == Token.ANDALSO) { // check if the last named entry is a key -> reposition for unamed defaults // (100,200,uid=150,250) -> keypos 1,2,1,2 if (ctx.selectCondition() != null) { if (ctx.selectCondition().Last().dataObjectEntry != null) { DataObjectEntrySymbol aSymbol = (DataObjectEntrySymbol)ctx.selectCondition().Last().dataObjectEntry.XPTreeNode; if (aSymbol.CheckValidity().HasValue&& aSymbol.IsValid.Value == true) { if (aSymbol.ObjectDefinition.Keys.Contains(aSymbol.Entryname)) { int pos = Array.FindIndex(aSymbol.ObjectDefinition.Keys, x => String.Compare(x, aSymbol.Entryname.ToUpper(), true) == 0); if (pos >= 0) { ctx.keypos = (uint)pos + 1; // keypos is starting from 1 ... -> will be increased to next key lower down } } } } } // simply increase and return return(ctx.keypos++); } } return(ctx.keypos); }
/// <summary> /// increase the key position depending on the logical Operator /// </summary> /// <param name="ctx"></param> /// <returns></returns> public uint incIncreaseKeyNo(SelectConditionsContext ctx) { // increase only if the last operator was an AND/ANDALSO if (ctx.logicalOperator_2() != null) { // if there is an AND or ANDALSO if (ctx.logicalOperator_2().Last().Operator.Token.ToUint == Token.AND || ctx.logicalOperator_2().Last().Operator.Token.ToUint == Token.ANDALSO) { // check if the last named entry is a key -> reposition for unamed defaults // (100,200,uid=150,250) -> keypos 1,2,1,2 if (ctx.selectCondition() != null ) { if (ctx.selectCondition().Last().dataObjectEntry != null) { DataObjectEntrySymbol aSymbol = (DataObjectEntrySymbol)ctx.selectCondition().Last().dataObjectEntry.XPTreeNode; if (aSymbol.CheckValidity().HasValue && aSymbol.IsValid.Value == true) if (aSymbol.ObjectDefinition.Keys.Contains(aSymbol.Entryname)) { int pos = Array.FindIndex(aSymbol.ObjectDefinition.Keys, x => String.Compare(x, aSymbol.Entryname.ToUpper(), true) == 0); if (pos >= 0) ctx.keypos = (uint)pos+1; // keypos is starting from 1 ... -> will be increased to next key lower down } } } // simply increase and return return ctx.keypos++; } } return ctx.keypos; }
/// <summary> /// build a XPT Node out of a selection conditions /// </summary> /// <param name="ctx"></param> /// <returns></returns> public bool BuildXPTNode(SelectConditionsContext ctx) { // L_SQUARE_BRACKET R_SQUARE_BRACKET // all if (ctx.selectCondition() == null || ctx.selectCondition().Count()==0) { // simple true operator ctx.XPTreeNode = LogicalExpression.TRUE(); return true; } // only one condition // selectCondition [$ClassName, $keypos] if (ctx.selectCondition().Count() == 1) { if (ctx.NOT().Count() == 0) ctx.XPTreeNode = ctx.selectCondition()[0].XPTreeNode; else ctx.XPTreeNode = LogicalExpression.NOT((IExpression)ctx.selectCondition()[0].XPTreeNode); return true; } // if we have more than this //| selectCondition [$ClassName, $keypos] (logicalOperator_2 selectCondition [$ClassName, $keypos])* if (ctx.selectCondition().Count() > 1) { eXPressionTree.LogicalExpression theLogical = (LogicalExpression)ctx.selectCondition()[0].XPTreeNode; if (theLogical == null) return false; for(uint i = 0; i < ctx.selectCondition().Count()-1;i++) { Operator anOperator = ctx.logicalOperator_2()[i].Operator; // x or y and z -> ( x or y) and z ) if (theLogical.Priority >= anOperator.Priority) { if ((LogicalExpression)ctx.selectCondition()[i + 1].XPTreeNode != null) theLogical = new LogicalExpression(anOperator, theLogical, (LogicalExpression)ctx.selectCondition()[i + 1].XPTreeNode); else return false; // negate if (ctx.NOT().Count() >= i+1 && ctx.NOT()[i + 1] != null) theLogical = LogicalExpression.NOT((IExpression)theLogical); } else { // x and y or z -> x and ( y or z ) // build the new (lower) operation in the higher level tree (right with the last operand) IExpression right = (IExpression)theLogical.RightOperand; theLogical.RightOperand = new LogicalExpression(anOperator, right, (IExpression)ctx.selectCondition()[i + 1].XPTreeNode); // negate if (ctx.NOT().Count() >= i + 1 && ctx.NOT()[i + 1] != null) theLogical.RightOperand = LogicalExpression.NOT((IExpression)theLogical.RightOperand); } } ctx.XPTreeNode = theLogical; return true; } return false; }
/// <summary> /// build a XPT Node out of a selection conditions /// </summary> /// <param name="ctx"></param> /// <returns></returns> public bool BuildXPTNode(SelectConditionsContext ctx) { // L_SQUARE_BRACKET R_SQUARE_BRACKET // all if (ctx.selectCondition() == null || ctx.selectCondition().Count() == 0) { // simple true operator ctx.XPTreeNode = LogicalExpression.TRUE(); return(true); } // only one condition // selectCondition [$ClassName, $keypos] if (ctx.selectCondition().Count() == 1) { if (ctx.NOT().Count() == 0) { ctx.XPTreeNode = ctx.selectCondition()[0].XPTreeNode; } else { ctx.XPTreeNode = LogicalExpression.NOT((IExpression)ctx.selectCondition()[0].XPTreeNode); } return(true); } // if we have more than this //| selectCondition [$ClassName, $keypos] (logicalOperator_2 selectCondition [$ClassName, $keypos])* if (ctx.selectCondition().Count() > 1) { eXPressionTree.LogicalExpression theLogical = (LogicalExpression)ctx.selectCondition()[0].XPTreeNode; if (theLogical == null) { return(false); } for (uint i = 0; i < ctx.selectCondition().Count() - 1; i++) { Operator anOperator = ctx.logicalOperator_2()[i].Operator; // x or y and z -> ( x or y) and z ) if (theLogical.Priority >= anOperator.Priority) { if ((LogicalExpression)ctx.selectCondition()[i + 1].XPTreeNode != null) { theLogical = new LogicalExpression(anOperator, theLogical, (LogicalExpression)ctx.selectCondition()[i + 1].XPTreeNode); } else { return(false); } // negate if (ctx.NOT().Count() >= i + 1 && ctx.NOT()[i + 1] != null) { theLogical = LogicalExpression.NOT((IExpression)theLogical); } } else { // x and y or z -> x and ( y or z ) // build the new (lower) operation in the higher level tree (right with the last operand) IExpression right = (IExpression)theLogical.RightOperand; theLogical.RightOperand = new LogicalExpression(anOperator, right, (IExpression)ctx.selectCondition()[i + 1].XPTreeNode); // negate if (ctx.NOT().Count() >= i + 1 && ctx.NOT()[i + 1] != null) { theLogical.RightOperand = LogicalExpression.NOT((IExpression)theLogical.RightOperand); } } } ctx.XPTreeNode = theLogical; return(true); } return(false); }