Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
68245f71d7 | |||
6e097ba621 | |||
e521a17d65 | |||
9055f65471 | |||
d51eb5f0d2 | |||
99114085d0 | |||
b6882f0088 | |||
4dff0306c3 | |||
b456708d48 | |||
e81b0b000a |
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>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<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>
|
||||
</Reference>
|
||||
@ -107,6 +108,7 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="CitoyensSerializer.cs" />
|
||||
<Compile Include="Converter\NegateBoolean.cs" />
|
||||
<Compile Include="ImportWindow.xaml.cs">
|
||||
<DependentUpon>ImportWindow.xaml</DependentUpon>
|
||||
@ -228,6 +230,40 @@
|
||||
<ItemGroup>
|
||||
<SplashScreen Include="hermes_splash.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="doc\img\main.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="doc\img\add.png" />
|
||||
<Resource Include="doc\img\first_launch_1.png" />
|
||||
<Resource Include="doc\img\first_launch_2.png" />
|
||||
<Resource Include="doc\img\list_1.png" />
|
||||
<Resource Include="doc\img\list_2.png" />
|
||||
<Resource Include="doc\img\menu_display.png" />
|
||||
<Resource Include="doc\img\menu_edit.png" />
|
||||
<Resource Include="doc\img\menu_file.png" />
|
||||
<Resource Include="doc\img\menu_tools.png" />
|
||||
<Resource Include="doc\img\smartscreen_1.png" />
|
||||
<Resource Include="doc\img\smartscreen_2.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="doc\img\publi_1.png" />
|
||||
<Resource Include="doc\img\publi_2.png" />
|
||||
<Resource Include="doc\img\publi_3.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="doc\img\ovh_1.png" />
|
||||
<Resource Include="doc\img\ovh_2.png" />
|
||||
<Resource Include="doc\img\ovh_3.png" />
|
||||
<Resource Include="doc\img\ovh_4.png" />
|
||||
<Resource Include="doc\img\ovh_5.png" />
|
||||
<Resource Include="doc\img\ovh_6.png" />
|
||||
<Resource Include="doc\img\ovh_7.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="doc\img\sms_1.png" />
|
||||
<Resource Include="doc\img\sms_2.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
|
@ -812,15 +812,15 @@
|
||||
{
|
||||
"Name" = "8:Microsoft Visual Studio"
|
||||
"ProductName" = "8:Hermes"
|
||||
"ProductCode" = "8:{CE173D1C-E589-4D0D-8443-272C16A0ECB7}"
|
||||
"PackageCode" = "8:{9F1DEC0D-1EB8-4407-884C-414E205F16ED}"
|
||||
"ProductCode" = "8:{3B44B09A-1491-4CE0-A6A5-ABD54F4C14F8}"
|
||||
"PackageCode" = "8:{618674BD-7E73-4707-ABF3-4183A348D565}"
|
||||
"UpgradeCode" = "8:{A8FB75F3-57A5-4B7D-A0AE-9E87F69529B0}"
|
||||
"AspNetVersion" = "8:2.0.50727.0"
|
||||
"RestartWWWService" = "11:FALSE"
|
||||
"RemovePreviousVersions" = "11:TRUE"
|
||||
"DetectNewerInstalledVersion" = "11:TRUE"
|
||||
"InstallAllUsers" = "11:FALSE"
|
||||
"ProductVersion" = "8:0.9.2"
|
||||
"ProductVersion" = "8:1.0.0"
|
||||
"Manufacturer" = "8:Aztrom"
|
||||
"ARPHELPTELEPHONE" = "8:"
|
||||
"ARPHELPLINK" = "8:"
|
||||
|
@ -17,9 +17,11 @@
|
||||
<RowDefinition Height="20"/>
|
||||
<RowDefinition Height="90"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="20"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Menu Grid.Row="0" Background="White">
|
||||
<MenuItem Header="Fichier">
|
||||
<MenuItem Header="Exporter" Click="Exporter_Click"/>
|
||||
<MenuItem Header="Importer" Click="Importer_Click" />
|
||||
<MenuItem Header="Quitter" Click="Quitter_Click"/>
|
||||
</MenuItem>
|
||||
@ -124,5 +126,21 @@
|
||||
<DataGridTextColumn Header="Date de modification" Visibility="{Binding Source={x:Reference dateModificationViewCheckBox}, Path=IsChecked, Converter={StaticResource Bool2VisibilityConv}}" Binding="{Binding DateModification, StringFormat='dd/MM/yyyy HH:mm'}" Width="*"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<StatusBar Grid.Row="3">
|
||||
<StatusBarItem Margin="0,0,30,0">
|
||||
<TextBlock>
|
||||
<Run Text="Affichés : "/>
|
||||
<Run Text="{Binding ElementName=dgCitoyens, Path=Items.Count, Mode=OneWay}"/>
|
||||
<Run Text=" éléments"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
<StatusBarItem>
|
||||
<TextBlock>
|
||||
<Run Text="Sélectionnés : "/>
|
||||
<Run Text="{Binding ElementName=dgCitoyens, Path=SelectedItems.Count, Mode=OneWay}"/>
|
||||
<Run Text=" éléments"/>
|
||||
</TextBlock>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -200,7 +200,7 @@ namespace Hermes {
|
||||
}
|
||||
if(mails.Count > 0) {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -255,8 +255,13 @@ namespace Hermes {
|
||||
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}\"");
|
||||
}
|
||||
|
||||
try {
|
||||
File.WriteAllText(csvPath, sb.ToString(), Encoding.GetEncoding("ISO-8859-1"));
|
||||
} catch(Exception) {
|
||||
MessageBox.Show("Erreur lors de la préparation des données pour le publipostage.", "Publipostage", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
@ -276,10 +281,79 @@ namespace Hermes {
|
||||
|
||||
private void Importer_Click(object sender, RoutedEventArgs e) {
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = "Classeur Excel|*.xls;*.xlsx;*.xlsm|Tous les ficiers|*.*";
|
||||
ofd.Filter = "Fichiers de données|*.csv|Tous les fichiers|*.*";
|
||||
if(ofd.ShowDialog() == true) {
|
||||
ImportWindow importWindow = new ImportWindow(this, ofd.FileName);
|
||||
importWindow.ShowDialog();
|
||||
if(Path.GetExtension(ofd.FileName).ToLower().Equals(".csv")) {
|
||||
StreamReader reader = null;
|
||||
Cursor previousCursor = Mouse.OverrideCursor;
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
if(ex is IOException || ex is UnauthorizedAccessException) {
|
||||
MessageBox.Show("Impossible d'ouvrir le fichier. Il est possible qu'il soit déjà utilisé par un autre programme ou que le chemin d'accès soit incorrect.", "Importer", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
MessageBox.Show("Erreur lors de l'import des données.", "Importer", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
} finally {
|
||||
Mouse.OverrideCursor = previousCursor;
|
||||
if(reader != null) {
|
||||
reader.Close();
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
} 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) {
|
||||
StreamWriter s = null;
|
||||
Cursor previousCursor = Mouse.OverrideCursor;
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
try {
|
||||
s = File.CreateText(sfd.FileName);
|
||||
CitoyensSerializer serializer = new CitoyensSerializer();
|
||||
s.WriteLine(serializer.GetCsvHeader());
|
||||
foreach(Citoyen citoyen in dgCitoyens.SelectedItems) {
|
||||
s.WriteLine(serializer.Serialize(citoyen));
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
if(ex is IOException || ex is UnauthorizedAccessException) {
|
||||
MessageBox.Show("Impossible d'ouvrir ou de créer le fichier. Il est possible qu'il soit déjà utilisé par un autre programme ou que le chemin d'accès soit incorrect.", "Importer", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
MessageBox.Show("Erreur lors de l'export des données.", "Exporter", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
} finally {
|
||||
Mouse.OverrideCursor = previousCursor;
|
||||
if(s != null) {
|
||||
s.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
// en utilisant '*', comme indiqué ci-dessous :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.9.2.0")]
|
||||
[assembly: AssemblyFileVersion("0.9.2.0")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: NeutralResourcesLanguage("fr-FR")]
|
||||
|
@ -26,7 +26,7 @@
|
||||
<GridViewColumn Header="Nom" DisplayMemberBinding="{Binding Nom}" Width="120"/>
|
||||
<GridViewColumn Header="Prénom" DisplayMemberBinding="{Binding Prenom}" Width="120"/>
|
||||
<GridViewColumn Header="Mobile" DisplayMemberBinding="{Binding Mobile}" Width="120"/>
|
||||
<GridViewColumn Header="Statut de l'envoi" DisplayMemberBinding="{Binding Status}" Width="290"/>
|
||||
<GridViewColumn Header="Statut de l'envoi" DisplayMemberBinding="{Binding Status}" Width="280"/>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
|
@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Hermes {
|
||||
public partial class SmsWindow : Window {
|
||||
@ -81,6 +82,8 @@ namespace Hermes {
|
||||
annulerButton.IsEnabled = false;
|
||||
messageTextBox.IsEnabled = false;
|
||||
sending = true;
|
||||
Cursor previousCursor = Mouse.OverrideCursor;
|
||||
Mouse.OverrideCursor = Cursors.Wait;
|
||||
|
||||
|
||||
string query = $"https://eu.api.ovh.com/1.0/sms/{pref.ovhSmsServiceName}/jobs";
|
||||
@ -99,21 +102,21 @@ namespace Hermes {
|
||||
string ts = ((Int32) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString();
|
||||
string signature = "$1$" + HashSHA1(pref.ovhSmsApplicationSecret + "+" + pref.ovhSmsConsumerKey + "+" + "POST" + "+" + query + "+" + bodyStr + "+" + ts);
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(query);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/json";
|
||||
req.Headers.Add("X-Ovh-Application:" + pref.ovhSmsApplicationKey);
|
||||
req.Headers.Add("X-Ovh-Consumer:" + pref.ovhSmsConsumerKey);
|
||||
req.Headers.Add("X-Ovh-Signature:" + signature);
|
||||
req.Headers.Add("X-Ovh-Timestamp:" + ts);
|
||||
|
||||
using(System.IO.Stream s = req.GetRequestStream()) {
|
||||
using(System.IO.StreamWriter sw = new System.IO.StreamWriter(s)) {
|
||||
sw.Write(bodyStr);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(query);
|
||||
req.Method = "POST";
|
||||
req.ContentType = "application/json";
|
||||
req.Headers.Add("X-Ovh-Application:" + pref.ovhSmsApplicationKey);
|
||||
req.Headers.Add("X-Ovh-Consumer:" + pref.ovhSmsConsumerKey);
|
||||
req.Headers.Add("X-Ovh-Signature:" + signature);
|
||||
req.Headers.Add("X-Ovh-Timestamp:" + ts);
|
||||
|
||||
using(System.IO.Stream s = req.GetRequestStream()) {
|
||||
using(System.IO.StreamWriter sw = new System.IO.StreamWriter(s)) {
|
||||
sw.Write(bodyStr);
|
||||
}
|
||||
}
|
||||
|
||||
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
|
||||
using(var stream = resp.GetResponseStream()) {
|
||||
var reader = new StreamReader(stream);
|
||||
@ -129,11 +132,24 @@ namespace Hermes {
|
||||
} catch(WebException ex) {
|
||||
error = true;
|
||||
WebResponse resp = ex.Response;
|
||||
using(var stream = resp.GetResponseStream()) {
|
||||
var reader = new StreamReader(stream);
|
||||
String result = reader.ReadToEnd().Trim();
|
||||
stat.Status = result;
|
||||
if(resp == null) {
|
||||
string errorMsg = ex.Message == null ? "" : ex.Message;
|
||||
stat.Status = $"Erreur de transmission : {errorMsg}";
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
using(var stream = resp.GetResponseStream()) {
|
||||
StreamReader reader = new StreamReader(stream);
|
||||
String result = reader.ReadToEnd().Trim();
|
||||
stat.Status = result;
|
||||
}
|
||||
} catch(Exception) {
|
||||
stat.Status = $"Erreur de transmission";
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
error = true;
|
||||
string errorMsg = ex.Message == null ? "" : ex.Message;
|
||||
stat.Status = $"Erreur de transmission : {errorMsg}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,9 +158,10 @@ namespace Hermes {
|
||||
annulerButton.IsEnabled = true;
|
||||
messageTextBox.IsEnabled = true;
|
||||
sending = false;
|
||||
Mouse.OverrideCursor = previousCursor;
|
||||
|
||||
if(error) {
|
||||
MessageBox.Show("Plusieurs envois se sont mal déroulés. Vérifiez la validité des numéros de téléphone.", "Envoi de SMS", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
MessageBox.Show("Plusieurs envois se sont mal déroulés. Certains numéros de téléphone ne sont peut-être pas valides.", "Envoi de SMS", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
doc/img/add.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
doc/img/first_launch_1.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
doc/img/first_launch_2.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
doc/img/list_1.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
doc/img/list_2.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
doc/img/main.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
doc/img/menu_display.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
doc/img/menu_edit.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
doc/img/menu_file.png
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
doc/img/menu_tools.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
doc/img/ovh_1.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
doc/img/ovh_2.png
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
doc/img/ovh_3.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
doc/img/ovh_4.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
doc/img/ovh_5.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
doc/img/ovh_6.png
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
doc/img/ovh_7.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
doc/img/publi_1.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
doc/img/publi_2.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
doc/img/publi_3.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
doc/img/smartscreen_1.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
doc/img/smartscreen_2.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
doc/img/sms_1.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
doc/img/sms_2.png
Normal file
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 68 KiB |