72 lines
3.1 KiB
C#
72 lines
3.1 KiB
C#
using Hermes.Model;
|
|
using System;
|
|
using System.Windows;
|
|
|
|
namespace Hermes {
|
|
public partial class PreferencesWindow : Window {
|
|
private ModelContext dbContext = null;
|
|
|
|
public PreferencesWindow(Window parent) {
|
|
InitializeComponent();
|
|
|
|
Owner = parent;
|
|
dbContext = ModelContext.Getinstance();
|
|
|
|
if(dbContext.Preferences.Local.Count > 0) {
|
|
Preferences pref = dbContext.Preferences.Local[0];
|
|
villeTextBox.Text = pref.Ville;
|
|
villeCPTextBox.Text = pref.VilleCP;
|
|
|
|
ovhSmsServiceNameTextBox.Text = pref.ovhSmsServiceName;
|
|
ovhSmsApplicationKeyTextBox.Text = pref.ovhSmsApplicationKey;
|
|
ovhSmsApplicationSecretTextBox.Text = pref.ovhSmsApplicationSecret;
|
|
ovhSmsConsumerKeyTextBox.Text = pref.ovhSmsConsumerKey;
|
|
}
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
|
if(dbContext.Preferences.Local.Count == 0) {
|
|
MessageBox.Show("La saisie d'information sur la commune est obligatoire.", "Saisie obligatoire", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
|
|
public void Enregistrer_Click(object sender, RoutedEventArgs e) {
|
|
if(String.IsNullOrWhiteSpace(villeCPTextBox.Text) || String.IsNullOrWhiteSpace(villeTextBox.Text)) {
|
|
MessageBox.Show("La saisie d'information sur la commune est obligatoire.", "Saisie obligatoire", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
if(dbContext.Preferences.Local.Count == 0) {
|
|
Preferences pref = new Preferences();
|
|
pref.Ville = villeTextBox.Text;
|
|
pref.VilleCP = villeCPTextBox.Text;
|
|
pref.ovhSmsServiceName = ovhSmsServiceNameTextBox.Text;
|
|
pref.ovhSmsApplicationKey = ovhSmsApplicationKeyTextBox.Text;
|
|
pref.ovhSmsApplicationSecret = ovhSmsApplicationSecretTextBox.Text;
|
|
pref.ovhSmsConsumerKey = ovhSmsConsumerKeyTextBox.Text;
|
|
dbContext.Preferences.Add(pref);
|
|
} else {
|
|
Preferences pref = dbContext.Preferences.Local[0];
|
|
pref.Ville = villeTextBox.Text;
|
|
pref.VilleCP = villeCPTextBox.Text;
|
|
pref.ovhSmsServiceName = ovhSmsServiceNameTextBox.Text;
|
|
pref.ovhSmsApplicationKey = ovhSmsApplicationKeyTextBox.Text;
|
|
pref.ovhSmsApplicationSecret = ovhSmsApplicationSecretTextBox.Text;
|
|
pref.ovhSmsConsumerKey = ovhSmsConsumerKeyTextBox.Text;
|
|
}
|
|
|
|
dbContext.SaveChanges();
|
|
Close();
|
|
}
|
|
|
|
public void Annuler_Click(object sender, RoutedEventArgs e) {
|
|
if(dbContext.Preferences.Local.Count == 0) {
|
|
MessageBox.Show("La saisie d'information sur la commune est obligatoire.", "Saisie obligatoire", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
Close();
|
|
}
|
|
}
|
|
}
|