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.
This commit is contained in:
Daniel Schick 2023-12-17 17:05:26 +01:00
parent 24757c1702
commit 73e729010d
2 changed files with 34 additions and 6 deletions

View File

@ -20,10 +20,10 @@ namespace BreCalClient
private static readonly List<Participant> tList = new();
private static readonly List<Participant> terList = new();
private static List<Berth> _berths = new();
private static readonly List<Berth> _berths = new();
private static List<Berth> _allBerths = new();
private static List<Participant> _participants = new();
private static List<Ship> _ships = new();
private static readonly List<Ship> _ships = new();
private static List<Ship> _allShips = new();
private readonly static ConcurrentDictionary<int, Ship> _shipLookupDict = new();

View File

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