Finalisation de la fonction de filtrage

This commit is contained in:
2020-12-02 23:27:43 +01:00
parent b95e14a29f
commit b56f785e3d
7 changed files with 85 additions and 29 deletions

View File

@@ -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;
}
}
}
}