private string GetRawFormula(TypeOperations type) { string rawFormula = string.Empty; switch (type) { case TypeOperations.Equals: rawFormula = "(({0}) - ({1}))::abs < 1000"; break; case TypeOperations.GreaterThan: rawFormula = "(({0}) - ({1})) > -1000"; break; case TypeOperations.LessThan: rawFormula = "(({0}) - ({1})) < 1000"; break; case TypeOperations.GreaterThanEquals: rawFormula = "(({0}) - ({1})) >= -1000"; break; case TypeOperations.LessThanEquals: rawFormula = "(({0}) - ({1})) <= 1000"; break; } return(rawFormula); }
public Operations(string id, TypeOperations type, object[] oparams) { OID = id; OType = type; OParams = oparams; }
private string[] GetOperands(MatchCollection match, string item, string inputFormula, TypeOperations Type) { Dictionary <string, string> dictOperators = GetOperators(); string[] operands = new string[0]; if (match.Count > 1) { operands = item.ToString().Split(new string[] { dictOperators[Type.ToString()] }, StringSplitOptions.None); } else { operands = inputFormula.ToString().Split(new string[] { dictOperators[Type.ToString()] }, StringSplitOptions.None); } return(operands); }
private string GetTranslatedFormula(string inputFormula, MatchCollection matchReference, TypeOperations Type) { string rawFormula = string.Empty; string[] operands = new string[0]; MatchCollection match = specialCharacter.Matches(inputFormula); if (matchReference.Count > 0) { foreach (var item in matchReference) { if (matchReference.Count == 1) { if (Type == TypeOperations.Equals) { operands = GetOperands(match, item.ToString(), inputFormula, TypeOperations.Equals); } else if (Type == TypeOperations.GreaterThan) { operands = GetOperands(match, item.ToString(), inputFormula, TypeOperations.GreaterThan); } else if (Type == TypeOperations.LessThan) { operands = GetOperands(match, item.ToString(), inputFormula, TypeOperations.LessThan); } else if (Type == TypeOperations.GreaterThanEquals) { operands = GetOperands(match, item.ToString(), inputFormula, TypeOperations.GreaterThanEquals); } else if (Type == TypeOperations.LessThanEquals) { operands = GetOperands(match, item.ToString(), inputFormula, TypeOperations.LessThanEquals); } else { } rawFormula = GetRawFormula(Type); string replaceFormula = string.Format(rawFormula, operands[0], operands[1]); if (match.Count > 1) { inputFormula = inputFormula.Replace(item.ToString(), replaceFormula); } else { inputFormula = replaceFormula; } } else { operands = item.ToString().Split(new string[] { " == " }, StringSplitOptions.None); rawFormula = GetRawFormula(Type); string replaceFormula = string.Format(rawFormula, operands[0], operands[1]); inputFormula = inputFormula.Replace(item.ToString(), replaceFormula); } } } return(inputFormula); }