added times controlling but no functions

This commit is contained in:
Daniel Schick 2023-08-21 19:11:23 +02:00
parent ee5420ff5b
commit 8fbb199aaa
5 changed files with 159 additions and 60 deletions

View File

@ -1,10 +1,4 @@
using BreCalClient.misc.Model; using BreCalClient.misc.Model;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
namespace BreCalClient namespace BreCalClient

View File

@ -129,7 +129,7 @@ namespace BreCalClient
if (esc.ShowDialog() ?? false) if (esc.ShowDialog() ?? false)
{ {
// create UI & save new dialog model // create UI & save new dialog model
this.UpdateShipcallUI(esc.Shipcall); this.UpdateShipcallUI(esc.Shipcall, new List<Times>());
this._api.ShipcallsPost(esc.Shipcall); this._api.ShipcallsPost(esc.Shipcall);
} }
} }
@ -230,7 +230,9 @@ namespace BreCalClient
{ {
foreach (Shipcall shipcall in shipcalls) foreach (Shipcall shipcall in shipcalls)
{ {
this.UpdateShipcallUI(shipcall); List<Times> currentTimes = await _api.TimesGetAsync(shipcall.Id);
this.UpdateShipcallUI(shipcall, currentTimes);
} }
List<ShipcallControl> removeList = new(); List<ShipcallControl> removeList = new();
@ -254,7 +256,7 @@ namespace BreCalClient
} }
} }
private void UpdateShipcallUI(Shipcall shipcall) private void UpdateShipcallUI(Shipcall shipcall, List<Times> times)
{ {
ShipcallControlModel? selectedSCMModel = null; ShipcallControlModel? selectedSCMModel = null;
@ -270,13 +272,15 @@ namespace BreCalClient
if (selectedSCMModel != null) if (selectedSCMModel != null)
{ {
selectedSCMModel.Shipcall = shipcall; selectedSCMModel.Shipcall = shipcall;
selectedSCMModel.Times = times;
} }
else else
{ {
// no: create new entry // no: create new entry
selectedSCMModel = new() selectedSCMModel = new()
{ {
Shipcall = shipcall Shipcall = shipcall,
Times = times
}; };
if (this._shipLookupDict.ContainsKey(shipcall.ShipId)) if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId]; selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
@ -291,7 +295,7 @@ namespace BreCalClient
Height = 120, Height = 120,
ShipcallControlModel = selectedSCMModel ShipcallControlModel = selectedSCMModel
}; };
sc.TimesRequested += Sc_TimesRequested; sc.EditTimesRequested += Sc_EditTimesRequested;
sc.EditRequested += Sc_EditRequested; sc.EditRequested += Sc_EditRequested;
this.stackPanel.Children.Add(sc); this.stackPanel.Children.Add(sc);
this._shipCallControlDict[shipcall.Id] = sc; this._shipCallControlDict[shipcall.Id] = sc;
@ -333,9 +337,10 @@ namespace BreCalClient
} }
} }
private void Sc_TimesRequested(ShipcallControl obj) private void Sc_EditTimesRequested(ShipcallControl obj, Times times)
{ {
// TODO: get the shipcall, load and show a list of the times // show a dialog that lets the user create / update times for the given shipcall
} }

View File

@ -46,7 +46,7 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Image Margin="2" Grid.Column="0" PreviewMouseUp="Image_PreviewMouseUp" x:Name="imageShipcallType" /> <Image Margin="2" Grid.Column="0" PreviewMouseUp="Image_PreviewMouseUp" x:Name="imageShipcallType" />
<Label Grid.Column="1" FontSize="10" x:Name="labelShipName" Foreground="White" Background="#203864" VerticalAlignment="Stretch" <Label Grid.Column="1" FontSize="12" x:Name="labelShipName" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" PreviewMouseUp="Image_PreviewMouseUp"/> HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" PreviewMouseUp="Image_PreviewMouseUp"/>
</Grid> </Grid>
<Viewbox Grid.Row="1" Grid.Column="0"> <Viewbox Grid.Row="1" Grid.Column="0">
@ -68,7 +68,7 @@
<TextBlock x:Name="textBlockLengthWidth" /> <TextBlock x:Name="textBlockLengthWidth" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="5" Grid.Column="0"> <Viewbox Grid.Row="5" Grid.Column="0">
<TextBlock Text="ETA" /> <TextBlock Text="ETA" x:Name="labelETA"/>
</Viewbox> </Viewbox>
<Viewbox Grid.Row="5" Grid.Column="1"> <Viewbox Grid.Row="5" Grid.Column="1">
<TextBlock x:Name="textBlockETA" /> <TextBlock x:Name="textBlockETA" />

