From 60d94c407a086a6dc0357c121c81eef11ae7af9b Mon Sep 17 00:00:00 2001 From: Valentin VERDIER Date: Tue, 1 Dec 2020 21:57:15 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20fonctionnalit=C3=A9=20de=20filt?= =?UTF-8?q?rage=20basique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainWindow.xaml | 36 +++++++++++++++++++++++++++++++----- MainWindow.xaml.cs | 28 +++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/MainWindow.xaml b/MainWindow.xaml index 0ecf28c..349bb91 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -11,11 +11,12 @@ Title="Hermes" Height="512" Width="1024"> + - + @@ -59,19 +60,44 @@ - + - + Égal à Supérieur à Inférieur à - + + + + + + + + + + + + + + + + + + Principale + Secondaire + + + + + + + - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index d7047de..7458512 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Data.Entity; using System.Collections.Generic; using System.Windows; using System.Windows.Input; +using System.Windows.Data; namespace Hermes { /// @@ -13,6 +14,7 @@ namespace Hermes { private ModelContext dbContext = null; private CitoyenModal citoyenModal = new CitoyenModal(); private PreferencesModal preferencesModal = new PreferencesModal(); + private CollectionViewSource citoyenCollectionViewSource = null; public MainWindow() { dbContext = ModelContext.Getinstance(); @@ -27,7 +29,9 @@ namespace Hermes { preferencesModal.Owner = this; dbContext.CitoyenSet.Load(); dbContext.Preferences.Load(); - dgCitoyens.ItemsSource = dbContext.CitoyenSet.Local; + citoyenCollectionViewSource = (CollectionViewSource) this.FindResource("citoyenCollectionViewSource"); + citoyenCollectionViewSource.Source = dbContext.CitoyenSet.Local; + //dgCitoyens.ItemsSource = dbContext.CitoyenSet.Local; } private void Options_Click(object sender, RoutedEventArgs e) { @@ -64,10 +68,32 @@ namespace Hermes { } } + private void Rechercher_Click(object sender, RoutedEventArgs e) { + citoyenCollectionViewSource.Filter += new FilterEventHandler(CitoyenFilter); + //citoyenCollectionViewSource.View.Refresh(); + } + + private void Reinitialiser_Click(object sender, RoutedEventArgs e) { + citoyenCollectionViewSource.Filter -= new FilterEventHandler(CitoyenFilter); + //citoyenCollectionViewSource.View.Refresh(); + } + protected override void OnClosed(EventArgs e) { dbContext.Dispose(); base.OnClosed(e); Application.Current.Shutdown(); } + + private void CitoyenFilter(object sender, FilterEventArgs e) { + Citoyen citoyen = (Citoyen) e.Item; + e.Accepted = true; + if(citoyen != null) { + if(!String.IsNullOrWhiteSpace(professionFilterTextBox.Text)) { + if(!citoyen.Profession.ToLower().Contains(professionFilterTextBox.Text.ToLower())) { + e.Accepted = false; + } + } + } + } } }