Finalisation de la fonction de filtrage
This commit is contained in:
parent
b95e14a29f
commit
b56f785e3d
14
App.xaml.cs
14
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 {
|
||||
/// <summary>
|
||||
/// Logique d'interaction pour App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public partial class App : Application {
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
Icon="hermes.png"
|
||||
Loaded="Window_Loaded"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="Hermes" Height="512" Width="1024">
|
||||
Title="Hermes" Height="640" Width="1024">
|
||||
<Window.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="Bool2VisibilityConv"/>
|
||||
<CollectionViewSource x:Key="citoyenCollectionViewSource"/>
|
||||
@ -87,6 +87,7 @@
|
||||
<Label>Résidence :</Label>
|
||||
<WrapPanel>
|
||||
<ComboBox Name="residenceFilterComboBox" Width="150" Margin="0,0,5,0">
|
||||
<ComboBoxItem IsSelected="True" Height="20"/>
|
||||
<ComboBoxItem>Principale</ComboBoxItem>
|
||||
<ComboBoxItem>Secondaire</ComboBoxItem>
|
||||
</ComboBox>
|
||||
@ -97,7 +98,7 @@
|
||||
<Button Margin="0,0,0,5" Height="25" Width="100" Click="Reinitialiser_Click">Réinitialiser</Button>
|
||||
</StackPanel>
|
||||
</WrapPanel>
|
||||
<DataGrid ItemsSource="{Binding Source={StaticResource citoyenCollectionViewSource}}" Background="White" Grid.Row="2" VerticalScrollBarVisibility="Visible" GridLinesVisibility="All" Margin="10" Name="dgCitoyens" AutoGenerateColumns="False" IsReadOnly="True" MouseDoubleClick="DgCitoyen_DoubleClick">
|
||||
<DataGrid AlternatingRowBackground="WhiteSmoke" VerticalGridLinesBrush="LightGray" HorizontalGridLinesBrush="LightGray" ItemsSource="{Binding Source={StaticResource citoyenCollectionViewSource}}" Background="White" Grid.Row="2" VerticalScrollBarVisibility="Visible" GridLinesVisibility="All" Margin="10" Name="dgCitoyens" AutoGenerateColumns="False" IsReadOnly="True" MouseDoubleClick="DgCitoyen_DoubleClick">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Civilité" Visibility="{Binding Source={x:Reference civiliteViewCheckBox}, Path=IsChecked, Converter={StaticResource Bool2VisibilityConv}}" Binding="{Binding Civilite}" Width="*"/>
|
||||
<DataGridTextColumn Header="Nom" Visibility="{Binding Source={x:Reference nomViewCheckBox}, Path=IsChecked, Converter={StaticResource Bool2VisibilityConv}}" Binding="{Binding Nom}" Width="*"/>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Hermes.Model.ModelContext> {
|
||||
public Configuration() {
|
||||
AutomaticMigrationsEnabled = false;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -19,7 +19,11 @@ namespace Hermes.Model {
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Citoyen> CitoyenSet { get; set; }
|
||||
public virtual DbSet<Preferences> Preferences { get; set; }
|
||||
public virtual DbSet<Citoyen> CitoyenSet {
|
||||
get; set;
|
||||
}
|
||||
public virtual DbSet<Preferences> Preferences {
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user