public Table ReadRecord() { FileDb _db = new FileDb(); _db.Open(DBFILE, false); // the easy way, using the expression parser // FilterExpressionGroup srchExpGrp = FilterExpressionGroup.Parse //("(FirstName ~= 'andrew' OR FirstName ~= 'nancy') AND LastName = 'Fuller'"); FilterExpressionGroup srchExpGrp = FilterExpressionGroup.Parse ("FirstName = 'Nancy'"); Table table = _db.SelectRecords(srchExpGrp, null, null, false); //// equivalent building it manually //var fname1Exp = new FilterExpression //("FirstName", "andrew", ComparisonOperatorEnum.Equal, MatchTypeEnum.IgnoreCase); //var fname2Exp = new FilterExpression //("FirstName", "nancy", ComparisonOperatorEnum.Equal, MatchTypeEnum.IgnoreCase); //var lnameExp = new FilterExpression //("LastName", "Fuller", ComparisonOperatorEnum.Equal, MatchTypeEnum.UseCase); //var fnamesGrp = new FilterExpressionGroup(); //fnamesGrp.Add(BoolOpEnum.Or, fname1Exp); //fnamesGrp.Add(BoolOpEnum.Or, fname2Exp); //var allNamesGrp = new FilterExpressionGroup(); //allNamesGrp.Add(BoolOpEnum.And, lnameExp); //allNamesGrp.Add(BoolOpEnum.And, fnamesGrp); //// should get the same records //table = _db.SelectRecords(allNamesGrp, null, null, false); _db.Dispose(); return(table); }
private void BtnRemoveByKey_Click(object sender, RoutedEventArgs e) { try { // the following two lines produce the same FilterExpression var exp1 = FilterExpression.Parse("~FirstName = nancy"); exp1 = new FilterExpression("FirstName", "nancy", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase); var exp2 = new FilterExpression("LastName", "leverling", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase); var expGrp = new FilterExpressionGroup(); expGrp.Add(BoolOpEnum.Or, exp1); expGrp.Add(BoolOpEnum.Or, exp2); Table table = _db.SelectRecords(expGrp, new string[] { "ID" }); foreach (Record record in table) { int id = (int)record["ID"]; bool bRet = _db.DeleteRecordByKey(id); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnGetMatchingRecords_Click(object sender, RoutedEventArgs e) { try { // Use the FilterExpressionGroup's filter parser to create a FilterExpressionGroup // The syntax is similar to SQL (do not preceed with WHERE) // Note that there are 2 ways to get a case-INSENSITIVE search: // Use either ~= or you can prefix the fieldname with ~ to ignore case // Both methods are shown below // (FileDb doesn't support UPPER or LOWER) // Note also that each set of parentheses will create a child FilterExpressionGroup string filter = "(~FirstName = 'steven' OR [FirstName] ~= 'NANCY') AND LastName = 'Fuller'"; FilterExpressionGroup filterExpGrp = FilterExpressionGroup.Parse(filter); Table table = _db.SelectRecords(filterExpGrp); displayRecords(table); // we can manually build the same FilterExpressionGroup var fname1Exp = new FilterExpression("FirstName", "steven", ComparisonOperatorEnum.Equal, MatchTypeEnum.IgnoreCase); // the following two lines produce the same FilterExpression var fname2Exp = FilterExpression.Parse("FirstName ~= 'NANCY'"); // equal/ignore case fname2Exp = new FilterExpression("FirstName", "NANCY", ComparisonOperatorEnum.Equal, MatchTypeEnum.IgnoreCase); var lnameExp = new FilterExpression("LastName", "Fuller", ComparisonOperatorEnum.Equal, MatchTypeEnum.UseCase); // NOTE: FileDb now supports CONTAINS which is very fast, so you could now do this too //fname2Exp = FilterExpression.Parse( "~FirstName CONTAINS 'NANCY'" ); // equal/ignore case //fname2Exp = new FilterExpression( "FirstName", "NANCY", ComparisonOperatorEnum.Contains, MatchTypeEnum.IgnoreCase ); var fnamesGrp = new FilterExpressionGroup(); fnamesGrp.Add(BoolOpEnum.Or, fname1Exp); fnamesGrp.Add(BoolOpEnum.Or, fname2Exp); var allNamesGrp = new FilterExpressionGroup(); allNamesGrp.Add(BoolOpEnum.And, lnameExp); allNamesGrp.Add(BoolOpEnum.And, fnamesGrp); table = _db.SelectRecords(allNamesGrp); displayRecords(table); // or just pass the string expression directly table = _db.SelectRecords(filter); displayRecords(table); // get the same records again as a typed list using your own custom class IList <Person> persons = _db.SelectRecords <Person>(filter); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected virtual List <Customer> ExecuteQuery(LogicalRuleOperator logicalOperator, params FilterExpression[] expressions) { var compositeFilter = new FilterExpressionGroup(typeof(Customer)) { LogicalOperator = logicalOperator }; compositeFilter.AddExpressions(expressions); var predicate = compositeFilter.ToPredicate(true); var result = _customers.AsQueryable().Where(predicate).Cast <Customer>().ToList(); return(result); }
public override IRuleExpressionGroup VisitRuleSet(RuleSetEntity ruleSet) { var group = new FilterExpressionGroup(typeof(Customer)) { Id = ruleSet.Id, LogicalOperator = ruleSet.LogicalOperator, IsSubGroup = ruleSet.IsSubGroup, Value = ruleSet.Id, RawValue = ruleSet.Id.ToString(), Provider = this // INFO: filter group does NOT access any descriptor }; return(group); }
private void BtnGetMatchingRecords_Click(object sender, RoutedEventArgs e) { try { // Use the FilterExpressionGroup's filter parser to create a FilterExpressionGroup // The syntax is similar to SQL (do not preceed with WHERE) // Note that we prefix the fieldname with ~ to get a case-INSENSITIVE search // (FileDb doesn't currently support UPPER or LOWER) // Note that we can also use LIKE when we want to ignore case, but the difference // is that LIKE will create a RegEx search which would be a little slower // Note also that each set of parentheses will create a child FilterExpressionGroup string filter = "(~FirstName = 'steven' OR [FirstName] LIKE 'NANCY') AND LastName = 'Fuller'"; FilterExpressionGroup filterExpGrp = FilterExpressionGroup.Parse(filter); Table table = _db.SelectRecords(filterExpGrp); displayRecords(table); // we can manually build the same FilterExpressionGroup var lnameExp = new FilterExpression("LastName", "Fuller", EqualityEnum.Equal, MatchTypeEnum.UseCase); var fname1Exp = new FilterExpression("FirstName", "steven", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase); // the following two lines produce the same FilterExpression var fname2Exp = FilterExpression.Parse("FirstName LIKE 'NANCY'"); fname2Exp = new FilterExpression("FirstName", "NANCY", EqualityEnum.Like); var fnamesGrp = new FilterExpressionGroup(); fnamesGrp.Add(BoolOpEnum.Or, fname1Exp); fnamesGrp.Add(BoolOpEnum.Or, fname2Exp); var allNamesGrp = new FilterExpressionGroup(); allNamesGrp.Add(BoolOpEnum.And, lnameExp); allNamesGrp.Add(BoolOpEnum.And, fnamesGrp); table = _db.SelectRecords(allNamesGrp); displayRecords(table); // or just pass the string expression directly table = _db.SelectRecords(filter); displayRecords(table); // get the same records again as a typed list using your own custom class IList <Person> persons = _db.SelectRecords <Person>(filter); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public int DeleteRecord() { FileDb _db = new FileDb(); _db.Open(DBFILE, false); // the easy way, using the expression parser // FilterExpressionGroup srchExpGrp = FilterExpressionGroup.Parse //("(FirstName ~= 'andrew' OR FirstName ~= 'nancy') AND LastName = 'Fuller'"); FilterExpressionGroup srchExpGrp = FilterExpressionGroup.Parse ("FirstName = 'Nancy'"); var ret = _db.DeleteRecords(srchExpGrp); _db.Dispose(); return(ret); }
public IPagedList <Customer> ProcessFilter( FilterExpression[] filters, LogicalRuleOperator logicalOperator, int pageIndex = 0, int pageSize = int.MaxValue) { Guard.NotNull(filters, nameof(filters)); if (filters.Length == 0) { return(new PagedList <Customer>(Enumerable.Empty <Customer>(), 0, int.MaxValue)); } // TODO: really untracked? var query = _rsCustomer.TableUntracked.Where(x => !x.Deleted); FilterExpressionGroup group = null; if (filters.Length == 1 && filters[0] is FilterExpressionGroup group2) { group = group2; } else { group = new FilterExpressionGroup(typeof(Customer)) { LogicalOperator = logicalOperator }; group.AddExpressions(filters); } // Create lambda predicate var predicate = group.ToPredicate(false); // Apply predicate to query query = query .Where(predicate) .Cast <Customer>() .OrderByDescending(c => c.CreatedOnUtc); return(new PagedList <Customer>(query, pageIndex, pageSize)); }
private void BtnUpdateMatchingRecords_Click(object sender, RoutedEventArgs e) { try { string filter = "(~FirstName = 'andrew' OR ~FirstName = 'nancy') AND ~LastName = 'fuller'"; FilterExpressionGroup filterExpGrp = FilterExpressionGroup.Parse(filter); Table table = _db.SelectRecords(filterExpGrp); displayRecords(table); // equivalent building it manually var fname1Exp = new FilterExpression("FirstName", "andrew", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase); // the following two lines produce the same FilterExpression var fname2Exp = FilterExpression.Parse("~FirstName = nancy"); fname2Exp = new FilterExpression("FirstName", "nancy", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase); var lnameExp = new FilterExpression("LastName", "fuller", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase); var fnamesGrp = new FilterExpressionGroup(); fnamesGrp.Add(BoolOpEnum.Or, fname1Exp); fnamesGrp.Add(BoolOpEnum.Or, fname2Exp); var allNamesGrp = new FilterExpressionGroup(); allNamesGrp.Add(BoolOpEnum.And, lnameExp); allNamesGrp.Add(BoolOpEnum.And, fnamesGrp); var fieldValues = new FieldValues(); fieldValues.Add("IsCitizen", false); int nRecs = _db.UpdateRecords(allNamesGrp, fieldValues); table = _db.SelectRecords(allNamesGrp); displayRecords(table); // or easiest of all use the filter string directly table = _db.SelectRecords(filter); displayRecords(table); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnRemoveByKey_Click( object sender, RoutedEventArgs e ) { try { var exp1 = new FilterExpression( "FirstName", "Nancy", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); var exp2 = new FilterExpression( "LastName", "Leverling", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); var expGrp = new FilterExpressionGroup(); expGrp.Add( BoolOpEnum.Or, exp1 ); expGrp.Add( BoolOpEnum.Or, exp2 ); FileDbNs.Table table = _db.SelectRecords( expGrp, new string[] { "ID" } ); foreach( Record record in table ) { int id = (int) record["ID"]; bool bRet = _db.DeleteRecordByKey( id ); } } catch( Exception ex ) { MessageBox.Show( ex.Message ); } }
private void RemoveByValue2_Click( object sender, RoutedEventArgs e ) { try { var lnameExp = new FilterExpression( "LastName", "peacock", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); var fname1Exp = new FilterExpression( "FirstName", "nancy", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); var allNamesGrp = new FilterExpressionGroup(); allNamesGrp.Add( BoolOpEnum.Or, lnameExp ); allNamesGrp.Add( BoolOpEnum.Or, fname1Exp ); // equivalent using parser string filter = "~LastName = 'peacock' OR ~FirstName = 'nancy'"; allNamesGrp = FilterExpressionGroup.Parse( filter ); int numDeleted = _db.DeleteRecords( allNamesGrp ); // or just call _db.DeleteMatchingRecords( filter ); } catch( Exception ex ) { MessageBox.Show( ex.Message ); } }
private void BtnUpdateMatchingRecords_Click( object sender, RoutedEventArgs e ) { try { string filter = "(~FirstName = 'andrew' OR ~FirstName = 'nancy') AND ~LastName = 'fuller'"; FilterExpressionGroup filterExpGrp = FilterExpressionGroup.Parse( filter ); FileDbNs.Table table = _db.SelectRecords( filterExpGrp ); displayRecords( table ); // equivalent building it manually var fname1Exp = new FilterExpression( "FirstName", "andrew", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); // the following lines produce the same FilterExpression var fname2Exp = FilterExpression.Parse( "~FirstName = nancy" ); fname2Exp = new FilterExpression( "FirstName", "nancy", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); var lnameExp = new FilterExpression( "LastName", "fuller", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); var fnamesGrp = new FilterExpressionGroup(); fnamesGrp.Add( BoolOpEnum.Or, fname1Exp ); fnamesGrp.Add( BoolOpEnum.Or, fname2Exp ); var allNamesGrp = new FilterExpressionGroup(); allNamesGrp.Add( BoolOpEnum.And, lnameExp ); allNamesGrp.Add( BoolOpEnum.And, fnamesGrp ); table = _db.SelectRecords( allNamesGrp ); displayRecords( table ); // now update the matching Record var fieldValues = new FieldValues(); fieldValues.Add( "IsCitizen", false ); int nRecs = _db.UpdateRecords( allNamesGrp, fieldValues ); table = _db.SelectRecords( allNamesGrp ); displayRecords( table ); // or easiest of all use the filter string directly table = _db.SelectRecords( filter ); displayRecords( table ); } catch( Exception ex ) { MessageBox.Show( ex.Message ); } }
private void BtnGetMatchingRecords_Click( object sender, RoutedEventArgs e ) { try { // Use the FilterExpressionGroup's filter parser to create a FilterExpressionGroup // The syntax is similar to SQL (do not preceed with WHERE) // Note that we prefix the fieldname with ~ to get a case-INSENSITIVE search // (FileDb doesn't currently support UPPER or LOWER) // Note that we can also use LIKE when we want to ignore case, but the difference // is that LIKE will create a RegEx search which would be a little slower // Note also that each set of parentheses will create a child FilterExpressionGroup string filter = "(~FirstName = 'steven' OR [FirstName] LIKE 'NANCY') AND LastName = 'Fuller'"; FilterExpressionGroup filterExpGrp = FilterExpressionGroup.Parse( filter ); FileDbNs.Table table = _db.SelectRecords( filterExpGrp ); displayRecords( table ); // we can manually build the same FilterExpressionGroup var fname1Exp = new FilterExpression( "FirstName", "steven", EqualityEnum.Equal, MatchTypeEnum.IgnoreCase ); // the following two lines produce the same FilterExpression var fname2Exp = FilterExpression.Parse( "FirstName LIKE 'NANCY'" ); fname2Exp = new FilterExpression( "FirstName", "NANCY", EqualityEnum.Like ); var lnameExp = new FilterExpression( "LastName", "Fuller", EqualityEnum.Equal, MatchTypeEnum.UseCase ); var fnamesGrp = new FilterExpressionGroup(); fnamesGrp.Add( BoolOpEnum.Or, fname1Exp ); fnamesGrp.Add( BoolOpEnum.Or, fname2Exp ); var allNamesGrp = new FilterExpressionGroup(); allNamesGrp.Add( BoolOpEnum.And, lnameExp ); allNamesGrp.Add( BoolOpEnum.And, fnamesGrp ); table = _db.SelectRecords( allNamesGrp ); displayRecords( table ); // or just pass the string expression directly table = _db.SelectRecords( filter ); displayRecords( table ); // get the same records again as a typed list using your own custom class IList<Person> persons = _db.SelectRecords<Person>( filter ); grid.Columns.Clear(); grid.ItemsSource = persons; } catch( Exception ex ) { MessageBox.Show( ex.Message ); } }