Exemplo n.º 1
0
        protected static string Function(FuncEnum func)
        {
            switch (func)
            {
            case FuncEnum.None:
                return("");

            case FuncEnum.Column:
                return("");

            case FuncEnum.CharLength:
                return(" char_length");

            case FuncEnum.DateFormat:
                return(" date_format");

            case FuncEnum.Trim:
                return(" trim");

            case FuncEnum.LTrim:
                return(" ltrim");

            case FuncEnum.RTrim:
                return(" rtrim");

            case FuncEnum.In:
                return(" in ");

            case FuncEnum.NotIn:
                return(" not in ");
            }
            return(" ");
        }
        private bool IsHavePower(IList<EmpModFunc> empModFuncs, Controller serviceBase, FuncEnum funcName)
        {
            bool retVal = false;

            string cls = serviceBase.GetType().FullName;

            if (empModFuncs != null)
            {
                foreach (EmpModFunc empModFunc in empModFuncs)
                {
                    //查找用户是否存在类的权限
                    if (empModFunc.ModFunc.Cls.Equals(cls))
                    {
                        if (empModFunc.FuncNames == null)
                        {
                            empModFunc.FuncNames = "";
                        }
                        //把函数枚举转为字符串形式,如"|Add|"
                        string funcNameStr = "|" + funcName + "|";
                        //查找函数权限
                        int find = empModFunc.FuncNames.IndexOf(funcNameStr);
                        if (find > -1)
                        {
                            retVal = true;
                            break;
                        }
                    }
                }
            }
            return retVal;
        }
Exemplo n.º 3
0
        //унарные операторы
        IOperand UnoOperand(IOperand a, FuncEnum operand)
        {
            IOperand value;

            switch (operand)
            {
            case FuncEnum.Nun:
                value = a;
                break;

            case FuncEnum.Sin:
                value = new Sin(a);
                break;

            case FuncEnum.Cos:
                value = new Cos(a);
                break;

            case FuncEnum.Log:
                value = new Ln(a);
                break;

            case FuncEnum.Min:
                value = new UnoMin(a);
                break;

            default:
                throw new Exception("Некорректная запись");
            }
            return(value);
        }
Exemplo n.º 4
0
        protected static void Function(FuncEnum func, StringBuilder sb)
        {
            switch (func)
            {
            case FuncEnum.None:
                return;

            case FuncEnum.CharLength:
                sb.Append(" char_length");
                return;

            case FuncEnum.DateFormat:
                sb.Append(" date_format");
                return;

            case FuncEnum.Trim:
                sb.Append(" trim");
                return;

            case FuncEnum.LTrim:
                sb.Append(" ltrim");
                return;

            case FuncEnum.RTrim:
                sb.Append(" rtrim");
                return;

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

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

            case FuncEnum.Count:
                sb.Append(" count");
                return;

            case FuncEnum.Sum:
                sb.Append(" sum");
                return;

            default:
                throw new Exception($"{XConfig.EC._008} - [[{func}]] 不能解析!!!");
            }
        }
Exemplo n.º 5
0
        //определение функции
        private void FindFunc(ref IValuesAndLink <char> nodeValue, out FuncEnum funcValue)
        {
            funcValue = FuncEnum.Nun;
            var strFunc = "";

            while (nodeValue != null && !NumbersPredicate(nodeValue.Value) && nodeValue.Value != UnoMinus && nodeValue.Value != OpenBracket && nodeValue.Value != CharVariable)
            {
                strFunc  += nodeValue.Value;
                nodeValue = nodeValue.Next;
            }

            switch (strFunc)
            {
            case "sin":
            {
                funcValue = FuncEnum.Sin;
                break;
            }

            case "cos":
            {
                funcValue = FuncEnum.Cos;
                break;
            }

            case "log":
            {
                funcValue = FuncEnum.Log;
                break;
            }

            default:
            {
                if (strFunc.Length > 0)
                {
                    throw new Exception("Введён неверный оператор");
                }
                break;
            }
            }
        }
