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 System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace BreCalClient

View File

@ -129,7 +129,7 @@ namespace BreCalClient
if (esc.ShowDialog() ?? false)
{
// create UI & save new dialog model
this.UpdateShipcallUI(esc.Shipcall);
this.UpdateShipcallUI(esc.Shipcall, new List<Times>());
this._api.ShipcallsPost(esc.Shipcall);
}
}
@ -230,7 +230,9 @@ namespace BreCalClient
{
foreach (Shipcall shipcall in shipcalls)
{
this.UpdateShipcallUI(shipcall);
List<Times> currentTimes = await _api.TimesGetAsync(shipcall.Id);
this.UpdateShipcallUI(shipcall, currentTimes);
}
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;
@ -270,13 +272,15 @@ namespace BreCalClient
if (selectedSCMModel != null)
{
selectedSCMModel.Shipcall = shipcall;
selectedSCMModel.Times = times;
}
else
{
// no: create new entry
selectedSCMModel = new()
{
Shipcall = shipcall
Shipcall = shipcall,
Times = times
};
if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
@ -291,7 +295,7 @@ namespace BreCalClient
Height = 120,
ShipcallControlModel = selectedSCMModel
};
sc.TimesRequested += Sc_TimesRequested;
sc.EditTimesRequested += Sc_EditTimesRequested;
sc.EditRequested += Sc_EditRequested;
this.stackPanel.Children.Add(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="*" />
</Grid.ColumnDefinitions>
<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"/>
</Grid>
<Viewbox Grid.Row="1" Grid.Column="0">
@ -68,7 +68,7 @@
<TextBlock x:Name="textBlockLengthWidth" />
</Viewbox>
<Viewbox Grid.Row="5" Grid.Column="0">
<TextBlock Text="ETA" />
<TextBlock Text="ETA" x:Name="labelETA"/>
</Viewbox>
<Viewbox Grid.Row="5" Grid.Column="1">
<TextBlock x:Name="textBlockETA" />

View File

@ -2,9 +2,11 @@
// Description: Show general shipcall info
//
using BreCalClient.misc.Model;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace BreCalClient
@ -28,7 +30,7 @@ namespace BreCalClient
public event Action<ShipcallControl>? EditRequested;
public event Action<ShipcallControl>? TimesRequested;
public event Action<ShipcallControl, Times>? EditTimesRequested;
public event Action<ShipcallControl>? OpenExtraRequested;
@ -68,6 +70,36 @@ namespace BreCalClient
if (name != null)
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;
switch(this.ShipcallControlModel?.Shipcall?.Type)
{
@ -86,7 +118,16 @@ namespace BreCalClient
this.textBlockAgency.Text = this.ShipcallControlModel?.Agency;
this.textBlockBerth.Text = this.ShipcallControlModel?.Berth;
this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign;
this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta.ToString();
if ((this.ShipcallControlModel?.Shipcall?.Type == 1) || (this.ShipcallControlModel?.Shipcall?.Type == 3))
{
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.textBlockLengthWidth.Text = $"{this.ShipcallControlModel?.Ship?.Length} / {this.ShipcallControlModel?.Ship?.Width}";
@ -99,11 +140,6 @@ namespace BreCalClient
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
}
private void buttonListTimes_Click(object sender, RoutedEventArgs e)
{
this.TimesRequested?.Invoke(this);
}
private void buttonEditShipcall_Click(object sender, RoutedEventArgs e)
@ -114,43 +150,86 @@ namespace BreCalClient
private void buttonOpenDropDown_Click(object sender, RoutedEventArgs e)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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
//
using BreCalClient.misc.Client;
using BreCalClient.misc.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace BreCalClient
{
@ -38,10 +35,12 @@ namespace BreCalClient
YELLOW,
BLINK_1,
BLINK_2
};
};
#endregion
#region Properties
public Shipcall? Shipcall { get; set; }
public Ship? Ship { get; set; }
@ -51,6 +50,36 @@ namespace BreCalClient
public Dictionary<int, Participant> AssignedParticipants { get; } = new();
public List<Times> Times { get; set; } = new();
public TrafficLightMode LightMode
{
get
{
if (IsFlagSet(StatusFlags.RED))
{
if (IsFlagSet((StatusFlags)StatusFlags.YELLOW))
{
if (IsFlagSet(StatusFlags.GREEN))
{
return TrafficLightMode.ALL;
}
return TrafficLightMode.RED_YELLOW;
}
return TrafficLightMode.RED;
}
if (IsFlagSet(StatusFlags.YELLOW))
return TrafficLightMode.YELLOW;
if (IsFlagSet(StatusFlags.GREEN))
return TrafficLightMode.GREEN;
return TrafficLightMode.OFF;
}
}
#endregion
#region public methods
public void AssignParticipants(List<Participant> participants)
{
this.AssignedParticipants.Clear();
@ -67,30 +96,24 @@ namespace BreCalClient
}
}
public TrafficLightMode LightMode
internal Times? GetTimesForParticipantType(Extensions.ParticipantType type)
{
get
{
if(IsFlagSet(StatusFlags.RED))
if (AssignedParticipants.ContainsKey((int)type)) {
int participantId = AssignedParticipants[(int)type].Id;
foreach (Times times in this.Times)
{
if(IsFlagSet((StatusFlags)StatusFlags.YELLOW))
{
if(IsFlagSet(StatusFlags.GREEN))
{
return TrafficLightMode.ALL;
}
return TrafficLightMode.RED_YELLOW;
}
return TrafficLightMode.RED;
if (times.ParticipantId == participantId)
return times;
}
if(IsFlagSet(StatusFlags.YELLOW))
return TrafficLightMode.YELLOW;
if(IsFlagSet(StatusFlags.GREEN))
return TrafficLightMode.GREEN;
return TrafficLightMode.OFF;
}
return null;
}
#endregion
#region helper
internal string? GetParticipantNameForType(Extensions.ParticipantType participantType)
{
foreach(Participant p in AssignedParticipants.Values)
@ -99,9 +122,7 @@ namespace BreCalClient
return p.Name;
}
return null;
}
#region private helper
}
private bool IsFlagSet(StatusFlags flag)
{