コード例 #1
0
        /// <summary>
        /// 解析用户输入的条件表达式
        /// </summary>
        /// <param name="parseCondition">条件表达式</param>
        /// <returns>解析结果</returns>
        public bool CacluateCondition(string parseCondition)
        {
            if (string.IsNullOrEmpty(parseCondition))
            {
                return(true);
            }
            ParseExpression pe = new ParseExpression();

            pe.UserFunctions = (IExpParsing)this;

            pe.ChangeExpression(parseCondition);
            object condValue = pe.Value();

            return((bool)condValue);
        }
コード例 #2
0
        /// <summary>
        /// 解析用户输入的条件表达式
        /// </summary>
        /// <param name="parseCondition">条件表达式</param>
        /// <returns>解析结果</returns>
        public decimal CacluateExpression(string Expression)
        {
            if (string.IsNullOrEmpty(Expression))
            {
                throw new Exception("Expression is null");
            }
            ParseExpression pe = new ParseExpression();

            pe.UserFunctions = (IExpParsing)this;

            pe.ChangeExpression(Expression);
            object  condValue = pe.Value();
            decimal result    = decimal.MinValue;

            decimal.TryParse(condValue.ToString(), out result);

            return(result);
        }
コード例 #3
0
ファイル: ParseExpression.cs プロジェクト: zyg0717/LJTH_SJSJ
        private object CalculateFunction(string strFuncName, ParamObject[] arrParams, ParseExpression parseObj)
        {
            object oValue = null;

            try
            {
                switch (strFuncName.ToLower())
                {
                case "now":
                    oValue = DateTime.Now;
                    break;

                case "today":
                    oValue = DateTime.Today;
                    break;

                case "dateinterval.day":
                    oValue = "d";
                    break;

                case "dateinterval.hour":
                    oValue = "h";
                    break;

                case "dateinterval.minute":
                    oValue = "n";
                    break;

                case "dateinterval.second":
                    oValue = "s";
                    break;

                case "dateinterval.millisecond":
                    oValue = "ms";
                    break;

                case "datediff":
                    oValue = DoDateDiff(arrParams);
                    break;

                case "mindate":
                    oValue = DateTime.MinValue;
                    break;

                case "maxdate":
                    oValue = DateTime.MaxValue;
                    break;

                default:
                {
                    if (UserFunctions != null)
                    {
                        oValue = UserFunctions.CalculateUserFunction(strFuncName, arrParams, this);
                    }

                    break;
                }
                }

                return(oValue);
            }
            catch (System.Exception ex)
            {
                throw new ApplicationException(string.Format("函数{0}错误,{1}", strFuncName, ex.Message));
            }
        }
コード例 #4
0
        /// <summary>
        /// 计算表达式
        /// </summary>
        /// <param name="strFuncName">函数名</param>
        /// <param name="paramObject">参数</param>
        /// <param name="parseObj">ParseExpression变量</param>
        /// <returns>计算结果</returns>
        public object CalculateExpression(string strFuncName, ParamObject[] paramObject, ParseExpression parseObj)
        {
            object returnValue = null;

            switch (strFuncName.ToLower())
            {
            case "getvalue":
                returnValue = GetValueFunction((string)paramObject[0].Value);         //属性名称
                break;

            case "getstringvalue":
                returnValue = GetStringValueFunction((string)paramObject[0].Value);         //属性名称
                break;

            case "istrue":
                returnValue = IsTrue((string)paramObject[0].Value);         //属性名称
                break;

            case "getdatevalue":
                returnValue = GetDateValueFunction((string)paramObject[0].Value);         //属性名称
                break;
            }

            return(returnValue);
        }
コード例 #5
0
 /// <summary>
 /// 实现IExpParsing接口CalculateUserFunction函数,目前未用
 /// </summary>
 /// <param name="strFuncName" >函数名称</param>
 /// <param name="arrParams" >参数数组</param>
 /// <param name="parseObj" >表达式对象</param>
 /// <returns>解析获得的结果对象</returns>
 public object CalculateUserFunction(string strFuncName, ParamObject[] arrParams, ParseExpression parseObj)
 {
     return(CalculateExpression(strFuncName, arrParams, parseObj));
 }