327 lines
16 KiB
C#
327 lines
16 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Show general shipcall info
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
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;
|
|
|
|
#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?, Extensions.ParticipantType>? EditTimesRequested;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// this is our datasource
|
|
/// </summary>
|
|
public ShipcallControlModel? ShipcallControlModel { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public void RefreshData()
|
|
{
|
|
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 ?? "- / -";
|
|
|
|
_mooring = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.MOORING);
|
|
name = _mooring?.Name;
|
|
this.labelMooring.Content = name ?? "- / -";
|
|
|
|
_pilot = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PILOT);
|
|
name = _pilot?.Name;
|
|
this.labelPilot.Content = name ?? "- / - ";
|
|
|
|
_tug = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TUG);
|
|
name = _tug?.Name;
|
|
this.labelTug.Content = name ?? "- / - ";
|
|
|
|
_port_administration = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PORT_ADMINISTRATION);
|
|
name = _port_administration?.Name;
|
|
this.labelPortAuthority.Content = name ?? "- / - ";
|
|
|
|
_terminal = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TERMINAL);
|
|
name = _terminal?.Name;
|
|
this.labelTerminal.Content = name ?? "- / - ";
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == _terminal?.Id))
|
|
{
|
|
this.labelTerminal.FontWeight = FontWeights.Bold;
|
|
this.labelTerminal.Foreground = Brushes.LightYellow;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == _pilot?.Id))
|
|
{
|
|
this.labelPilot.FontWeight = FontWeights.Bold;
|
|
this.labelPilot.Foreground = Brushes.LightYellow;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == _mooring?.Id))
|
|
{
|
|
this.labelMooring.FontWeight = FontWeights.Bold;
|
|
this.labelMooring.Foreground = Brushes.LightYellow;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == _port_administration?.Id))
|
|
{
|
|
this.labelPortAuthority.FontWeight = FontWeights.Bold;
|
|
this.labelPortAuthority.Foreground = Brushes.LightYellow;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == _tug?.Id))
|
|
{
|
|
this.labelTug.FontWeight = FontWeights.Bold;
|
|
this.labelTug.Foreground = Brushes.LightYellow;
|
|
}
|
|
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD))
|
|
{
|
|
this.labelShipName.FontWeight = FontWeights.Bold;
|
|
this.labelShipName.Foreground = Brushes.LightYellow;
|
|
}
|
|
|
|
this.labelShipName.Content = this.ShipcallControlModel?.Ship?.Name;
|
|
switch (this.ShipcallControlModel?.Shipcall?.Type)
|
|
{
|
|
case 1: // incoming
|
|
this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_down_red.png"));
|
|
break;
|
|
case 2: // outgoing
|
|
this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_up_blue.png"));
|
|
break;
|
|
case 3: // shifting
|
|
this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_right_green.png"));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
this.textBlockBerth.Text = this.ShipcallControlModel?.Berth;
|
|
this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign;
|
|
if ((this.ShipcallControlModel?.Shipcall?.Type == 1) || (this.ShipcallControlModel?.Shipcall?.Type == 3))
|
|
{
|
|
this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta?.ToString("dd.MM. HH:mm");
|
|
}
|
|
if (this.ShipcallControlModel?.Shipcall?.Type == 2)
|
|
{
|
|
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 != 1)
|
|
{
|
|
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;
|
|
}
|
|
|
|
foreach (Times times in this.ShipcallControlModel.Times)
|
|
{
|
|
string? berthText = null;
|
|
if ((BreCalLists.Berths != null) && times.BerthId.HasValue)
|
|
{
|
|
Berth? berth = BreCalLists.Berths.Find((x) => x.Id == times.BerthId);
|
|
berthText = berth?.Name;
|
|
}
|
|
if (berthText == null)
|
|
{
|
|
if (this.ShipcallControlModel?.Shipcall?.Type == (int)Extensions.TypeEnum.Outgoing)
|
|
{
|
|
Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel.Shipcall?.DepartureBerthId);
|
|
berthText = berth?.Name;
|
|
}
|
|
else
|
|
{
|
|
Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel?.Shipcall?.ArrivalBerthId);
|
|
berthText = berth?.Name;
|
|
}
|
|
}
|
|
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.AGENCY)
|
|
{
|
|
this.labelAgencyBerth.Content = berthText;
|
|
this.labelAgencyETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockAgencyRemarks.Text = times.Remarks;
|
|
this.textBlockAgencyBerthRemarks.Text = times.BerthInfo;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != 1)
|
|
{
|
|
this.labelAgencyETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.MOORING)
|
|
{
|
|
this.labelMooringETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockMooringRemarks.Text = times.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != 1)
|
|
{
|
|
this.labelMooringETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.PORT_ADMINISTRATION)
|
|
{
|
|
this.labelPortAuthorityETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockPortAuthorityRemarks.Text = times.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != 1)
|
|
{
|
|
this.labelPortAuthorityETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.PILOT)
|
|
{
|
|
this.labelPilotETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockPilotRemarks.Text = times.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != 1)
|
|
{
|
|
this.labelPilotETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.TUG)
|
|
{
|
|
this.labelTugETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockTugRemarks.Text = times.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != 1)
|
|
{
|
|
this.labelTugETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
}
|
|
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.TERMINAL)
|
|
{
|
|
this.labelOperationsStart.Content = times.OperationsStart.HasValue ? times.OperationsStart.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockTerminalRemarks.Text = times.Remarks;
|
|
if (this.ShipcallControlModel?.Shipcall?.Type != 1)
|
|
{
|
|
this.labelOperationsStart.Content = times.OperationsEnd.HasValue ? times.OperationsEnd.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
}
|
|
this.textBlockTerminalBerthRemarks.Text = times.BerthInfo;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#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
|
|
|
|
}
|
|
}
|