2020-11-30 00:19:37 +01:00
|
|
|
|
using Hermes.Model;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Data.Entity;
|
2020-09-07 22:24:37 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
2020-12-01 21:57:15 +01:00
|
|
|
|
using System.Windows.Data;
|
2020-09-07 22:24:37 +02:00
|
|
|
|
|
2020-11-30 00:19:37 +01:00
|
|
|
|
namespace Hermes {
|
|
|
|
|
public partial class MainWindow : Window {
|
|
|
|
|
private ModelContext dbContext = null;
|
2020-09-07 22:24:37 +02:00
|
|
|
|
private CitoyenModal citoyenModal = new CitoyenModal();
|
2020-11-30 00:19:37 +01:00
|
|
|
|
private PreferencesModal preferencesModal = new PreferencesModal();
|
2020-12-01 21:57:15 +01:00
|
|
|
|
private CollectionViewSource citoyenCollectionViewSource = null;
|
2020-12-01 22:06:27 +01:00
|
|
|
|
private bool isEnabledFilter = false;
|
2020-11-30 00:19:37 +01:00
|
|
|
|
|
|
|
|
|
public MainWindow() {
|
|
|
|
|
dbContext = ModelContext.Getinstance();
|
|
|
|
|
//dbContext.Database.Log = log => System.Console.WriteLine(log);
|
|
|
|
|
dbContext.Database.CreateIfNotExists();
|
2020-09-07 22:24:37 +02:00
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-30 00:19:37 +01:00
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
|
|
|
|
citoyenModal.Owner = this;
|
|
|
|
|
preferencesModal.Owner = this;
|
|
|
|
|
dbContext.CitoyenSet.Load();
|
|
|
|
|
dbContext.Preferences.Load();
|
2020-12-01 21:57:15 +01:00
|
|
|
|
citoyenCollectionViewSource = (CollectionViewSource) this.FindResource("citoyenCollectionViewSource");
|
|
|
|
|
citoyenCollectionViewSource.Source = dbContext.CitoyenSet.Local;
|
2020-11-30 00:19:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Options_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
preferencesModal.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Ajouter_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
citoyenModal.EnableCreateMode();
|
2020-09-07 22:24:37 +02:00
|
|
|
|
citoyenModal.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-30 00:19:37 +01:00
|
|
|
|
private void Supprimer_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
if(dgCitoyens.SelectedItems.Count > 0) {
|
|
|
|
|
MessageBoxResult result = MessageBox.Show("Voulez-vous supprimer ces citoyens ?", "Suppression", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
|
|
if(result == MessageBoxResult.Yes) {
|
|
|
|
|
List<Citoyen> clist = new List<Citoyen>();
|
|
|
|
|
foreach(Citoyen c in dgCitoyens.SelectedItems) {
|
|
|
|
|
clist.Add(c);
|
|
|
|
|
}
|
|
|
|
|
foreach(Citoyen c in clist) {
|
|
|
|
|
dbContext.CitoyenSet.Remove(c);
|
|
|
|
|
}
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MessageBox.Show("Aucun citoyen sélectionné", "Suppression", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DgCitoyen_DoubleClick(object sender, MouseButtonEventArgs e) {
|
|
|
|
|
if(dgCitoyens.SelectedItem != null) {
|
|
|
|
|
citoyenModal.EnableEditMode((Citoyen) dgCitoyens.SelectedItem);
|
|
|
|
|
citoyenModal.ShowDialog();
|
|
|
|
|
}
|
2020-09-07 22:24:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 21:57:15 +01:00
|
|
|
|
private void Rechercher_Click(object sender, RoutedEventArgs e) {
|
2020-12-01 22:06:27 +01:00
|
|
|
|
if(isEnabledFilter) {
|
|
|
|
|
citoyenCollectionViewSource.View.Refresh();
|
|
|
|
|
} else {
|
|
|
|
|
citoyenCollectionViewSource.Filter += new FilterEventHandler(CitoyenFilter);
|
|
|
|
|
isEnabledFilter = true;
|
|
|
|
|
}
|
2020-12-01 21:57:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Reinitialiser_Click(object sender, RoutedEventArgs e) {
|
2020-12-01 22:06:27 +01:00
|
|
|
|
if(isEnabledFilter) {
|
|
|
|
|
citoyenCollectionViewSource.Filter -= new FilterEventHandler(CitoyenFilter);
|
|
|
|
|
isEnabledFilter = false;
|
|
|
|
|
}
|
2020-12-02 23:27:43 +01:00
|
|
|
|
ageOperationFilterComboBox.SelectedIndex = 0;
|
|
|
|
|
ageFilterTextBox.Text = null;
|
|
|
|
|
professionFilterTextBox.Text = null;
|
|
|
|
|
quartierFilterTextBox.Text = null;
|
|
|
|
|
adresseFilterTextBox.Text = null;
|
|
|
|
|
residenceFilterComboBox.SelectedIndex = 0;
|
2020-12-01 21:57:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-30 00:19:37 +01:00
|
|
|
|
protected override void OnClosed(EventArgs e) {
|
|
|
|
|
dbContext.Dispose();
|
2020-09-07 22:24:37 +02:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
}
|
2020-12-01 21:57:15 +01:00
|
|
|
|
|
|
|
|
|
private void CitoyenFilter(object sender, FilterEventArgs e) {
|
|
|
|
|
Citoyen citoyen = (Citoyen) e.Item;
|
|
|
|
|
e.Accepted = true;
|
|
|
|
|
if(citoyen != null) {
|
2020-12-02 23:27:43 +01:00
|
|
|
|
if(!String.IsNullOrEmpty(professionFilterTextBox.Text)) {
|
|
|
|
|
if(citoyen.Profession == null || !citoyen.Profession.ToLower().Contains(professionFilterTextBox.Text.ToLower())) {
|
2020-12-01 21:57:15 +01:00
|
|
|
|
e.Accepted = false;
|
2020-12-02 23:27:43 +01:00
|
|
|
|
return;
|
2020-12-01 21:57:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-02 23:27:43 +01:00
|
|
|
|
|
|
|
|
|
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;
|
2020-12-03 23:49:45 +01:00
|
|
|
|
string addr = $"{citoyen.Adresse} {addrBat}".ToLower();
|
2020-12-02 23:27:43 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
2020-12-01 21:57:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-07 22:24:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|