208 lines
9.4 KiB
C#
208 lines
9.4 KiB
C#
// Copyright (c) 2017 schick Informatik
|
|
// Description: Extra methods needed sometimes. Das WaitCursor (fire- and forget) Verfahren gefällt mir sehr gut, ich hoffe
|
|
// es funktioniert unter den meisten Umständen ;-) Idee von hier:
|
|
// https://stackoverflow.com/a/7482321
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using System.Reflection;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Threading;
|
|
|
|
using bsmd.database;
|
|
|
|
namespace ENI2.Util
|
|
{
|
|
public static class UIHelper
|
|
{
|
|
|
|
private static bool isBusy;
|
|
private static readonly Random r = new Random();
|
|
|
|
|
|
public enum BusyStateEnum
|
|
{
|
|
NEUTRAL,
|
|
BUSY,
|
|
FAIL,
|
|
SUCCESS
|
|
}
|
|
|
|
public static void SetBusyState()
|
|
{
|
|
SetBusyState(true);
|
|
}
|
|
|
|
private static void SetBusyState(bool busy)
|
|
{
|
|
|
|
if(busy != isBusy)
|
|
{
|
|
isBusy = busy;
|
|
Mouse.OverrideCursor = isBusy ? Cursors.Wait : null;
|
|
}
|
|
|
|
if(isBusy)
|
|
{
|
|
_ = new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, Application.Current.Dispatcher);
|
|
}
|
|
}
|
|
|
|
private static void dispatcherTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
if (sender is DispatcherTimer timer)
|
|
{
|
|
SetBusyState(false);
|
|
timer.Stop();
|
|
}
|
|
}
|
|
|
|
public static bool IsModal(this Window window)
|
|
{
|
|
return (bool)typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(window);
|
|
}
|
|
|
|
public static Color GetRandomBrightColor()
|
|
{
|
|
return Color.FromRgb((byte) r.Next(150, 255), (byte) r.Next(150, 255), (byte) r.Next(150, 255));
|
|
}
|
|
|
|
public static BitmapSource CreateBitmapSource(this System.Drawing.Bitmap bitmap)
|
|
{
|
|
if (bitmap == null)
|
|
throw new ArgumentNullException("bitmap");
|
|
|
|
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
|
|
|
|
System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(rect,
|
|
System.Drawing.Imaging.ImageLockMode.ReadWrite,
|
|
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
|
|
try
|
|
{
|
|
var size = rect.Width * rect.Height * 4;
|
|
|
|
return BitmapSource.Create(
|
|
bitmap.Width,
|
|
bitmap.Height,
|
|
bitmap.HorizontalResolution,
|
|
bitmap.VerticalResolution,
|
|
PixelFormats.Bgra32,
|
|
null,
|
|
bitmapData.Scan0,
|
|
size,
|
|
bitmapData.Stride);
|
|
}
|
|
finally
|
|
{
|
|
bitmap.UnlockBits(bitmapData);
|
|
}
|
|
}
|
|
|
|
public static void SetMessageIcons(List<Message> messages)
|
|
{
|
|
foreach (Message aMessage in messages)
|
|
{
|
|
switch (aMessage.MessageNotificationClass)
|
|
{
|
|
case Message.NotificationClass.VISIT:
|
|
case Message.NotificationClass.TRANSIT:
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textOverview;
|
|
aMessage.ENINotificationIconString = "../Resources/documents.png";
|
|
aMessage.ENINotificationDetailIndex = 0;
|
|
break;
|
|
case Message.NotificationClass.NOA_NOD:
|
|
case Message.NotificationClass.AGNT:
|
|
aMessage.ENINotificationIconString = "../Resources/eye_blue.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textPortCall;
|
|
aMessage.ENINotificationDetailIndex = 1;
|
|
break;
|
|
case Message.NotificationClass.NAME:
|
|
case Message.NotificationClass.INFO:
|
|
case Message.NotificationClass.SERV:
|
|
case Message.NotificationClass.LADG:
|
|
aMessage.ENINotificationIconString = "../Resources/anchor.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textPortNotification;
|
|
aMessage.ENINotificationDetailIndex = 2;
|
|
break;
|
|
case Message.NotificationClass.WAS:
|
|
case Message.NotificationClass.WAS_RCPT:
|
|
aMessage.ENINotificationIconString = "../Resources/garbage.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textWaste;
|
|
aMessage.ENINotificationDetailIndex = 3;
|
|
break;
|
|
case Message.NotificationClass.ATA:
|
|
case Message.NotificationClass.POBA:
|
|
case Message.NotificationClass.TIEFA:
|
|
case Message.NotificationClass.BKRA:
|
|
aMessage.ENINotificationIconString = "../Resources/arrow_down_right_red.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textArrivalNotification;
|
|
aMessage.ENINotificationDetailIndex = 4;
|
|
break;
|
|
case Message.NotificationClass.SEC:
|
|
aMessage.ENINotificationIconString = "../Resources/shield_yellow.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textSecurity;
|
|
aMessage.ENINotificationDetailIndex = 5;
|
|
break;
|
|
case Message.NotificationClass.PRE72H:
|
|
aMessage.ENINotificationIconString = "../Resources/alarmclock.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textPSC72h;
|
|
aMessage.ENINotificationDetailIndex = 6;
|
|
break;
|
|
case Message.NotificationClass.MDH:
|
|
aMessage.ENINotificationIconString = "../Resources/medical_bag.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textMDH;
|
|
aMessage.ENINotificationDetailIndex = 7;
|
|
break;
|
|
case Message.NotificationClass.ATD:
|
|
case Message.NotificationClass.TIEFD:
|
|
case Message.NotificationClass.BKRD:
|
|
case Message.NotificationClass.POBD:
|
|
aMessage.ENINotificationIconString = "../Resources/arrow_up_right_green.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textDepartureNotification;
|
|
aMessage.ENINotificationDetailIndex = 8;
|
|
break;
|
|
case Message.NotificationClass.STAT:
|
|
aMessage.ENINotificationIconString = "../Resources/containership.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textShipData;
|
|
aMessage.ENINotificationDetailIndex = 9;
|
|
break;
|
|
case Message.NotificationClass.BPOL:
|
|
case Message.NotificationClass.CREW:
|
|
case Message.NotificationClass.PAS:
|
|
case Message.NotificationClass.CREWD:
|
|
case Message.NotificationClass.PASD:
|
|
aMessage.ENINotificationIconString = "../Resources/policeman_german.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textBorderPolice;
|
|
aMessage.ENINotificationDetailIndex = 10;
|
|
break;
|
|
|
|
case Message.NotificationClass.HAZA:
|
|
aMessage.ENINotificationIconString = "../Resources/sign_warning_radiation.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textDGArrival;
|
|
aMessage.ENINotificationDetailIndex = 11;
|
|
break;
|
|
case Message.NotificationClass.HAZD:
|
|
aMessage.ENINotificationIconString = "../Resources/sign_warning_radiation.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textDGDeparture;
|
|
aMessage.ENINotificationDetailIndex = 12;
|
|
break;
|
|
case Message.NotificationClass.TOWA:
|
|
case Message.NotificationClass.TOWD:
|
|
aMessage.ENINotificationIconString = "../Resources/ship2.png";
|
|
aMessage.ENINotificationDetailGroup = Properties.Resources.textTowage;
|
|
aMessage.ENINotificationDetailIndex = 13;
|
|
break;
|
|
default:
|
|
aMessage.ENINotificationDetailGroup = "unspecified";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|