diff --git a/App.config b/App.config index 193aecc..ba49194 100644 --- a/App.config +++ b/App.config @@ -1,6 +1,78 @@ - + - - - - \ No newline at end of file + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/App.xaml b/App.xaml index 57ce66a..4d8d199 100644 --- a/App.xaml +++ b/App.xaml @@ -2,9 +2,5 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Hermes" - StartupUri="MainWindow.xaml" - Exit="Application_Exit"> - - - + StartupUri="MainWindow.xaml"> diff --git a/App.xaml.cs b/App.xaml.cs index 38ee452..721f915 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -13,8 +13,5 @@ namespace Hermes /// public partial class App : Application { - private void Application_Exit(object sender, ExitEventArgs e) { - DataAccess.CloseConnection(); - } } } diff --git a/Citoyen.cs b/Citoyen.cs deleted file mode 100644 index b579925..0000000 --- a/Citoyen.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Hermes -{ - public class Citoyen - { - public int Id { get; set; } - public string Nom { get; set; } - public string Prenom { get; set; } - public DateTime DateNaissance { get; set; } - public string Adresse { get; set; } - public string Profession { get; set; } - public int TypeResidence { get; set; } - public string Mail { get; set; } - public string Tel { get; set; } - - public string TypeResidenceLabel { - get - { - return TypeResidence == 0 ? "Principale" : "Secondaire"; - } - } - - public int Age { - get - { - return DateTime.Now.Year - DateNaissance.Year; - } - set - { - DateNaissance = new DateTime(DateTime.Now.Year - value, 1, 1); - } - } - - public Citoyen() {} - - public Citoyen(int id, string nom, string prenom, DateTime dateNaissance, string adresse, string profession, int typeResidence, string mail, string tel) { - Id = id; - Nom = nom; - Prenom = prenom; - DateNaissance = dateNaissance; - Adresse = adresse; - Profession = profession; - TypeResidence = typeResidence; - Mail = mail; - Tel = tel; - } - } -} diff --git a/CitoyenDAO.cs b/CitoyenDAO.cs deleted file mode 100644 index a1d92c3..0000000 --- a/CitoyenDAO.cs +++ /dev/null @@ -1,153 +0,0 @@ -using Microsoft.Data.Sqlite; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Hermes -{ - public static class CitoyenDAO - { - private static Citoyen ReadCitoyen(SqliteDataReader reader) { - Citoyen citoyen = new Citoyen(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), DateTime.Now, reader.GetString(4), reader.GetString(5), reader.GetInt32(6), reader.GetString(7), reader.GetString(8)); - citoyen.DateNaissance = DateTime.ParseExact(reader.GetString(3), "yyyy", CultureInfo.InvariantCulture); - return citoyen; - } - - private static List ReadCitoyens(SqliteDataReader reader) { - List citoyens = new List(); - - while (reader.Read()) - { - citoyens.Add(ReadCitoyen(reader)); - } - - return citoyens; - } - - - public static List FetchAll() { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen", db); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static List FetchByAgeSup(int age) { - SqliteConnection db = DataAccess.GetConnection(); - - int year = DateTime.Now.Year - age; - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen WHERE date_naissance < $year", db); - selectCmd.Parameters.AddWithValue("$year", year.ToString()); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static List FetchByAgeEquals(int age) - { - SqliteConnection db = DataAccess.GetConnection(); - - int year = DateTime.Now.Year - age; - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen WHERE date_naissance = $year", db); - selectCmd.Parameters.AddWithValue("$year", year.ToString()); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static List FetchByAgeInf(int age) - { - SqliteConnection db = DataAccess.GetConnection(); - - int year = DateTime.Now.Year - age; - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen WHERE date_naissance > $year", db); - selectCmd.Parameters.AddWithValue("$year", year.ToString()); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static List FetchByProfession(string pattern) - { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen WHERE LOWER(date_naissance) LIKE $pattern", db); - selectCmd.Parameters.AddWithValue("$pattern", "%" + pattern.ToLower() + "%"); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static List FetchByAdresse(string pattern) - { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen WHERE LOWER(adresse) LIKE $pattern", db); - selectCmd.Parameters.AddWithValue("$pattern", "%" + pattern.ToLower() + "%"); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static List FetchByTypeResidence(int type) - { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand selectCmd = new SqliteCommand("SELECT id, nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel FROM citoyen WHERE type_residence = $type", db); - selectCmd.Parameters.AddWithValue("$type", type); - SqliteDataReader reader = selectCmd.ExecuteReader(); - - return ReadCitoyens(reader); - } - - public static void Add(Citoyen citoyen) { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand insertCmd = new SqliteCommand("INSERT INTO citoyen (nom, prenom, date_naissance, adresse, profession, type_residence, mail, tel) VALUES ($nom, $prenom, $date_naissance, $adresse, $profession, $type_residence, $mail, $tel)", db); - insertCmd.Parameters.AddWithValue("$nom", citoyen.Nom); - insertCmd.Parameters.AddWithValue("$prenom", citoyen.Prenom); - insertCmd.Parameters.AddWithValue("$date_naissance", citoyen.DateNaissance.ToString("yyyy")); - insertCmd.Parameters.AddWithValue("$adresse", citoyen.Adresse); - insertCmd.Parameters.AddWithValue("$profession", citoyen.Profession); - insertCmd.Parameters.AddWithValue("$type_residence", citoyen.TypeResidence); - insertCmd.Parameters.AddWithValue("$mail", citoyen.Mail); - insertCmd.Parameters.AddWithValue("$tel", citoyen.Tel); - - insertCmd.ExecuteNonQuery(); - } - - public static void Update(Citoyen citoyen) { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand insertCmd = new SqliteCommand("UPDATE citoyen SET nom = $nom, prenom = $prenom, date_naissance = $date_naissance, adresse = $adresse, profession = $profession, type_residence = $type_residence, mail = $mail, tel = $tel WHERE id = $id", db); - insertCmd.Parameters.AddWithValue("$id", citoyen.Id); - insertCmd.Parameters.AddWithValue("$nom", citoyen.Nom); - insertCmd.Parameters.AddWithValue("$prenom", citoyen.Prenom); - insertCmd.Parameters.AddWithValue("$date_naissance", citoyen.DateNaissance.ToString("yyyyMMdd")); - insertCmd.Parameters.AddWithValue("$adresse", citoyen.Adresse); - insertCmd.Parameters.AddWithValue("$profession", citoyen.Profession); - insertCmd.Parameters.AddWithValue("$type_residence", citoyen.TypeResidence); - insertCmd.Parameters.AddWithValue("$mail", citoyen.Mail); - insertCmd.Parameters.AddWithValue("$tel", citoyen.Tel); - - insertCmd.ExecuteNonQuery(); - } - - public static void Remove(Citoyen citoyen) { - SqliteConnection db = DataAccess.GetConnection(); - - SqliteCommand insertCmd = new SqliteCommand("DELETE FROM citoyen WHERE id = $id", db); - insertCmd.Parameters.AddWithValue("$id", citoyen.Id); - - insertCmd.ExecuteNonQuery(); - } - } -} diff --git a/CitoyenModal.xaml b/CitoyenModal.xaml index 70933b6..77fd897 100644 --- a/CitoyenModal.xaml +++ b/CitoyenModal.xaml @@ -5,38 +5,144 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Hermes" mc:Ignorable="d" - Title="Informations" Height="279" Width="640" + Title="Informations" Height="390" Width="750" + Icon="hermes.png" ResizeMode="NoResize" + xmlns:Validation="clr-namespace:Hermes.Validation" + xmlns:Converter="clr-namespace:Hermes.Converter" + Loaded="Window_Loaded" + WindowStartupLocation="CenterOwner" Closing="Window_Closing"> + + + + + - - - - - - - - - - - - - - - - Principale - Secondaire + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + Principale + Secondaire + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CitoyenModal.xaml.cs b/CitoyenModal.xaml.cs index bd40170..1d95ce0 100644 --- a/CitoyenModal.xaml.cs +++ b/CitoyenModal.xaml.cs @@ -1,32 +1,100 @@ -using System; +using Hermes.Model; +using System; 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.Shapes; -namespace Hermes -{ +namespace Hermes { /// /// Logique d'interaction pour CitoyenModal.xaml /// - public partial class CitoyenModal : Window - { - public CitoyenModal() - { + public partial class CitoyenModal : Window { + private ModelContext dbContext = null; + private Citoyen citoyen = null; + private List _isInvalidElements = new List(); + private bool _modeCreate = true; + + public static List Civilites = new List(); + + 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(); + } } } diff --git a/Converter/NegateBoolean.cs b/Converter/NegateBoolean.cs new file mode 100644 index 0000000..e5f1a34 --- /dev/null +++ b/Converter/NegateBoolean.cs @@ -0,0 +1,15 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace Hermes.Converter { + class NegateBoolean : IValueConverter { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + return !(bool) value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + return !(bool) value; + } + } +} diff --git a/DataAccess.cs b/DataAccess.cs deleted file mode 100644 index 5062c81..0000000 --- a/DataAccess.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.Data.Sqlite; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security.Policy; -using System.Text; -using System.Threading.Tasks; - -namespace Hermes -{ - public static class DataAccess - { - private static SqliteConnection db= null; - - public static SqliteConnection GetConnection() { - if (db != null) { - return db; - } - - var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hermes.db"); - if (!System.IO.File.Exists(dbpath)) { - FileStream fs = File.Create(dbpath); - fs.Close(); - } - db = new SqliteConnection($"Filename={dbpath}"); - db.Open(); - - var createTableCmd = "CREATE TABLE IF NOT EXISTS citoyen (id INTEGER PRIMARY KEY, nom TEXT NOT NULL, prenom TEXT NOT NULL, date_naissance TEXT NOT NULL, adresse TEXT NOT NULL, profession TEXT, type_residence INTEGER NOT NULL, mail TEXT, tel TEXT)"; - - SqliteCommand createTable = new SqliteCommand(createTableCmd, db); - createTable.ExecuteReader(); - - return db; - } - - public static void CloseConnection() { - if (db != null) { - db.Close(); - db = null; - } - } - } -} diff --git a/Hermes.csproj b/Hermes.csproj index 25cae39..0e3c500 100644 --- a/Hermes.csproj +++ b/Hermes.csproj @@ -1,5 +1,6 @@  + Debug @@ -16,6 +17,21 @@ true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -37,36 +53,24 @@ 4 - - packages\Microsoft.Data.Sqlite.Core.3.1.7\lib\netstandard2.0\Microsoft.Data.Sqlite.dll + + packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll - - packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.2\lib\net461\SQLitePCLRaw.batteries_v2.dll + + packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll - - packages\SQLitePCLRaw.core.2.0.2\lib\netstandard2.0\SQLitePCLRaw.core.dll - - - packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.2\lib\net461\SQLitePCLRaw.nativelibrary.dll - - - packages\SQLitePCLRaw.provider.dynamic_cdecl.2.0.2\lib\netstandard2.0\SQLitePCLRaw.provider.dynamic_cdecl.dll + + packages\EntityFramework.SqlServerCompact.6.4.4\lib\net45\EntityFramework.SqlServerCompact.dll - - packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll - + - - packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll - - packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll - - - packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - + + @@ -85,9 +89,20 @@ MSBuild:Compile Designer - - SearchModal.xaml + + + + 202011292109022_V1.cs + + + + + + PreferencesModal.xaml + + + Designer MSBuild:Compile @@ -100,17 +115,14 @@ App.xaml Code - - CitoyenModal.xaml - MainWindow.xaml Code - + Designer MSBuild:Compile @@ -129,11 +141,15 @@ Settings.settings True + + 202011292109022_V1.cs + ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -142,12 +158,38 @@ + + + + + + False + Microsoft .NET Framework 4.8 %28x86 et x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + - Ce projet fait référence à des packages NuGet qui sont manquants sur cet ordinateur. Utilisez l'option de restauration des packages NuGet pour les télécharger. Pour plus d'informations, consultez http://go.microsoft.com/fwlink/?LinkID=322105. Le fichier manquant est : {0}. - + + + + + + if not exist "$(TargetDir)x86" md "$(TargetDir)x86" + xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\x86\*.*" "$(TargetDir)x86" + if not exist "$(TargetDir)amd64" md "$(TargetDir)amd64" + xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\amd64\*.*" "$(TargetDir)amd64" + \ No newline at end of file diff --git a/MainWindow.xaml b/MainWindow.xaml index d50a512..296c15e 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -5,30 +5,56 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Hermes" mc:Ignorable="d" - Title="Hermes" Height="450" Width="800"> + Icon="hermes.png" + Loaded="Window_Loaded" + WindowStartupLocation="CenterScreen" + Title="Hermes" Height="512" Width="1024"> + + + - + - - + + + + + + + + + + + + - + + + - - - + + - - + + + + + + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 4f946cd..d7047de 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -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 { /// /// Logique d'interaction pour MainWindow.xaml /// - 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 citoyens = new List(); - 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 clist = new List(); + 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(); } diff --git a/Migrations/202011292109022_V1.Designer.cs b/Migrations/202011292109022_V1.Designer.cs new file mode 100644 index 0000000..5ece8a4 --- /dev/null +++ b/Migrations/202011292109022_V1.Designer.cs @@ -0,0 +1,29 @@ +// +namespace Hermes.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.4.4")] + public sealed partial class V1 : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(V1)); + + string IMigrationMetadata.Id + { + get { return "202011292109022_V1"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Migrations/202011292109022_V1.cs b/Migrations/202011292109022_V1.cs new file mode 100644 index 0000000..a9668d6 --- /dev/null +++ b/Migrations/202011292109022_V1.cs @@ -0,0 +1,57 @@ +namespace Hermes.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class V1 : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.Citoyens", + c => new + { + Id = c.Int(nullable: false, identity: true), + Civilite = c.String(maxLength: 4000), + Nom = c.String(maxLength: 4000), + NomNaissance = c.String(maxLength: 4000), + Prenom = c.String(maxLength: 4000), + DateNaissance = c.DateTime(), + Profession = c.String(maxLength: 4000), + TypeResidence = c.Boolean(nullable: false), + Mail = c.String(maxLength: 4000), + Tel = c.String(maxLength: 4000), + TelPort = c.String(maxLength: 4000), + Quartier = c.String(maxLength: 4000), + AdresseNumero = c.String(maxLength: 4000), + AdresseRue = c.String(maxLength: 4000), + AdresseBatiment = c.String(maxLength: 4000), + AdresseExtNumero = c.String(maxLength: 4000), + AdresseExtRue = c.String(maxLength: 4000), + AdresseExtCP = c.String(maxLength: 4000), + AdresseExtVille = c.String(maxLength: 4000), + DateCreation = c.DateTime(nullable: false), + DateModification = c.DateTime(nullable: false), + }) + .PrimaryKey(t => t.Id); + + CreateTable( + "dbo.Preferences", + c => new + { + Id = c.Int(nullable: false, identity: true), + VilleCP = c.String(maxLength: 4000), + Ville = c.String(maxLength: 4000), + SmsApiKey = c.String(maxLength: 4000), + }) + .PrimaryKey(t => t.Id); + + } + + public override void Down() + { + DropTable("dbo.Preferences"); + DropTable("dbo.Citoyens"); + } + } +} diff --git a/Migrations/202011292109022_V1.resx b/Migrations/202011292109022_V1.resx new file mode 100644 index 0000000..e7dba67 --- /dev/null +++ b/Migrations/202011292109022_V1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Migrations/Configuration.cs b/Migrations/Configuration.cs new file mode 100644 index 0000000..4b798fc --- /dev/null +++ b/Migrations/Configuration.cs @@ -0,0 +1,20 @@ +namespace Hermes.Migrations { + using System; + using System.Data.Entity; + using System.Data.Entity.Migrations; + using System.Linq; + + internal sealed class Configuration : DbMigrationsConfiguration { + public Configuration() { + AutomaticMigrationsEnabled = false; + ContextKey = "Hermes"; + } + + protected override void Seed(Hermes.Model.ModelContext context) { + // This method will be called after migrating to the latest version. + + // You can use the DbSet.AddOrUpdate() helper extension method + // to avoid creating duplicate seed data. + } + } +} diff --git a/Model/Citoyen.cs b/Model/Citoyen.cs new file mode 100644 index 0000000..8aee2b4 --- /dev/null +++ b/Model/Citoyen.cs @@ -0,0 +1,240 @@ +using System; +using Hermes.Model; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Hermes.Model { + public class Citoyen : INotifyPropertyChanged { + private int _id; + private string _civilite; + private string _nom; + private string _nomNaissance; + private string _prenom; + private DateTime? _dateNaissance = null; + private string _profession; + private bool _typeResidence = false; + private string _mail; + private string _tel; + private string _telPort; + private string _quartier; + private string _adresseNumero; + private string _adresseRue; + private string _adresseBatiment; + private string _adresseExtNumero; + private string _adresseExtRue; + private string _adresseExtCP; + private string _adresseExtVille; + private DateTime _dateCreation; + private DateTime _dateModification; + + public int Id { get => _id; set => _id = value; } + public string Civilite { + get => _civilite; + set { + _civilite = value; + OnPropertyChanged(); + } + } + public string Nom { + get => _nom; + set { + _nom = value; + OnPropertyChanged(); + } + } + public string NomNaissance { + get => _nomNaissance; + set { + _nomNaissance = value; + OnPropertyChanged(); + } + } + public string Prenom { + get => _prenom; + set { + _prenom = value; + OnPropertyChanged(); + } + } + public DateTime? DateNaissance { + get => _dateNaissance; + set { + _dateNaissance = value; + OnPropertyChanged(); + OnPropertyChanged("Age"); + } + } + public string Profession { + get => _profession; + set { + _profession = value; + OnPropertyChanged(); + } + } + public bool TypeResidence { + get => _typeResidence; + set { + _typeResidence = value; + if(_typeResidence == false) { + AdresseExtNumero = null; + AdresseExtRue = null; + AdresseExtCP = null; + AdresseExtVille = null; + } + OnPropertyChanged(); + OnPropertyChanged("TypeResidenceLabel"); + } + } + public string Mail { + get => _mail; + set { + _mail = value; + OnPropertyChanged(); + } + } + public string Tel { + get => _tel; + set { + _tel = value; + OnPropertyChanged(); + } + } + public string TelPort { + get => _telPort; + set { + _telPort = value; + OnPropertyChanged(); + } + } + public string Quartier { + get => _quartier; + set { + _quartier = value; + OnPropertyChanged(); + } + } + public string AdresseNumero { + get => _adresseNumero; + set { + _adresseNumero = value; + OnPropertyChanged(); + } + } + public string AdresseRue { + get => _adresseRue; + set { + _adresseRue = value; + OnPropertyChanged(); + } + } + public string AdresseBatiment { + get => _adresseBatiment; + set { + _adresseBatiment = value; + OnPropertyChanged(); + } + } + public string AdresseExtNumero { + get => TypeResidence == false ? null : _adresseExtNumero; + set { + _adresseExtNumero = value; + OnPropertyChanged(); + } + } + public string AdresseExtRue { + get => TypeResidence == false ? null : _adresseExtRue; + set { + _adresseExtRue = value; + OnPropertyChanged(); + } + } + public string AdresseExtCP { + get => TypeResidence == false ? null : _adresseExtCP; + set { + _adresseExtCP = value; + OnPropertyChanged(); + } + } + public string AdresseExtVille { + get => TypeResidence == false ? null : _adresseExtVille; + set { + _adresseExtVille = value; + OnPropertyChanged(); + } + } + public DateTime DateCreation { + get => _dateCreation; + set { + _dateCreation = value; + OnPropertyChanged(); + } + } + public DateTime DateModification { + get => _dateModification; + set { + _dateModification = value; + OnPropertyChanged(); + } + } + + [NotMapped] + public string TypeResidenceLabel { get => TypeResidence == false ? "Principale" : "Secondaire"; } + + [NotMapped] + public string Age { + get { + if(DateNaissance.HasValue) { + return (DateTime.Now.Year - DateNaissance.Value.Year).ToString(); + } + return ""; + } + + set { + if(String.IsNullOrWhiteSpace(value)) { + DateNaissance = null; + } else { + try { + DateNaissance = new DateTime(DateTime.Now.Year - Int32.Parse(value), 1, 1); + } catch(Exception) {} + } + } + } + + [NotMapped] + public string AdresseCP => ModelContext.Getinstance().Preferences.Local[0].VilleCP; + + [NotMapped] + public string AdresseVille => ModelContext.Getinstance().Preferences.Local[0].Ville; + + public event PropertyChangedEventHandler PropertyChanged; + + protected void OnPropertyChanged([CallerMemberName] string name = null) { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + } + + public void Copyto(Citoyen citoyen) { + citoyen.Id = Id; + citoyen.Civilite = Civilite; + citoyen.Nom = Nom; + citoyen.NomNaissance = NomNaissance; + citoyen.Prenom = Prenom; + citoyen.DateNaissance = DateNaissance; + citoyen.Profession = Profession; + citoyen.TypeResidence = TypeResidence; + citoyen.Mail = Mail; + citoyen.Tel = Tel; + citoyen.TelPort = TelPort; + citoyen.Quartier = Quartier; + citoyen.AdresseNumero = AdresseNumero; + citoyen.AdresseRue = AdresseRue; + citoyen.AdresseBatiment = AdresseBatiment; + citoyen.AdresseExtNumero = AdresseExtNumero; + citoyen.AdresseExtRue = AdresseExtRue; + citoyen.AdresseExtCP = AdresseExtCP; + citoyen.AdresseExtVille = AdresseExtVille; + citoyen.DateCreation = DateCreation; + citoyen.DateModification = DateModification; + } + } +} diff --git a/Model/ModelContext.cs b/Model/ModelContext.cs new file mode 100644 index 0000000..cce04eb --- /dev/null +++ b/Model/ModelContext.cs @@ -0,0 +1,25 @@ +using System; +using System.Data.Entity; +using System.IO; + +namespace Hermes.Model { + public class ModelContext : DbContext { + private static ModelContext instance = new ModelContext(); + + public static ModelContext Getinstance() { + return instance; + } + + public ModelContext() + : base("Data Source=" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hermes.sdf")) { + Database.SetInitializer(new MigrateDatabaseToLatestVersion()); + } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) { + base.OnModelCreating(modelBuilder); + } + + public virtual DbSet CitoyenSet { get; set; } + public virtual DbSet Preferences { get; set; } + } +} diff --git a/Model/Preferences.cs b/Model/Preferences.cs new file mode 100644 index 0000000..2f69508 --- /dev/null +++ b/Model/Preferences.cs @@ -0,0 +1,10 @@ +using System; + +namespace Hermes.Model { + public class Preferences { + public int Id { get; set; } + public string VilleCP { get; set; } + public string Ville { get; set; } + public string SmsApiKey { get; set; } + } +} diff --git a/PreferencesModal.xaml b/PreferencesModal.xaml new file mode 100644 index 0000000..0b4d43a --- /dev/null +++ b/PreferencesModal.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PreferencesModal.xaml.cs b/PreferencesModal.xaml.cs new file mode 100644 index 0000000..05f4b52 --- /dev/null +++ b/PreferencesModal.xaml.cs @@ -0,0 +1,21 @@ +using Hermes.Model; +using System.Windows; + +namespace Hermes { + /// + /// Logique d'interaction pour PreferencesModal.xaml + /// + public partial class PreferencesModal : Window { + private ModelContext dbContext = null; + + public PreferencesModal() { + dbContext = ModelContext.Getinstance(); + InitializeComponent(); + } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { + e.Cancel = true; + this.Hide(); + } + } +} diff --git a/Properties/DataSources/Hermes.Model.Citoyen.datasource b/Properties/DataSources/Hermes.Model.Citoyen.datasource new file mode 100644 index 0000000..e91eb9c --- /dev/null +++ b/Properties/DataSources/Hermes.Model.Citoyen.datasource @@ -0,0 +1,10 @@ + + + + Hermes.Model.Citoyen, Hermes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/SearchModal.xaml b/SearchModal.xaml deleted file mode 100644 index 485f66a..0000000 --- a/SearchModal.xaml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Supérieur à - Inférieur à - Egal à - - - - - - - - - - - - Principale - Secondaire - - - - - - \ No newline at end of file diff --git a/SearchModal.xaml.cs b/SearchModal.xaml.cs deleted file mode 100644 index e11ba88..0000000 --- a/SearchModal.xaml.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -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.Shapes; - -namespace Hermes -{ - /// - /// Logique d'interaction pour SearchModal.xaml - /// - public partial class SearchModal : Window - { - public SearchModal() - { - InitializeComponent(); - } - - private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - e.Cancel = true; - this.Hide(); - } - } -} diff --git a/Validation/Age.cs b/Validation/Age.cs new file mode 100644 index 0000000..3183389 --- /dev/null +++ b/Validation/Age.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; +using System.Windows.Controls; + +namespace Hermes.Validation { + class Age : ValidationRule { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) { + if(string.IsNullOrEmpty((string) value)) { + return ValidationResult.ValidResult; + } + + try { + if(Int32.Parse((string) value) <= 0) { + throw new ArgumentException(); + } + } catch(Exception) { + return new ValidationResult(false, "Ce champ doit contenir un age au format numérique"); + } + return ValidationResult.ValidResult; + } + } +} diff --git a/Validation/MandatoryString.cs b/Validation/MandatoryString.cs new file mode 100644 index 0000000..e67c401 --- /dev/null +++ b/Validation/MandatoryString.cs @@ -0,0 +1,13 @@ +using System.Globalization; +using System.Windows.Controls; + +namespace Hermes.Validation { + class MandatoryString : ValidationRule { + public override ValidationResult Validate(object value, CultureInfo cultureInfo) { + if(string.IsNullOrWhiteSpace((string) value)) { + return new ValidationResult(false, "Ce champ est obligatoire"); + } + return ValidationResult.ValidResult; + } + } +} diff --git a/hermes.png b/hermes.png new file mode 100644 index 0000000..8ef4a16 Binary files /dev/null and b/hermes.png differ diff --git a/packages.config b/packages.config index 2088b48..fa7238f 100644 --- a/packages.config +++ b/packages.config @@ -1,13 +1,6 @@  - - - - - - - - - - + + + \ No newline at end of file