git_bsmd/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs
Daniel Schick a9594e7702 Version 2.3.6.13:
Highlighting erster Ansatz, immer weitere Korrekturen rund um HIS-Nord Versand
2017-08-24 16:54:40 +00:00

548 lines
25 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;
using System.Windows.Media.Imaging;
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.labelBSMDStatusInternal.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 Context-Menu Meldeklassen
// wenn man das mal aufwendig "schön" machen will (die Items enabled abh. vom Zustand der Meldeklasse) sollte man
// Command Bindings verwenden. Hier ist das erklärt: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/commanding-overview#code-snippet-2
this.dataGridMessages.ContextMenu = new ContextMenu();
MenuItem sendItem = new MenuItem();
sendItem.Header = Properties.Resources.textSendToNSW;
sendItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/mail_forward.png")) };
//sendItem.Command =
sendItem.Click += new RoutedEventHandler(this.contextSendMessage);
this.dataGridMessages.ContextMenu.Items.Add(sendItem);
MenuItem resetItem = new MenuItem();
resetItem.Header = Properties.Resources.textReset;
resetItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/mail_delete.png")) };
resetItem.Click += new RoutedEventHandler(this.contextResetMessage);
this.dataGridMessages.ContextMenu.Items.Add(resetItem);
MenuItem errorItem = new MenuItem();
errorItem.Header = Properties.Resources.textErrors;
errorItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/error.png")) };
errorItem.Click += new RoutedEventHandler(this.buttonErrors_Click);
this.dataGridMessages.ContextMenu.Items.Add(errorItem);
MenuItem vioItem = new MenuItem();
vioItem.Header = Properties.Resources.textViolations;
vioItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/sign_warning.png")) };
vioItem.Click += new RoutedEventHandler(this.buttonWarnings_Click);
this.dataGridMessages.ContextMenu.Items.Add(vioItem);
#endregion
#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 public methods
public void ShowLockedBy(ReportingParty reportingParty)
{
this.stackPanelLock.Visibility = Visibility.Visible;
this.textBlockLockUserName.Text = reportingParty.FirstName + " " + reportingParty.LastName;
}
#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 contextSendMessage(object sender, RoutedEventArgs e)
{
//MessageBox.Show("not yet..");
MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmSend, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
foreach (Message selectedMessage in this.dataGridMessages.SelectedItems)
{
selectedMessage.InternalStatus = Message.BSMDStatus.TOSEND;
selectedMessage.StatusInfo = string.Format(Properties.Resources.textMessageSentAt, DateTime.Now);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedMessage);
}
// komplette Anmeldung auf "zu versenden" stellen
this.Core.BSMDStatusInternal = MessageCore.BSMDStatus.TOSEND;
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core);
this.dataGridMessages.Items.Refresh();
}
}
private void contextResetMessage(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmReset, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
foreach (Message selectedMessage in this.dataGridMessages.SelectedItems)
{
selectedMessage.Reset = true;
selectedMessage.InternalStatus = Message.BSMDStatus.TOSEND;
selectedMessage.StatusInfo = string.Format(Properties.Resources.textMessageResetAt, DateTime.Now);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedMessage);
}
// komplette Anmeldung auf "zu versenden" stellen
this.Core.BSMDStatusInternal = MessageCore.BSMDStatus.TOSEND;
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core);
this.dataGridMessages.Items.Refresh();
}
}
private void buttonStorno_Click(object sender, RoutedEventArgs e)
{
if (this.Core.Cancelled ?? false)
{
MessageBox.Show(Properties.Resources.textAlreadyCancelled);
}
else
{
MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmCancel, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
this.Core.Cancelled = true;
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core);
}
}
}
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.GetSingleCon(Properties.Settings.Default.ConnectionString).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.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessageCoreQueryStatusFlag(this.Core.Id.Value);
if (statusFlag ?? true)
{
double elapsedSec = (DateTime.Now - _startStatusCheck).TotalSeconds;
if (elapsedSec < Properties.Settings.Default.RequestTimeout)
{
// not yet.. (calling ui thread async)
this.Dispatcher.BeginInvoke(new Action(() =>
{
this.labelBusyTimeElapsed.Content = string.Format(Properties.Resources.textSecondsElapsed, elapsedSec.ToString("N0"));
}));
}
else
{
this._checkStatusTimer.Stop();
this.Dispatcher.BeginInvoke(new Action(() =>
{
MessageBox.Show(Properties.Resources.textRequestTimedOut, Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Warning);
this.busyIndicator.IsBusy = false;
}));
}
}
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 buttonInfoCore_Click(object sender, RoutedEventArgs e)
{
SimplePropertyViewDialog spvd = new SimplePropertyViewDialog();
spvd.IsModal = false;
spvd.DisplayObject = this.Core;
spvd.Show();
}
private void buttonErrors_Click(object sender, RoutedEventArgs e)
{
if(this.dataGridMessages.SelectedItems.Count > 0)
{
Message selectedMessage = this.dataGridMessages.SelectedItems[0] as Message;
ErrorListDialog eld = new ErrorListDialog();
eld.Errors = selectedMessage.ErrorList;
eld.ShowDialog();
}
}
private void buttonWarnings_Click(object sender, RoutedEventArgs e)
{
if (this.dataGridMessages.SelectedItems.Count > 0)
{
Message selectedMessage = this.dataGridMessages.SelectedItems[0] as Message;
ViolationListDialog vld = new ViolationListDialog();
vld.Violations = selectedMessage.ViolationList;
vld.ShowDialog();
}
}
#endregion
}
}