From 73e729010d020ceff0a27c30c354569236b8810f Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Sun, 17 Dec 2023 17:05:26 +0100 Subject: [PATCH] Automatically open a dialog for an outgoing call after an incoming call was created. The dialog is filled with the defaults of the incoming call, adding two days to ETA to set the ETD. --- src/BreCalClient/BreCalLists.cs | 4 ++-- src/BreCalClient/MainWindow.xaml.cs | 36 +++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/BreCalClient/BreCalLists.cs b/src/BreCalClient/BreCalLists.cs index 49ddbe8..39746cd 100644 --- a/src/BreCalClient/BreCalLists.cs +++ b/src/BreCalClient/BreCalLists.cs @@ -20,10 +20,10 @@ namespace BreCalClient private static readonly List tList = new(); private static readonly List terList = new(); - private static List _berths = new(); + private static readonly List _berths = new(); private static List _allBerths = new(); private static List _participants = new(); - private static List _ships = new(); + private static readonly List _ships = new(); private static List _allShips = new(); private readonly static ConcurrentDictionary _shipLookupDict = new(); diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 34175a2..3a12737 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -180,7 +180,14 @@ namespace BreCalClient private void buttonNew_Click(object sender, RoutedEventArgs e) { - EditShipcallControl esc = new(); + NewWithModel(null); + } + + private void NewWithModel(ShipcallControlModel? model) + { + EditShipcallControl esc = new(); + if (model != null) + esc.ShipcallModel = model; if (esc.ShowDialog() ?? false) { @@ -197,16 +204,37 @@ namespace BreCalClient this._api.ShipcallsPost(esc.ShipcallModel.Shipcall); // save new ship call this.AddShipcall(esc.ShipcallModel); } - catch(Exception ex) + catch (Exception ex) { this.ShowErrorDialog(ex.ToString(), ex.Message); } _refreshImmediately = true; // set flag to avoid timer loop termination _tokenSource.Cancel(); // force timer loop end + + // if this was an arrival, create the matching departure call and open it + if (esc.ShipcallModel.Shipcall?.Type == (int)Extensions.TypeEnum.Incoming) + { + ShipcallControlModel scmOut = new(); + scmOut.Shipcall = new(); + scmOut.Shipcall.Type = (int)Extensions.TypeEnum.Outgoing; + scmOut.Shipcall.ShipId = esc.ShipcallModel.Shipcall.ShipId; + scmOut.Ship = esc.ShipcallModel.Ship; + DateTime eta = esc.ShipcallModel.Shipcall?.Eta ?? DateTime.Now; + scmOut.Shipcall.Etd = eta.AddDays(2); + scmOut.Shipcall.DepartureBerthId = esc.ShipcallModel.Shipcall?.ArrivalBerthId; + if (esc.ShipcallModel.Shipcall != null) + { + scmOut.Shipcall.Participants = new(); + scmOut.Shipcall.Participants.AddRange(esc.ShipcallModel.Shipcall.Participants); + foreach(ParticipantType pType in esc.ShipcallModel.AssignedParticipants.Keys) + scmOut.AssignedParticipants[pType] = esc.ShipcallModel.AssignedParticipants[pType]; + } + NewWithModel(scmOut); + } } - } - } + } + } private void buttonInfo_Click(object sender, RoutedEventArgs e) {