Exemplo n.º 1
0
 /// <summary>
 /// u can pass here sqlLogic, if you use this method in cycle or/and already have opened one.
 /// if not, new sqlLogic instance will be opened.
 /// </summary>
 public static ValueOperatorPair[] GetValueOperatorPairs(tblFilter filter, ISqlLogic sqlLogic = null)
 {
     //try {
     if (filter.autoUpdatedList.HasValue && filter.autoUpdatedList.Value)
     {
         var ValsOps = sqlLogic.FetchDataDistinct(new[] { filter.Key }, filter.tblRecepientFilter.tblRecepientFilterTableName.Name)
                       .Select(x => new ValueOperatorPair(x[filter.Key].ToString(), "=", filter.Type)).ToArray();
         return(ValsOps);
     }
     else
     {
         var vals    = JsonConvert.DeserializeObject <string[]>(filter.ValuesJSON);
         var ops     = JsonConvert.DeserializeObject <string[]>(filter.OperatorsJSON);
         var ValsOps = new ValueOperatorPair[vals.Length];
         for (int i = 0; i < vals.Length; i++)
         {
             ValsOps[i] = new ValueOperatorPair(vals[i], ops[i], filter.Type);
         }
         return(ValsOps);
     }
     //}
     //catch {
     //    return new ValueOperatorPair[1];
     //}
 }
Exemplo n.º 2
0
        //------------------------------------------
        //Private Part

        /// <summary>
        /// Returns Dictionary:
        /// key: filter ID
        /// value: actual settings
        /// </summary>
        Dictionary <int, ValueOperatorPair[]> GetFiltersActualSettings(tblFilter[] filters, FilterValueContainer[] userInputedValues)
        {
            var filtsToValOps = new Dictionary <int, ValueOperatorPair[]>();

            foreach (var f in filters)
            {
                var valops = tblFilterHelper.GetValueOperatorPairs(f, Manager.SqlLogic);
                if (NullBoolToBool(f.allowUserInput))
                {
                    //if user was selecting from list.
                    if (NullBoolToBool(f.autoUpdatedList) || valops.Length > 1)
                    {
                        valops = valops
                                 //HERE WE USE STRING CHECK to Compare... =\
                                 .Where(x => userInputedValues.Any
                                            (y => y.FilterId == f.Id && y.Values != null &&
                                            y.Values.Any(z => GetValueFormatted(z) == x.Value.ToString())
                                            )
                                        )
                                 .ToArray();
                    }
                    //if user typed value directly
                    else
                    {
                        var    val = userInputedValues.First(x => x.FilterId == f.Id);
                        string formattedValue;
                        if (IfValueValidGetValueFormatted(val.Values, f.Type, out formattedValue))
                        {
                            valops = new[] { new ValueOperatorPair(formattedValue, valops[0].Operator, f.Type) }
                        }
                        ;
                        else
                        {
                            valops = new ValueOperatorPair[0];
                        }
                    }
                }
                filtsToValOps.Add(f.Id, valops);
            }

            return(filtsToValOps);
        }