From b56f785e3dfed5368b31ea6e0e488aeee0884bac Mon Sep 17 00:00:00 2001 From: Valentin VERDIER Date: Wed, 2 Dec 2020 23:27:43 +0100 Subject: [PATCH] Finalisation de la fonction de filtrage --- App.xaml.cs | 14 +++--------- MainWindow.xaml | 5 +++-- MainWindow.xaml.cs | 44 +++++++++++++++++++++++++++++++++++-- Migrations/Configuration.cs | 7 ++---- Model/Citoyen.cs | 20 ++++++++++++++--- Model/ModelContext.cs | 8 +++++-- Model/Preferences.cs | 16 ++++++++++---- 7 files changed, 85 insertions(+), 29 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index 721f915..43f61e8 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,17 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; -namespace Hermes -{ +namespace Hermes { /// /// Logique d'interaction pour App.xaml /// - public partial class App : Application - { + public partial class App : Application { } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 349bb91..f995406 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -8,7 +8,7 @@ Icon="hermes.png" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" - Title="Hermes" Height="512" Width="1024"> + Title="Hermes" Height="640" Width="1024"> @@ -87,6 +87,7 @@ + Principale Secondaire @@ -97,7 +98,7 @@ - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 8cb2693..5488961 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -83,6 +83,12 @@ namespace Hermes { citoyenCollectionViewSource.Filter -= new FilterEventHandler(CitoyenFilter); isEnabledFilter = false; } + ageOperationFilterComboBox.SelectedIndex = 0; + ageFilterTextBox.Text = null; + professionFilterTextBox.Text = null; + quartierFilterTextBox.Text = null; + adresseFilterTextBox.Text = null; + residenceFilterComboBox.SelectedIndex = 0; } protected override void OnClosed(EventArgs e) { @@ -95,11 +101,45 @@ namespace Hermes { Citoyen citoyen = (Citoyen) e.Item; e.Accepted = true; if(citoyen != null) { - if(!String.IsNullOrWhiteSpace(professionFilterTextBox.Text)) { - if(!citoyen.Profession.ToLower().Contains(professionFilterTextBox.Text.ToLower())) { + if(!String.IsNullOrEmpty(professionFilterTextBox.Text)) { + if(citoyen.Profession == null || !citoyen.Profession.ToLower().Contains(professionFilterTextBox.Text.ToLower())) { e.Accepted = false; + return; } } + + try { + int ageFilter = Int32.Parse(ageFilterTextBox.Text); + if(!citoyen.AgeInt.HasValue + || (ageOperationFilterComboBox.SelectedIndex == 0 && ageFilter != citoyen.AgeInt) + || (ageOperationFilterComboBox.SelectedIndex == 1 && ageFilter >= citoyen.AgeInt) + || (ageOperationFilterComboBox.SelectedIndex == 2 && ageFilter <= citoyen.AgeInt)) { + e.Accepted = false; + return; + } + } catch(Exception) { } + + if(!String.IsNullOrEmpty(quartierFilterTextBox.Text)) { + if(citoyen.Quartier == null || !citoyen.Quartier.ToLower().Contains(quartierFilterTextBox.Text.ToLower())) { + e.Accepted = false; + return; + } + } + + string addrBat = citoyen.AdresseBatiment == null ? "" : citoyen.AdresseBatiment; + string addr = $"{citoyen.AdresseNumero} {citoyen.AdresseRue} {addrBat}".ToLower(); + if(!String.IsNullOrEmpty(adresseFilterTextBox.Text)) { + if(!addr.Contains(adresseFilterTextBox.Text.ToLower())) { + e.Accepted = false; + return; + } + } + + if((residenceFilterComboBox.SelectedIndex == 1 && citoyen.TypeResidence != false) + || (residenceFilterComboBox.SelectedIndex == 2 && citoyen.TypeResidence != true)) { + e.Accepted = false; + return; + } } } } diff --git a/Migrations/Configuration.cs b/Migrations/Configuration.cs index 4b798fc..7f98cd1 100644 --- a/Migrations/Configuration.cs +++ b/Migrations/Configuration.cs @@ -1,9 +1,6 @@ -namespace Hermes.Migrations { - using System; - using System.Data.Entity; - using System.Data.Entity.Migrations; - using System.Linq; +using System.Data.Entity.Migrations; +namespace Hermes.Migrations { internal sealed class Configuration : DbMigrationsConfiguration { public Configuration() { AutomaticMigrationsEnabled = false; diff --git a/Model/Citoyen.cs b/Model/Citoyen.cs index 8aee2b4..32f1f26 100644 --- a/Model/Citoyen.cs +++ b/Model/Citoyen.cs @@ -28,7 +28,9 @@ namespace Hermes.Model { private DateTime _dateCreation; private DateTime _dateModification; - public int Id { get => _id; set => _id = value; } + public int Id { + get => _id; set => _id = value; + } public string Civilite { get => _civilite; set { @@ -179,7 +181,9 @@ namespace Hermes.Model { } [NotMapped] - public string TypeResidenceLabel { get => TypeResidence == false ? "Principale" : "Secondaire"; } + public string TypeResidenceLabel { + get => TypeResidence == false ? "Principale" : "Secondaire"; + } [NotMapped] public string Age { @@ -196,11 +200,21 @@ namespace Hermes.Model { } else { try { DateNaissance = new DateTime(DateTime.Now.Year - Int32.Parse(value), 1, 1); - } catch(Exception) {} + } catch(Exception) { } } } } + [NotMapped] + public int? AgeInt { + get { + if(DateNaissance.HasValue) { + return DateTime.Now.Year - DateNaissance.Value.Year; + } + return null; + } + } + [NotMapped] public string AdresseCP => ModelContext.Getinstance().Preferences.Local[0].VilleCP; diff --git a/Model/ModelContext.cs b/Model/ModelContext.cs index cce04eb..5aac39e 100644 --- a/Model/ModelContext.cs +++ b/Model/ModelContext.cs @@ -19,7 +19,11 @@ namespace Hermes.Model { base.OnModelCreating(modelBuilder); } - public virtual DbSet CitoyenSet { get; set; } - public virtual DbSet Preferences { get; set; } + public virtual DbSet CitoyenSet { + get; set; + } + public virtual DbSet Preferences { + get; set; + } } } diff --git a/Model/Preferences.cs b/Model/Preferences.cs index 2f69508..f8a48d3 100644 --- a/Model/Preferences.cs +++ b/Model/Preferences.cs @@ -2,9 +2,17 @@ namespace Hermes.Model { public class Preferences { - public int Id { get; set; } - public string VilleCP { get; set; } - public string Ville { get; set; } - public string SmsApiKey { get; set; } + public int Id { + get; set; + } + public string VilleCP { + get; set; + } + public string Ville { + get; set; + } + public string SmsApiKey { + get; set; + } } }