Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Fix create profile windows, add remove profile and modify profile fea…
Browse files Browse the repository at this point in the history
…ture
  • Loading branch information
Ash Frost committed Apr 13, 2020
1 parent 440ecac commit 2d75758
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 39 deletions.
7 changes: 4 additions & 3 deletions AttestationsGenerator/AttestationsGenerator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<DockPanel Loaded="Window_Loaded">
<Menu DockPanel.Dock="Top" Height="23">
<MenuItem Header="_Options" Height="23">
<MenuItem Header="_Créer un profile" Click="Create_Profile_Click" />
<MenuItem Header="_Modifier un profile" Click="Modify_Profile_Click"/>
<MenuItem Header="_Supprimer un profile" Click="Delete_Profile_Click"/>
<MenuItem Header="_Générer un template de fichier profiles.json" Click="Generate_Profiles_Click" />
<MenuItem Header="_Charger le fichier profiles.json" Click="Load_Profiles_Click" />
</MenuItem>
</Menu>
<Grid>
<Grid Margin="0,0,0,0">
<ComboBox Name="Profiles_ComboBox" Margin="10,10,10,0" VerticalAlignment="Top"/>
<ComboBox Name="Exit_Reasons_ComboBox" Margin="10,37,10,0" VerticalAlignment="Top" SelectedIndex="0">
<ComboBoxItem>Déplacements entre domicile et travail</ComboBoxItem>
Expand Down
47 changes: 41 additions & 6 deletions AttestationsGenerator/AttestationsGenerator.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace AttestationsGenerator
/// </summary>
public partial class MainWindow : Window
{
private List<Profile> profiles = new List<Profile>();
public static List<Profile> profiles = new List<Profile>();

public MainWindow()
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
}
56 changes: 40 additions & 16 deletions AttestationsGenerator/CreateProfile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Grid>
<Label Content="Nom complet : " HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="FullName" HorizontalAlignment="Left" Margin="150,17,0,0" VerticalAlignment="Top" Width="152"/>
<Label Content="Date de naissance :" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="DateBirth" HorizontalAlignment="Left" Margin="150,47,0,0" VerticalAlignment="Top" Width="152"/>
<Label Content="Lieu de naissance :" HorizontalAlignment="Left" Margin="10,70,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="CityBirth" HorizontalAlignment="Left" Margin="150,77,0,0" VerticalAlignment="Top" Width="152"/>
<Label Content="Adresse :" HorizontalAlignment="Left" Margin="10,100,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="Address" HorizontalAlignment="Left" Margin="150,107,0,0" VerticalAlignment="Top" Width="152"/>
<Label Content="Ville : " HorizontalAlignment="Left" Margin="10,130,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="City" HorizontalAlignment="Left" Margin="150,137,0,0" VerticalAlignment="Top" Width="152"/>
<Button Content="Créer le profile" HorizontalAlignment="Left" Margin="110,170,0,0" VerticalAlignment="Top" Width="100" Click="Create_Profile"/>

Title="Créer un profile" Height="225" Width="318" ResizeMode="NoResize">
<Window.Resources>
<Style x:Key="placeHolder" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBox Text="{Binding Path=Text,
RelativeSource={RelativeSource TemplatedParent},
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
x:Name="textSource"
Background="Transparent"
Panel.ZIndex="2" />
<TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="Transparent"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
<Setter Property="Foreground" Value="LightGray"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Margin="0,0,0,0">
<TextBox Style="{StaticResource placeHolder}" Tag="Nom complet" x:Name="FullName" Margin="10,10,10,0" VerticalAlignment="Top" FontSize="16" KeyUp="OnKeyUpHandler"/>
<TextBox Style="{StaticResource placeHolder}" Tag="Date de naissance" x:Name="DateBirth" Margin="10,38,10,0" VerticalAlignment="Top" FontSize="16" KeyUp="OnKeyUpHandler"/>
<TextBox Style="{StaticResource placeHolder}" Tag="Lieu de naissance" x:Name="CityBirth" Margin="10,66,10,0" VerticalAlignment="Top" FontSize="16" KeyUp="OnKeyUpHandler"/>
<TextBox Style="{StaticResource placeHolder}" Tag="Adresse" x:Name="Address" Margin="10,94,10,0" VerticalAlignment="Top" FontSize="16" KeyUp="OnKeyUpHandler"/>
<TextBox Style="{StaticResource placeHolder}" Tag="Ville" x:Name="City" Margin="10,122,10,0" VerticalAlignment="Top" FontSize="16" KeyUp="OnKeyUpHandler"/>
<Button x:Name="CreateProfileButton" Content="Créer le profile" Margin="10,150,10,10" Click="Create_Profile"/>
</Grid>
</Window>
</Window>
44 changes: 37 additions & 7 deletions AttestationsGenerator/CreateProfile.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace AttestationsGenerator
{
Expand All @@ -18,7 +19,7 @@ public CreateProfile()
InitializeComponent();
}