View File

@ -2,9 +2,11 @@
// Description: Show general shipcall info // Description: Show general shipcall info
// //
using BreCalClient.misc.Model;
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
namespace BreCalClient namespace BreCalClient
@ -28,7 +30,7 @@ namespace BreCalClient
public event Action<ShipcallControl>? EditRequested; public event Action<ShipcallControl>? EditRequested;
public event Action<ShipcallControl>? TimesRequested; public event Action<ShipcallControl, Times>? EditTimesRequested;
public event Action<ShipcallControl>? OpenExtraRequested; public event Action<ShipcallControl>? OpenExtraRequested;
@ -68,6 +70,36 @@ namespace BreCalClient
if (name != null) if (name != null)
this.labelTerminal.Content = name; this.labelTerminal.Content = name;
if(App.Participant.IsFlagSet(Extensions.ParticipantType.TERMINAL)) {
this.labelTerminal.FontWeight = FontWeights.Bold;
this.labelTerminal.Foreground = Brushes.LightYellow;
}
if(App.Participant.IsFlagSet(Extensions.ParticipantType.PILOT))
{
this.labelPilot.FontWeight = FontWeights.Bold;
this.labelPilot.Foreground = Brushes.LightYellow;
}
if(App.Participant.IsFlagSet(Extensions.ParticipantType.AGENCY))
{
this.labelAgent.FontWeight = FontWeights.Bold;
this.labelAgent.Foreground = Brushes.LightYellow;
}
if(App.Participant.IsFlagSet(Extensions.ParticipantType.MOORING))
{
this.labelMooring.FontWeight = FontWeights.Bold;
this.labelMooring.Foreground = Brushes.LightYellow;
}
if(App.Participant.IsFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION))
{
this.labelPortAuthority.FontWeight = FontWeights.Bold;
this.labelPortAuthority.Foreground = Brushes.LightYellow;
}
if (App.Participant.IsFlagSet(Extensions.ParticipantType.TUG))
{
this.labelTug.FontWeight = FontWeights.Bold;
this.labelTug.Foreground = Brushes.LightYellow;
}
this.labelShipName.Content = this.ShipcallControlModel?.Ship?.Name; this.labelShipName.Content = this.ShipcallControlModel?.Ship?.Name;
switch(this.ShipcallControlModel?.Shipcall?.Type) switch(this.ShipcallControlModel?.Shipcall?.Type)
{ {
@ -86,7 +118,16 @@ namespace BreCalClient
this.textBlockAgency.Text = this.ShipcallControlModel?.Agency; this.textBlockAgency.Text = this.ShipcallControlModel?.Agency;
this.textBlockBerth.Text = this.ShipcallControlModel?.Berth; this.textBlockBerth.Text = this.ShipcallControlModel?.Berth;
this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign; this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign;
if ((this.ShipcallControlModel?.Shipcall?.Type == 1) || (this.ShipcallControlModel?.Shipcall?.Type == 3))
{
this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta.ToString(); this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta.ToString();
}
if(this.ShipcallControlModel?.Shipcall?.Type == 2)
{
this.labelETA.Text = "ETD";
this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Etd.ToString();
}
this.textBlockIMO.Text = this.ShipcallControlModel?.Ship?.Imo.ToString(); this.textBlockIMO.Text = this.ShipcallControlModel?.Ship?.Imo.ToString();
this.textBlockLengthWidth.Text = $"{this.ShipcallControlModel?.Ship?.Length} / {this.ShipcallControlModel?.Ship?.Width}"; this.textBlockLengthWidth.Text = $"{this.ShipcallControlModel?.Ship?.Length} / {this.ShipcallControlModel?.Ship?.Width}";
@ -101,11 +142,6 @@ namespace BreCalClient
} }
private void buttonListTimes_Click(object sender, RoutedEventArgs e)
{
this.TimesRequested?.Invoke(this);
}
private void buttonEditShipcall_Click(object sender, RoutedEventArgs e) private void buttonEditShipcall_Click(object sender, RoutedEventArgs e)
{ {
this.EditRequested?.Invoke(this); this.EditRequested?.Invoke(this);
@ -116,41 +152,84 @@ namespace BreCalClient
this.OpenExtraRequested?.Invoke(this); this.OpenExtraRequested?.Invoke(this);
} }
#endregion
private void labelAgent_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
}
private void Image_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void Image_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
this.EditRequested?.Invoke(this); this.EditRequested?.Invoke(this);
} }
private void labelAgent_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (App.Participant.IsFlagSet(Extensions.ParticipantType.AGENCY))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
}
}
private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsFlagSet(Extensions.ParticipantType.MOORING))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING);
if(times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
}
} }
private void labelPortAuthority_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelPortAuthority_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
}
} }
private void labelPilot_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelPilot_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsFlagSet(Extensions.ParticipantType.PILOT))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
}
} }
private void labelTug_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelTug_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsFlagSet(Extensions.ParticipantType.TUG))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
}
} }
private void labelTerminal_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) private void labelTerminal_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{ {
if (App.Participant.IsFlagSet(Extensions.ParticipantType.TERMINAL))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
}
}
#endregion
} }
} }
}

