Amélioration de la gestion d'erreur + Ajout du nombre d'éléments affichés et sélectionnés en ba de la fenêtre principale
This commit is contained in:
		@ -812,15 +812,15 @@
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
        "Name" = "8:Microsoft Visual Studio"
 | 
					        "Name" = "8:Microsoft Visual Studio"
 | 
				
			||||||
        "ProductName" = "8:Hermes"
 | 
					        "ProductName" = "8:Hermes"
 | 
				
			||||||
        "ProductCode" = "8:{2F4EE848-55DE-4984-B2BF-B6CC88401417}"
 | 
					        "ProductCode" = "8:{34F15BE4-83E0-406C-AB16-5CCB92F214C7}"
 | 
				
			||||||
        "PackageCode" = "8:{251B34BB-BC8A-4537-B4CA-14054A145302}"
 | 
					        "PackageCode" = "8:{A3A58C60-1261-4F23-91A2-F2308E51DDAE}"
 | 
				
			||||||
        "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.3"
 | 
					        "ProductVersion" = "8:0.9.4"
 | 
				
			||||||
        "Manufacturer" = "8:Aztrom"
 | 
					        "Manufacturer" = "8:Aztrom"
 | 
				
			||||||
        "ARPHELPTELEPHONE" = "8:"
 | 
					        "ARPHELPTELEPHONE" = "8:"
 | 
				
			||||||
        "ARPHELPLINK" = "8:"
 | 
					        "ARPHELPLINK" = "8:"
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,7 @@
 | 
				
			|||||||
            <RowDefinition Height="20"/>
 | 
					            <RowDefinition Height="20"/>
 | 
				
			||||||
            <RowDefinition Height="90"/>
 | 
					            <RowDefinition Height="90"/>
 | 
				
			||||||
            <RowDefinition Height="*"/>
 | 
					            <RowDefinition Height="*"/>
 | 
				
			||||||
 | 
					            <RowDefinition Height="20"/>
 | 
				
			||||||
        </Grid.RowDefinitions>
 | 
					        </Grid.RowDefinitions>
 | 
				
			||||||
        <Menu Grid.Row="0" Background="White">
 | 
					        <Menu Grid.Row="0" Background="White">
 | 
				
			||||||
            <MenuItem Header="Fichier">
 | 
					            <MenuItem Header="Fichier">
 | 
				
			||||||
@ -125,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="*"/>
 | 
					                <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.Columns>
 | 
				
			||||||
        </DataGrid>
 | 
					        </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>
 | 
					    </Grid>
 | 
				
			||||||
</Window>
 | 
					</Window>
 | 
				
			||||||
 | 
				
			|||||||
