internal static object GetValue(PgTableViewFilterM item) { switch (item.FieldType) { case AbsM.EFieldType.Integer: { return(ExtraFunctions.Converts.To <int?>(item.Value)); } case AbsM.EFieldType.Text: { return(ExtraFunctions.Converts.To <string>(item.Value)); } case AbsM.EFieldType.Date: case AbsM.EFieldType.DateTime: { return(ExtraFunctions.Converts.To <DateTime?>(item.Value)); } case AbsM.EFieldType.Real: { return(ExtraFunctions.Converts.To <double?>(item.Value)); } default: { return(null); } } }
private static Params GetWhereParams(PgTVM.PgTableViewFilterM filter, int n) { string name = (filter.Field.Table == null) ? "all" : filter.Field.Name; var par = new Params( string.Format(":{0}{1}", name, n), PgTVM.PgTableViewFilterM.GetValue(filter), Pg_M.PgFieldM.GetDbType(filter.FieldType) ); return(par); }
/// <summary> /// Конструктор менеджера фильтров. /// </summary> /// <param name="source">Источник, в котором хранится экземпляр класса</param> /// <param name="fixedFilterPattern">Паттерн фиксированного фильтра</param> public PgTableViewFilterVM(PgTableViewVM source, FilterRelationModel fixedFilterPattern) { this._source = source; GetFilterField(); GetFilterRelation(); GetFilterOperation(); _dynamicFilter = new PgTVM.PgTableViewFiltersM(this); if (fixedFilterPattern != null) { _fixedFilter = new PgTVM.PgTableViewFilterM(this); SetFilterFromPattern(_fixedFilter, fixedFilterPattern); } _filters = new ObservableCollection <PgTVM.PgTableViewFiltersM>(new[] { _dynamicFilter }); ReloadFiltersFromSqLite(); }
public static bool FilterHasError(PgTVM.IPgTableViewFilterM iFilter) { if (iFilter is PgTVM.PgTableViewFilterM) { PgTVM.PgTableViewFilterM filter = iFilter as PgTVM.PgTableViewFilterM; return(filter.HasError); } else if (iFilter is PgTVM.PgTableViewFiltersM) { PgTVM.PgTableViewFiltersM container = iFilter as PgTVM.PgTableViewFiltersM; bool result = false; foreach (PgTVM.IPgTableViewFilterM innerIFilter in container.Container) { result |= FilterHasError(innerIFilter); } return(result); } else { return(false); } }
/// <summary> /// Устанавливает активный фильтр из FilterRelationModel /// </summary> /// <param name="iFilter"></param> /// <param name="pattern"></param> public void SetFilterFromPattern(PgTVM.IPgTableViewFilterM iFilter, FilterRelationModel pattern) { switch (pattern.Type) { case TypeRelation.AND: case TypeRelation.OR: { PgTVM.PgTableViewFiltersM container = iFilter as PgTVM.PgTableViewFiltersM; container.Container.Clear(); container.TRelation = pattern.Type; foreach (FilterRelationModel relM in pattern.Arguments) { if (relM.Type == TypeRelation.ELEMENT) { PgTVM.PgTableViewFilterM innerelement = new PgTVM.PgTableViewFilterM(container, false); container.Container.Add(innerelement); SetFilterFromPattern(innerelement, relM); } else { PgTVM.PgTableViewFiltersM innercontainer = new PgTVM.PgTableViewFiltersM(container, false); container.Container.Add(innercontainer); SetFilterFromPattern(innercontainer, relM); } } break; } case TypeRelation.ELEMENT: { PgTVM.PgTableViewFilterM element = (PgTVM.PgTableViewFilterM)iFilter; element.Field = element.Source.FindField(pattern.Element.Column); element.TOperation = pattern.Element.Type; element.Value = pattern.Element.Value; break; } } }
private static string GetWhereFilter(PgTVM.PgTableViewFilterM filter, Params paParams) { string format = "lower(\"{0}\") LIKE lower({1})"; if (filter.FieldType == AbsM.EFieldType.Text) { switch (filter.TOperation) { case TypeOperation.Empty: format = "\"{0}\" is NULL"; break; case TypeOperation.NotEmpty: format = "\"{0}\" is NOT NULL"; break; case TypeOperation.Equal: format = "lower(\"{0}\") LIKE lower({1})"; break; case TypeOperation.NotEqual: format = "lower(\"{0}\") NOT LIKE lower({1})"; break; case TypeOperation.Contains: paParams.value = string.Format("%{0}%", paParams.value); break; case TypeOperation.InEnd: paParams.value = string.Format("%{0}", paParams.value); break; case TypeOperation.InBegin: paParams.value = string.Format("{0}%", paParams.value); break; case TypeOperation.NotContains: paParams.value = string.Format("%{0}%", paParams.value); format = "lower(\"{0}\") NOT LIKE lower({1})"; break; } } else { switch (filter.TOperation) { case TypeOperation.Empty: format = "\"{0}\" is NULL"; break; case TypeOperation.NotEmpty: format = "\"{0}\" is NOT NULL"; break; case TypeOperation.More: format = "\"{0}\" > {1}"; break; case TypeOperation.MoreOrEqual: format = "\"{0}\" >= {1}"; break; case TypeOperation.Less: format = "\"{0}\" < {1}"; break; case TypeOperation.LessOrEqual: format = "\"{0}\" <= {1}"; break; case TypeOperation.Equal: format = "\"{0}\" = {1}"; break; case TypeOperation.NotEqual: format = "\"{0}\" <> {1}"; break; } } if (filter.Field.Table == null) { // todo: (Dias) Для поле даты (и времени) использовать соответствующий параметр var fields = filter.Source.Fields.Where(f => f.Table != null).Select(f => string.Format(format, f.Name + "\"::\"text", paParams.paramName)).ToArray(); var join = string.Join(" OR ", fields); return(string.Format("({0})", join)); } else { if (filter.UseOwnValue && ((Pg_M.PgFieldM)filter.Field).RefTable != null) { return(string.Format(format, "id!" + filter.Field.Name, paParams.paramName)); } else { return(string.Format(format, filter.Field.Name, paParams.paramName)); } } }