Exemple #1
0
        /// <summary>
        /// 解析用户输入的条件表达式
        /// </summary>
        /// <param name="parseCondition">条件表达式</param>
        /// <returns>解析结果</returns>
        public bool CacluateCondition(string parseCondition)
        {
            ParseExpression pe = new ParseExpression();

            pe.UserFunctions = (IExpParsing)this;

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

            return((bool)condValue);
        }
Exemple #2
0
        /// <summary>
        /// 检查基本属性
        /// </summary>
        /// <param name="propertyName">属性名称</param>
        /// <param name="operatorString">操作符</param>
        /// <param name="expectativeValue">期待值</param>
        /// <returns></returns>
        private double GetABSFunction(string propertyName)
        {
            double returnValue = 0;

            ParseExpression pe = new ParseExpression();

            pe.OutputIdentifiers = true;
            pe.UserFunctions     = new WorkflowExpressionParser(this._BizObject);
            pe.ChangeExpression(propertyName);
            string s = pe.Value().ToString();

            returnValue = Math.Abs(Double.Parse(s));
            return(returnValue);
        }
Exemple #3
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 "abs":
                returnValue = GetABSFunction((string)paramObject[0].Value);                 //取绝对值
                break;

            case "getstringvalue":
                returnValue = GetStringValueFunction((string)paramObject[0].Value);         //取字符串值
                break;
            }

            return(returnValue);
        }
Exemple #4
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));
 }
        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));
            }
        }