private string ConstructFilterExpression(DataView view, SearchEventArgs args) { string format = ((view.ToTable().Columns[args.SearchColumn].DataType == typeof(string)) || (view.ToTable().Columns[args.SearchColumn].DataType == typeof(DateTime))) ? "[{0}] {1} '{2}'" : "[{0}] {1} {2}"; string str2 = "[{0}] {1} ({2})"; string str3 = "[{0}] LIKE '{1}'"; string str4 = "[{0}] NOT LIKE '{1}'"; switch (args.SearchOperation) { case SearchOperation.IsEqualTo: return(string.Format(format, args.SearchColumn, "=", args.SearchString)); case SearchOperation.IsLessThan: return(string.Format(format, args.SearchColumn, "<", args.SearchString)); case SearchOperation.IsLessOrEqualTo: return(string.Format(format, args.SearchColumn, "<=", args.SearchString)); case SearchOperation.IsGreaterThan: return(string.Format(format, args.SearchColumn, ">", args.SearchString)); case SearchOperation.IsGreaterOrEqualTo: return(string.Format(format, args.SearchColumn, ">=", args.SearchString)); case SearchOperation.IsIn: return(string.Format(str2, args.SearchColumn, "in", args.SearchString)); case SearchOperation.IsNotIn: return(string.Format(str2, args.SearchColumn, "not in", args.SearchString)); case SearchOperation.BeginsWith: return(string.Format(str3, args.SearchColumn, args.SearchString + "%")); case SearchOperation.DoesNotBeginWith: return(string.Format(str4, args.SearchColumn, args.SearchString + "%")); case SearchOperation.EndsWith: return(string.Format(str3, args.SearchColumn, "%" + args.SearchString)); case SearchOperation.DoesNotEndWith: return(string.Format(str4, args.SearchColumn, "%" + args.SearchString)); case SearchOperation.Contains: return(string.Format(str3, args.SearchColumn, "%" + args.SearchString + "%")); case SearchOperation.DoesNotContain: return(string.Format(str4, args.SearchColumn, "%" + args.SearchString + "%")); } throw new Exception("Invalid search operation."); }
public void PerformSearch(DataView view) { var search = new JavaScriptSerializer().Deserialize <JsonMultipleSearch>(_searchFilters); string str = ""; foreach (MultipleSearchRule rule in search.rules) { var args2 = new SearchEventArgs(); args2.SearchColumn = rule.field; args2.SearchString = rule.data; args2.SearchOperation = this.GetSearchOperationFromString(rule.op); var e = args2; _grid.OnSearching(e); if (!e.Cancel) { string str2 = (str.Length > 0) ? (" " + search.groupOp + " ") : ""; str = str + str2 + this.ConstructFilterExpression(view, e); } view.RowFilter = str; _grid.OnSearched(new EventArgs()); } }
public void PerformSearch(DataView view, string search) { if (!string.IsNullOrEmpty(search) && Convert.ToBoolean(search)) { var args2 = new SearchEventArgs(); args2.SearchColumn = _searchColunm; args2.SearchString = _searchString; args2.SearchOperation = GetSearchOperationFromString(_searchOperation); var e = args2; _grid.OnSearching(e); if (!e.Cancel) { try { view.RowFilter = ConstructFilterExpression(view, e); } catch (Exception) { } } _grid.OnSearched(new EventArgs()); } }
private string ConstructFilterExpression(DataView view, SearchEventArgs args) { bool flag; if (view != null) { flag = (view.ToTable().Columns[args.SearchColumn].DataType == typeof(string)) || (view.ToTable().Columns[args.SearchColumn].DataType == typeof(DateTime)); } else { var column = _grid.Columns.FromDataField(args.SearchColumn); if (column.SearchDataType == SearchDataType.NotSet) { throw new ArgumentException("SearchDataType for the respective column must be set in order to get custom search string (where clause)"); } flag = (column.SearchDataType == SearchDataType.String) || (column.SearchDataType == SearchDataType.Date); } string format = flag ? "[{0}] {1} '{2}'" : "[{0}] {1} {2}"; string str2 = "[{0}] {1} ({2})"; string str3 = "[{0}] LIKE '{1}'"; string str4 = "[{0}] NOT LIKE '{1}'"; switch (args.SearchOperation) { case SearchOperation.IsEqualTo: return(string.Format(format, args.SearchColumn, "=", args.SearchString)); case SearchOperation.IsLessThan: return(string.Format(format, args.SearchColumn, "<", args.SearchString)); case SearchOperation.IsLessOrEqualTo: return(string.Format(format, args.SearchColumn, "<=", args.SearchString)); case SearchOperation.IsGreaterThan: return(string.Format(format, args.SearchColumn, ">", args.SearchString)); case SearchOperation.IsGreaterOrEqualTo: return(string.Format(format, args.SearchColumn, ">=", args.SearchString)); case SearchOperation.IsIn: return(string.Format(str2, args.SearchColumn, "in", args.SearchString)); case SearchOperation.IsNotIn: return(string.Format(str2, args.SearchColumn, "not in", args.SearchString)); case SearchOperation.BeginsWith: return(string.Format(str3, args.SearchColumn, args.SearchString + "%")); case SearchOperation.DoesNotBeginWith: return(string.Format(str4, args.SearchColumn, args.SearchString + "%")); case SearchOperation.EndsWith: return(string.Format(str3, args.SearchColumn, "%" + args.SearchString)); case SearchOperation.DoesNotEndWith: return(string.Format(str4, args.SearchColumn, "%" + args.SearchString)); case SearchOperation.Contains: return(string.Format(str3, args.SearchColumn, "%" + args.SearchString + "%")); case SearchOperation.DoesNotContain: return(string.Format(str4, args.SearchColumn, "%" + args.SearchString + "%")); } throw new Exception("Invalid search operation."); }