work on shipcall control

This commit is contained in:
Daniel Schick 2023-08-14 16:00:34 +02:00
parent 7655ebe724
commit 84462aead4
5 changed files with 111 additions and 54 deletions

View File

@ -2,28 +2,17 @@
// Description: Bremen calling main window // Description: Bremen calling main window
// //
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BreCalClient.misc.Api; using BreCalClient.misc.Api;
using BreCalClient.misc.Client; using BreCalClient.misc.Client;
using BreCalClient.misc.Model; using BreCalClient.misc.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace BreCalClient namespace BreCalClient
{ {
@ -145,38 +134,50 @@ namespace BreCalClient
if(selectedSCMModel != null) if(selectedSCMModel != null)
{ {
selectedSCMModel.Shipcall = shipcall; selectedSCMModel.Shipcall = shipcall;
} }
else else
{ {
// no: create new entry // no: create new entry
ShipcallControlModel scm = new ShipcallControlModel(); selectedSCMModel = new ShipcallControlModel();
scm.Shipcall = shipcall; selectedSCMModel.Shipcall = shipcall;
if (this._shipLookupDict.ContainsKey(shipcall.ShipId)) if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
scm.Ship = this._shipLookupDict[shipcall.ShipId]; selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0)) if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))
scm.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name1; selectedSCMModel.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name1;
_controlModels.Add(scm); _controlModels.Add(selectedSCMModel);
this.Dispatcher.Invoke(new Action(() => this.Dispatcher.Invoke(new Action(() =>
{ {
ShipcallControl sc = new ShipcallControl(); ShipcallControl sc = new ShipcallControl();
sc.Height = 120; sc.Height = 120;
sc.ShipcallControlModel = scm; sc.ShipcallControlModel = selectedSCMModel;
sc.TimesRequested += Sc_TimesRequested; sc.TimesRequested += Sc_TimesRequested;
sc.EditRequested += Sc_EditRequested; sc.EditRequested += Sc_EditRequested;
this.stackPanel.Children.Add(sc); this.stackPanel.Children.Add(sc);
})); }));
} }
selectedSCMModel.AssignParticipants(this._participants);
} }
// test for deletion, anything in the display that is not in the lookup result List<ShipcallControl> removeList = new();
foreach(ShipcallControlModel scm in this._controlModels) foreach (ShipcallControlModel scm in this._controlModels)
{ {
if(shipcalls.Find(s => s.Id == scm.Shipcall?.Id) == null)
} {
foreach (ShipcallControl sc in this.stackPanel.Children)
if (sc.ShipcallControlModel?.Shipcall?.Id == scm.Shipcall?.Id)
removeList.Add(sc);
}
}
foreach(ShipcallControl sc in removeList)
{
this.Dispatcher.Invoke(new Action(() =>
{
this.stackPanel.Children.Remove(sc);
}));
}
await Task.Delay(TimeSpan.FromSeconds(SHIPCALL_UPDATE_INTERVAL_SECONDS), _tokenSource.Token); await Task.Delay(TimeSpan.FromSeconds(SHIPCALL_UPDATE_INTERVAL_SECONDS), _tokenSource.Token);
} }

View File

