482 lines
24 KiB
C#
482 lines
24 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Show general shipcall info
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using log4net;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ShipcallControl.xaml
|
|
/// </summary>
|
|
public partial class ShipcallControl : UserControl
|
|
{
|
|
#region Fields
|
|
|
|
Participant? _agency;
|
|
Participant? _pilot;
|
|
Participant? _mooring;
|
|
Participant? _terminal;
|
|
Participant? _tug;
|
|
Participant? _port_administration;
|
|
private static readonly ILog _log = LogManager.GetLogger(typeof(ShipcallControl));
|
|
|
|
#endregion
|
|
|
|
#region Construction
|
|
|
|
public ShipcallControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region events
|
|
|
|
public event Action<ShipcallControl>? EditRequested;
|
|
|
|
public event Action<ShipcallControl, Times?>? EditAgencyRequested;
|
|
|
|
internal event Action<ShipcallControl, Times?, ParticipantType>? EditTimesRequested;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// this is our datasource
|
|
/// </summary>
|
|
public ShipcallControlModel? ShipcallControlModel { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public void RefreshData()
|
|
{
|
|
try
|
|
{
|
|
if (this.ShipcallControlModel != null)
|
|
{
|
|
string agentName = "";
|
|
string? name;
|
|
_agency = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.AGENCY);
|
|
name = _agency?.Name;
|
|
if (name != null) agentName = name;
|
|
this.labelAgent.Content = name ?? "- / -";
|
|
if(_agency == null)
|
|
{
|
|
// clear agency display controls
|
|
this.labelAgencyBerth.Content = "";
|
|
this.labelAgencyETAETDValue.Content = "";
|
|
this.textBlockAgencyRemarks.Text = "";
|
|
this.textBlockAgencyBerthRemarks.Text = "";
|
|
}
|
|
|
|
_mooring = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.MOORING);
|
|
name = _mooring?.Name;
|
|
this.labelMooring.Content = name ?? "- / -";
|
|
if(_mooring == null)
|
|
{
|
|
this.labelMooringETAETDValue.Content = "";
|
|
this.textBlockMooringRemarks.Text = "";
|
|
}
|
|
|
|
_pilot = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PILOT);
|
|
name = _pilot?.Name;
|
|
this.labelPilot.Content = name ?? "- / - ";
|
|
if(_pilot == null)
|
|
{
|
|
this.labelPilotETAETDValue.Content = "";
|
|
this.textBlockPilotRemarks.Text = "";
|
|
}
|
|
|
|
_tug = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TUG);
|
|
name = _tug?.Name;
|
|
this.labelTug.Content = name ?? "- / - ";
|
|
if(_tug == null)
|
|
{
|
|
this.labelTugETAETDValue.Content = "";
|
|
this.textBlockTugRemarks.Text = "";
|
|
}
|
|
|
|
_port_administration = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PORT_ADMINISTRATION);
|
|
name = _port_administration?.Name;
|
|
this.labelPortAuthority.Content = name ?? "- / - ";
|
|
if(_port_administration == null)
|
|
{
|
|
this.labelPortAuthorityETAETDValue.Content = "";
|
|
this.textBlockPortAuthorityRemarks.Text = "";
|
|
}
|
|
|
|
_terminal = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TERMINAL);
|
|
name = _terminal?.Name;
|
|
this.labelTerminal.Content = name ?? "- / - ";
|
|
if(_terminal == null)
|
|
{
|
|
this.textBlockTerminalRemarks.Text = "";
|
|
this.textBlockTerminalBerthRemarks.Text = "";
|
|
this.labelTerminalBerth.Content = "";
|
|
this.labelOperationsStart.Content = "";
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == _terminal?.Id))
|
|
{
|
|
this.labelTerminal.FontWeight = FontWeights.Bold;
|
|
this.labelTerminal.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelTerminal.FontWeight = FontWeights.Normal;
|
|
this.labelTerminal.Foreground = Brushes.White;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == _pilot?.Id))
|
|
{
|
|
this.labelPilot.FontWeight = FontWeights.Bold;
|
|
this.labelPilot.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelPilot.FontWeight = FontWeights.Normal;
|
|
this.labelPilot.Foreground = Brushes.White;
|
|
}
|
|
|
|
if ((App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == _agency?.Id)) ||
|
|
(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) && (_agency != null) && _agency.IsFlagSet(Extensions.ParticipantFlag.ALLOW_BSMD)))
|
|
{
|
|
this.labelAgent.FontWeight = FontWeights.Bold;
|
|
this.labelAgent.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelAgent.FontWeight = FontWeights.Normal;
|
|
this.labelAgent.Foreground = Brushes.White;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == _mooring?.Id))
|
|
{
|
|
this.labelMooring.FontWeight = FontWeights.Bold;
|
|
this.labelMooring.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelMooring.FontWeight = FontWeights.Normal;
|
|
this.labelMooring.Foreground = Brushes.White;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == _port_administration?.Id))
|
|
{
|
|
this.labelPortAuthority.FontWeight = FontWeights.Bold;
|
|
this.labelPortAuthority.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelPortAuthority.FontWeight = FontWeights.Normal;
|
|
this.labelPortAuthority.Foreground = Brushes.White;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == _tug?.Id))
|
|
{
|
|
this.labelTug.FontWeight = FontWeights.Bold;
|
|
this.labelTug.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelTug.FontWeight = FontWeights.Normal;
|
|
this.labelTug.Foreground = Brushes.White;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD))
|
|
{
|
|
this.labelShipName.FontWeight = FontWeights.Bold;
|
|
this.labelShipName.Foreground = Brushes.LightYellow;
|
|
}
|
|
else
|
|
{
|
|
this.labelShipName.FontWeight = FontWeights.Normal;
|
|
this.labelShipName.Foreground = Brushes.White;
|
|
}
|
|
|
|
this.textBlockShipName.Text = this.ShipcallControlModel?.Ship?.Name;
|
|
// this.labelShipName.Content = this.ShipcallControlModel?.Ship?.Name;
|
|
switch (this.ShipcallControlModel?.Shipcall?.Type)
|
|
{
|
|
case ShipcallType.Arrival: // incoming
|
|
this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_down_red.png"));
|
|
break;
|
|
case ShipcallType.Departure: // outgoing
|
|
this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_up_blue.png"));
|
|
break;
|
|
case ShipcallType.Shifting: // shifting
|
|
this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_right_green.png"));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
switch(this.ShipcallControlModel?.LightMode)
|
|
{
|
|
case ShipcallControlModel.TrafficLightMode.GREEN:
|
|
this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/check.png"));
|
|
break;
|
|
case ShipcallControlModel.TrafficLightMode.YELLOW:
|
|
this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/sign_warning.png"));
|
|
break;
|
|
case ShipcallControlModel.TrafficLightMode.RED:
|
|
this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/delete2.png"));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (this.ShipcallControlModel?.Shipcall?.Canceled ?? false)
|
|
{
|
|
this.Background = Brushes.LightGray;
|
|
//this.Foreground = Brushes.DarkGray;
|
|
this.labelShipName.Foreground = Brushes.LightGray;
|
|
this.textBlockShipName.TextDecorations.Add(TextDecorations.Strikethrough);
|
|
}
|
|
else
|
|
{
|
|
if (this.ShipcallControlModel?.Shipcall?.Evaluation != null)
|
|
{
|
|
ShipcallControlModel.TrafficLightMode resultColor = (ShipcallControlModel.TrafficLightMode)(this.ShipcallControlModel?.Shipcall?.Evaluation ?? 0); // der nullable Operator hier ist so doof, die VS validation blickts einfach nicht
|
|
switch (resultColor)
|
|
{
|
|
//case ShipcallControlModel.TrafficLightMode.GREEN:
|
|
// this.Background = Brushes.LightGreen;
|
|
// break;
|
|
case ShipcallControlModel.TrafficLightMode.YELLOW:
|
|
this.Background = Brushes.LightYellow;
|
|
break;
|
|
case ShipcallControlModel.TrafficLightMode.RED:
|
|
this.Background = new SolidColorBrush(Color.FromArgb(200, 255, 100, 100));
|
|
break;
|
|
default:
|
|
this.Background = Brushes.Transparent;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(this.ShipcallControlModel?.Shipcall?.EvaluationMessage))
|
|
this.imageEvaluation.ToolTip = this.ShipcallControlModel?.Shipcall?.EvaluationMessage;
|
|
else
|
|
this.imageEvaluation.ToolTip = null;
|
|
|
|
this.textBlockBerth.Text = this.ShipcallControlModel?.Berth;
|
|
this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type == ShipcallType.Arrival)
|
|
{
|
|
this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta?.ToString("dd.MM. HH:mm");
|
|
}
|
|
if ((this.ShipcallControlModel?.Shipcall?.Type == ShipcallType.Departure) || (this.ShipcallControlModel?.Shipcall?.Type == ShipcallType.Shifting))
|
|
{
|
|
this.labelETA.Text = "ETD";
|
|
this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Etd?.ToString("dd.MM. HH:mm");
|
|
}
|
|
|
|
this.textBlockIMO.Text = this.ShipcallControlModel?.Ship?.Imo.ToString();
|
|
this.textBlockLengthWidth.Text = $"{this.ShipcallControlModel?.Ship?.Length} / {this.ShipcallControlModel?.Ship?.Width}";
|
|
|
|
// rename labels if this is not an incoming
|
|
// must be here because there may not be a times record for each participant (yet)
|
|
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelETAETDAgent.Content = "ETD";
|
|
this.labelETAETDMooring.Content = "ETD";
|
|
this.labelETAETDPilot.Content = "ETD";
|
|
this.labelETAETDPortAuthority.Content = "ETD";
|
|
this.labelETAETDTug.Content = "ETD";
|
|
this.labelETAETDTerminal.Content = BreCalClient.Resources.Resources.textOperationsEnd;
|
|
}
|
|
|
|
if (this.ShipcallControlModel != null)
|
|
{
|
|
|
|
Times? agencyTimes = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
|
|
if (agencyTimes != null)
|
|
{
|
|
this.labelAgencyBerth.Content = this.ShipcallControlModel?.GetBerthText(agencyTimes);
|
|
this.labelAgencyETAETDValue.Content = agencyTimes.EtaBerth.HasValue ? agencyTimes.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockAgencyRemarks.Text = agencyTimes.Remarks;
|
|
this.textBlockAgencyBerthRemarks.Text = agencyTimes.BerthInfo;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelAgencyETAETDValue.Content = agencyTimes.EtdBerth.HasValue ? agencyTimes.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// no agency times set (yet)
|
|
this.labelAgencyBerth.Content = "";
|
|
this.labelAgencyETAETDValue.Content = "- / -";
|
|
this.textBlockAgencyRemarks.Text = "";
|
|
this.textBlockAgencyBerthRemarks.Text = "";
|
|
}
|
|
|
|
Times? mooringTimes = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING);
|
|
if (mooringTimes != null)
|
|
{
|
|
|
|
this.labelMooringETAETDValue.Content = mooringTimes.EtaBerth.HasValue ? mooringTimes.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockMooringRemarks.Text = mooringTimes.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelMooringETAETDValue.Content = mooringTimes.EtdBerth.HasValue ? mooringTimes.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.labelMooringETAETDValue.Content = "- / ";
|
|
this.textBlockMooringRemarks.Text = "";
|
|
}
|
|
|
|
Times? portAuthorityTimes = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION);
|
|
if (portAuthorityTimes != null)
|
|
{
|
|
this.labelPortAuthorityETAETDValue.Content = portAuthorityTimes.EtaBerth.HasValue ? portAuthorityTimes.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockPortAuthorityRemarks.Text = portAuthorityTimes.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelPortAuthorityETAETDValue.Content = portAuthorityTimes.EtdBerth.HasValue ? portAuthorityTimes.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.labelPortAuthorityETAETDValue.Content = "- / -";
|
|
this.textBlockPortAuthorityRemarks.Text = "";
|
|
}
|
|
|
|
Times? pilotTimes = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT);
|
|
if (pilotTimes != null)
|
|
{
|
|
this.labelPilotETAETDValue.Content = pilotTimes.EtaBerth.HasValue ? pilotTimes.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockPilotRemarks.Text = pilotTimes.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelPilotETAETDValue.Content = pilotTimes.EtdBerth.HasValue ? pilotTimes.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.labelPilotETAETDValue.Content = "- / -";
|
|
this.textBlockPilotRemarks.Text = "";
|
|
}
|
|
|
|
Times? tugTimes = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG);
|
|
if (tugTimes != null)
|
|
{
|
|
this.labelTugETAETDValue.Content = tugTimes.EtaBerth.HasValue ? tugTimes.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockTugRemarks.Text = tugTimes.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelTugETAETDValue.Content = tugTimes.EtdBerth.HasValue ? tugTimes.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.labelTugETAETDValue.Content = "- / -";
|
|
this.textBlockTugRemarks.Text = "";
|
|
}
|
|
|
|
Times? terminalTimes = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
|
|
if (terminalTimes != null)
|
|
{
|
|
this.labelTerminalBerth.Content = this.ShipcallControlModel?.GetBerthText(terminalTimes);
|
|
this.labelOperationsStart.Content = terminalTimes.OperationsStart.HasValue ? terminalTimes.OperationsStart.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockTerminalRemarks.Text = terminalTimes.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.labelOperationsStart.Content = terminalTimes.OperationsEnd.HasValue ? terminalTimes.OperationsEnd.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
this.textBlockTerminalBerthRemarks.Text = terminalTimes.BerthInfo;
|
|
}
|
|
else
|
|
{
|
|
this.labelTerminalBerth.Content = "";
|
|
this.labelOperationsStart.Content = "";
|
|
this.textBlockTerminalRemarks.Text = "";
|
|
this.textBlockTerminalBerthRemarks.Text = "";
|
|
}
|
|
|
|
}
|
|
this.DataContext = this.ShipcallControlModel;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_log.ErrorFormat("Something went wrong during data refresh: {0}", ex.ToString());
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region event handler
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
// TBD
|
|
}
|
|
|
|
private void buttonEditShipcall_Click(object? sender, RoutedEventArgs? e)
|
|
{
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD))
|
|
this.EditRequested?.Invoke(this);
|
|
}
|
|
|
|
private void Image_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
this.buttonEditShipcall_Click(null, null);
|
|
}
|
|
|
|
private void labelAgent_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
|
|
this.EditAgencyRequested?.Invoke(this, times);
|
|
}
|
|
|
|
private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING);
|
|
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.MOORING);
|
|
}
|
|
|
|
private void labelPortAuthority_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION);
|
|
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PORT_ADMINISTRATION);
|
|
}
|
|
|
|
private void labelPilot_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT);
|
|
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PILOT);
|
|
}
|
|
|
|
private void labelTug_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG);
|
|
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TUG);
|
|
}
|
|
|
|
private void labelTerminal_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
|
|
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TERMINAL);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|