public object TranslateFilterSyntax(LlExpressionPart part, ref object name, int argumentCount, object[] arguments)
{
switch (part)
{
case LlExpressionPart.Unknown:
{
return null;
}
case LlExpressionPart.Boolean:
{
if (arguments[0] != null)
{
return ((bool)arguments[0] ? "true" : "false");
}
else
{
return "null";
}
}
case LlExpressionPart.Text:
{
if (arguments[0] != null)
{
return String.Format("'{0}'", arguments[0]);
}
else
{
return "null";
}
}
case LlExpressionPart.Number:
{
if (arguments[0] != null)
{
return arguments[0].ToString();
}
else
{
return "null";
}
}
case LlExpressionPart.Date:
{
if (arguments[0] != null)
{
return String.Format("#{0}#", ((DateTime)arguments[0]).ToString(CultureInfo.InvariantCulture));
}
else
{
return "null";
}
}
case LlExpressionPart.UnaryOperatorSign:
{
return (String.Format("(-({0}))", arguments[0]));
}
case LlExpressionPart.UnaryOperatorNegation:
{
return (String.Format("(NOT ({0}))", arguments[0]));
}
case LlExpressionPart.BinaryOperatorAdd:
{
return (String.Format("({0}+{1})", arguments[0], arguments[1]));
}
case LlExpressionPart.BinaryOperatorSubstract:
{
return (String.Format("({0}-{1})", arguments[0], arguments[1]));
}
case LlExpressionPart.BinaryOperatorMultiply:
{
return (String.Format("({0}*{1})", arguments[0], arguments[1]));
}
case LlExpressionPart.BinaryOperatorDivide:
{
return (String.Format("({0}/{1})", arguments[0], arguments[1]));
}
case LlExpressionPart.BinaryOperatorModulo:
{
return (String.Format("({0}%{1})", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationXor:
{
return (String.Format("(({0} AND NOT {1}) OR (NOT {0} AND {1}))", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationOr:
{
return (String.Format("({0} OR {1})", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationAnd:
{
return (String.Format("({0} AND {1})", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationEqual:
{
if (!name.ToString().Equals("@ARG:MULTIVALUE", StringComparison.InvariantCultureIgnoreCase))
{
return (String.Format("({0} = {1})", arguments[0], arguments[1]));
}
else
{
return (String.Format("({0} IN ({1}))", arguments[0], arguments[1]));
}
}
case LlExpressionPart.RelationNotEqual:
{
if (!name.ToString().Equals("@ARG:MULTIVALUE", StringComparison.InvariantCultureIgnoreCase))
{
return (String.Format("({0} <> {1})", arguments[0], arguments[1]));
}
else
{
return (String.Format("(NOT {0} IN ({1}))", arguments[0], arguments[1]));
}
}
case LlExpressionPart.RelationLarger:
{
return (String.Format("({0} > {1})", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationLargerEqual:
{
return (String.Format("({0} >= {1})", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationSmaller:
{
return (String.Format("({0} < {1})", arguments[0], arguments[1]));
}
case LlExpressionPart.RelationSmallerEqual:
{
return (String.Format("({0} <= {1})", arguments[0], arguments[1]));
}
case LlExpressionPart.Function:
{
switch (name.ToString().ToUpper())
{
case "":
return (String.Format("({0})", arguments[0]));
case "ISNULL":
return (String.Format("(ISNULL({0}))", arguments[0]));
case "STARTSWITH":
return (String.Format("({0} LIKE '{1}%')", arguments[0], EscapeArgumentForRowFilter(arguments[1].ToString())));
case "ENDSWITH":
return (String.Format("({0} LIKE '%{1}')", arguments[0], EscapeArgumentForRowFilter(arguments[1].ToString())));
case "CONTAINS":
return (String.Format("({0} LIKE '{1}')", arguments[0], EscapeArgumentForRowFilter(arguments[1].ToString())));
case "MID$":
{
long arg1 = Convert.ToInt64(arguments[1]);
if (arg1 < 0)
{
return null;
}
if (argumentCount == 3)
return (String.Format("(SUBSTRING({0},{1},{2}))", arguments[0], arg1 + 1, arguments[2]));
else
return String.Empty;
}
case "LEFT$":
return (String.Format("(SUBSTRING({0},1,{1}))", arguments[0], arguments[1]));
case "LEN":
return (String.Format("(LEN({0}))", arguments[0]));
case "EMPTY":
if (argumentCount == 1)
return (String.Format("(LEN({0})=0)", arguments[0]));
else
return (String.Format("(LEN(TRIM({0}))=0)", arguments[0]));
case "ATRIM$":
return (String.Format("(TRIM({0}))", arguments[0]));
case "COND":
return (String.Format("(IIF({0},{1},{2}))", arguments[0], arguments[1], arguments[2]));
case "DATEINRANGE":
return (String.Format("(({0} >= {1}) AND ({0} <= {2}))", arguments[0], arguments[1], arguments[2]));
case "NUMINRANGE":
return (String.Format("(({0} >= {1}) AND ({0} <= {2}))", arguments[0], arguments[1], arguments[2]));
}
return null;
}
case LlExpressionPart.Field:
{
if (arguments[0] == null || !arguments[0].ToString().StartsWith(TableName + "."))
{
return null;
}
return String.Format("[{0}]", arguments[0].ToString().Substring(TableName.Length + 1));
}
default:
return null;
}
}