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) {