Ajout d'une fonctionnalité d'import/export CSV + amélioration de l'écran de démarrage
This commit is contained in:
parent
d68c6b0f8a
commit
e81b0b000a
342
CitoyensSerializer.cs
Normal file
342
CitoyensSerializer.cs
Normal file
@ -0,0 +1,342 @@
|
|||||||
|
using Hermes.Model;
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.VisualBasic.FileIO;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Hermes {
|
||||||
|
class CitoyensSerializer {
|
||||||
|
public const string CIVILITE_FIELD = "Civilité";
|
||||||
|
public const string NOM_FIELD = "Nom";
|
||||||
|
public const string NOM_NAISSANCE_FIELD = "Nom de naissance";
|
||||||
|
public const string PRENOM_FIELD = "Prénom";
|
||||||
|
public const string DATE_NAISSANCE_FIELD = "Date de naissance";
|
||||||
|
public const string PROFESSION_FIELD = "Profession";
|
||||||
|
public const string TYPE_RESIDENCE_FIELD = "Résidence secondaire";
|
||||||
|
public const string MAIL_FIELD = "E-Mail";
|
||||||
|
public const string TEL_FIELD = "Téléphone";
|
||||||
|
public const string TEL_PORT_FIELD = "Mobile";
|
||||||
|
public const string QUARTIER_FIELD = "Quartier";
|
||||||
|
public const string ADRESSE_FIELD = "Adresse locale";
|
||||||
|
public const string ADRESSE_BATIMENT_FIELD = "Bâtiment";
|
||||||
|
public const string ADRESSE_NUMERO_BATIMENT_FIELD = "Numéro d'appartement";
|
||||||
|
public const string ADRESSE_EXT_FIELD = "Adresse";
|
||||||
|
public const string ADRESSE_EXT_CP_FIELD = "Code postal";
|
||||||
|
public const string ADRESSE_EXT_VILLE_FIELD = "Ville";
|
||||||
|
public const string DATE_CREATION_FIELD = "Date de création";
|
||||||
|
public const string DATE_MODIFICATION_FIELD = "Date de modification";
|
||||||
|
|
||||||
|
public const string TYPE_RESIDENCE_LABEL_FIELD = "Résidence";
|
||||||
|
public const string AGE_FIELD = "Age";
|
||||||
|
public const string ADRESSE_CP_FIELD = "Code postal local";
|
||||||
|
public const string ADRESSE_VILLE_FIELD = "Ville locale";
|
||||||
|
public const string ADRESSE_PRINCIPALE_FIELD = "Adresse principale";
|
||||||
|
public const string ADRESSE_PRINCIPALE_CP_FIELD = "Code postal principal";
|
||||||
|
public const string ADRESSE_PRINCIPALE_VILLE_FIELD = "Ville principale";
|
||||||
|
public const string ADRESSE_SECONDAIRE_FIELD = "Adresse secondaire";
|
||||||
|
public const string ADRESSE_SECONDAIRE_CP_FIELD = "Code postal secondaire";
|
||||||
|
public const string ADRESSE_SECONDAIRE_VILLE_FIELD = "Ville secondaire";
|
||||||
|
public const string UNKNOWN_FIELD = "unknown";
|
||||||
|
|
||||||
|
private string[] fields = null;
|
||||||
|
|
||||||
|
public CitoyensSerializer(string[] pField) {
|
||||||
|
fields = pField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CitoyensSerializer() {
|
||||||
|
fields = new string[] {
|
||||||
|
CIVILITE_FIELD,
|
||||||
|
NOM_FIELD,
|
||||||
|
NOM_NAISSANCE_FIELD,
|
||||||
|
PRENOM_FIELD,
|
||||||
|
DATE_NAISSANCE_FIELD,
|
||||||
|
PROFESSION_FIELD,
|
||||||
|
TYPE_RESIDENCE_FIELD,
|
||||||
|
MAIL_FIELD,
|
||||||
|
TEL_FIELD,
|
||||||
|
TEL_PORT_FIELD,
|
||||||
|
QUARTIER_FIELD,
|
||||||
|
ADRESSE_FIELD,
|
||||||
|
ADRESSE_BATIMENT_FIELD,
|
||||||
|
ADRESSE_NUMERO_BATIMENT_FIELD,
|
||||||
|
ADRESSE_EXT_FIELD,
|
||||||
|
ADRESSE_EXT_CP_FIELD,
|
||||||
|
ADRESSE_EXT_VILLE_FIELD,
|
||||||
|
DATE_CREATION_FIELD,
|
||||||
|
DATE_MODIFICATION_FIELD
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetCsvHeader() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
if(fields != null) {
|
||||||
|
for(int i = 0; i < fields.Length; i++) {
|
||||||
|
sb.Append($"\"{fields[i]}\"");
|
||||||
|
if(i < fields.Length - 1) {
|
||||||
|
sb.Append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Serialize(Citoyen citoyen) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
if(fields != null) {
|
||||||
|
for(int i = 0; i < fields.Length; i++) {
|
||||||
|
sb.Append("\"");
|
||||||
|
switch(fields[i]) {
|
||||||
|
case CIVILITE_FIELD:
|
||||||
|
sb.Append(citoyen.Civilite == null ? "" : citoyen.Civilite.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOM_FIELD:
|
||||||
|
sb.Append(citoyen.Nom == null ? "" : citoyen.Nom.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOM_NAISSANCE_FIELD:
|
||||||
|
sb.Append(citoyen.NomNaissance == null ? "" : citoyen.NomNaissance.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRENOM_FIELD:
|
||||||
|
sb.Append(citoyen.Prenom == null ? "" : citoyen.Prenom.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DATE_NAISSANCE_FIELD:
|
||||||
|
sb.Append(citoyen.DateNaissance == null ? "" : (new DateTimeOffset(citoyen.DateNaissance.Value)).ToUnixTimeSeconds().ToString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROFESSION_FIELD:
|
||||||
|
sb.Append(citoyen.Profession == null ? "" : citoyen.Profession.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_RESIDENCE_FIELD:
|
||||||
|
sb.Append(citoyen.TypeResidence.ToString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAIL_FIELD:
|
||||||
|
sb.Append(citoyen.Mail == null ? "" : citoyen.Mail.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEL_FIELD:
|
||||||
|
sb.Append(citoyen.Tel == null ? "" : citoyen.Tel.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEL_PORT_FIELD:
|
||||||
|
sb.Append(citoyen.TelPort == null ? "" : citoyen.TelPort.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QUARTIER_FIELD:
|
||||||
|
sb.Append(citoyen.Quartier == null ? "" : citoyen.Quartier.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_FIELD:
|
||||||
|
sb.Append(citoyen.Adresse == null ? "" : citoyen.Adresse.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_BATIMENT_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseBatiment == null ? "" : citoyen.AdresseBatiment.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_NUMERO_BATIMENT_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseNumeroBatiment == null ? "" : citoyen.AdresseNumeroBatiment.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_EXT_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseExt == null ? "" : citoyen.AdresseExt.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_EXT_CP_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseExtCP == null ? "" : citoyen.AdresseExtCP.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_EXT_VILLE_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseExtVille == null ? "" : citoyen.AdresseExtVille.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DATE_CREATION_FIELD:
|
||||||
|
sb.Append((new DateTimeOffset(citoyen.DateCreation)).ToUnixTimeSeconds().ToString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DATE_MODIFICATION_FIELD:
|
||||||
|
sb.Append((new DateTimeOffset(citoyen.DateModification)).ToUnixTimeSeconds().ToString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case AGE_FIELD:
|
||||||
|
sb.Append(citoyen.Age);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_CP_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseCP == null ? "" : citoyen.AdresseCP.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_VILLE_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseVille == null ? "" : citoyen.AdresseVille.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_PRINCIPALE_FIELD:
|
||||||
|
sb.Append(citoyen.AdressePrincipale == null ? "" : citoyen.AdressePrincipale.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_PRINCIPALE_CP_FIELD:
|
||||||
|
sb.Append(citoyen.AdressePrincipaleCP == null ? "" : citoyen.AdressePrincipaleCP.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_PRINCIPALE_VILLE_FIELD:
|
||||||
|
sb.Append(citoyen.AdressePrincipaleVille == null ? "" : citoyen.AdressePrincipaleVille.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_SECONDAIRE_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseSecondaire == null ? "" : citoyen.AdresseSecondaire.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_SECONDAIRE_CP_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseSecondaireCP == null ? "" : citoyen.AdresseSecondaireCP.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_SECONDAIRE_VILLE_FIELD:
|
||||||
|
sb.Append(citoyen.AdresseSecondaireVille == null ? "" : citoyen.AdresseSecondaireVille.Replace("\"", ""));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sb.Append("\"");
|
||||||
|
if(i < fields.Length - 1) {
|
||||||
|
sb.Append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string[] ParseHeader(string line) {
|
||||||
|
TextFieldParser parser = new TextFieldParser(new StringReader(line));
|
||||||
|
|
||||||
|
parser.HasFieldsEnclosedInQuotes = true;
|
||||||
|
parser.SetDelimiters(";");
|
||||||
|
|
||||||
|
return parser.ReadFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Citoyen Deserialize(string line) {
|
||||||
|
TextFieldParser parser = new TextFieldParser(new StringReader(line));
|
||||||
|
|
||||||
|
parser.HasFieldsEnclosedInQuotes = true;
|
||||||
|
parser.SetDelimiters(";");
|
||||||
|
|
||||||
|
string[] props = parser.ReadFields();
|
||||||
|
|
||||||
|
if(props == null || props.Length != fields.Length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Citoyen citoyen = new Citoyen();
|
||||||
|
|
||||||
|
for(int i = 0; i < fields.Length; i++) {
|
||||||
|
switch(fields[i]) {
|
||||||
|
case CIVILITE_FIELD:
|
||||||
|
citoyen.Civilite = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOM_FIELD:
|
||||||
|
citoyen.Nom = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOM_NAISSANCE_FIELD:
|
||||||
|
citoyen.NomNaissance = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRENOM_FIELD:
|
||||||
|
citoyen.Prenom = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DATE_NAISSANCE_FIELD:
|
||||||
|
if(!string.IsNullOrWhiteSpace(props[i])) {
|
||||||
|
try {
|
||||||
|
citoyen.DateNaissance = DateTimeOffset.FromUnixTimeSeconds(long.Parse(props[i])).LocalDateTime;
|
||||||
|
} catch(Exception) {}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROFESSION_FIELD:
|
||||||
|
citoyen.Profession = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_RESIDENCE_FIELD:
|
||||||
|
try {
|
||||||
|
citoyen.TypeResidence = bool.Parse(props[i]);
|
||||||
|
} catch(Exception) {}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MAIL_FIELD:
|
||||||
|
citoyen.Mail = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEL_FIELD:
|
||||||
|
citoyen.Tel = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEL_PORT_FIELD:
|
||||||
|
citoyen.TelPort = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QUARTIER_FIELD:
|
||||||
|
citoyen.Quartier = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_FIELD:
|
||||||
|
citoyen.Adresse = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_BATIMENT_FIELD:
|
||||||
|
citoyen.AdresseBatiment = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_NUMERO_BATIMENT_FIELD:
|
||||||
|
citoyen.AdresseNumeroBatiment = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_EXT_FIELD:
|
||||||
|
citoyen.AdresseExt = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_EXT_CP_FIELD:
|
||||||
|
citoyen.AdresseExtCP = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADRESSE_EXT_VILLE_FIELD:
|
||||||
|
citoyen.AdresseExtVille = props[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DATE_CREATION_FIELD:
|
||||||
|
try {
|
||||||
|
citoyen.DateCreation = DateTimeOffset.FromUnixTimeSeconds(long.Parse(props[i])).LocalDateTime;
|
||||||
|
} catch(Exception) {
|
||||||
|
citoyen.DateCreation = DateTime.Now;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DATE_MODIFICATION_FIELD:
|
||||||
|
try {
|
||||||
|
citoyen.DateModification = DateTimeOffset.FromUnixTimeSeconds(long.Parse(props[i])).LocalDateTime;
|
||||||
|
} catch(Exception) {
|
||||||
|
citoyen.DateModification = DateTime.Now;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return citoyen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -77,6 +77,7 @@
|
|||||||
<HintPath>packages\Microsoft.Office.Interop.Word.15.0.4797.1003\lib\net20\Microsoft.Office.Interop.Word.dll</HintPath>
|
<HintPath>packages\Microsoft.Office.Interop.Word.15.0.4797.1003\lib\net20\Microsoft.Office.Interop.Word.dll</HintPath>
|
||||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@ -107,6 +108,7 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
|
<Compile Include="CitoyensSerializer.cs" />
|
||||||
<Compile Include="Converter\NegateBoolean.cs" />
|
<Compile Include="Converter\NegateBoolean.cs" />
|
||||||
<Compile Include="ImportWindow.xaml.cs">
|
<Compile Include="ImportWindow.xaml.cs">
|
||||||
<DependentUpon>ImportWindow.xaml</DependentUpon>
|
<DependentUpon>ImportWindow.xaml</DependentUpon>
|
||||||
|
@ -154,6 +154,12 @@
|
|||||||
"Entry"
|
"Entry"
|
||||||
{
|
{
|
||||||
"MsmKey" = "8:_UNDEFINED"
|
"MsmKey" = "8:_UNDEFINED"
|
||||||
|
"OwnerKey" = "8:_5FE7F4CD40C5D5EAEC6A24FAE0548A1E"
|
||||||
|
"MsmSig" = "8:_UNDEFINED"
|
||||||
|
}
|
||||||
|
"Entry"
|
||||||
|
{
|
||||||
|
"MsmKey" = "8:_UNDEFINED"
|
||||||
"OwnerKey" = "8:_EDA497A114444E23814EEE023731C727"
|
"OwnerKey" = "8:_EDA497A114444E23814EEE023731C727"
|
||||||
"MsmSig" = "8:_UNDEFINED"
|
"MsmSig" = "8:_UNDEFINED"
|
||||||
}
|
}
|
||||||
@ -187,12 +193,6 @@
|
|||||||
"OwnerKey" = "8:_19F88EB0C5E322CF5572D8C5A094E0A2"
|
"OwnerKey" = "8:_19F88EB0C5E322CF5572D8C5A094E0A2"
|
||||||
"MsmSig" = "8:_UNDEFINED"
|
"MsmSig" = "8:_UNDEFINED"
|
||||||
}
|
}
|
||||||
"Entry"
|
|
||||||
{
|
|
||||||
"MsmKey" = "8:_UNDEFINED"
|
|
||||||
"OwnerKey" = "8:_5FE7F4CD40C5D5EAEC6A24FAE0548A1E"
|
|
||||||
"MsmSig" = "8:_UNDEFINED"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"Configurations"
|
"Configurations"
|
||||||
{
|
{
|
||||||
@ -812,15 +812,15 @@
|
|||||||
{
|
{
|
||||||
"Name" = "8:Microsoft Visual Studio"
|
"Name" = "8:Microsoft Visual Studio"
|
||||||
"ProductName" = "8:Hermes"
|
"ProductName" = "8:Hermes"
|
||||||
"ProductCode" = "8:{CE173D1C-E589-4D0D-8443-272C16A0ECB7}"
|
"ProductCode" = "8:{2F4EE848-55DE-4984-B2BF-B6CC88401417}"
|
||||||
"PackageCode" = "8:{9F1DEC0D-1EB8-4407-884C-414E205F16ED}"
|
"PackageCode" = "8:{251B34BB-BC8A-4537-B4CA-14054A145302}"
|
||||||
"UpgradeCode" = "8:{A8FB75F3-57A5-4B7D-A0AE-9E87F69529B0}"
|
"UpgradeCode" = "8:{A8FB75F3-57A5-4B7D-A0AE-9E87F69529B0}"
|
||||||
"AspNetVersion" = "8:2.0.50727.0"
|
"AspNetVersion" = "8:2.0.50727.0"
|
||||||
"RestartWWWService" = "11:FALSE"
|
"RestartWWWService" = "11:FALSE"
|
||||||
"RemovePreviousVersions" = "11:TRUE"
|
"RemovePreviousVersions" = "11:TRUE"
|
||||||
"DetectNewerInstalledVersion" = "11:TRUE"
|
"DetectNewerInstalledVersion" = "11:TRUE"
|
||||||
"InstallAllUsers" = "11:FALSE"
|
"InstallAllUsers" = "11:FALSE"
|
||||||
"ProductVersion" = "8:0.9.2"
|
"ProductVersion" = "8:0.9.3"
|
||||||
"Manufacturer" = "8:Aztrom"
|
"Manufacturer" = "8:Aztrom"
|
||||||
"ARPHELPTELEPHONE" = "8:"
|
"ARPHELPTELEPHONE" = "8:"
|
||||||
"ARPHELPLINK" = "8:"
|
"ARPHELPLINK" = "8:"
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Menu Grid.Row="0" Background="White">
|
<Menu Grid.Row="0" Background="White">
|
||||||
<MenuItem Header="Fichier">
|
<MenuItem Header="Fichier">
|
||||||
|
<MenuItem Header="Exporter" Click="Exporter_Click"/>
|
||||||
<MenuItem Header="Importer" Click="Importer_Click" />
|
<MenuItem Header="Importer" Click="Importer_Click" />
|
||||||
<MenuItem Header="Quitter" Click="Quitter_Click"/>
|
<MenuItem Header="Quitter" Click="Quitter_Click"/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
@ -200,7 +200,7 @@ namespace Hermes {
|
|||||||
}
|
}
|
||||||
if(mails.Count > 0) {
|
if(mails.Count > 0) {
|
||||||
if(noMail) {
|
if(noMail) {
|
||||||
MessageBox.Show("Certains des citoyens sélectionnés ne disposent pas d'une adresse E-Mail. Voulez-vous continuer ?", "Envoi de courriel", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
result = MessageBox.Show("Certains des citoyens sélectionnés ne disposent pas d'une adresse E-Mail. Voulez-vous continuer ?", "Envoi de courriel", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
||||||
if(result == MessageBoxResult.No) {
|
if(result == MessageBoxResult.No) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -255,10 +255,10 @@ namespace Hermes {
|
|||||||
string villeSecondaire = citoyen.AdresseSecondaireVille == null ? "" : citoyen.AdresseSecondaireVille;
|
string villeSecondaire = citoyen.AdresseSecondaireVille == null ? "" : citoyen.AdresseSecondaireVille;
|
||||||
|
|
||||||
sb.AppendLine($"\"{civilite}\";\"{nom}\";\"{nomNaissance}\";\"{prenom}\";\"{profession}\";\"{typeResidence}\";\"{mail}\";\"{tel}\";\"{telPort}\";\"{quartier}\";\"{batiment}\";\"{numeroBatiment}\";\"{adresseLocale}\";\"{cpLocal}\";{villeLocale};\"{adressePrincipale}\";\"{cpPrincipal}\";\"{villePrincipale}\";\"{adresseSecondaire}\";\"{cpSecondaire}\";\"{villeSecondaire}\"");
|
sb.AppendLine($"\"{civilite}\";\"{nom}\";\"{nomNaissance}\";\"{prenom}\";\"{profession}\";\"{typeResidence}\";\"{mail}\";\"{tel}\";\"{telPort}\";\"{quartier}\";\"{batiment}\";\"{numeroBatiment}\";\"{adresseLocale}\";\"{cpLocal}\";{villeLocale};\"{adressePrincipale}\";\"{cpPrincipal}\";\"{villePrincipale}\";\"{adresseSecondaire}\";\"{cpSecondaire}\";\"{villeSecondaire}\"");
|
||||||
|
|
||||||
File.WriteAllText(csvPath, sb.ToString(), Encoding.GetEncoding("ISO-8859-1"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(csvPath, sb.ToString(), Encoding.GetEncoding("ISO-8859-1"));
|
||||||
|
|
||||||
OpenFileDialog ofd = new OpenFileDialog();
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
ofd.Filter = "Document World|*.doc;*.docx;*.dotx|Tous les ficiers|*.*";
|
ofd.Filter = "Document World|*.doc;*.docx;*.dotx|Tous les ficiers|*.*";
|
||||||
|
|
||||||
@ -276,10 +276,56 @@ namespace Hermes {
|
|||||||
|
|
||||||
private void Importer_Click(object sender, RoutedEventArgs e) {
|
private void Importer_Click(object sender, RoutedEventArgs e) {
|
||||||
OpenFileDialog ofd = new OpenFileDialog();
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
ofd.Filter = "Classeur Excel|*.xls;*.xlsx;*.xlsm|Tous les ficiers|*.*";
|
ofd.Filter = "Fichiers de données|*.xls;*.xlsx;*.xlsm;*.csv";
|
||||||
if(ofd.ShowDialog() == true) {
|
if(ofd.ShowDialog() == true) {
|
||||||
ImportWindow importWindow = new ImportWindow(this, ofd.FileName);
|
if(Path.GetExtension(ofd.FileName).ToLower().Equals(".csv")) {
|
||||||
importWindow.ShowDialog();
|
try {
|
||||||
|
StreamReader reader = File.OpenText(ofd.FileName);
|
||||||
|
string csvHeader = reader.ReadLine();
|
||||||
|
if(csvHeader == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string[] fields = CitoyensSerializer.ParseHeader(csvHeader);
|
||||||
|
CitoyensSerializer serializer = new CitoyensSerializer(fields);
|
||||||
|
while(!reader.EndOfStream) {
|
||||||
|
string line = reader.ReadLine();
|
||||||
|
Citoyen citoyen = serializer.Deserialize(line);
|
||||||
|
if(citoyen != null) {
|
||||||
|
dbContext.CitoyenSet.Add(citoyen);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(Exception ex) {
|
||||||
|
MessageBox.Show("Erreur lors de l'import des données", "Importer", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ImportWindow importWindow = new ImportWindow(this, ofd.FileName);
|
||||||
|
importWindow.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Exporter_Click(object sender, RoutedEventArgs e) {
|
||||||
|
if(dgCitoyens.SelectedItems.Count == 0) {
|
||||||
|
MessageBox.Show("Aucun citoyen sélectionné.", "Exporter", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveFileDialog sfd = new SaveFileDialog();
|
||||||
|
sfd.Filter = "Fichier CSV|*.csv";
|
||||||
|
sfd.OverwritePrompt = true;
|
||||||
|
if(sfd.ShowDialog() == true) {
|
||||||
|
try {
|
||||||
|
StreamWriter s = File.CreateText(sfd.FileName);
|
||||||
|
CitoyensSerializer serializer = new CitoyensSerializer();
|
||||||
|
s.WriteLine(serializer.GetCsvHeader());
|
||||||
|
foreach(Citoyen citoyen in dgCitoyens.SelectedItems) {
|
||||||
|
s.WriteLine(serializer.Serialize(citoyen));
|
||||||
|
}
|
||||||
|
s.Close();
|
||||||
|
} catch(Exception) {
|
||||||
|
MessageBox.Show("Erreur lors de l'export des données", "Exporter", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,6 @@ using System.Windows;
|
|||||||
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
||||||
// en utilisant '*', comme indiqué ci-dessous :
|
// en utilisant '*', comme indiqué ci-dessous :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.9.2.0")]
|
[assembly: AssemblyVersion("0.9.3.0")]
|
||||||
[assembly: AssemblyFileVersion("0.9.2.0")]
|
[assembly: AssemblyFileVersion("0.9.3.0")]
|
||||||
[assembly: NeutralResourcesLanguage("fr-FR")]
|
[assembly: NeutralResourcesLanguage("fr-FR")]
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 128 KiB |
Loading…
x
Reference in New Issue
Block a user