Ejemplo n.º 1
0
        public ConditionItem Between(object valueA, object valueB)
        {
            ConditionItem conditionItem = new ConditionItem();

            conditionItem.sqlStr = string.Format(excuteImport.sqlSetting.ConditionItem_BetweenObject, GetName, excuteImport.sqlSetting.Flag, Name);
            ConditionItem conditionItem2 = conditionItem;

            conditionItem2.lstDbParmeters.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + Name + "0", valueA));
            conditionItem2.lstDbParmeters.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + Name + "1", valueB));
            return(conditionItem2);
        }
Ejemplo n.º 2
0
        public ConditionItem CharNum(char c, int num)
        {
            ConditionItem conditionItem = new ConditionItem();

            conditionItem.sqlStr = string.Format(excuteImport.sqlSetting.Column_CharNum, GetName, GetName, excuteImport.sqlSetting.Flag, Name, excuteImport.sqlSetting.Flag, Name);
            ConditionItem conditionItem2 = conditionItem;

            conditionItem2.lstDbParmeters.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + Name + "0", c));
            conditionItem2.lstDbParmeters.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + Name + "1", num));
            return(conditionItem2);
        }
Ejemplo n.º 3
0
        public ConditionItem NotEquals(object value)
        {
            ConditionItem conditionItem = new ConditionItem();

            if (value == null)
            {
                conditionItem.sqlStr         = string.Format(excuteImport.sqlSetting.ConditonItem_NotEquals_object_null, GetName);
                conditionItem.lstDbParmeters = null;
            }
            else
            {
                conditionItem.sqlStr = string.Format(excuteImport.sqlSetting.ConditionItem_NotEquals_object, GetName, excuteImport.sqlSetting.Flag, Name);
                conditionItem.lstDbParmeters.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + Name, value));
            }
            return(conditionItem);
        }
Ejemplo n.º 4
0
        public ConditionItem NotIn(Collection <object> value)
        {
            ConditionItem conditionItem = new ConditionItem();
            StringBuilder stringBuilder = new StringBuilder();
            int           count         = value.Count;

            for (int i = 0; i < count; i++)
            {
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(",");
                }
                stringBuilder.Append(excuteImport.sqlSetting.Flag + Name + i);
                conditionItem.lstDbParmeters.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + Name + i, value[i]));
            }
            conditionItem.sqlStr = string.Format(excuteImport.sqlSetting.ConditionItem_NotIn_objects, GetName, stringBuilder.ToString());
            return(conditionItem);
        }
Ejemplo n.º 5
0
 public ReflectionGenerics SetWhereClip(ConditionItem whereClip)
 {
     WhereClip.Add(whereClip);
     return(this);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取参数列表
        /// </summary>
        public void GetPartmerStrings(ExcuteImport excuteImport, ref string sqlWhereClip, ref List <DbParameter> lstDbParameter)
        {
            StringBuilder stringBuilder = new StringBuilder(); //新建一个可变长度的字符串拼接类

            if (flag)
            {
                using (IEnumerator <object> enumerator = GetEnumerator())                //使用集合迭代器
                {
                    while (enumerator.MoveNext())                                        //操作集合中的数据
                    {
                        ConditionItem conditionItem = (ConditionItem)enumerator.Current; //将迭代器中的数据转换成ConditionItem类型
                        if (stringBuilder.ToString().Length > 0)
                        {
                            stringBuilder.Append(" AND ");                  //在现有字符串后面拼接上AND
                        }
                        List <DbParameter> list = new List <DbParameter>(); //新建一个参数集合
                        if (conditionItem.lstDbParmeters != null)
                        {
                            //如果该数据的参数集合不为空,则向参数列表中添加参数
                            for (int i = 0; i < conditionItem.lstDbParmeters.Count; i++)
                            {
                                list.Add(excuteImport.DbParameterCopy(conditionItem.lstDbParmeters[i]));
                            }
                        }
                        string text   = conditionItem.sqlStr; //将ConditionItem写成成Sql语句式
                        int    count  = lstDbParameter.Count;
                        int    count2 = list.Count;
                        if (count2 > 0)
                        {
                            text = text.Replace(list[count2 - 1].ParameterName, list[count2 - 1].ParameterName + "_" + count);
                            list[count2 - 1].ParameterName = list[count2 - 1].ParameterName + "_" + count;
                        }
                        if (count2 > 1)
                        {
                            for (int num = list.Count - 2; num >= 0; num--)
                            {
                                text = ((!text.Contains(list[num].ParameterName + ",")) ? text.Replace(list[num].ParameterName + " ", list[num].ParameterName + "_" + count + " ") : text.Replace(list[num].ParameterName + ",", list[num].ParameterName + "_" + count + ","));
                                list[num].ParameterName = list[num].ParameterName + "_" + count;
                            }
                        }
                        lstDbParameter.AddRange(list);  //将转换好的list装入参数集合容器
                        stringBuilder.Append(" " + text);
                    }
                }
            }
            else
            {
                using (IEnumerator <object> enumerator2 = GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        object current = enumerator2.Current;
                        //如果是符号,将其转换成字符串类型
                        if (current is Symbol)
                        {
                            stringBuilder.Append(current.ToString());
                        }
                        else if (current is ConditionItem)
                        {
                            ConditionItem conditionItem2 = new ConditionItem();
                            conditionItem2 = current as ConditionItem;
                            List <DbParameter> lstDbParameter2 = new List <DbParameter>();
                            if (conditionItem2.lstDbParmeters != null)
                            {
                                for (int j = 0; j < conditionItem2.lstDbParmeters.Count; j++)
                                {
                                    lstDbParameter2.Add(excuteImport.DbParameterCopy(conditionItem2.lstDbParmeters[j]));
                                }
                            }
                            string text2  = conditionItem2.sqlStr;
                            int    count3 = lstDbParameter.Count;
                            int    count4 = lstDbParameter2.Count;
                            if (count4 > 0)
                            {
                                text2 = text2.Replace(lstDbParameter2[count4 - 1].ParameterName, lstDbParameter2[count4 - 1].ParameterName + "_" + count3);
                                lstDbParameter2[count4 - 1].ParameterName = lstDbParameter2[count4 - 1].ParameterName + "_" + count3;
                            }
                            else if (count4 > 1)
                            {
                                for (int num2 = lstDbParameter2.Count - 2; num2 >= 0; num2--)
                                {
                                    text2 = ((!text2.Contains(lstDbParameter2[num2].ParameterName + ",")) ? text2.Replace(lstDbParameter2[num2].ParameterName + " ", lstDbParameter2[num2].ParameterName + "_" + count3 + " ") : text2.Replace(lstDbParameter2[num2].ParameterName + ",", lstDbParameter2[num2].ParameterName + "_" + count3 + "_"));
                                    lstDbParameter2[num2].ParameterName = lstDbParameter2[num2] + "_" + count3;
                                }
                            }
                            lstDbParameter.AddRange(lstDbParameter2);
                            stringBuilder.Append(" " + text2);
                        }
                    }
                }
            }
            //获取whereClip的String格式
            stringBuilder.Append(" ");
            sqlWhereClip = stringBuilder.ToString();
        }
Ejemplo n.º 7
0
 public WhereClip AddComClip(ConditionItem value)
 {
     flag = true;
     Add(value);
     return(this);
 }