From e18188cd85c15ba810b4b02791b52bd6d51bb676 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 1 Oct 2024 08:19:11 +0200 Subject: [PATCH] don't allow a changed port when creating departure after a new arrival --- src/BreCalClient/EditShipcallControl.xaml.cs | 29 ++++++++++---------- src/BreCalClient/MainWindow.xaml.cs | 1 + src/BreCalClient/ShipcallControlModel.cs | 2 ++ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs index 8257ad0..fbce9ab 100644 --- a/src/BreCalClient/EditShipcallControl.xaml.cs +++ b/src/BreCalClient/EditShipcallControl.xaml.cs @@ -57,7 +57,7 @@ namespace BreCalClient { if (!first) shipcallTypes.Add(shipcallType); else first = false; - } + } this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths; this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths; @@ -87,21 +87,21 @@ namespace BreCalClient } private void comboBoxShip_SelectionChanged(object sender, SelectionChangedEventArgs e) - { + { if (this.comboBoxShip.SelectedItem != null) { ShipModel? ship = this.comboBoxShip.SelectedItem as ShipModel; this.integerUpDownIMO.Value = ship?.Ship.Imo; this.textBoxCallsign.Text = ship?.Ship.Callsign; this.doubleUpDownLength.Value = ship?.Ship.Length; - this.doubleUpDownWidth.Value = ship?.Ship.Width; + this.doubleUpDownWidth.Value = ship?.Ship.Width; } else { this.integerUpDownIMO.Value = null; this.textBoxCallsign.Text = string.Empty; this.doubleUpDownLength.Value = null; - this.doubleUpDownWidth.Value = null; + this.doubleUpDownWidth.Value = null; } this.CheckForCompletion(); } @@ -119,7 +119,7 @@ namespace BreCalClient { switch (type) { - case ShipcallType.Arrival: + case ShipcallType.Arrival: this.datePickerETD.Visibility = Visibility.Hidden; this.labelETD.Visibility = Visibility.Hidden; this.datePickerETA.Visibility = Visibility.Visible; @@ -176,7 +176,7 @@ namespace BreCalClient this.comboBoxAgency.SelectedIndex = -1; this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.AGENCY); } - + #endregion #region private methods @@ -210,7 +210,7 @@ namespace BreCalClient if(this.datePickerETD.Value.HasValue) isEnabled &= (this.datePickerETD.Value.Value > DateTime.Now); isEnabled &= !this.datePickerETD.Value.IsTooFar(); - break; + break; case ShipcallType.Arrival: isEnabled &= this.comboBoxArrivalBerth.SelectedItem != null; isEnabled &= this.datePickerETA.Value.HasValue; @@ -233,7 +233,7 @@ namespace BreCalClient break; } } - + isEnabled &= this.comboBoxAgency.SelectedItem != null; this.buttonOK.IsEnabled = isEnabled; @@ -255,7 +255,7 @@ namespace BreCalClient { this.ShipcallModel.Shipcall.ArrivalBerthId = (this.comboBoxArrivalBerth.SelectedItem != null) ? ((Berth)this.comboBoxArrivalBerth.SelectedItem).Id : null; this.ShipcallModel.Shipcall.DepartureBerthId = (this.comboBoxDepartureBerth.SelectedItem != null) ? ((Berth)this.comboBoxDepartureBerth.SelectedItem).Id : null; - } + } else // shifting { this.ShipcallModel.Shipcall.DepartureBerthId = (this.comboBoxArrivalBerth.SelectedItem != null) ? ((Berth)this.comboBoxArrivalBerth.SelectedItem).Id : null; @@ -270,11 +270,11 @@ namespace BreCalClient ParticipantAssignment pa = new() { ParticipantId = participant.Id, - + Type = (int)Extensions.ParticipantType.AGENCY }; this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.AGENCY] = pa; - } + } else { // AGENCY was set before and now is set to nothing @@ -351,7 +351,7 @@ namespace BreCalClient } if (this.ShipcallModel.Shipcall.Participants == null) this.ShipcallModel.Shipcall.Participants = new(); - + if(this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY)) { if (BreCalLists.ParticipantLookupDict.ContainsKey(this.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId)) @@ -363,6 +363,7 @@ namespace BreCalClient if (BreCalLists.PortLookupDict.ContainsKey(this.ShipcallModel.Shipcall.PortId)) this.comboBoxHarbour.SelectedValue = this.ShipcallModel.Shipcall.PortId; + this.comboBoxHarbour.IsEnabled = this.ShipcallModel.AllowPortChange; } } @@ -422,7 +423,7 @@ namespace BreCalClient private void comboBoxDepartureBerth_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.CheckForCompletion(); - } + } private void buttonEditShips_Click(object sender, RoutedEventArgs e) { @@ -430,7 +431,7 @@ namespace BreCalClient { ShipApi = this.ShipApi }; - + shipListDialog.ShowDialog(); // reload combobox diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 810300a..7fa3882 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -289,6 +289,7 @@ namespace BreCalClient scmOut.Shipcall.ShipId = esc.ShipcallModel.Shipcall.ShipId; scmOut.Shipcall.PortId = esc.ShipcallModel.Shipcall.PortId; scmOut.Ship = esc.ShipcallModel.Ship; + scmOut.AllowPortChange = false; DateTime eta = esc.ShipcallModel.Shipcall?.Eta ?? DateTime.Now; scmOut.Shipcall.Etd = eta.AddDays(2); scmOut.Shipcall.DepartureBerthId = esc.ShipcallModel.Shipcall?.ArrivalBerthId; diff --git a/src/BreCalClient/ShipcallControlModel.cs b/src/BreCalClient/ShipcallControlModel.cs index 945e3d4..201dec1 100644 --- a/src/BreCalClient/ShipcallControlModel.cs +++ b/src/BreCalClient/ShipcallControlModel.cs @@ -118,6 +118,8 @@ namespace BreCalClient } } + public bool AllowPortChange { get; set; } = true; + #endregion #region public methods