Exemplo n.º 1
0
        internal protected static void Compare(CompareXEnum compare, StringBuilder sb, Context dc)
        {
            switch (compare)
            {
            case CompareXEnum.None:
                return;

            case CompareXEnum.Equal:
                sb.Append("=");
                return;

            case CompareXEnum.NotEqual:
                sb.Append("<>");
                return;

            case CompareXEnum.LessThan:
                sb.Append("<");
                return;

            case CompareXEnum.LessThanOrEqual:
                sb.Append("<=");
                return;

            case CompareXEnum.GreaterThan:
                sb.Append(">");
                return;

            case CompareXEnum.GreaterThanOrEqual:
                sb.Append(">=");
                return;

            case CompareXEnum.Like:
                sb.Append(" like ");
                return;

            case CompareXEnum.NotLike:
                sb.Append(" not like ");
                return;

            case CompareXEnum.In:
                sb.Append(" in ");
                return;

            case CompareXEnum.NotIn:
                sb.Append(" not in ");
                return;

            default:
                throw XConfig.EC.Exception(XConfig.EC._023, compare.ToString());
            }
        }
Exemplo n.º 2
0
        internal ColumnParam GetKey(Expression bodyL, FuncEnum func, CompareXEnum compareX, string format = "")
        {
            if (bodyL.NodeType == ExpressionType.MemberAccess)
            {
                var leftBody = bodyL as MemberExpression;
                var prop     = default(PropertyInfo);

                //
                var mType = default(Type);
                var alias = GetAlias(leftBody);
                if (func == FuncEnum.CharLength ||
                    func == FuncEnum.ToString_CS_DateTime_Format)
                {
                    var exp = leftBody.Expression;
                    if (exp is MemberExpression)
                    {
                        var clMemExpr = exp as MemberExpression;
                        mType = clMemExpr.Expression.Type;
                        prop  = mType.GetProperty(clMemExpr.Member.Name);
                    }
                    else if (exp is ParameterExpression)
                    {
                        mType = leftBody.Expression.Type;
                        prop  = mType.GetProperty(leftBody.Member.Name);
                    }
                    else
                    {
                        throw XConfig.EC.Exception(XConfig.EC._005, bodyL.ToString());
                    }
                }
                else
                {
                    mType = leftBody.Expression.Type;
                    prop  = mType.GetProperty(leftBody.Member.Name);
                }

                //
                var type = prop.PropertyType;
                var tbm  = default(TableModelCache);
                try
                {
                    tbm = DC.XC.GetTableModel(mType);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("004") &&
                        ex.Message.Contains("[XTable]"))
                    {
                        throw XConfig.EC.Exception(XConfig.EC._094, $"表达式 -- {bodyL.ToString()} -- 不能正确解析!");
                    }
                }
                var attr = tbm.PCA.FirstOrDefault(it => prop.Name.Equals(it.PropName, StringComparison.OrdinalIgnoreCase)).ColAttr;
                return(new ColumnParam
                {
                    Prop = prop.Name,
                    Key = attr.Name,
                    Alias = alias,
                    ValType = type,
                    TbMType = mType,
                    Format = format
                });
            }
            else if (bodyL.NodeType == ExpressionType.Convert)
            {
                var exp   = bodyL as UnaryExpression;
                var opMem = exp.Operand;
                return(GetKey(opMem, func, compareX));
            }
            else if (bodyL.NodeType == ExpressionType.Call)
            {
                var mcExpr = bodyL as MethodCallExpression;
                if (func == FuncEnum.Trim ||
                    func == FuncEnum.LTrim ||
                    func == FuncEnum.RTrim)
                {
                    var mem = mcExpr.Object;
                    return(GetKey(mem, func, compareX));
                }
                else if (compareX == CompareXEnum.In)
                {
                    var mem = mcExpr.Arguments[0];
                    return(GetKey(mem, func, compareX));
                }
                else if (func == FuncEnum.ToString_CS_DateTime_Format)
                {
                    var mem = mcExpr.Object;
                    var val = DC.VH.ValueProcess(mcExpr.Arguments[0], XConfig.CSTC.String);
                    return(GetKey(mem, func, compareX, val.Val.ToString()));
                }
                else if (func == FuncEnum.ToString_CS)
                {
                    var mem = mcExpr.Object;
                    return(GetKey(mem, func, compareX));
                }
                else
                {
                    throw XConfig.EC.Exception(XConfig.EC._018, $"{bodyL.NodeType}-{func}");
                }
            }
            else
            {
                throw XConfig.EC.Exception(XConfig.EC._017, bodyL.NodeType.ToString());
            }
        }