74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using Hermes.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
|
|
namespace Hermes {
|
|
public partial class CitoyenWindow : Window {
|
|
private Citoyen editRef = null;
|
|
private List<object> _isInvalidElements = new List<object>();
|
|
|
|
public CitoyenWindow(Window parent, Citoyen context = null) {
|
|
InitializeComponent();
|
|
|
|
DataContext = new Citoyen();
|
|
Owner = parent;
|
|
|
|
if(context != null) {
|
|
editRef = context;
|
|
editRef.Copyto((Citoyen) DataContext);
|
|
} else {
|
|
((Citoyen) DataContext).Civilite = "Monsieur";
|
|
}
|
|
|
|
List<string> civilites = new List<string>();
|
|
civilites.Add("Monsieur");
|
|
civilites.Add("Madame");
|
|
civiliteComboBox.ItemsSource = civilites;
|
|
}
|
|
|
|
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 Save_Click(object sender, RoutedEventArgs e) {
|
|
nomTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
ageTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
|
|
if(_isInvalidElements.Count == 0) {
|
|
ModelContext dbContext = ModelContext.Getinstance();
|
|
if(editRef == null) {
|
|
((Citoyen) DataContext).DateCreation = DateTime.Now;
|
|
((Citoyen) DataContext).DateModification = DateTime.Now;
|
|
dbContext.CitoyenSet.Add((Citoyen) DataContext);
|
|
} else {
|
|
Citoyen context = (Citoyen) DataContext;
|
|
context.Copyto(editRef);
|
|
editRef.DateModification = DateTime.Now;
|
|
}
|
|
dbContext.SaveChanges();
|
|
Close();
|
|
}
|
|
}
|
|
|
|
public void Cancel_Click(object sender, RoutedEventArgs e) {
|
|
Close();
|
|
}
|
|
}
|
|
}
|