915 lines
38 KiB
C#
915 lines
38 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 ENI2.Excel;
|
|
using ENI2.Report;
|
|
|
|
using System.Windows.Media.Imaging;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Media;
|
|
using Microsoft.Win32;
|
|
using System.Diagnostics;
|
|
using System.ComponentModel;
|
|
using static bsmd.database.Message;
|
|
using PdfSharp.Fonts;
|
|
using System.Linq;
|
|
|
|
namespace ENI2.DetailViewControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for OverViewDetailControl.xaml
|
|
/// </summary>
|
|
public partial class OverViewDetailControl : DetailBaseControl
|
|
{
|
|
|
|
#region Fields
|
|
|
|
private Message _message = null;
|
|
private Message _ataMessage;
|
|
private Message _atdMessage;
|
|
private Message _noanodMessage;
|
|
private Timer _checkStatusTimer;
|
|
private DateTime _startStatusCheck;
|
|
private readonly object _collectionLock = new object();
|
|
// private MessageSendStatusDialog mssd = null;
|
|
|
|
#endregion
|
|
|
|
#region Construction
|
|
|
|
public OverViewDetailControl()
|
|
{
|
|
InitializeComponent();
|
|
this.Loaded += OverViewDetailControl_Loaded;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Initialize
|
|
|
|
private void OverViewDetailControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
// die Controls nach Änderungen monitoren
|
|
// diese Einträge gehen auf core
|
|
this.textBoxTicketNo.TextChanged += CoreTextBox_TextChanged;
|
|
this.textBoxDisplayId.TextChanged += CoreTextBox_TextChanged;
|
|
this.textBoxIMO.TextChanged += CoreTextBox_TextChanged;
|
|
this.textBoxENI.TextChanged += CoreTextBox_TextChanged;
|
|
this.locodePoC.PropertyChanged += CoreLocode_LocodeChanged;
|
|
|
|
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);
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
bool iAmAdmin = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsAdmin;
|
|
|
|
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.IsReadOnly = !iAmAdmin;
|
|
this.textBoxIMO.IsReadOnly = !iAmAdmin;
|
|
this.locodePoC.IsEnabled = iAmAdmin;
|
|
this.textBoxDisplayId.IsReadOnly = !iAmAdmin;
|
|
|
|
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();
|
|
|
|
this.comboBoxInitialHis.ItemsSource = Util.EnumHelper.GetAllValuesAndDescription(typeof(Message.NSWProvider));
|
|
this.comboBoxInitialHis.DataContext = this.Core;
|
|
this.buttonExcelImport.IsEnabled = !this.Core.DisplayId.IsNullOrEmpty();
|
|
|
|
Binding vtBinding = new Binding
|
|
{
|
|
Source = this.Core,
|
|
Path = this.Core.IsTransit ? new PropertyPath("TransitId") : new PropertyPath("VisitId"),
|
|
Mode = BindingMode.TwoWay,
|
|
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
|
|
};
|
|
BindingOperations.SetBinding(textBoxDisplayId, TextBox.TextProperty, vtBinding);
|
|
|
|
if (this.Core.Cancelled ?? false) this.ShowCancelledLabel();
|
|
|
|
#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
|
|
{
|
|
Header = Properties.Resources.textSendToNSW,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/mail_forward.png")) }
|
|
};
|
|
//sendItem.Command =
|
|
sendItem.Click += this.contextSendMessage;
|
|
this.dataGridMessages.ContextMenu.Items.Add(sendItem);
|
|
|
|
MenuItem resetItem = new MenuItem
|
|
{
|
|
Header = Properties.Resources.textReset,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/mail_delete.png")) }
|
|
};
|
|
resetItem.Click += this.contextResetMessage;
|
|
this.dataGridMessages.ContextMenu.Items.Add(resetItem);
|
|
|
|
MenuItem systemErrorItem = new MenuItem
|
|
{
|
|
Header = Properties.Resources.textSystemErrors,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/hand_red_card.png")) }
|
|
};
|
|
systemErrorItem.Click += this.buttonSystemErrors_Click;
|
|
this.dataGridMessages.ContextMenu.Items.Add(systemErrorItem);
|
|
|
|
MenuItem errorItem = new MenuItem
|
|
{
|
|
Header = Properties.Resources.textErrors,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/error.png")) }
|
|
};
|
|
errorItem.Click += this.buttonErrors_Click;
|
|
this.dataGridMessages.ContextMenu.Items.Add(errorItem);
|
|
|
|
MenuItem vioItem = new MenuItem
|
|
{
|
|
Header = Properties.Resources.textViolations,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/sign_warning.png")) }
|
|
};
|
|
vioItem.Click += this.buttonWarnings_Click;
|
|
this.dataGridMessages.ContextMenu.Items.Add(vioItem);
|
|
|
|
/*
|
|
MenuItem pdfItem = new MenuItem
|
|
{
|
|
Header = Properties.Resources.textCreatePDF,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/document_pdf.png")) }
|
|
};
|
|
pdfItem.Click += this.buttonCreatePDF_Click;
|
|
this.dataGridMessages.ContextMenu.Items.Add(pdfItem);
|
|
*/
|
|
|
|
MenuItem historyItem = new MenuItem
|
|
{
|
|
Header = Properties.Resources.textHistoryItems,
|
|
Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/clock_history.png")) }
|
|
};
|
|
historyItem.Click += HistoryItem_Click;
|
|
this.dataGridMessages.ContextMenu.Items.Add(historyItem);
|
|
historyItem.IsEnabled = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsAdmin; // TODO: rechtzeitig wieder entfernen!
|
|
|
|
#endregion
|
|
|
|
#region lokale Meldeklassen
|
|
|
|
Message crewdMessage = null;
|
|
Message pasdMessage = null;
|
|
|
|
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;
|
|
if (aMessage.MessageNotificationClass == Message.NotificationClass.CREWD)
|
|
crewdMessage = aMessage;
|
|
if (aMessage.MessageNotificationClass == Message.NotificationClass.PASD)
|
|
pasdMessage = aMessage;
|
|
}
|
|
|
|
#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
|
|
{
|
|
MessageCore = this.Core,
|
|
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
|
|
{
|
|
MessageCore = this.Core,
|
|
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
|
|
{
|
|
MessageCore = this.Core,
|
|
MessageHeader = this._noanodMessage
|
|
};
|
|
_noanodMessage.Elements.Add(noa_nod);
|
|
}
|
|
|
|
this.dateTimePickerETD.DataContext = noa_nod;
|
|
this.dateTimePickerETA.DataContext = noa_nod;
|
|
this.ControlMessages.Add(this._noanodMessage);
|
|
|
|
#endregion
|
|
|
|
#region Meldeklassen einrichten und Icons / Gruppen / Index zuordnen
|
|
|
|
Util.UIHelper.SetMessageIcons(this.Messages);
|
|
|
|
#endregion
|
|
|
|
#region 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??!
|
|
}
|
|
|
|
#endregion
|
|
|
|
BindingOperations.EnableCollectionSynchronization(this.Messages, _collectionLock);
|
|
this.dataGridMessages.ItemsSource = this.Messages;
|
|
|
|
this.OnRequestValidate(false);
|
|
|
|
base.Initialize(); // wenn Meldeklassen erst bei der Init. erzeugt werden, fehlen die Handler, die hier erneut festgelegt werden
|
|
this._initialized = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public void ShowLockedBy(ReportingParty reportingParty)
|
|
{
|
|
if (reportingParty != null)
|
|
{
|
|
this.stackPanelLock.Visibility = Visibility.Visible;
|
|
this.textBlockLockUserName.Text = reportingParty.FirstName + " " + reportingParty.LastName;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Reporting party empty, cannot show locked by!", "Notification", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
public void UpdateCore()
|
|
{
|
|
this.UnregisterTextboxChange(this.textBoxDisplayId);
|
|
|
|
this.textBoxDisplayId.DataContext = null;
|
|
this.textBoxDisplayId.DataContext = this.Core;
|
|
this.textBoxDisplayId.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget();
|
|
|
|
this.RegisterTextboxChange(this.textBoxDisplayId, Message.NotificationClass.ATA);
|
|
|
|
this.labelBSMDStatusInternal.DataContext = null;
|
|
this.labelBSMDStatusInternal.DataContext = this.Core;
|
|
this.labelBSMDStatusInternal.GetBindingExpression(Label.ContentProperty)?.UpdateTarget();
|
|
|
|
this.buttonExcelImport.IsEnabled = !this.Core.DisplayId.IsNullOrEmpty();
|
|
|
|
//MessageBox.Show(string.Format("Visit/Transit ID updated: {0}", this.Core.DisplayId));
|
|
//ShowIdDialog sid = new ShowIdDialog(this.Core)
|
|
//{
|
|
// DisplayId = this.Core.DisplayId
|
|
//};
|
|
//sid.UpdateId(this.Core.DisplayId);
|
|
//sid.Show();
|
|
this.Core.IsDirty = false; // ist ja schon gespeichert..
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private methods
|
|
|
|
private void jumpToMessage(Message message)
|
|
{
|
|
this.OnJumpToListElementRequest(message.ENINotificationDetailIndex);
|
|
}
|
|
|
|
private void ShowCancelledLabel()
|
|
{
|
|
this.labelCancelled.Content = Properties.Resources.textCancelled;
|
|
this.labelCancelled.Background = Brushes.Yellow;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region mouse event handler
|
|
|
|
private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (sender != null)
|
|
{
|
|
if ((sender is DataGrid grid) && (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 HistoryItem_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if(this.dataGridMessages.SelectedItems.Count > 0)
|
|
{
|
|
Message historyMessage = this.dataGridMessages.SelectedItems[0] as Message;
|
|
MessageHistoryDialog mhd = new MessageHistoryDialog();
|
|
mhd.Messages = this.Messages;
|
|
mhd.MessageHistories = DBManager.Instance.GetMessageHistories(historyMessage.Id.Value);
|
|
mhd.RequestReload += () => this.OnRequestReload(this.Core.Id.Value);
|
|
mhd.Show();
|
|
}
|
|
}
|
|
|
|
private void contextSendMessage(object sender, RoutedEventArgs e)
|
|
{
|
|
MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmSend, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
this.SendMessages(this.dataGridMessages.SelectedItems.Cast<Message>());
|
|
}
|
|
}
|
|
|
|
private void SendMessages(IEnumerable<Message> messages)
|
|
{
|
|
bool somethingsNotSaved = false;
|
|
|
|
foreach (Message selectedMessage in messages)
|
|
{
|
|
if (selectedMessage.IsDirty) somethingsNotSaved = true;
|
|
}
|
|
|
|
if (somethingsNotSaved)
|
|
{
|
|
if (MessageBox.Show(Properties.Resources.textUnsavedChangesSendAnyWay, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
|
|
return;
|
|
}
|
|
|
|
List<Message> watchList = new List<Message>();
|
|
foreach (Message selectedMessage in messages)
|
|
{
|
|
if (selectedMessage.Reset) selectedMessage.Reset = false; // "nochmal" Versenden ist möglich
|
|
selectedMessage.InternalStatus = Message.BSMDStatus.TOSEND;
|
|
string userName = "?";
|
|
if (App.UserId.HasValue && DBManager.Instance.GetReportingPartyDict().ContainsKey(App.UserId.Value))
|
|
{
|
|
userName = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].Logon;
|
|
}
|
|
selectedMessage.ChangedBy = string.Format("{0} at {1} (Send)", userName, DateTime.Now);
|
|
selectedMessage.StatusInfo = string.Format(Properties.Resources.textMessageSentAt, DateTime.Now);
|
|
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedMessage);
|
|
watchList.Add(selectedMessage);
|
|
}
|
|
|
|
// komplette Anmeldung auf "zu versenden" stellen
|
|
this.Core.BSMDStatusInternal = MessageCore.BSMDStatus.TOSEND;
|
|
this.Core.DefaultReportingPartyId = App.UserId;
|
|
|
|
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core); // löst auch den Watchdog aus
|
|
this.OnRequestSendValidation();
|
|
this.dataGridMessages.Items.Refresh();
|
|
|
|
/*
|
|
if (this.mssd == null)
|
|
{
|
|
this.mssd = new MessageSendStatusDialog(this.Core);
|
|
this.mssd.Closed += (s,args) => { this.mssd = null; };
|
|
this.mssd.SendComplete += (() => {
|
|
this.Dispatcher.Invoke(() =>
|
|
{
|
|
if (this.mssd != null)
|
|
{
|
|
this.mssd.Close();
|
|
this.OnRequestReload(this.Core.Id.Value);
|
|
}
|
|
});
|
|
});
|
|
this.mssd.Show();
|
|
}
|
|
this.mssd.Activate(); // bring to foreground
|
|
this.mssd.AddMessages(watchList);
|
|
*/
|
|
}
|
|
|
|
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)
|
|
{
|
|
// Testen, ob der Reset an dasselbe HIS geht wie da wo die Meldung ursprünglich angelegt wurde
|
|
foreach(Message selectedMessage in this.dataGridMessages.SelectedItems)
|
|
{
|
|
if (selectedMessage.HIS != this.Core.InitialHIS)
|
|
{
|
|
string abortMsg = string.Format(Properties.Resources.textMessageHisNotMatching, selectedMessage.HIS, selectedMessage.MessageNotificationClassDisplay, this.Core.InitialHIS);
|
|
MessageBox.Show(abortMsg, Properties.Resources.textErrorMessage, MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
return;
|
|
}
|
|
}
|
|
|
|
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;
|
|
this.Core.DefaultReportingPartyId = App.UserId;
|
|
|
|
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
|
|
{
|
|
if((this.Core.InitialHIS != _message.HIS) && (_message.HIS != Message.NSWProvider.UNDEFINED))
|
|
{
|
|
MessageBox.Show(Properties.Resources.textHISNotMatching, Properties.Resources.textConfirm, MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
return;
|
|
}
|
|
|
|
MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmCancel, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
this.Core.Cancelled = true;
|
|
this.Core.BSMDStatusInternal = MessageCore.BSMDStatus.TOSEND;
|
|
this.Core.DefaultReportingPartyId = App.UserId;
|
|
this.ShowCancelledLabel();
|
|
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core);
|
|
|
|
this.OnRequestDisable();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonCopy_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.OnRequestCopy();
|
|
}
|
|
|
|
private void buttonSendPDF_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SelectImportClassesDialog sicd = new SelectImportClassesDialog();
|
|
sicd.Messages = this.Messages;
|
|
sicd.IsTransit = this.Core.IsTransit;
|
|
if ((sicd.ShowDialog() ?? false) && (sicd.SelectedClasses.Count > 0))
|
|
{
|
|
string preferredFileName = string.Format("{0}_{1}.pdf", this.Core.Shipname, this.Core.DisplayId);
|
|
// get here if user selected some classes
|
|
SaveFileDialog sfd = new SaveFileDialog
|
|
{
|
|
Filter = "PDF Files|*.pdf",
|
|
FileName = preferredFileName
|
|
};
|
|
if (sfd.ShowDialog() ?? false)
|
|
{
|
|
Util.UIHelper.SetBusyState();
|
|
ReportManager rm = new ReportManager();
|
|
|
|
// TODO!!
|
|
// https://docs.pdfsharp.net/PDFsharp/Topics/Fonts/Font-Resolving.html
|
|
// https://docs.pdfsharp.net/MigraDoc/DOM/Document/MigraDocSettings.html
|
|
GlobalFontSettings.UseWindowsFontsUnderWindows = true;
|
|
GlobalFontSettings.UseWindowsFontsUnderWsl2 = true;
|
|
|
|
// create PDF from message classes
|
|
if (rm.Create(sfd.FileName, this.Core, sicd.SelectedClasses, out string importResultText))
|
|
{
|
|
MessageBox.Show("Report created: " + sfd.FileName, "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
// Clipboard.SetText(sfd.FileName);
|
|
Process.Start(sfd.FileName);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(importResultText, "PDF create failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 CoreLocode_LocodeChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
this.OnNotificationClassChanged(null);
|
|
}
|
|
|
|
private void CoreTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
this.OnNotificationClassChanged(null);
|
|
}
|
|
|
|
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(() =>
|
|
{
|
|
MessageCore reloadedCore = DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessageCoreById(this.Core.Id.Value);
|
|
CoreStatusInfoDialog csid = new CoreStatusInfoDialog
|
|
{
|
|
Core = reloadedCore
|
|
};
|
|
csid.Show();
|
|
this.busyIndicator.IsBusy = false;
|
|
this.OnRequestReload(this.Core.Id.Value);
|
|
}));
|
|
}
|
|
}
|
|
|
|
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(this.Core.Id.Value)));
|
|
}
|
|
|
|
private void buttonInfoCore_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SimplePropertyViewDialog spvd = new SimplePropertyViewDialog
|
|
{
|
|
DisplayObject = this.Core
|
|
};
|
|
spvd.Show();
|
|
|
|
//CoreStatusInfoDialog csid = new CoreStatusInfoDialog();
|
|
//csid.IsModal = false;
|
|
//csid.Core = this.Core;
|
|
//csid.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
|
|
{
|
|
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
|
|
{
|
|
Violations = selectedMessage.ViolationList
|
|
};
|
|
vld.ShowDialog();
|
|
}
|
|
}
|
|
|
|
private void buttonSystemErrors_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (this.dataGridMessages.SelectedItems.Count > 0)
|
|
{
|
|
Message selectedMessage = this.dataGridMessages.SelectedItems[0] as Message;
|
|
SystemErrorDialog sed = new SystemErrorDialog
|
|
{
|
|
SystemErrors = selectedMessage.SystemErrorList
|
|
};
|
|
sed.ShowDialog();
|
|
}
|
|
}
|
|
|
|
private void buttonValidate_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.OnRequestValidate(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// update class fields from named excel sheet
|
|
/// </summary>
|
|
private void buttonExcelImport_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SelectImportClassesDialog sicd = new SelectImportClassesDialog();
|
|
sicd.IsTransit = this.Core.IsTransit;
|
|
sicd.Messages = this.Messages;
|
|
if((sicd.ShowDialog() ?? false) && (sicd.SelectedClasses.Count > 0))
|
|
{
|
|
// get here if user selected some classes
|
|
OpenFileDialog ofd = new OpenFileDialog
|
|
{
|
|
Filter = "Excel Files|*.xls;*.xlsx"
|
|
};
|
|
if (ofd.ShowDialog() ?? false)
|
|
{
|
|
Util.UIHelper.SetBusyState();
|
|
|
|
ExcelManager em = new ExcelManager();
|
|
// start importer
|
|
if(em.Import(ofd.FileName, this.Core, sicd.SelectedClasses, out string importResultText))
|
|
{
|
|
// reload this core
|
|
this.OnRequestReload(this.Core.Id.Value);
|
|
|
|
// validate all selected import classes (Finger with "selection")
|
|
this.OnRequestValidate(true);
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(importResultText, "Import failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// export all classes to excel reference sheet
|
|
/// </summary>
|
|
private void buttonExcelExport_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string filename = string.Format("{0}_{1}_ref.xlsx", this.Core.Shipname, this.Core.DisplayId);
|
|
this.ExportData(filename, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Export all classes in "new" sheet version (>= 7.0).. this to return the current format to the ships
|
|
/// </summary>
|
|
private void buttonFormblattNeu_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string filename = string.Format("{0}_EU-NoAD-Data-Collecting-Tool-5_0.xlsx", this.Core.Shipname);
|
|
this.ExportData(filename, false);
|
|
}
|
|
|
|
private void ExportData(string filename, bool isRefSheet)
|
|
{
|
|
SaveFileDialog sfd = new SaveFileDialog()
|
|
{
|
|
Filter = "Excel Files|*.xls;*.xlsx",
|
|
FileName = filename
|
|
};
|
|
if (sfd.ShowDialog() ?? false)
|
|
{
|
|
Util.UIHelper.SetBusyState();
|
|
ExcelManager em = new ExcelManager();
|
|
|
|
try
|
|
{
|
|
em.Export(sfd.FileName, this.Core, this.Messages, out string resultMessage, isRefSheet);
|
|
MessageBox.Show("Exported " + sfd.FileName, "Export successful", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
Process.Start(sfd.FileName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Export failed", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonSendAll_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SelectImportClassesDialog sicd = new SelectImportClassesDialog();
|
|
List<Message.NotificationClass> readyToSendMessages = new List<Message.NotificationClass>();
|
|
|
|
// Evaluate a number of criteria for messages that should not be preselected for sending
|
|
bool addToSend;
|
|
foreach (Message message in this.Messages)
|
|
{
|
|
addToSend = true;
|
|
|
|
if ((message.ErrorCount ?? 0) > 0) continue;
|
|
switch(message.MessageNotificationClass)
|
|
{
|
|
case NotificationClass.HAZA:
|
|
addToSend = XtraSendLogic.ShouldSendMessage(message) && ((message.ViolationCount ?? 0) == 0); break;
|
|
case NotificationClass.HAZD:
|
|
addToSend = XtraSendLogic.ShouldSendMessage(message) && ((message.ViolationCount ?? 0) == 0); break;
|
|
case NotificationClass.BPOL:
|
|
if (message.Elements.Count > 0)
|
|
{
|
|
if (message.Elements[0] is BPOL bpol)
|
|
{
|
|
if (bpol.PortOfItineraries.Count == 0) addToSend = false;
|
|
}
|
|
if((message.ViolationCount ?? 0) > 0) addToSend = false;
|
|
}
|
|
break;
|
|
case NotificationClass.WAS:
|
|
if ((message.PositionViolationCount ?? 0) > 0) addToSend = false;
|
|
break;
|
|
case NotificationClass.WAS_RCPT:
|
|
addToSend = false;
|
|
break;
|
|
case NotificationClass.NOA_NOD:
|
|
if ((message.PositionViolationCount ?? 0) > 0) addToSend = false;
|
|
break;
|
|
case NotificationClass.INFO:
|
|
if (Core.PoC == "DEHAM") addToSend = false;
|
|
else addToSend = ((message.ViolationCount ?? 0) > 0);
|
|
break;
|
|
default:
|
|
if((message.ViolationCount ?? 0) > 0) addToSend = false;
|
|
if(Message.IsListClass(message.MessageNotificationClass) && (message.Elements.Count == 0)) addToSend = false;
|
|
|
|
break;
|
|
}
|
|
|
|
if(addToSend)
|
|
readyToSendMessages.Add(message.MessageNotificationClass);
|
|
}
|
|
|
|
sicd.Messages = this.Messages;
|
|
sicd.PreselectedClasses.AddRange(readyToSendMessages);
|
|
sicd.IsTransit = this.Core.IsTransit;
|
|
sicd.IsImportMode = false;
|
|
|
|
if ((sicd.ShowDialog() ?? false) && (sicd.SelectedClasses.Count > 0))
|
|
{
|
|
// now send all selected messages
|
|
List<Message> toSendMessages = new List<Message>();
|
|
foreach(NotificationClass notificationClass in sicd.SelectedClasses)
|
|
{
|
|
Message selectedMessage = this.Messages.Find(x => x.MessageNotificationClass == notificationClass);
|
|
if (selectedMessage != null)
|
|
{
|
|
toSendMessages.Add(selectedMessage);
|
|
}
|
|
}
|
|
if (toSendMessages.Count > 0)
|
|
{
|
|
this.SendMessages(toSendMessages);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|