Esempio n. 1
0
        /// <summary>
        /// 获取复杂查询条件(具有逻辑优先级的复杂比较条件)
        /// </summary>
        /// <param name="compare">实体对象比较类</param>
        /// <returns>基本表达式</returns>
        public DMEDb_OQL1 Where(DMEDb_OQLCompare compare)
        {
            whereString = " Where " + compare.CompareString;
            paras = compare.ComparedParameters;

            useWhereMethod = true;
            //this.CurrEntity.PropertyGetting += new EventHandler<PropertyGettingEventArgs>(CurrEntity_PropertyGetting);
            return this;
        }
Esempio n. 2
0
 /// <summary>
 /// 将当前实体属性的值和要比较的值进行比较,得到一个新的实体比较对象
 /// </summary>
 /// <param name="field">实体对象属性</param>
 /// <param name="Value">要比较的值</param>
 /// <returns>比较表达式</returns>
 public new DMEDb_OQLCompare Equals(object field,object Value)
 {
     this.compareIndex++;
     DMEDb_OQLCompare cmp = new DMEDb_OQLCompare();
     string paraName = "@CP" + this.compareIndex;
     cmp.compareValueList.Add(paraName.Substring (1), Value);
     cmp.CompareString = this.currPropName + "=" + paraName;
     return cmp;
 }
