132 lines
4.9 KiB
C#
132 lines
4.9 KiB
C#
// Copyright (c) 2017 Informatibüro Daniel Schick
|
|
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Markup;
|
|
|
|
using bsmd.database;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System;
|
|
using System.Net;
|
|
using ENI2.LockingServiceReference;
|
|
using System.Threading;
|
|
|
|
namespace ENI2
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
// "global" statics, da gibt es sicher noch einen eleganteren Weg..
|
|
private static ServiceClient _lockingServiceClient = null;
|
|
private static Guid? _userId = null;
|
|
|
|
// Splash screen
|
|
private static SplashScreenWindow _splashScreenWindow;
|
|
private ManualResetEvent ResetSplashCreated;
|
|
private Thread _splashThread;
|
|
|
|
public App() : base()
|
|
{
|
|
this.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
|
|
|
|
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
|
|
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
|
|
}
|
|
|
|
public static ServiceClient LockingServiceClient { get { return _lockingServiceClient; } }
|
|
|
|
public static SplashScreenWindow SplashScreen { get { return _splashScreenWindow; } }
|
|
|
|
public static Guid? UserId { get { return _userId; } set { _userId = value; } }
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
this.ResetSplashCreated = new ManualResetEvent(false);
|
|
this._splashThread = new Thread(ShowSplash);
|
|
_splashThread.SetApartmentState(ApartmentState.STA);
|
|
_splashThread.IsBackground = true;
|
|
_splashThread.Name = "Splash Screen";
|
|
_splashThread.Start();
|
|
|
|
ResetSplashCreated.WaitOne();
|
|
|
|
base.OnStartup(e);
|
|
|
|
// initialize static / localized lookups from sqlite database
|
|
|
|
string langKey = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
|
|
|
|
Dictionary<int, string> cargoHandlingDict = LocalizedLookup.getLADGCargoHandlingStrings(langKey);
|
|
foreach (int key in cargoHandlingDict.Keys)
|
|
LADG.CargoHandlingDict.Add(key, cargoHandlingDict[key]);
|
|
|
|
EventManager.RegisterClassHandler(typeof(DatePicker), DatePicker.PreviewKeyDownEvent, new KeyEventHandler(this.DatePicker_PreviewKeyDown));
|
|
CREW.NationalityDict = LocalizedLookup.getNationalities();
|
|
STAT.VesselTypeDict = LocalizedLookup.getVesselTypes();
|
|
STAT.TransportModeDict = LocalizedLookup.getTransportModes();
|
|
HAZ.PackageTypes = LocalizedLookup.getPackageTypes();
|
|
|
|
// Connect to locking service (if enabled)
|
|
|
|
try
|
|
{
|
|
if (ENI2.Properties.Settings.Default.UseLocking)
|
|
App._lockingServiceClient = new ServiceClient("BasicHttpBinding_IService", ENI2.Properties.Settings.Default.LockingServerAddress);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Trace.WriteLine("Exception creating locking service client: {0}", ex.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
string errorMessage = string.Format("An unhandled exception occurred: {0}\r\n{1}", e.Exception.Message, e.Exception.StackTrace);
|
|
MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void DatePicker_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
var dp = sender as DatePicker;
|
|
if (dp == null) return;
|
|
|
|
if (e.Key == Key.D && Keyboard.Modifiers == ModifierKeys.Control)
|
|
{
|
|
e.Handled = true;
|
|
dp.SetValue(DatePicker.SelectedDateProperty, DateTime.Today);
|
|
return;
|
|
}
|
|
|
|
if (!dp.SelectedDate.HasValue) return;
|
|
|
|
var date = dp.SelectedDate.Value;
|
|
if (e.Key == Key.Up)
|
|
{
|
|
e.Handled = true;
|
|
dp.SetValue(DatePicker.SelectedDateProperty, date.AddDays(1));
|
|
}
|
|
else if (e.Key == Key.Down)
|
|
{
|
|
e.Handled = true;
|
|
dp.SetValue(DatePicker.SelectedDateProperty, date.AddDays(-1));
|
|
}
|
|
}
|
|
|
|
private void ShowSplash()
|
|
{
|
|
_splashScreenWindow = new SplashScreenWindow();
|
|
_splashScreenWindow.Show();
|
|
|
|
ResetSplashCreated.Set();
|
|
System.Windows.Threading.Dispatcher.Run();
|
|
}
|
|
|
|
}
|
|
}
|