This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from flopal/master
Ajout de la création de profile
- Loading branch information
Showing
5 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Window x:Class="AttestationsGenerator.CreateProfile" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
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"/> | ||
|
||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace AttestationsGenerator | ||
{ | ||
/// <summary> | ||
/// Logique d'interaction pour Window1.xaml | ||
/// </summary> | ||
public partial class CreateProfile : Window | ||
{ | ||
|
||
public CreateProfile() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private List<TextBox> get_all_textbox() | ||
{ | ||
return new List<TextBox>() | ||
{ | ||
FullName, | ||
DateBirth, | ||
CityBirth, | ||
Address, | ||
City | ||
}; | ||
} | ||
|
||
private void Create_Profile(object sender, RoutedEventArgs e) | ||
{ | ||
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); | ||
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||
string configPath = Path.Combine(path, "AttestationsGenerator"); | ||
if (!File.Exists(configPath + "\\profiles.json")) | ||
{ | ||
List<Profile> templateProfiles = new List<Profile> | ||
{ | ||
p | ||
}; | ||
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 | ||
{ | ||
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)); | ||
} | ||
this.Close(); | ||
} | ||
} | ||
} |