@ -257,7 +257,12 @@ namespace Hermes {
 | 
				
			|||||||
                        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"));
 | 
					                    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();
 | 
					                    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,11 +281,14 @@ 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 = "Fichiers de données|*.xls;*.xlsx;*.xlsm;*.csv";
 | 
					            ofd.Filter = "Fichiers de données|*.csv|Tous les fichiers|*.*";
 | 
				
			||||||
            if(ofd.ShowDialog() == true) {
 | 
					            if(ofd.ShowDialog() == true) {
 | 
				
			||||||
                if(Path.GetExtension(ofd.FileName).ToLower().Equals(".csv")) {
 | 
					                if(Path.GetExtension(ofd.FileName).ToLower().Equals(".csv")) {
 | 
				
			||||||
 | 
					                    StreamReader reader = null;
 | 
				
			||||||
 | 
					                    Cursor previousCursor = Mouse.OverrideCursor;
 | 
				
			||||||
 | 
					                    Mouse.OverrideCursor = Cursors.Wait;
 | 
				
			||||||
                    try {
 | 
					                    try {
 | 
				
			||||||
                        StreamReader reader = File.OpenText(ofd.FileName);
 | 
					                        reader = File.OpenText(ofd.FileName);
 | 
				
			||||||
                        string csvHeader = reader.ReadLine();
 | 
					                        string csvHeader = reader.ReadLine();
 | 
				
			||||||
                        if(csvHeader == null) {
 | 
					                        if(csvHeader == null) {
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
@ -292,11 +300,20 @@ namespace Hermes {
 | 
				
			|||||||
                            Citoyen citoyen = serializer.Deserialize(line);
 | 
					                            Citoyen citoyen = serializer.Deserialize(line);
 | 
				
			||||||
                            if(citoyen != null) {
 | 
					                            if(citoyen != null) {
 | 
				
			||||||
                                dbContext.CitoyenSet.Add(citoyen);
 | 
					                                dbContext.CitoyenSet.Add(citoyen);
 | 
				
			||||||
                                dbContext.SaveChanges();
 | 
					 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } catch(Exception ex) {
 | 
					                    } catch(Exception ex) {
 | 
				
			||||||
                        MessageBox.Show("Erreur lors de l'import des données", "Importer", MessageBoxButton.OK, MessageBoxImage.Error);
 | 
					                        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 {
 | 
					                } else {
 | 
				
			||||||
                    ImportWindow importWindow = new ImportWindow(this, ofd.FileName);
 | 
					                    ImportWindow importWindow = new ImportWindow(this, ofd.FileName);
 | 
				
			||||||
@ -315,16 +332,27 @@ namespace Hermes {
 | 
				
			|||||||
            sfd.Filter = "Fichier CSV|*.csv";
 | 
					            sfd.Filter = "Fichier CSV|*.csv";
 | 
				
			||||||
            sfd.OverwritePrompt = true;
 | 
					            sfd.OverwritePrompt = true;
 | 
				
			||||||
            if(sfd.ShowDialog() == true) {
 | 
					            if(sfd.ShowDialog() == true) {
 | 
				
			||||||
 | 
					                StreamWriter s = null;
 | 
				
			||||||
 | 
					                Cursor previousCursor = Mouse.OverrideCursor;
 | 
				
			||||||
 | 
					                Mouse.OverrideCursor = Cursors.Wait;
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    StreamWriter s = File.CreateText(sfd.FileName);
 | 
					                    s = File.CreateText(sfd.FileName);
 | 
				
			||||||
                    CitoyensSerializer serializer = new CitoyensSerializer();
 | 
					                    CitoyensSerializer serializer = new CitoyensSerializer();
 | 
				
			||||||
                    s.WriteLine(serializer.GetCsvHeader());
 | 
					                    s.WriteLine(serializer.GetCsvHeader());
 | 
				
			||||||
                    foreach(Citoyen citoyen in dgCitoyens.SelectedItems) {
 | 
					                    foreach(Citoyen citoyen in dgCitoyens.SelectedItems) {
 | 
				
			||||||
                        s.WriteLine(serializer.Serialize(citoyen));
 | 
					                        s.WriteLine(serializer.Serialize(citoyen));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    s.Close();
 | 
					                } catch(Exception ex) {
 | 
				
			||||||
                } catch(Exception) {
 | 
					                    if(ex is IOException || ex is UnauthorizedAccessException) {
 | 
				
			||||||
                    MessageBox.Show("Erreur lors de l'export des données", "Exporter", MessageBoxButton.OK, MessageBoxImage.Error);
 | 
					                        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
 | 
					// 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.3.0")]
 | 
					[assembly: AssemblyVersion("0.9.4.0")]
 | 
				
			||||||
[assembly: AssemblyFileVersion("0.9.3.0")]
 | 
					[assembly: AssemblyFileVersion("0.9.4.0")]
 | 
				
			||||||
[assembly: NeutralResourcesLanguage("fr-FR")]
 | 
					[assembly: NeutralResourcesLanguage("fr-FR")]
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ using System.Text;
 | 
				
			|||||||
using System.Text.RegularExpressions;
 | 
					using System.Text.RegularExpressions;
 | 
				
			||||||
using System.Windows;
 | 
					using System.Windows;
 | 
				
			||||||
using System.Windows.Documents;
 | 
					using System.Windows.Documents;
 | 
				
			||||||
 | 
					using System.Windows.Input;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Hermes {
 | 
					namespace Hermes {
 | 
				
			||||||
    public partial class SmsWindow : Window {
 | 
					    public partial class SmsWindow : Window {
 | 
				
			||||||
@ -81,6 +82,8 @@ namespace Hermes {
 | 
				
			|||||||
            annulerButton.IsEnabled = false;
 | 
					            annulerButton.IsEnabled = false;
 | 
				
			||||||
            messageTextBox.IsEnabled = false;
 | 
					            messageTextBox.IsEnabled = false;
 | 
				
			||||||
            sending = true;
 | 
					            sending = true;
 | 
				
			||||||
 | 
					            Cursor previousCursor = Mouse.OverrideCursor;
 | 
				
			||||||
 | 
					            Mouse.OverrideCursor = Cursors.Wait;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            string query = $"https://eu.api.ovh.com/1.0/sms/{pref.ovhSmsServiceName}/jobs";
 | 
					            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 ts = ((Int32) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString();
 | 
				
			||||||
                    string signature = "$1$" + HashSHA1(pref.ovhSmsApplicationSecret + "+" + pref.ovhSmsConsumerKey + "+" + "POST" + "+" + query + "+" + bodyStr + "+" + ts);
 | 
					                    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 {
 | 
					                    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();
 | 
					                        HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
 | 
				
			||||||
                        using(var stream = resp.GetResponseStream()) {
 | 
					                        using(var stream = resp.GetResponseStream()) {
 | 
				
			||||||
                            var reader = new StreamReader(stream);
 | 
					                            var reader = new StreamReader(stream);
 | 
				
			||||||
@ -134,6 +137,10 @@ namespace Hermes {
 | 
				
			|||||||
                            String result = reader.ReadToEnd().Trim();
 | 
					                            String result = reader.ReadToEnd().Trim();
 | 
				
			||||||
                            stat.Status = result;
 | 
					                            stat.Status = result;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					                    } catch(Exception ex) {
 | 
				
			||||||
 | 
					                        error = true;
 | 
				
			||||||
 | 
					                        string errorMsg = ex.Message == null ? "" : ex.Message;
 | 
				
			||||||
 | 
					                        stat.Status = $"Erreur de transmission : {errorMsg}";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -142,6 +149,7 @@ namespace Hermes {
 | 
				
			|||||||
            annulerButton.IsEnabled = true;
 | 
					            annulerButton.IsEnabled = true;
 | 
				
			||||||
            messageTextBox.IsEnabled = true;
 | 
					            messageTextBox.IsEnabled = true;
 | 
				
			||||||
            sending = false;
 | 
					            sending = false;
 | 
				
			||||||
 | 
					            Mouse.OverrideCursor = previousCursor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(error) {
 | 
					            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. Vérifiez la validité des numéros de téléphone.", "Envoi de SMS", MessageBoxButton.OK, MessageBoxImage.Error);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user