Participants can be of multiple types (e.g. agent and terminal), therefore the participant type must be stored in the times data record in order to assign times correctly during display and to differentiate in calculation.
284 lines
15 KiB
C#
284 lines
15 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Show general shipcall info
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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 Construction
|
|
|
|
public ShipcallControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region events
|
|
|
|
public event Action<ShipcallControl>? EditRequested;
|
|
|
|
internal event Action<ShipcallControl, Times?, Extensions.ParticipantType>? EditTimesRequested;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// this is our datasource
|
|
/// </summary>
|
|
public ShipcallControlModel? ShipcallControlModel { get; set; }
|
|
|
|
/// <summary>
|
|
/// these are all participants (currently loaded)
|
|
/// </summary>
|
|
public Dictionary<int, Participant>? ParticipantDict { get; set; }
|
|
|
|
/// <summary>
|
|
/// For berth name lookup
|
|
/// </summary>
|
|
public List<Berth>? Berths {get; set;}
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public void RefreshData()
|
|
{
|
|
if (this.ShipcallControlModel == null) return;
|
|
string agentName = "";
|
|
string? name;
|
|
name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.AGENCY);
|
|
if (name != null) agentName = name;
|
|
this.labelAgent.Content = name ?? "- / -";
|
|
|
|
name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.MOORING);
|
|
this.labelMooring.Content = name ?? "- / -";
|
|
|
|
name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.PILOT);
|
|
this.labelPilot.Content = name ?? "- / - ";
|
|
|
|
name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.TUG);
|
|
this.labelTug.Content = name ?? "- / - ";
|
|
|
|
name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.PORT_ADMINISTRATION);
|
|
this.labelPortAuthority.Content = name ?? "- / - ";
|
|
|
|
name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.TERMINAL);
|
|
this.labelTerminal.Content = name ?? "- / - ";
|
|
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.TERMINAL)))
|
|
{
|
|
this.labelTerminal.FontWeight = FontWeights.Bold;
|
|
this.labelTerminal.Foreground = Brushes.LightYellow;
|
|
}
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.PILOT)))
|
|
{
|
|
this.labelPilot.FontWeight = FontWeights.Bold;
|
|
this.labelPilot.Foreground = Brushes.LightYellow;
|
|
}
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.AGENCY)))
|
|
{
|
|
this.labelAgent.FontWeight = FontWeights.Bold;
|
|
this.labelAgent.Foreground = Brushes.LightYellow;
|
|
}
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.MOORING)))
|
|
{
|
|
this.labelMooring.FontWeight = FontWeights.Bold;
|
|
this.labelMooring.Foreground = Brushes.LightYellow;
|
|
}
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.PORT_ADMINISTRATION)))
|
|
{
|
|
this.labelPortAuthority.FontWeight = FontWeights.Bold;
|
|
this.labelPortAuthority.Foreground = Brushes.LightYellow;
|
|
}
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.TUG)))
|
|
{
|
|
this.labelTug.FontWeight = FontWeights.Bold;
|
|
this.labelTug.Foreground = Brushes.LightYellow;
|
|
}
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) ||
|
|
(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == this.ShipcallControlModel.GetParticipantIdForType(Extensions.ParticipantType.AGENCY))))
|
|
{
|
|
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}";
|
|
this.textBlockAgency.Text = agentName.TruncateDots(10);
|
|
|
|
if (this.ParticipantDict != null)
|
|
{
|
|
if (this.ShipcallControlModel != null)
|
|
{
|
|
foreach (Times times in this.ShipcallControlModel.Times)
|
|
{
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.AGENCY)
|
|
{
|
|
this.labelAgencyETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.labelAgencyETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockAgencyRemarks.Text = times.Remarks;
|
|
}
|
|
if (times.ParticipantType == (int) Extensions.ParticipantType.MOORING)
|
|
{
|
|
this.labelMooringETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.labelMooringETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockMooringRemarks.Text = times.Remarks;
|
|
}
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.PORT_ADMINISTRATION)
|
|
{
|
|
this.labelPortAuthorityETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.labelPortAuthorityETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockPortAuthorityRemarks.Text = times.Remarks;
|
|
}
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.PILOT)
|
|
{
|
|
this.labelPilotETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.labelPilotETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockPilotRemarks.Text = times.Remarks;
|
|
}
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.TUG)
|
|
{
|
|
this.labelTugETA.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.labelTugETD.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockTugRemarks.Text = times.Remarks;
|
|
}
|
|
if (times.ParticipantType == (int)Extensions.ParticipantType.TERMINAL)
|
|
{
|
|
if (this.Berths != null)
|
|
{
|
|
Berth? berth = this.Berths.Find((x) => x.Id == times.BerthId);
|
|
this.labelTerminalBerth.Content = (berth != null) ? berth.Name : "";
|
|
}
|
|
this.labelOperationsStart.Content = times.OperationsStart.HasValue ? times.OperationsStart.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.labelOperationsEnd.Content = times.OperationsEnd.HasValue ? times.OperationsEnd.Value.ToString("dd.MM.yyyy HH:mm") : "- / -";
|
|
this.textBlockTerminalRemarks.Text = times.Remarks;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region event handler
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void buttonEditShipcall_Click(object? sender, RoutedEventArgs? e)
|
|
{
|
|
if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) ||
|
|
(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.AGENCY))))
|
|
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)
|
|
{
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.AGENCY)))
|
|
{
|
|
this.EditRequested?.Invoke(this);
|
|
}
|
|
}
|
|
|
|
private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
{
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.MOORING)))
|
|
{
|
|
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)
|
|
{
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.PORT_ADMINISTRATION)))
|
|
{
|
|
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)
|
|
{
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.PILOT)))
|
|
{
|
|
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)
|
|
{
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.TUG)))
|
|
{
|
|
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)
|
|
{
|
|
if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == this.ShipcallControlModel?.GetParticipantIdForType(Extensions.ParticipantType.TERMINAL)))
|
|
{
|
|
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
|
|
this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TERMINAL);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|