Ejemplo n.º 1
0
        /// <summary>
        /// 获取满足条件的GuideLine列表
        /// </summary>
        /// <param name="paramNames"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        public List <GuideLine> GetMatchList(List <string> paramNames, List <string> paramValues)
        {
            List <GuideLine> list        = new List <GuideLine>();
            ConditionItemBLL condItemBLL = new ConditionItemBLL();

            if (paramNames == null)
            {
                paramNames = new List <string>();
            }
            if (paramValues == null)
            {
                paramValues = new List <string>();
            }
            if (paramNames.Count != paramValues.Count)
            {
                throw new Exception("参数名称和值必须成对出现!");
            }
            List <GuideLine> allList = GetList("");

            if (paramNames.Count == 0)
            {
                return(allList);
            }
            foreach (GuideLine gl in allList)
            {
                if (gl.EnterCondItemList == null || gl.EnterCondItemList.Count == 0)
                {
                    //list.Add(gl);
                    continue;
                }
                bool isMatch = IsMatch(gl.EnterLogicalOperator, gl.EnterCondItemList, paramNames, paramValues);
                if (isMatch)
                {
                    list.Add(gl);
                }
            }
            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 是否满足逻辑条件
        /// </summary>
        /// <param name="logicOperator">逻辑运算</param>
        /// <param name="condList">条件列表</param>
        /// <param name="paramNames">参数列表</param>
        /// <param name="paramValues">参数值列表</param>
        /// <returns></returns>
        public bool IsMatch(LogicOperator logicOperator, List <ConditionItem> condList, List <string> paramNames, List <string> paramValues)
        {
            if (condList == null || condList.Count == 0)
            {
                return(true);//todo 条件项为空时返回true?
            }
            bool             isMatch     = false;
            ConditionItemBLL condItemBLL = new ConditionItemBLL();

            switch (logicOperator)
            {
            case LogicOperator.And:
                isMatch = true;
                foreach (ConditionItem item in condList)
                {
                    isMatch = isMatch && condItemBLL.IsMatch(item, paramNames, paramValues);
                }
                break;

            case LogicOperator.Or:
                isMatch = false;
                foreach (ConditionItem item in condList)
                {
                    isMatch = isMatch || condItemBLL.IsMatch(item, paramNames, paramValues);
                }
                break;

            case LogicOperator.Not:
                isMatch = !condItemBLL.IsMatch(condList[0], paramNames, paramValues);
                break;

            default:
                break;
            }
            return(isMatch);
        }