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
//
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.Client;
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
{
@ -145,38 +134,50 @@ namespace BreCalClient
if(selectedSCMModel != null)
{
selectedSCMModel.Shipcall = shipcall;
selectedSCMModel.Shipcall = shipcall;
}
else
{
// no: create new entry
ShipcallControlModel scm = new ShipcallControlModel();
scm.Shipcall = shipcall;
selectedSCMModel = new ShipcallControlModel();
selectedSCMModel.Shipcall = shipcall;
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))
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(() =>
{
ShipcallControl sc = new ShipcallControl();
sc.Height = 120;
sc.ShipcallControlModel = scm;
sc.ShipcallControlModel = selectedSCMModel;
sc.TimesRequested += Sc_TimesRequested;
sc.EditRequested += Sc_EditRequested;
this.stackPanel.Children.Add(sc);
}));
}
}
selectedSCMModel.AssignParticipants(this._participants);
}
// test for deletion, anything in the display that is not in the lookup result
foreach(ShipcallControlModel scm in this._controlModels)
List<ShipcallControl> removeList = new();
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);
}

View File

@ -20,15 +20,16 @@
<ColumnDefinition Width=".15*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.Row="0" >
<Grid Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" >
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".05*"/>
<RowDefinition Height=".125*"/>
<RowDefinition Height=".125*"/>
@ -38,25 +39,26 @@
<ColumnDefinition Width=".4*" />
<ColumnDefinition Width=".6*" />
</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" />
</Viewbox>
<Viewbox Grid.Row="2" Grid.Column="0">
<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"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Viewbox Grid.Row="1" Grid.Column="0">
<TextBlock Text="IMO" />
</Viewbox>
<Viewbox Grid.Row="2" Grid.Column="1">
<Viewbox Grid.Row="1" Grid.Column="1">
<TextBlock Text="{Binding Ship.Imo}" />
</Viewbox>
<Viewbox Grid.Row="3" Grid.Column="0">
<Viewbox Grid.Row="2" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textCallsign}" />
</Viewbox>
<Viewbox Grid.Row="3" Grid.Column="1">
<Viewbox Grid.Row="2" Grid.Column="1">
<TextBlock Text="{Binding Ship.Callsign}" />
</Viewbox>
<Viewbox Grid.Row="4" Grid.Column="0">
<Viewbox Grid.Row="3" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textLengthWidth}" />
</Viewbox>
<Viewbox Grid.Row="4" Grid.Column="1">
<Viewbox Grid.Row="3" Grid.Column="1">
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}m/{1}m">
@ -66,29 +68,43 @@
</TextBlock.Text>
</TextBlock>
</Viewbox>
<Viewbox Grid.Row="6" Grid.Column="0">
<Viewbox Grid.Row="5" Grid.Column="0">
<TextBlock Text="ETA" />
</Viewbox>
<Viewbox Grid.Row="6" Grid.Column="1">
<Viewbox Grid.Row="5" Grid.Column="1">
<TextBlock Text="{Binding Shipcall.Eta}" />
</Viewbox>
<Viewbox Grid.Row="7" Grid.Column="0">
<Viewbox Grid.Row="6" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textBerth}" />
</Viewbox>
<Viewbox Grid.Row="7" Grid.Column="1">
<Viewbox Grid.Row="6" Grid.Column="1">
<TextBlock Text="{Binding Berth}" />
</Viewbox>
<Viewbox Grid.Row="8" Grid.Column="0">
<Viewbox Grid.Row="7" Grid.Column="0">
<TextBlock Text="{x:Static p:Resources.textAgency}" />
</Viewbox>
<Viewbox Grid.Row="8" Grid.Column="1">
<Viewbox Grid.Row="7" Grid.Column="1">
<TextBlock Text="{Binding Agency}" />
</Viewbox>
</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.Style>
<Style TargetType="Image">

View File

@ -47,6 +47,9 @@ namespace BreCalClient
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
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)
@ -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 System;
using System.Collections.Generic;
namespace BreCalClient
{
@ -41,7 +42,23 @@ namespace BreCalClient
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
{

View File

@ -80,6 +80,8 @@ def PostShipcalls(schemaModel):
new_id = commands.execute_scalar("select last_insert_id()")
# 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?)"
for participant_id in schemaModel["participants"]:
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
# 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"]:
found_participant = False