Esempio n. 3
0
        /// <summary>
        /// 将当前实体属性的值和要比较的值进行比较,得到一个新的实体比较对象
        /// </summary>
        /// <param name="field">实体对象属性</param>
        /// <param name="compareTypeString">数据库比较类型字符串</param>
        /// <param name="Value">要比较的值</param>
        /// <returns>比较表达式</returns>
        public DMEDb_OQLCompare Comparer(object field, string compareTypeString, object Value)
        {
            string[] cmpStrs = { "=", "<>", ">=", "<=", "like", "is","in","not in" };
            if (String.IsNullOrEmpty(compareTypeString))
                compareTypeString = "=";
            else
                compareTypeString = compareTypeString.Trim().ToLower();
            bool flag = false;
            foreach (string str in cmpStrs)
            {
                if (compareTypeString == str)
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
                throw new Exception("比较符号必须是 =,>=,<=,<>,like,is,in,not in 中的一种。");

            this.compareIndex++;
            DMEDb_OQLCompare cmp = new DMEDb_OQLCompare();
            if (compareTypeString == "is")
            {
                cmp.CompareString = this.currPropName + " IS " + Value.ToString();//此处可能不安全,IS NULL,IS NOT NULL
            }
            else if (compareTypeString == "in")
            {
                cmp.CompareString = this.currPropName + " IN ( " + Value.ToString() + " )";//此处可能不安全

            }
            else if (compareTypeString == "not in")
            {
                cmp.CompareString = this.currPropName + " NOT IN ( " + Value.ToString() + " )";//此处可能不安全

            }
            else
            {
                string paraName = "@CP" + this.compareIndex;
                cmp.compareValueList.Add(paraName.Substring(1), Value);
                cmp.CompareString = this.currPropName +" "+ compareTypeString+" " + paraName;
            }
            return cmp;
        }
Esempio n. 4
0
        /// <summary>
        /// 将当前实体属性的值和要比较的值进行比较,得到一个新的实体比较对象
        /// </summary>
        /// <param name="field">实体对象属性</param>
        /// <param name="type">比较类型枚举</param>
        /// <param name="Value">要比较的值</param>
        /// <returns>比较表达式</returns>
        public DMEDb_OQLCompare Comparer(object field, CompareType type, object Value)
        {
            //string typeStr = "";
            //switch (type)
            //{
            //    case CompareType.Equal: typeStr = "="; break;
            //    case CompareType.Greater: typeStr = ">"; break;
            //    case CompareType.Like: typeStr = "LIKE"; break;
            //    case CompareType.NoGreater: typeStr = "<="; break;
            //    case CompareType.NoSmaller: typeStr = ">="; break;
            //    case CompareType.NotEqual: typeStr = "<>"; break;
            //    case CompareType.Smaller: typeStr = "<"; break;
            //    default: typeStr = "="; break;
            //}
            //this._DbCompareTypeStr = typeStr;
            //this._CompareValue = Value;
            //

            //
            //this.CompareString = this.CompareFieldName + typeStr+" @" + this.CompareFieldName;
            this.compareIndex++;
            DMEDb_OQLCompare cmp = new DMEDb_OQLCompare();
            if (type == CompareType.IS)
            {
                cmp.CompareString = this.currPropName + " IS " + Value.ToString();//此处可能不安全
            }
            else if (type == CompareType.IN )
            {
                cmp.CompareString = this.currPropName + " IN ( " + Value.ToString() + " )";//此处可能不安全
            }
            else if (type == CompareType.NotIn )
            {
                cmp.CompareString = this.currPropName + " NOT IN ( " + Value.ToString() + " )";//此处可能不安全
            }
            else
            {
                string paraName = "@CP" + this.compareIndex;
                cmp.compareValueList.Add(paraName.Substring(1), Value);
                //cmp.compareTypeList.Add(type);
                //cmp.propertyList.Add(this.currPropName);
                cmp.CompareString = this.currPropName + GetDbCompareTypeStr(type) + paraName;
            }
            return cmp;
        }
Esempio n. 5
0
        /// <summary>
        /// 对一组OQLCompare 对象,执行CompareLogic 类型的比较,通常用于构造复杂的带括号的条件查询
        /// </summary>
        /// <seealso cref="http://www.cnblogs.com/bluedoctor/archive/2011/02/24/1963606.html"/>
        /// <param name="compares">OQL比较对象列表</param>
        /// <param name="logic">各组比较条件的组合方式,And,Or,Not</param>
        /// <returns>新的条件比较对象</returns>
        public DMEDb_OQLCompare Comparer(List<DMEDb_OQLCompare> compares, CompareLogic logic)
        {
            if (compares == null || compares.Count ==0)
                throw new Exception("OQL 条件比较对象集合不能为空或者空引用!");
            if (compares.Count == 1)
                return compares[0];
            DMEDb_OQLCompare cmp = new DMEDb_OQLCompare();
            string typeString = logic == CompareLogic.AND ? " And " : logic == CompareLogic.OR ? " Or " : " Not ";
            foreach (DMEDb_OQLCompare item in compares)
            {
                cmp.CompareString += item.CompareString + typeString;
                if (item.ComparedParameters != null)
                    foreach (string key in item.ComparedParameters.Keys)
                    {
                        cmp.ComparedParameters.Add(key, item.ComparedParameters[key]);
                    }

            }
            cmp.CompareString = cmp.CompareString.Substring(0, cmp.CompareString.Length - typeString.Length);
            cmp.CompareString = " ( "+cmp.CompareString+" ) ";
            return cmp;
        }
Esempio n. 6
0
        /// <summary>
        /// 采用两个实体比较对象按照某种比较逻辑进行处理,构造一个新的实体比较对象
        /// </summary>
        /// <seealso cref="http://www.cnblogs.com/bluedoctor/archive/2010/11/28/1870095.html"/>
        /// <param name="compare1">比较逻辑符号左边的实体比较对象</param>
        /// <param name="logic">比较逻辑</param>
        /// <param name="compare2">比较逻辑符号左边的实体比较对象</param>
        public DMEDb_OQLCompare(DMEDb_OQLCompare compare1, CompareLogic logic, DMEDb_OQLCompare compare2)
        {
            //propertyList.AddRange(compare1.propertyList);
            //compareValueList.AddRange(compare1.compareValueList);
            //compareTypeList.AddRange(compare1.compareTypeList);

            //propertyList.AddRange(compare2.propertyList);
            //compareValueList.AddRange(compare2.compareValueList);
            //compareTypeList.AddRange(compare2.compareTypeList);
            //compareLogicStrList.AddRange(compare1.compareLogicStrList);

            dictionaryAddRange(compareValueList, compare1.compareValueList);
            dictionaryAddRange(compareValueList, compare2.compareValueList);

            switch (logic)
            {
                case CompareLogic.AND:
                    //this.compareLogicStrList.Add(" AND ");
                    this.CompareString = " (" + compare1.CompareString + " AND " + compare2.CompareString + ") ";
                    break;
                case CompareLogic.OR:
                    //this.compareLogicStrList.Add(" OR ");
                    this.CompareString = " (" + compare1.CompareString + " OR " + compare2.CompareString + ") ";
                    break;
                //case CompareLogic.NOT :
                //    this.compareLogicStrList.Add(" NOT ");
                //    this.CompareString = " NOT (" + compare1.CompareString + " AND " + compare2.CompareString + ") ";
                //    break;

            }
        }