@ -20,15 +20,16 @@
<ColumnDefinition Width=".15*" /> <ColumnDefinition Width=".15*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.Row="0" > <Grid Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height=".125*"/> <RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/> <RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/> <RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".05*"/> <RowDefinition Height=".05*"/>
<RowDefinition Height=".125*"/> <RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/> <RowDefinition Height=".125*"/>
@ -38,25 +39,26 @@
<ColumnDefinition Width=".4*" /> <ColumnDefinition Width=".4*" />
<ColumnDefinition Width=".6*" /> <ColumnDefinition Width=".6*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Viewbox Grid.Row="0" Grid.Column="0" Stretch="Uniform" Grid.RowSpan="2" Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Ship.Name}" Background="#203864" Foreground="White" /> <Label Grid.Row="0" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="2" FontSize="10" Content="{Binding Ship.Name}" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
</Viewbox> HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Viewbox Grid.Row="2" Grid.Column="0">
<Viewbox Grid.Row="1" Grid.Column="0">
<TextBlock Text="IMO" /> <TextBlock Text="IMO" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="2" Grid.Column="1"> <Viewbox Grid.Row="1" Grid.Column="1">
<TextBlock Text="{Binding Ship.Imo}" /> <TextBlock Text="{Binding Ship.Imo}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="3" Grid.Column="0"> <Viewbox Grid.Row="2" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textCallsign}" /> <TextBlock Text="{x:Static p:Resources.textCallsign}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="3" Grid.Column="1"> <Viewbox Grid.Row="2" Grid.Column="1">
<TextBlock Text="{Binding Ship.Callsign}" /> <TextBlock Text="{Binding Ship.Callsign}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="4" Grid.Column="0"> <Viewbox Grid.Row="3" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textLengthWidth}" /> <TextBlock Text="{x:Static p:Resources.textLengthWidth}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="4" Grid.Column="1"> <Viewbox Grid.Row="3" Grid.Column="1">
<TextBlock> <TextBlock>
<TextBlock.Text> <TextBlock.Text>
<MultiBinding StringFormat="{}{0}m/{1}m"> <MultiBinding StringFormat="{}{0}m/{1}m">
@ -66,29 +68,43 @@
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
</Viewbox> </Viewbox>
<Viewbox Grid.Row="6" Grid.Column="0"> <Viewbox Grid.Row="5" Grid.Column="0">
<TextBlock Text="ETA" /> <TextBlock Text="ETA" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="6" Grid.Column="1"> <Viewbox Grid.Row="5" Grid.Column="1">
<TextBlock Text="{Binding Shipcall.Eta}" /> <TextBlock Text="{Binding Shipcall.Eta}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="7" Grid.Column="0"> <Viewbox Grid.Row="6" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textBerth}" /> <TextBlock Text="{x:Static p:Resources.textBerth}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="7" Grid.Column="1"> <Viewbox Grid.Row="6" Grid.Column="1">
<TextBlock Text="{Binding Berth}" /> <TextBlock Text="{Binding Berth}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="8" Grid.Column="0"> <Viewbox Grid.Row="7" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textAgency}" /> <TextBlock Text="{x:Static p:Resources.textAgency}" />
</Viewbox> </Viewbox>
<Viewbox Grid.Row="8" Grid.Column="1"> <Viewbox Grid.Row="7" Grid.Column="1">
<TextBlock Text="{Binding Agency}" /> <TextBlock Text="{Binding Agency}" />
</Viewbox> </Viewbox>
</Grid> </Grid>
<Label Grid.Row="0" Grid.Column="1" Grid.RowSpan="1" FontSize="10" Content="Agent" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="labelAgent"/>
<Label Grid.Row="0" Grid.Column="2" Grid.RowSpan="1" FontSize="10" Content="Mooring" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="labelMooring"/>
<Label Grid.Row="0" Grid.Column="3" Grid.RowSpan="1" FontSize="10" Content="Port authority" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="labelPortAuthority"/>
<Label Grid.Row="0" Grid.Column="4" Grid.RowSpan="1" FontSize="10" Content="Pilot" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="labelPilot"/>
<Label Grid.Row="0" Grid.Column="5" Grid.RowSpan="1" FontSize="10" Content="Tug" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="labelTug"/>
<Label Grid.Row="0" Grid.Column="6" Grid.RowSpan="1" FontSize="10" Content="Terminal" Foreground="White" Background="#203864" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Name="labelTerminal"/>
<!-- Image Margin="2" Grid.Column="3" Grid.Row="0" Grid.RowSpan="3"> <!-- Image Margin="2" Grid.Column="3" Grid.Row="0" Grid.RowSpan="3">
<Image.Style> <Image.Style>
<Style TargetType="Image"> <Style TargetType="Image">

View File

@ -47,6 +47,9 @@ namespace BreCalClient
private void UserControl_Loaded(object sender, RoutedEventArgs e) private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
this.DataContext = this.ShipcallControlModel; this.DataContext = this.ShipcallControlModel;
if (this.ShipcallControlModel == null) return;
this.labelAgent.Content = this.ShipcallControlModel.AssignedParticipants.ContainsKey(8) ? this.ShipcallControlModel.AssignedParticipants[8].Name : string.Empty;
this.labelMooring.Content = this.ShipcallControlModel.AssignedParticipants.ContainsKey(16) ? this.ShipcallControlModel.AssignedParticipants[16].Name : string.Empty;
} }
private void buttonListTimes_Click(object sender, RoutedEventArgs e) private void buttonListTimes_Click(object sender, RoutedEventArgs e)
@ -77,3 +80,20 @@ namespace BreCalClient
} }
} }
/*
* Description("not assigned")]
NONE = 0,
[Description("BSMD")]
BSMD = 1,
[Description("Terminal")]
TERMINAL = 2,
[Description("Lotsen")]
PILOT = 4,
[Description("Agentur")]
AGENCY = 8,
[Description("Festmacher")]
MOORING = 16,
[Description("Hafenamt")]
PORT_ADMINISTRATION = 32,
[Description("Schlepper")]
TUG = 64,*/

View File

@ -4,6 +4,7 @@
using BreCalClient.misc.Model; using BreCalClient.misc.Model;
using System; using System;
using System.Collections.Generic;
namespace BreCalClient namespace BreCalClient
{ {
@ -41,7 +42,23 @@ namespace BreCalClient
public string? Berth { get; set; } public string? Berth { get; set; }
public string Test { get { return "Gurkensalat"; } } public Dictionary<int, Participant> AssignedParticipants { get; } = new();
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;
}
}
}
}
public TrafficLightMode LightMode public TrafficLightMode LightMode
{ {

View File

@ -80,6 +80,8 @@ def PostShipcalls(schemaModel):
new_id = commands.execute_scalar("select last_insert_id()") new_id = commands.execute_scalar("select last_insert_id()")
# add participant assignments # add participant assignments
# TODO: make sure there are not two participants of the same type
pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id) VALUES (?shipcall_id?, ?participant_id?)" pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id) VALUES (?shipcall_id?, ?participant_id?)"
for participant_id in schemaModel["participants"]: for participant_id in schemaModel["participants"]:
commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_id}) commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_id})
@ -135,6 +137,7 @@ def PutShipcalls(schemaModel):
pdata = commands.query(pquery,param={"id" : schemaModel["id"]}) # existing list of assignments pdata = commands.query(pquery,param={"id" : schemaModel["id"]}) # existing list of assignments
# loop across passed participant ids, creating entries for those not present in pdata # loop across passed participant ids, creating entries for those not present in pdata
# TODO: make sure there are not two participants of the same type
for participant_id in schemaModel["participants"]: for participant_id in schemaModel["participants"]:
found_participant = False found_participant = False