private List<TextBox> get_all_textbox()
private List<TextBox> Get_All_Textbox()
{
return new List<TextBox>()
{
Expand All @@ -32,15 +33,33 @@ private List<TextBox> get_all_textbox()

private void Create_Profile(object sender, RoutedEventArgs e)
{
foreach (TextBox tb in get_all_textbox())
CreateProfileProcess();
}

private void CreateProfileProcess()
{
foreach (TextBox tb in Get_All_Textbox())
{
if (string.IsNullOrEmpty(tb.Text) || string.IsNullOrWhiteSpace(tb.Text))
{
_ = MessageBox.Show("Veuillez remplir tous les champs.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
Profile p = new Profile(FullName.Text, DateBirth.Text, CityBirth.Text, Address.Text, City.Text);
Profile p = MainWindow.GetFromFullName(FullName.Text);
Boolean newProfile = false;
if (p == null)
{
newProfile = true;
p = new Profile(FullName.Text, DateBirth.Text, CityBirth.Text, Address.Text, City.Text);
}
else
{
p.BirthDate = DateBirth.Text;
p.BirthPlace = CityBirth.Text;
p.Address = Address.Text;
p.City = City.Text;
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string configPath = Path.Combine(path, "AttestationsGenerator");
if (!File.Exists(configPath + "\\profiles.json"))
Expand All @@ -51,13 +70,24 @@ private void Create_Profile(object sender, RoutedEventArgs e)
};
File.WriteAllText(configPath + "\\profiles.json", JsonConvert.SerializeObject(templateProfiles, Formatting.Indented));
_ = MessageBox.Show("Votre fichier profiles.json à été généré.", "Réussite", MessageBoxButton.OK, MessageBoxImage.Information);
} else
}
else
{
List<Profile> profiles = JsonConvert.DeserializeObject<List<Profile>>(File.ReadAllText(configPath + "\\profiles.json"));
profiles.Add(p);
File.WriteAllText(configPath + "\\profiles.json", JsonConvert.SerializeObject(profiles, Formatting.Indented));
if (newProfile)
{
MainWindow.profiles.Add(p);
}
File.WriteAllText(configPath + "\\profiles.json", JsonConvert.SerializeObject(MainWindow.profiles, Formatting.Indented));
}
this.Close();
}

private void OnKeyUpHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
CreateProfileProcess();
}
}
}
}
15 changes: 14 additions & 1 deletion AttestationsGenerator/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace AttestationsGenerator
{
class Profile
public class Profile
{
public string Fullname { get; set; }
public string BirthDate { get; set; }
Expand All @@ -22,5 +22,18 @@ public Profile(string fullname, string birthDate, string birthPlace, string addr
this.Address = address;
this.City = city;
}

public override bool Equals(object obj)
{
return obj is Profile profile &&
Fullname == profile.Fullname;
}

public override int GetHashCode()
{
int hashCode = 1578132623;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Fullname);
return hashCode;
}
}
}
28 changes: 22 additions & 6 deletions Setup/Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
"Items"
{
"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2"
{
"Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)"
"ProductCode" = "8:.NETFramework,Version=v4.7.2"
}
}
}
}
"Release"
Expand All @@ -152,6 +160,14 @@
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
"Items"
{
"{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.7.2"
{
"Name" = "8:Microsoft .NET Framework 4.7.2 (x86 and x64)"
"ProductCode" = "8:.NETFramework,Version=v4.7.2"
}
}
}
}
}
Expand Down Expand Up @@ -413,15 +429,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:Générateur d'attestation"
"ProductCode" = "8:{A1B271DF-308D-4BAF-BC3A-100E6461FD1D}"
"PackageCode" = "8:{27BC3DBC-BC39-4F7E-BCE5-BFA714BD2C39}"
"ProductCode" = "8:{020FAC96-A373-4DB8-A5F6-9A4C026B8897}"
"PackageCode" = "8:{AE60F0C9-B871-43EA-A604-D7A8359F46FE}"
"UpgradeCode" = "8:{3A184958-1664-4602-BDA6-DAB7424E4270}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.0.1"
"InstallAllUsers" = "11:TRUE"
"ProductVersion" = "8:1.0.2"
"Manufacturer" = "8:BabaWorld"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down Expand Up @@ -949,7 +965,7 @@
{
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_825E0423722B445EA90B777D55F5FD77"
{
"SourcePath" = "8:..\\AttestationsGenerator\\obj\\Debug\\AttestationsGenerator.exe"
"SourcePath" = "8:..\\AttestationsGenerator\\obj\\Release\\AttestationsGenerator.exe"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_4DE44A582CA34D3FA3FEFB7867A402F8"
Expand Down

0 comments on commit 2d75758

Please sign in to comment.