Exemplo n.º 6
0
        internal protected static void Function(FuncEnum func, StringBuilder sb, Context dc)
        {
            switch (func)
            {
            case FuncEnum.None:
                return;

            case FuncEnum.CharLength:
                Spacing(sb); sb.Append("char_length");
                return;

            case FuncEnum.ToString_CS_DateTime_Format:
                Spacing(sb); sb.Append("date_format");
                return;

            case FuncEnum.Trim:
                Spacing(sb); sb.Append("trim");
                return;

            case FuncEnum.LTrim:
                Spacing(sb); sb.Append("ltrim");
                return;

            case FuncEnum.RTrim:
                Spacing(sb); sb.Append("rtrim");
                return;

            case FuncEnum.Count:
                Spacing(sb); sb.Append("count");
                return;

            case FuncEnum.Sum:
            case FuncEnum.SumNullable:
                Spacing(sb); sb.Append("sum");
                return;

            default:
                throw XConfig.EC.Exception(XConfig.EC._008, func.ToString());
            }
        }
Exemplo n.º 7
0
        private bool IsHavePower(IList <EmpModFunc> empModFuncs, Controller serviceBase, FuncEnum funcName)
        {
            bool retVal = false;

            string cls = serviceBase.GetType().FullName;

            if (empModFuncs != null)
            {
                foreach (EmpModFunc empModFunc in empModFuncs)
                {
                    //查找用户是否存在类的权限
                    if (empModFunc.ModFunc.Cls.Equals(cls))
                    {
                        if (empModFunc.FuncNames == null)
                        {
                            empModFunc.FuncNames = "";
                        }
                        //把函数枚举转为字符串形式,如"|Add|"
                        string funcNameStr = "|" + funcName + "|";
                        //查找函数权限
                        int find = empModFunc.FuncNames.IndexOf(funcNameStr);
                        if (find > -1)
                        {
                            retVal = true;
                            break;
                        }
                    }
                }
            }
            return(retVal);
        }
Exemplo n.º 8
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());
            }
        }
Exemplo n.º 9
0
        private (string key, string alias, Type valType, string classFullName, string format) GetKey(Expression bodyL, FuncEnum func, string format = "")
        {
            if (bodyL.NodeType == ExpressionType.Convert)
            {
                var exp   = bodyL as UnaryExpression;
                var opMem = exp.Operand;
                return(GetKey(opMem, func));
            }
            else if (bodyL.NodeType == ExpressionType.MemberAccess)
            {
                var leftBody = bodyL as MemberExpression;
                var info     = default(PropertyInfo);

                //
                var mType = default(Type);
                var alias = GetAlias(leftBody);
                if (func == FuncEnum.CharLength ||
                    func == FuncEnum.DateFormat)
                {
                    var exp = leftBody.Expression;
                    if (exp is MemberExpression)
                    {
                        var clMemExpr = exp as MemberExpression;
                        mType = clMemExpr.Expression.Type;
                        info  = mType.GetProperty(clMemExpr.Member.Name);
                    }
                    else if (exp is ParameterExpression)
                    {
                        mType = leftBody.Expression.Type;
                        info  = mType.GetProperty(leftBody.Member.Name);
                    }
                    else
                    {
                        throw new Exception($"{XConfig.EC._005} -- [[{bodyL.ToString()}]] 不能解析!!!");
                    }
                }
                else
                {
                    mType = leftBody.Expression.Type;
                    info  = mType.GetProperty(leftBody.Member.Name);
                }

                //
                var type  = info.PropertyType;
                var attr  = DC.SC.GetXColumnAttribute(info, DC.SC.GetAttrKey(XConfig.XColumnFullName, info.Name, mType.FullName));
                var field = string.Empty;
                if (attr != null)
                {
                    field = attr.Name;
                }
                else
                {
                    field = info.Name;
                }

                //
                return(field, alias, type, mType.FullName, format);
            }
            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));
                }
                else if (func == FuncEnum.In)
                {
                    var mem = mcExpr.Arguments[0];
                    return(GetKey(mem, func));
                }
                else if (func == FuncEnum.DateFormat)
                {
                    var mem = mcExpr.Object;
                    var val = DC.VH.ValueProcess(mcExpr.Arguments[0], XConfig.TC.String);
                    return(GetKey(mem, func, val.val.ToString()));
                }
            }

            return(default(string), default(string), default(Type), default(string), default(string));
        }