Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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 );
            }
        }
Ejemplo n.º 6
0
        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 );
            }
        }
Ejemplo n.º 7
0
        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 );
            }
        }
Ejemplo n.º 8
0
        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 );
            }
        }