Files
BeWoPlaner/BeWo/View/MessageDialog.xaml.cs

121 lines
3.7 KiB
C#
Raw Normal View History

2017-06-11 16:01:01 +02:00
using System;
using System.Windows;
using System.Windows.Controls;
2017-11-07 13:46:55 +01:00
using System.Windows.Documents;
using System.Windows.Input;
using System.Xaml;
using BeWo.ServiceProxy;
using BS.Shared;
using BS.Shared.Extensions;
using XamlReader = System.Windows.Markup.XamlReader;
2017-06-11 16:01:01 +02:00
namespace BeWo.View
{
public partial class MessageDialog
2017-06-11 16:01:01 +02:00
{
2017-11-07 13:46:55 +01:00
public MessageDialog()
2017-06-11 16:01:01 +02:00
{
InitializeComponent();
2017-11-07 13:46:55 +01:00
DataContext = this;
2020-09-15 13:23:34 +02:00
OkayButton.Visibility = Visibility.Collapsed;
2017-11-07 13:46:55 +01:00
}
public MessageDialog(Action pAfterPasswordConfirmationCallBack)
2017-11-07 13:46:55 +01:00
{
IsInConfirmationWithPasswordMode = true;
2017-11-07 13:46:55 +01:00
AfterPasswordConfirmationCallBack = pAfterPasswordConfirmationCallBack;
InitializeComponent();
DataContext = this;
OkayButton.IsDefault = true;
CountButton.IsDefault = false;
2017-11-07 13:46:55 +01:00
}
public Action AfterPasswordConfirmationCallBack { get; set; }
public bool IsInConfirmationWithPasswordMode { get; set; }
private ICommand _OpenBrowserCommand;
public ICommand OpenBrowserCommand => _OpenBrowserCommand ?? (_OpenBrowserCommand = new OpenBrowserCommandImpl());
2017-11-07 13:46:55 +01:00
public class OpenBrowserCommandImpl : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (parameter != null)
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(parameter.ToString()));
}
}
}
public void SetXaml(string xamlCode)
2017-11-07 13:46:55 +01:00
{
try
{
if(XamlReader.Parse(xamlCode) is UIElement element)
2017-11-07 13:46:55 +01:00
{
txtMessage.Visibility = Visibility.Collapsed;
rootGrid.Children.Add(element);
}
}
catch(Exception e)
2017-11-07 13:46:55 +01:00
{
//ignore
}
2017-06-11 16:01:01 +02:00
}
public string Message
2017-06-11 16:01:01 +02:00
{
get => txtMessage.Text;
set => txtMessage.Text = value;
2017-06-11 16:01:01 +02:00
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
//DialogResult = true;
2017-11-07 13:46:55 +01:00
Close();
}
private void OpenBrowserCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
if (e.OriginalSource is Hyperlink)
{
System.Diagnostics.Process.Start(
new System.Diagnostics.ProcessStartInfo((e.OriginalSource as Hyperlink).NavigateUri.ToString()));
}
}
private void OpenBrowserCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
e.Handled = true;
2017-06-11 16:01:01 +02:00
}
private void OkayButton_OnClick(object sender, RoutedEventArgs e)
{
ServiceFacade.DoUserServiceAsync(u => u.IsUserValid(BeWoApp.UserName, PasswordBox.Password, null), result =>
{
if(result == UserValidationResult.UserValid)
{
AfterPasswordConfirmationCallBack?.Invoke();
this.Dispatch(Close);
}
else
{
MessageBox.Show("Anmeldeinformationen nicht bekannt. Bitte überprüfen Sie den " + BS.Shared.Translation.Translator.Translate("Benutzernamen") + " und das Passwort!", "Fehler bei der Anmeldung", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}, true);
}
2017-06-11 16:01:01 +02:00
}
}