Configuration de l'installateur + Amélioration envoi de mail et publipostage et fenêtre de configuration
This commit is contained in:
@@ -5,6 +5,9 @@ using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Hermes {
|
||||
public partial class MainWindow : Window {
|
||||
@@ -29,9 +32,16 @@ namespace Hermes {
|
||||
dbContext.Preferences.Load();
|
||||
citoyenCollectionViewSource = (CollectionViewSource) this.FindResource("citoyenCollectionViewSource");
|
||||
citoyenCollectionViewSource.Source = dbContext.CitoyenSet.Local;
|
||||
|
||||
if(dbContext.Preferences.Local.Count == 0) {
|
||||
MessageBox.Show("Il s'agit du premier lancement de Hermes. Veuillez renseigner les informations sur votre commune.", "Premier lancement", MessageBoxButton.OK, MessageBoxImage.None);
|
||||
preferencesModal.LoadPreferences();
|
||||
preferencesModal.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void Options_Click(object sender, RoutedEventArgs e) {
|
||||
preferencesModal.LoadPreferences();
|
||||
preferencesModal.ShowDialog();
|
||||
}
|
||||
|
||||
@@ -58,6 +68,82 @@ namespace Hermes {
|
||||
}
|
||||
}
|
||||
|
||||
private void Courriel_Click(object sender, RoutedEventArgs e) {
|
||||
if(dgCitoyens.SelectedItems.Count > 0) {
|
||||
MessageBoxResult result = MessageBox.Show("Voulez-vous envoyer un courriel à ces citoyens ?", "Envoi de courriel", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if(result == MessageBoxResult.Yes) {
|
||||
List<string> mails = new List<string>();
|
||||
foreach(Citoyen citoyen in dgCitoyens.SelectedItems) {
|
||||
if(!String.IsNullOrWhiteSpace(citoyen.Mail)) {
|
||||
mails.Add(citoyen.Mail);
|
||||
}
|
||||
}
|
||||
if(mails.Count > 0) {
|
||||
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
|
||||
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
|
||||
foreach(string mail in mails) {
|
||||
Microsoft.Office.Interop.Outlook.Recipient rcp = mailItem.Recipients.Add(mail);
|
||||
rcp.Type = (int) Microsoft.Office.Interop.Outlook.OlMailRecipientType.olBCC;
|
||||
}
|
||||
mailItem.Recipients.ResolveAll();
|
||||
MessageBox.Show("Assurez-vous que Microsoft OutLook soit démarré avant de continuer", "Envoi de courriel", MessageBoxButton.OK, MessageBoxImage.None);
|
||||
mailItem.Display(true);
|
||||
} else {
|
||||
MessageBox.Show("Aucun des citoyens sélectionnés ne disposent d'une adresse E-Mail", "Envoi de courriel", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MessageBox.Show("Aucun citoyen sélectionné", "Suppression", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||
}
|
||||
}
|
||||
|
||||
private void Publipostage_Click(object sender, RoutedEventArgs e) {
|
||||
if(dgCitoyens.SelectedItems.Count > 0) {
|
||||
MessageBoxResult result = MessageBox.Show("Voulez-vous réaliser une tâche de publipostage pour ces citoyens ?", "Publipostage", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if(result == MessageBoxResult.Yes) {
|
||||
string csvPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hermes_tmp_datasource.csv");
|
||||
string csvHeader = "\"Civilité\";\"Nom\";\"Nom de naissance\";\"Prénom\";\"Profession\";\"Type de résidence\";\"E-Mail\";\"Téléphone\";\"Mobile\";\"Quartier\";\"Bâtiment\";\"Adresse principale\";\"Code postal principal\";\"Ville principale\";\"Adresse secondaire\";\"Code postal secondaire\";\"Ville secondaire\"";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(csvHeader);
|
||||
foreach(Citoyen citoyen in dgCitoyens.SelectedItems) {
|
||||
string civilite = citoyen.Civilite == null ? "" : citoyen.Civilite;
|
||||
string nom = citoyen.Nom == null ? "" : citoyen.Nom;
|
||||
string nomNaissance = citoyen.NomNaissance == null ? "" : citoyen.NomNaissance;
|
||||
string prenom = citoyen.Prenom == null ? "" : citoyen.Prenom;
|
||||
string profession = citoyen.Profession == null ? "" : citoyen.Profession;
|
||||
string typeResidence = citoyen.TypeResidenceLabel == null ? "" : citoyen.TypeResidenceLabel;
|
||||
string mail = citoyen.Mail == null ? "" : citoyen.Mail;
|
||||
string tel = citoyen.Tel == null ? "" : citoyen.Tel;
|
||||
string telPort = citoyen.TelPort == null ? "" : citoyen.TelPort;
|
||||
string quartier = citoyen.Quartier == null ? "" : citoyen.Quartier;
|
||||
string batiment = citoyen.AdresseBatiment == null ? "" : citoyen.AdresseBatiment;
|
||||
string adressePrincipale = citoyen.AdressePrincipale == null ? "" : citoyen.AdressePrincipale;
|
||||
string cpPrincipal = citoyen.AdressePrincipaleCP == null ? "" : citoyen.AdressePrincipaleCP;
|
||||
string villePrincipale = citoyen.AdressePrincipaleVille == null ? "" : citoyen.AdressePrincipaleVille;
|
||||
string adresseSecondaire = citoyen.AdresseSecondaire == null ? "" : citoyen.AdresseSecondaire;
|
||||
string cpSecondaire = citoyen.AdresseSecondaireCP == null ? "" : citoyen.AdresseSecondaireCP;
|
||||
string villeSecondaire = citoyen.AdresseSecondaireVille == null ? "" : citoyen.AdresseSecondaireVille;
|
||||
|
||||
sb.AppendLine($"\"{civilite}\";\"{nom}\";\"{nomNaissance}\";\"{prenom}\";\"{profession}\";\"{typeResidence}\";\"{mail}\";\"{tel}\";\"{telPort}\";\"{quartier}\";\"{batiment}\";\"{adressePrincipale}\";\"{cpPrincipal}\";\"{villePrincipale}\";\"{adresseSecondaire}\";\"{cpSecondaire}\";\"{villeSecondaire}\"");
|
||||
|
||||
File.WriteAllText(csvPath, sb.ToString(), Encoding.GetEncoding("ISO-8859-1"));
|
||||
}
|
||||
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
ofd.Filter = "Document World|*.doc;*.docx;*.dotx|Tous les ficiers|*.*";
|
||||
|
||||
if(ofd.ShowDialog() == true) {
|
||||
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
|
||||
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ofd.FileName);
|
||||
doc.MailMerge.OpenDataSource(csvPath, false, false, true);
|
||||
app.Visible = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MessageBox.Show("Aucun citoyen sélectionné", "Publipostage", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||
}
|
||||
}
|
||||
|
||||
private void DgCitoyen_DoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
if(dgCitoyens.SelectedItem != null) {
|
||||
citoyenModal.EnableEditMode((Citoyen) dgCitoyens.SelectedItem);
|
||||
|
||||
Reference in New Issue
Block a user