// 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 { /// /// Interaction logic for ShipcallControl.xaml /// 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? EditRequested; public event Action? EditAgencyRequested; internal event Action? EditTimesRequested; #endregion #region Properties /// /// this is our datasource /// 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 ?? "- / -"; _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:,,,/BreCalDevelClient;component/Resources/arrow_down_red.png")); break; case 2: // outgoing this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_up_blue.png")); break; case 3: // 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?.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; this.textBlockBerth.Text = this.ShipcallControlModel?.Berth; this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign; if (this.ShipcallControlModel?.Shipcall?.Type == 1) { this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta?.ToString("dd.MM. HH:mm"); } if ((this.ShipcallControlModel?.Shipcall?.Type == 2) || (this.ShipcallControlModel?.Shipcall?.Type == 3)) { 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; } if (this.ShipcallControlModel != null) { foreach (Times times in this.ShipcallControlModel.Times) { string? berthText = null; if ((BreCalLists.Berths != null) && times.BerthId.HasValue && (this.ShipcallControlModel?.Shipcall?.Type != (int) Extensions.TypeEnum.Shifting)) { Berth? berth = BreCalLists.Berths.Find((x) => x.Id == times.BerthId); berthText = berth?.Name; } if (berthText == null) { if (this.ShipcallControlModel?.Shipcall?.Type == (int)Extensions.TypeEnum.Incoming) { Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel.Shipcall?.ArrivalBerthId); berthText = berth?.Name; } else { Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel?.Shipcall?.DepartureBerthId); 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.labelTerminalBerth.Content = berthText; 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; } } } 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 } }