From 2d757585f0006684082dad40d86a9f436d556d31 Mon Sep 17 00:00:00 2001 From: Ash Frost Date: Mon, 13 Apr 2020 19:29:19 +0200 Subject: [PATCH] Fix create profile windows, add remove profile and modify profile feature --- .../AttestationsGenerator.xaml | 7 ++- .../AttestationsGenerator.xaml.cs | 47 ++++++++++++++-- AttestationsGenerator/CreateProfile.xaml | 56 +++++++++++++------ AttestationsGenerator/CreateProfile.xaml.cs | 44 ++++++++++++--- AttestationsGenerator/Profile.cs | 15 ++++- Setup/Setup.vdproj | 28 ++++++++-- 6 files changed, 158 insertions(+), 39 deletions(-) diff --git a/AttestationsGenerator/AttestationsGenerator.xaml b/AttestationsGenerator/AttestationsGenerator.xaml index 8141f4f..d3311a0 100644 --- a/AttestationsGenerator/AttestationsGenerator.xaml +++ b/AttestationsGenerator/AttestationsGenerator.xaml @@ -3,18 +3,19 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:AttestationsGenerator" mc:Ignorable="d" - Title="Générateur d'attestation" Height="167" Width="317" ResizeMode="CanMinimize"> + Title="Générateur d'attestation" Height="167" Width="358" ResizeMode="CanMinimize"> + + - + Déplacements entre domicile et travail diff --git a/AttestationsGenerator/AttestationsGenerator.xaml.cs b/AttestationsGenerator/AttestationsGenerator.xaml.cs index bcbf97b..49a48bd 100644 --- a/AttestationsGenerator/AttestationsGenerator.xaml.cs +++ b/AttestationsGenerator/AttestationsGenerator.xaml.cs @@ -17,7 +17,7 @@ namespace AttestationsGenerator /// public partial class MainWindow : Window { - private List profiles = new List(); + public static List profiles = new List(); public MainWindow() { @@ -99,15 +99,12 @@ private void Button_Click(object sender, RoutedEventArgs e) } } - private Profile GetFromFullName(string fullname) => profiles.Find(profil => profil.Fullname == fullname); + public static Profile GetFromFullName(string fullname) => profiles.Find(profil => profil.Fullname == fullname); private void Create_Profile_Click(object sender, RoutedEventArgs e) { new CreateProfile().ShowDialog(); - if (LoadProfilesFile()) - { - _ = MessageBox.Show("Votre fichier profiles.json à été correctement lu.", "Réussite", MessageBoxButton.OK, MessageBoxImage.Information); - } + _ = LoadProfilesFile(); } private void Generate_Profiles_Click(object sender, RoutedEventArgs e) @@ -191,5 +188,43 @@ private Boolean LoadProfilesFile() } } + + private void Delete_Profile_Click(object sender, RoutedEventArgs e) + { + if (Profiles_ComboBox.Items.Count == 0) + { + _ = MessageBox.Show("Aucun profile à supprimer.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + if (MessageBox.Show(String.Format("Vous vous apprêtez à supprimer le profile {0:s}, souhaitez vous vraiment continuer ?.", Profiles_ComboBox.SelectedItem), "Êtes-vous sûr ?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) + { + string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + string configPath = Path.Combine(path, "AttestationsGenerator"); + profiles.Remove(GetFromFullName(Profiles_ComboBox.SelectedItem.ToString())); + File.WriteAllText(configPath + "\\profiles.json", JsonConvert.SerializeObject(profiles, Formatting.Indented)); + _ = LoadProfilesFile(); + _ = MessageBox.Show("Profile supprimé.", "Réussite", MessageBoxButton.OK, MessageBoxImage.Information); + } + } + + private void Modify_Profile_Click(object sender, RoutedEventArgs e) + { + if (Profiles_ComboBox.Items.Count == 0) + { + _ = MessageBox.Show("Aucun profile à modifier.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + Profile profile = GetFromFullName(Profiles_ComboBox.SelectedItem.ToString()); + CreateProfile createProfile = new CreateProfile(); + createProfile.FullName.Text = profile.Fullname; + createProfile.FullName.IsEnabled = false; + createProfile.DateBirth.Text = profile.BirthDate; + createProfile.CityBirth.Text = profile.BirthPlace; + createProfile.Address.Text = profile.Address; + createProfile.City.Text = profile.City; + createProfile.CreateProfileButton.Content = "Modifier le profile"; + createProfile.ShowDialog(); + _ = LoadProfilesFile(); + } } } diff --git a/AttestationsGenerator/CreateProfile.xaml b/AttestationsGenerator/CreateProfile.xaml index 3b8ef13..2c5ed39 100644 --- a/AttestationsGenerator/CreateProfile.xaml +++ b/AttestationsGenerator/CreateProfile.xaml @@ -3,21 +3,45 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:AttestationsGenerator" mc:Ignorable="d" - Title="Créer un profile" Height="230" Width="320"> - -