101 lines
3.6 KiB
C#
101 lines
3.6 KiB
C#
using Hermes.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
|
|
namespace Hermes {
|
|
/// <summary>
|
|
/// Logique d'interaction pour CitoyenModal.xaml
|
|
/// </summary>
|
|
public partial class CitoyenModal : Window {
|
|
private ModelContext dbContext = null;
|
|
private Citoyen citoyen = null;
|
|
private List<object> _isInvalidElements = new List<object>();
|
|
private bool _modeCreate = true;
|
|
|
|
public static List<string> Civilites = new List<string>();
|
|
|
|
public CitoyenModal() {
|
|
dbContext = ModelContext.Getinstance();
|
|
DataContext = new Citoyen();
|
|
Civilites.Add("M");
|
|
Civilites.Add("Mme");
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
|
civiliteComboBox.ItemsSource = Civilites;
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
|
e.Cancel = true;
|
|
this.Hide();
|
|
}
|
|
|
|
private void ValidationError(object sender, ValidationErrorEventArgs e) {
|
|
if(!_isInvalidElements.Contains(sender)) {
|
|
_isInvalidElements.Add(sender);
|
|
}
|
|
}
|
|
|
|
private void BindingTargetUpdated(object sender, DataTransferEventArgs e) {
|
|
if(_isInvalidElements.Contains(sender)) {
|
|
_isInvalidElements.Remove(sender);
|
|
}
|
|
}
|
|
|
|
private void BindingSourceUpdated(object sender, DataTransferEventArgs e) {
|
|
if(_isInvalidElements.Contains(sender)) {
|
|
_isInvalidElements.Remove(sender);
|
|
}
|
|
}
|
|
|
|
public void EnableCreateMode() {
|
|
DataContext = new Citoyen();
|
|
civiliteComboBox.SelectedIndex = 0;
|
|
_modeCreate = true;
|
|
}
|
|
|
|
public void EnableEditMode(Citoyen citoyen) {
|
|
this.citoyen = citoyen;
|
|
Citoyen citoyenContext = new Citoyen();
|
|
this.citoyen.Copyto(citoyenContext);
|
|
DataContext = citoyenContext;
|
|
_modeCreate = false;
|
|
}
|
|
|
|
public void Save_Click(object sender, RoutedEventArgs e) {
|
|
nomTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
nomNaissanceTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
prenomTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
ageTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
adresseNumeroTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
adresseRueTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
if(_isInvalidElements.Count == 0) {
|
|
if(_modeCreate) {
|
|
((Citoyen) DataContext).DateCreation = DateTime.Now;
|
|
((Citoyen) DataContext).DateModification = DateTime.Now;
|
|
dbContext.CitoyenSet.Add((Citoyen) DataContext);
|
|
} else {
|
|
Citoyen citoyenContext = (Citoyen) DataContext;
|
|
citoyenContext.Copyto(citoyen);
|
|
citoyen.DateModification = DateTime.Now;
|
|
citoyen = null;
|
|
}
|
|
DataContext = null;
|
|
dbContext.SaveChanges();
|
|
Close();
|
|
}
|
|
}
|
|
|
|
public void Cancel_Click(object sender, RoutedEventArgs e) {
|
|
DataContext = null;
|
|
citoyen = null;
|
|
Close();
|
|
}
|
|
}
|
|
}
|