View File

@ -2,12 +2,9 @@
// Description: Container model for shipcall related info // Description: Container model for shipcall related info
// //
using BreCalClient.misc.Client;
using BreCalClient.misc.Model; using BreCalClient.misc.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace BreCalClient namespace BreCalClient
{ {
@ -42,6 +39,8 @@ namespace BreCalClient
#endregion #endregion
#region Properties
public Shipcall? Shipcall { get; set; } public Shipcall? Shipcall { get; set; }
public Ship? Ship { get; set; } public Ship? Ship { get; set; }
@ -51,21 +50,7 @@ namespace BreCalClient
public Dictionary<int, Participant> AssignedParticipants { get; } = new(); public Dictionary<int, Participant> AssignedParticipants { get; } = new();
public void AssignParticipants(List<Participant> participants) public List<Times> Times { get; set; } = new();
{
this.AssignedParticipants.Clear();
if (Shipcall != null)
{
foreach (int participantId in Shipcall.Participants)
{
foreach(Participant participant in participants)
{
if(participant.Id == participantId)
AssignedParticipants[participant.Type] = participant;
}
}
}
}
public TrafficLightMode LightMode public TrafficLightMode LightMode
{ {
@ -91,6 +76,44 @@ namespace BreCalClient
} }
} }
#endregion
#region public methods
public void AssignParticipants(List<Participant> participants)
{
this.AssignedParticipants.Clear();
if (Shipcall != null)
{
foreach (int participantId in Shipcall.Participants)
{
foreach(Participant participant in participants)
{
if(participant.Id == participantId)
AssignedParticipants[participant.Type] = participant;
}
}
}
}
internal Times? GetTimesForParticipantType(Extensions.ParticipantType type)
{
if (AssignedParticipants.ContainsKey((int)type)) {
int participantId = AssignedParticipants[(int)type].Id;
foreach (Times times in this.Times)
{
if (times.ParticipantId == participantId)
return times;
}
}
return null;
}
#endregion
#region helper
internal string? GetParticipantNameForType(Extensions.ParticipantType participantType) internal string? GetParticipantNameForType(Extensions.ParticipantType participantType)
{ {
foreach(Participant p in AssignedParticipants.Values) foreach(Participant p in AssignedParticipants.Values)
@ -101,8 +124,6 @@ namespace BreCalClient
return null; return null;
} }
#region private helper
private bool IsFlagSet(StatusFlags flag) private bool IsFlagSet(StatusFlags flag)
{ {
if(this.Shipcall == null) return false; if(this.Shipcall == null) return false;