git_bsmd/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs

429 lines
18 KiB
C#

// Copyright (c) 2017 schick Informatik
// Description: Haupt-Übersichtsansicht eines Anlaufs / Auftrags (Core)
//
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Timers;
using bsmd.database;
using ENI2.EditControls;
namespace ENI2.DetailViewControls
{
/// <summary>
/// Interaction logic for OverViewDetailControl.xaml
/// </summary>
public partial class OverViewDetailControl : DetailBaseControl
{
private Message _message = null;
private Message _ataMessage;
private Message _atdMessage;
private Message _noanodMessage;
private Timer _checkStatusTimer;
private DateTime _startStatusCheck;
public OverViewDetailControl()
{
InitializeComponent();
this.Loaded += OverViewDetailControl_Loaded;
}
private void OverViewDetailControl_Loaded(object sender, RoutedEventArgs e)
{
// die Controls nach Änderungen monitoren
this.RegisterTextboxChange(this.textBoxTicketNo, this.Core.IsTransit ? Message.NotificationClass.TRANSIT : Message.NotificationClass.VISIT);
this.RegisterTextboxChange(this.textBoxDisplayId, this.Core.IsTransit ? Message.NotificationClass.TRANSIT : Message.NotificationClass.VISIT);
this.RegisterDateTimePickerChange(this.dateTimePickerATA, Message.NotificationClass.ATA);
this.RegisterDateTimePickerChange(this.dateTimePickerATD, Message.NotificationClass.ATD);
this.RegisterDateTimePickerChange(this.dateTimePickerETA, Message.NotificationClass.NOA_NOD);
this.RegisterDateTimePickerChange(this.dateTimePickerETD, Message.NotificationClass.NOA_NOD);
}
#region Initialize
public override void Initialize()
{
base.Initialize();
Message.NotificationClass notificationClass = this.Core.IsTransit ? Message.NotificationClass.TRANSIT : Message.NotificationClass.VISIT;
if (this.Messages == null) return;
if (this.Core == null) return;
this.textBoxENI.DataContext = this.Core;
this.textBoxIMO.DataContext = this.Core;
this.locodePoC.DataContext = this.Core;
this.textBoxTicketNo.DataContext = this.Core;
this.labelCreated.Content = this.Core.Created?.ToString();
Binding vtBinding = new Binding();
vtBinding.Source = this.Core;
vtBinding.Path = this.Core.IsTransit ? new PropertyPath("TransitId") : new PropertyPath("VisitId");
vtBinding.Mode = BindingMode.TwoWay;
vtBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
BindingOperations.SetBinding(textBoxDisplayId, TextBox.TextProperty, vtBinding);
#region Meldeklassen einrichten und Icons / Gruppen / Index zuordnen
foreach (Message aMessage in this.Messages)
{
if (aMessage.MessageNotificationClass == notificationClass)
_message = aMessage;
if (aMessage.MessageNotificationClass == Message.NotificationClass.ATA)
this._ataMessage = aMessage;
if (aMessage.MessageNotificationClass == Message.NotificationClass.ATD)
this._atdMessage = aMessage;
if (aMessage.MessageNotificationClass == Message.NotificationClass.NOA_NOD)
this._noanodMessage = aMessage;
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:
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:
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;
}
}
#endregion
// Meldeklassen nach ihrem Vorkommen in den Detailansichten sortieren (SH, 12.5.17)
this.Messages.Sort((a, b) =>
{
if (a.ENINotificationDetailIndex == b.ENINotificationDetailIndex)
return a.MessageNotificationClassDisplay.CompareTo(b.MessageNotificationClassDisplay);
return a.ENINotificationDetailIndex.CompareTo(b.ENINotificationDetailIndex);
});
if (_message != null)
{
// kann das eigentlich passieren??!
}
#region init ATA
// ganz hakelig ich weiß dafür kapiert das gleich jeder
if (this._ataMessage == null)
{
this._ataMessage = this.Core.CreateMessage(Message.NotificationClass.ATA);
this.Messages.Add(this._ataMessage);
this._ataMessage.ENINotificationIconString = "../Resources/arrow_down_right_red.png";
this._ataMessage.ENINotificationDetailGroup = Properties.Resources.textArrivalNotification;
this._ataMessage.ENINotificationDetailIndex = 4;
}
ATA ata = null;
if (this._ataMessage.Elements.Count > 0)
ata = this._ataMessage.Elements[0] as ATA;
if (ata == null)
{
ata = new ATA();
ata.MessageCore = this.Core;
ata.MessageHeader = this._ataMessage;
_ataMessage.Elements.Add(ata);
}
this.dateTimePickerATA.DataContext = ata;
this.ControlMessages.Add(this._ataMessage);
#endregion
#region init ATD
if (this._atdMessage == null)
{
this._atdMessage = this.Core.CreateMessage(Message.NotificationClass.ATD);
this.Messages.Add(this._atdMessage);
this._atdMessage.ENINotificationIconString = "../Resources/arrow_up_right_green.png";
this._atdMessage.ENINotificationDetailGroup = Properties.Resources.textDepartureNotification;
this._atdMessage.ENINotificationDetailIndex = 10;
}
ATD atd = null;
if (this._atdMessage.Elements.Count > 0)
atd = this._atdMessage.Elements[0] as ATD;
if (atd == null)
{
atd = new ATD();
atd.MessageCore = this.Core;
atd.MessageHeader = this._atdMessage;
_atdMessage.Elements.Add(atd);
}
this.dateTimePickerATD.DataContext = atd;
this.ControlMessages.Add(this._atdMessage);
#endregion
#region init NOA_NOD
if (this._noanodMessage == null)
{
this._noanodMessage = this.Core.CreateMessage(Message.NotificationClass.NOA_NOD);
this.Messages.Add(this._noanodMessage);
_noanodMessage.ENINotificationIconString = "../Resources/eye_blue.png";
_noanodMessage.ENINotificationDetailGroup = Properties.Resources.textPortCall;
_noanodMessage.ENINotificationDetailIndex = 1;
}
NOA_NOD noa_nod = null;
if (this._noanodMessage.Elements.Count > 0)
noa_nod = this._noanodMessage.Elements[0] as NOA_NOD;
if (noa_nod == null)
{
noa_nod = new NOA_NOD();
noa_nod.MessageCore = this.Core;
noa_nod.MessageHeader = this._noanodMessage;
_noanodMessage.Elements.Add(noa_nod);
}
this.dateTimePickerETD.DataContext = noa_nod;
this.dateTimePickerETA.DataContext = noa_nod;
this.ControlMessages.Add(this._noanodMessage);
#endregion
this.dataGridMessages.ItemsSource = this.Messages;
this._initialized = true;
}
#endregion
#region private methods
private void jumpToMessage(Message message)
{
this.OnJumpToListElementRequest(message.ENINotificationDetailIndex);
}
#endregion
#region mouse event handler
private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (sender != null)
{
DataGrid grid = sender as DataGrid;
if ((grid != null) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1))
{
DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
Message selectedMessage = grid.SelectedItem as Message;
this.jumpToMessage(selectedMessage);
}
}
}
private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if ((e.Key == Key.Return) || (e.Key == Key.Enter))
{
Message selectedMessage = this.dataGridMessages.SelectedItem as Message;
this.jumpToMessage(selectedMessage);
}
else
{
base.OnPreviewKeyDown(e);
}
}
#endregion
#region Command button event handler
private void buttonStorno_Click(object sender, RoutedEventArgs e)
{
}
private void buttonCopy_Click(object sender, RoutedEventArgs e)
{
}
private void buttonSendPDF_Click(object sender, RoutedEventArgs e)
{
}
private void buttonQueryHIS_Click(object sender, RoutedEventArgs e)
{
this._startStatusCheck = DateTime.Now;
this.Core.QueryNSWStatus = true;
this.Core.StatusCheckErrorCode = string.Empty;
this.Core.StatusCheckErrorMessage = string.Empty;
DBManager.Instance.Save(this.Core);
this.busyIndicator.IsBusy = true;
// Hintergrund-Thread starten, der gelegentlich auf das Ergebnis prüft..
if (_checkStatusTimer == null)
{
_checkStatusTimer = new Timer(3000);
_checkStatusTimer.Elapsed += _checkStatusTimer_Elapsed;
_checkStatusTimer.AutoReset = true;
}
_checkStatusTimer.Start();
}
#endregion
#region event handler
private void _checkStatusTimer_Elapsed(object sender, ElapsedEventArgs e)
{
bool? statusFlag = DBManager.Instance.GetMessageCoreQueryStatusFlag(this.Core.Id.Value);
if (statusFlag ?? true)
{
// not yet.. (calling ui thread async)
this.Dispatcher.BeginInvoke(new Action(() =>
{
this.labelBusyTimeElapsed.Content = string.Format(Properties.Resources.textSecondsElapsed, (DateTime.Now - _startStatusCheck).TotalSeconds.ToString("N0"));
}));
}
else
{
this._checkStatusTimer.Stop();
this.Dispatcher.BeginInvoke(new Action(() =>
{
this.busyIndicator.IsBusy = false;
this.OnRequestReload();
}));
}
}
private void buttonStopWaiting_Click(object sender, RoutedEventArgs e)
{
this._checkStatusTimer.Stop();
this.busyIndicator.IsBusy = false;
}
private void buttonRefresh_Click(object sender, RoutedEventArgs e)
{
// reload Core and all message classes
// container class needs to dismiss all created controls
this.Dispatcher.BeginInvoke(new Action(() =>
{
this.OnRequestReload();
}));
}
private void buttonLock_Click(object sender, RoutedEventArgs e)
{
this.Dispatcher.BeginInvoke(new Action(() =>
{
bool reqValue = true;
if (this.Core.Locked ?? false) // I locked it already, means unlock now
reqValue = false;
this.OnRequestLock(reqValue);
}));
}
private void buttonInfoCore_Click(object sender, RoutedEventArgs e)
{
SimplePropertyViewDialog spvd = new SimplePropertyViewDialog();
spvd.IsModal = false;
spvd.DisplayObject = this.Core;
spvd.Show();
}
#endregion
}
}