Example #1
0
        /// <summary>
        /// 创建不等于条件表达式
        /// </summary>
        /// <param name="fieldname">左边字段名称</param>
        /// <param name="parametname">右边参数名称</param>
        /// <param name="parametvalue">右边参数值</param>
        /// <param name="paramet">返回与条件表达式一起使用的参数表达式</param>
        /// <returns></returns>
        internal static string CreateNotEqWhere(
            string fieldname,
            string parametname,
            object parametvalue,
            out IDataParamet paramet)
        {
            paramet = null;
            if (string.IsNullOrEmpty(fieldname) || string.IsNullOrEmpty(parametname))
            {
                return(null);
            }
            string left = fieldname;

            if (MsSqlServerHelper.IsValidFieldName(fieldname))
            {
                left = MsSqlServerHelper.GetFeildNameInSqlExpress(fieldname);
            }
            if (parametvalue == null)
            {
                return(string.Format("{0} IS NOT NULL", left));
            }
            string right = MsSqlServerHelper.GetParametName(parametname);

            paramet = new DataParamet()
            {
                Direction = System.Data.ParameterDirection.Input, Name = parametname, Value = parametvalue, ValueType = parametvalue.GetType()
            };
            return(string.Format("{0}<>{1}", left, right));
        }
Example #2
0
 /// <summary>
 /// 合并条件表达式为或者表达式
 /// </summary>
 /// <param name="wheres">表达式数组</param>
 /// <param name="paramets">表达式参数数组</param>
 /// <param name="rtparamets">合并后的表达式参数数组</param>
 /// <returns>或者表达式</returns>
 internal static string UnionWhereForOr(
     IEnumerable <string> wheres,
     IEnumerable <IDataParamet> paramets,
     out IEnumerable <IDataParamet> rtparamets)
 {
     rtparamets = null;
     if (paramets != null)
     {
         List <IDataParamet> rt = new List <IDataParamet>();
         foreach (var a in paramets)
         {
             if (rt.FirstOrDefault(f => string.Equals(MsSqlServerHelper.GetParametName(f.Name), MsSqlServerHelper.GetParametName(a.Name), StringComparison.OrdinalIgnoreCase)) == null)
             {
                 rt.Add(a);
             }
         }
         if (rt.Count > 0)
         {
             rtparamets = rt.ToArray();
         }
     }
     if (wheres != null)
     {
         StringBuilder xb = new StringBuilder();
         foreach (var s in wheres)
         {
             if (xb.Length == 0)
             {
                 xb.AppendFormat("({0})", s);
             }
             else
             {
                 xb.AppendFormat(" OR ({0})", s);
             }
         }
         return(xb.ToString());
     }
     return(null);
 }
Example #3
0
        /// <summary>
        /// 创建以parametvalue开始或在parametvalue中以列的值开始的条件表达式
        /// </summary>
        /// <param name="fieldname">列字段名称</param>
        /// <param name="parametname">参数名称</param>
        /// <param name="parametvalue">参数值</param>
        /// <param name="parametIsExpress">是否是取在parametvalue中以列的值开始的条件表达式</param>
        /// <param name="paramet"></param>
        /// <returns></returns>
        internal static string CreateFirstIndexOfWhere(
            string fieldname,
            string parametname,
            string parametvalue,
            bool parametIsExpress,
            out IDataParamet paramet)
        {
            paramet = null;
            if (string.IsNullOrEmpty(fieldname) || string.IsNullOrEmpty(parametname))
            {
                return(null);
            }
            string left = fieldname;

            if (MsSqlServerHelper.IsValidFieldName(fieldname))
            {
                left = MsSqlServerHelper.GetFeildNameInSqlExpress(fieldname);
            }
            if (parametvalue == null)
            {
                return(null);
            }
            string right = MsSqlServerHelper.GetParametName(parametname);

            paramet = new DataParamet()
            {
                Direction = System.Data.ParameterDirection.Input, Name = parametname, Value = parametvalue, ValueType = parametvalue.GetType()
            };
            if (parametIsExpress)
            {
                return(string.Format("CHARINDEX({1},{0})=1", left, right));
            }
            else
            {
                return(string.Format("CHARINDEX({0},{1})=1", left, right));
            }
        }