121 lines
3.7 KiB
C#
121 lines
3.7 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
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;
|
|
|
|
namespace BeWo.View
|
|
{
|
|
public partial class MessageDialog
|
|
{
|
|
public MessageDialog()
|
|
{
|
|
InitializeComponent();
|
|
DataContext = this;
|
|
|
|
OkayButton.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
public MessageDialog(Action pAfterPasswordConfirmationCallBack)
|
|
{
|
|
IsInConfirmationWithPasswordMode = true;
|
|
|
|
AfterPasswordConfirmationCallBack = pAfterPasswordConfirmationCallBack;
|
|
|
|
InitializeComponent();
|
|
DataContext = this;
|
|
|
|
OkayButton.IsDefault = true;
|
|
CountButton.IsDefault = false;
|
|
}
|
|
|
|
public Action AfterPasswordConfirmationCallBack { get; set; }
|
|
|
|
public bool IsInConfirmationWithPasswordMode { get; set; }
|
|
|
|
private ICommand _OpenBrowserCommand;
|
|
public ICommand OpenBrowserCommand => _OpenBrowserCommand ?? (_OpenBrowserCommand = new OpenBrowserCommandImpl());
|
|
|
|
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)
|
|
{
|
|
try
|
|
{
|
|
if(XamlReader.Parse(xamlCode) is UIElement element)
|
|
{
|
|
txtMessage.Visibility = Visibility.Collapsed;
|
|
rootGrid.Children.Add(element);
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
//ignore
|
|
}
|
|
}
|
|
|
|
public string Message
|
|
{
|
|
get => txtMessage.Text;
|
|
set => txtMessage.Text = value;
|
|
}
|
|
|
|
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
//DialogResult = true;
|
|
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;
|
|
}
|
|
|
|
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.SharedLauncher.Translation.Translator.Translate("Benutzernamen") + " und das Passwort!", "Fehler bei der Anmeldung", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
}
|
|
}, true);
|
|
}
|
|
}
|
|
}
|