Restructuration

This commit is contained in:
2020-11-30 00:19:37 +01:00
parent 1bcaa3c841
commit c3b67ca667
28 changed files with 1082 additions and 452 deletions

View File

@@ -1,48 +1,71 @@
using System;
using Hermes.Model;
using System;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Hermes
{
namespace Hermes {
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public partial class MainWindow : Window {
private ModelContext dbContext = null;
private CitoyenModal citoyenModal = new CitoyenModal();
private SearchModal searchModal = new SearchModal();
private PreferencesModal preferencesModal = new PreferencesModal();
public MainWindow() {
dbContext = ModelContext.Getinstance();
//dbContext.Database.Log = log => System.Console.WriteLine(log);
dbContext.Database.CreateIfNotExists();
public MainWindow()
{
InitializeComponent();
List<Citoyen> citoyens = new List<Citoyen>();
citoyens.Add(new Citoyen(0, "Dupont", "Jean", new DateTime(1994, 3, 24), "14 rue de la République, Lyon", "Jardinier", 0, "jean.dupont@test.fr", "04 00 00 00 00"));
dgCitoyens.ItemsSource = citoyens;
}
private void Ajouter_Click(object sender, RoutedEventArgs e)
{
private void Window_Loaded(object sender, RoutedEventArgs e) {
citoyenModal.Owner = this;
preferencesModal.Owner = this;
dbContext.CitoyenSet.Load();
dbContext.Preferences.Load();
dgCitoyens.ItemsSource = dbContext.CitoyenSet.Local;
}
private void Options_Click(object sender, RoutedEventArgs e) {
preferencesModal.ShowDialog();
}
private void Ajouter_Click(object sender, RoutedEventArgs e) {
citoyenModal.EnableCreateMode();
citoyenModal.ShowDialog();
}
private void Rechercher_Click(object sender, RoutedEventArgs e)
{
searchModal.ShowDialog();
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);
}
}
protected override void OnClosed(EventArgs e)
{
private void DgCitoyen_DoubleClick(object sender, MouseButtonEventArgs e) {
if(dgCitoyens.SelectedItem != null) {
citoyenModal.EnableEditMode((Citoyen) dgCitoyens.SelectedItem);
citoyenModal.ShowDialog();
}
}
protected override void OnClosed(EventArgs e) {
dbContext.Dispose();
base.OnClosed(e);
Application.Current.Shutdown();
}