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" | ||||
|         "ProductName" = "8:Hermes" | ||||
|         "ProductCode" = "8:{2F4EE848-55DE-4984-B2BF-B6CC88401417}" | ||||
|         "PackageCode" = "8:{251B34BB-BC8A-4537-B4CA-14054A145302}" | ||||
|         "ProductCode" = "8:{34F15BE4-83E0-406C-AB16-5CCB92F214C7}" | ||||
|         "PackageCode" = "8:{A3A58C60-1261-4F23-91A2-F2308E51DDAE}" | ||||
|         "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.3" | ||||
|         "ProductVersion" = "8:0.9.4" | ||||
|         "Manufacturer" = "8:Aztrom" | ||||
|         "ARPHELPTELEPHONE" = "8:" | ||||
|         "ARPHELPLINK" = "8:" | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
|             <RowDefinition Height="20"/> | ||||
|             <RowDefinition Height="90"/> | ||||
|             <RowDefinition Height="*"/> | ||||
|             <RowDefinition Height="20"/> | ||||
|         </Grid.RowDefinitions> | ||||
|         <Menu Grid.Row="0" Background="White"> | ||||
|             <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="*"/> | ||||
|             </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> | ||||
|  | ||||
| @ -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}\""); | ||||
|                     } | ||||
|  | ||||
|                     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(); | ||||
|                     ofd.Filter = "Document World|*.doc;*.docx;*.dotx|Tous les ficiers|*.*"; | ||||
| @ -276,11 +281,14 @@ namespace Hermes { | ||||
|  | ||||
|         private void Importer_Click(object sender, RoutedEventArgs e) { | ||||
|             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(Path.GetExtension(ofd.FileName).ToLower().Equals(".csv")) { | ||||
|                     StreamReader reader = null; | ||||
|                     Cursor previousCursor = Mouse.OverrideCursor; | ||||
|                     Mouse.OverrideCursor = Cursors.Wait; | ||||
|                     try { | ||||
|                         StreamReader reader = File.OpenText(ofd.FileName); | ||||
|                         reader = File.OpenText(ofd.FileName); | ||||
|                         string csvHeader = reader.ReadLine(); | ||||
|                         if(csvHeader == null) { | ||||
|                             return; | ||||
| @ -292,11 +300,20 @@ namespace Hermes { | ||||
|                             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); | ||||
|                         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); | ||||
| @ -315,16 +332,27 @@ namespace Hermes { | ||||
|             sfd.Filter = "Fichier CSV|*.csv"; | ||||
|             sfd.OverwritePrompt = true; | ||||
|             if(sfd.ShowDialog() == true) { | ||||
|                 StreamWriter s = null; | ||||
|                 Cursor previousCursor = Mouse.OverrideCursor; | ||||
|                 Mouse.OverrideCursor = Cursors.Wait; | ||||
|                 try { | ||||
|                     StreamWriter s = File.CreateText(sfd.FileName); | ||||
|                     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(); | ||||
|                 } 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 | ||||
| // en utilisant '*', comme indiqué ci-dessous : | ||||
| // [assembly: AssemblyVersion("1.0.*")] | ||||
| [assembly: AssemblyVersion("0.9.3.0")] | ||||
| [assembly: AssemblyFileVersion("0.9.3.0")] | ||||
| [assembly: AssemblyVersion("0.9.4.0")] | ||||
| [assembly: AssemblyFileVersion("0.9.4.0")] | ||||
| [assembly: NeutralResourcesLanguage("fr-FR")] | ||||
|  | ||||
| @ -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,6 +102,7 @@ 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); | ||||
|  | ||||
|                     try { | ||||
|                         HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(query); | ||||
|                         req.Method = "POST"; | ||||
|                         req.ContentType = "application/json"; | ||||
| @ -113,7 +117,6 @@ namespace Hermes { | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                     try { | ||||
|                         HttpWebResponse resp = (HttpWebResponse) req.GetResponse(); | ||||
|                         using(var stream = resp.GetResponseStream()) { | ||||
|                             var reader = new StreamReader(stream); | ||||
| @ -134,6 +137,10 @@ namespace Hermes { | ||||
|                             String result = reader.ReadToEnd().Trim(); | ||||
|                             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; | ||||
|             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); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user