From 7f011d7dc9308e189366b45d26a0a9ca3720cd37 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 4 Dec 2024 09:34:36 +0100 Subject: [PATCH] fixed init when Port has been preselected but no berth --- src/BreCalClient/EditShipcallControl.xaml.cs | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs index 7d6a0ee..78876c9 100644 --- a/src/BreCalClient/EditShipcallControl.xaml.cs +++ b/src/BreCalClient/EditShipcallControl.xaml.cs @@ -49,8 +49,7 @@ namespace BreCalClient #region Event handler private void Window_Loaded(object sender, RoutedEventArgs e) - { - this.comboBoxAgency.ItemsSource = BreCalLists.Participants_Agent; + { this.comboBoxShip.ItemsSource = BreCalLists.Ships; Array types = Enum.GetValues(typeof(ShipcallType)); @@ -60,10 +59,7 @@ namespace BreCalClient { if (!first) shipcallTypes.Add(shipcallType); else first = false; - } - - this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths; - this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths; + } this.comboBoxTimeRef.ItemsSource = BreCalLists.TimeRefs; this.comboBoxHarbour.ItemsSource = BreCalLists.Ports.Where(x => App.Participant.Ports.Contains(x.Id)); @@ -326,8 +322,8 @@ namespace BreCalClient this.comboBoxTimeRef.SelectedIndex = this.ShipcallModel.Shipcall.TimeRefPoint ?? 1; this.comboBoxCategories.SelectedItem = new EnumToStringConverter().Convert(this.ShipcallModel.Shipcall.Type, typeof(ShipcallType), new object(), System.Globalization.CultureInfo.CurrentCulture); if (this.ShipcallModel.Shipcall.Eta != DateTime.MinValue) - this.datePickerETA.Value = this.ShipcallModel.Shipcall.Eta; - // this.textBoxVoyage.Text = this.ShipcallModel.Shipcall.Voyage; + this.datePickerETA.Value = this.ShipcallModel.Shipcall.Eta; + this.datePickerETD.Value = this.ShipcallModel.Shipcall.Etd; if (BreCalLists.Ships.Find(x => x.Ship.Id == this.ShipcallModel.Shipcall.ShipId) != null) { @@ -338,6 +334,16 @@ namespace BreCalClient } this.checkBoxCancelled.IsChecked = this.ShipcallModel.Shipcall.Canceled ?? false; + if (BreCalLists.PortLookupDict.ContainsKey(this.ShipcallModel.Shipcall.PortId)) + this.comboBoxHarbour.SelectedValue = this.ShipcallModel.Shipcall.PortId; + List availableBerths = BreCalLists.GetBerthsByPort(this.ShipcallModel.Shipcall.PortId); + this.comboBoxArrivalBerth.ItemsSource = availableBerths; + this.comboBoxDepartureBerth.ItemsSource = availableBerths; + + // Filter agency combobox by port + List availableAgencies = BreCalLists.GetParticipants(this.ShipcallModel.Shipcall.PortId, ParticipantType.AGENCY); + this.comboBoxAgency.ItemsSource = availableAgencies; + if (this.ShipcallModel.Shipcall.Type != ShipcallType.Shifting) // incoming, outgoing { this.comboBoxArrivalBerth.SelectedValue = this.ShipcallModel.Shipcall.ArrivalBerthId; @@ -358,9 +364,7 @@ namespace BreCalClient this.comboBoxAgency.SelectedValue = this.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId; } } - - if (BreCalLists.PortLookupDict.ContainsKey(this.ShipcallModel.Shipcall.PortId)) - this.comboBoxHarbour.SelectedValue = this.ShipcallModel.Shipcall.PortId; + this.comboBoxHarbour.SelectionChanged += this.comboBoxHarbour_SelectionChanged; this.comboBoxHarbour.IsEnabled = this.ShipcallModel.AllowPortChange;