Exemplo n.º 1
0
        public static WhereSqlClauseBuilder ConvertToWhereBuilder(this IDataFilter filter)
        {
            Type type = filter.GetType();

            PropertyInfo[] propertyInfos = type.GetProperties();

            WhereSqlClauseBuilder sqlBuilder = new WhereSqlClauseBuilder();

            foreach (PropertyInfo p in propertyInfos)
            {
                FieldAndOperator f_a_o = null;
                if (filter.FilterDict != null && filter.FilterDict.Keys.Contains(p.Name))
                {
                    f_a_o = filter.FilterDict[p.Name];
                }
                else
                {
                    FilterFieldAttribute filterFieldAttr = (FilterFieldAttribute)Attribute.GetCustomAttribute(p, typeof(FilterFieldAttribute));
                    if (filterFieldAttr == null)
                    {
                        continue;
                    }

                    filterFieldAttr.Fao.DefaultV = filterFieldAttr.DefaultV;
                    f_a_o = filterFieldAttr.Fao;
                    f_a_o.IsFilterNull = filterFieldAttr.IsFilterNull;
                }
                object value = p.GetValue(filter, null);

                var defaultV = f_a_o.DefaultV ?? GetDefaultValue(p.PropertyType);

                if (value == null || value.Equals(defaultV))
                {
                    continue;
                }

                sqlBuilder.AppendItem(f_a_o.TableFieldName, value, f_a_o.Operator, f_a_o.IsFilterNull);
            }
            return(sqlBuilder);
        }
Exemplo n.º 2
0
 protected string EscapeAndSafeQuote(string s)
 {
     return(WhereSqlClauseBuilder.EscapeLikeString(SafeQuote(s)));
 }