Пример #1
0
 public void AssignStartupFilter(FieldFilter[] filter)
 {
     SortedDictionary<string, string> list = CreateFilterExpressions(filter);
     List<string> dataViewFilter = new List<string>();
     foreach (string fieldName in list.Keys)
         dataViewFilter.Add(String.Format("{0}:{1}", fieldName, list[fieldName]));
     Properties["StartupFilter"] = dataViewFilter;
 }
Пример #2
0
 private SortedDictionary<string, string> CreateFilterExpressions(FieldFilter[] filter)
 {
     // prepare a list of filter expressions
     SortedDictionary<string, string> list = new SortedDictionary<string, string>();
     foreach (FieldFilter ff in filter)
     {
         string filterExpression = null;
         if (!(list.TryGetValue(ff.FieldName, out filterExpression)))
             filterExpression = String.Empty;
         else
             filterExpression = (filterExpression + "\\0");
         if (ff.Value is Array)
         {
             object[] values = ((object[])(ff.Value));
             if (ff.Operation == RowFilterOperation.Between)
                 ff.Value = String.Format("{0}$and${1}", DataControllerBase.ValueToString(values[0]), DataControllerBase.ValueToString(values[1]));
             else
                 if ((ff.Operation == RowFilterOperation.Includes) || (ff.Operation == RowFilterOperation.DoesNotInclude))
                 {
                     StringBuilder svb = new StringBuilder();
                     foreach (object o in values)
                     {
                         if (svb.Length > 0)
                             svb.Append("$or$");
                         svb.Append(DataControllerBase.ValueToString(o));
                     }
                     ff.Value = svb.ToString();
                 }
         }
         else
             ff.Value = DataControllerBase.ValueToString(ff.Value);
         if (ff.Operation == RowFilterOperation.None)
             filterExpression = null;
         else
             filterExpression = (filterExpression
                         + (RowFilterAttribute.ComparisonOperations[Convert.ToInt32(ff.Operation)] + Convert.ToString(ff.Value).Replace("\'", "\\\'")));
         list[ff.FieldName] = filterExpression;
     }
     return list;
 }
Пример #3
0
 public void AssignFilter(FieldFilter[] filter)
 {
     SortedDictionary<string, string> list = CreateFilterExpressions(filter);
     // create a filter
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("var dv = Web.DataView.find(\'{0}\');dv.beginFilter();var f;", this.ID);
     foreach (string fieldName in list.Keys)
         if (String.IsNullOrEmpty(list[fieldName]))
             sb.AppendFormat("f=dv.findField(\'{0}\');if(f)dv.removeFromFilter(f);", fieldName);
         else
             sb.AppendFormat("f=dv.findField(\'{0}\');if(f)dv.applyFilter(f,\':\', \'{1}\');", fieldName, list[fieldName]);
     sb.Append("dv.endFilter();");
     ScriptManager.RegisterClientScriptBlock(Page, typeof(DataViewExtender), ("AsyncPostBackScript" + this.ID), sb.ToString(), true);
 }