Work in progress, edit dialog completed, saving new elements works

This commit is contained in:
Daniel Schick 2023-08-23 09:38:44 +02:00
parent 8fbb199aaa
commit f255b16ff4
11 changed files with 386 additions and 43 deletions

View File

@ -0,0 +1,55 @@
<Window x:Class="BreCalClient.EditTimesControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BreCalClient"
xmlns:p = "clr-namespace:BreCalClient.Resources"
xmlns:db="clr-namespace:BreCalClient;assembly=BreCalClient"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="{x:Static p:Resources.textEditTimes}" Height="320" Width="400" Loaded="Window_Loaded" ResizeMode="NoResize" Icon="Resources/containership.ico">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".25*" />
<ColumnDefinition Width=".75*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="28" />
<RowDefinition Height="56" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="2" Content="{x:Static p:Resources.textFixed}" />
<Label Grid.Row="1" Grid.Column="0" Content="{x:Static p:Resources.textETABerth}" HorizontalContentAlignment="Right" />
<Label Grid.Row="2" Grid.Column="0" Content="{x:Static p:Resources.textETDBerth}" HorizontalContentAlignment="Right" />
<Label Grid.Row="3" Grid.Column="0" Content="{x:Static p:Resources.textLockTime}" HorizontalContentAlignment="Right" />
<Label Grid.Row="4" Grid.Column="0" Content="{x:Static p:Resources.textZoneEntryTime}" HorizontalContentAlignment="Right" />
<Label Grid.Row="5" Grid.Column="0" Content="{x:Static p:Resources.textOperationsStart}" HorizontalContentAlignment="Right" />
<Label Grid.Row="6" Grid.Column="0" Content="{x:Static p:Resources.textOperationsEnd}" HorizontalContentAlignment="Right" />
<Label Grid.Row="7" Grid.Column="0" Content="{x:Static p:Resources.textRemarks}" HorizontalContentAlignment="Right" />
<xctk:DateTimePicker IsEnabled="False" Grid.Row="1" Grid.Column="1" Margin="2" Name="datePickerETABerth" />
<CheckBox IsEnabled="False" Grid.Row="1" Grid.Column="2" Margin="4,0,0,0" Name="checkBoxEtaBerthFixed" VerticalAlignment="Center" />
<xctk:DateTimePicker IsEnabled="False" Grid.Row="2" Grid.Column="1" Margin="2" Name="datePickerETDBerth" />
<CheckBox IsEnabled="False" Grid.Row="2" Grid.Column="2" Margin="4,0,0,0" Name="checkBoxEtDBerthFixed" VerticalAlignment="Center" />
<xctk:DateTimePicker IsEnabled="False" Grid.Row="3" Grid.Column="1" Margin="2" Name="datePickerLockTime" />
<CheckBox IsEnabled="False" Grid.Row="3" Grid.Column="2" Margin="4,0,0,0" Name="checkBoxLockTimeFixed" VerticalAlignment="Center" />
<xctk:DateTimePicker IsEnabled="False" Grid.Row="4" Grid.Column="1" Margin="2" Name="datePickerZoneEntry" />
<CheckBox IsEnabled="False" Grid.Row="4" Grid.Column="2" Margin="4,0,0,0" Name="checkBoxZoneEntryFixed" VerticalAlignment="Center" />
<xctk:DateTimePicker IsEnabled="False" Grid.Row="5" Grid.Column="1" Margin="2" Name="datePickerOperationStart" />
<xctk:DateTimePicker IsEnabled="False" Grid.Row="6" Grid.Column="1" Margin="2" Name="datePickerOperationEnd" />
<TextBox Grid.Row="7" Grid.Column="1" Margin="2" Name="textBoxRemarks" TextWrapping="Wrap" AcceptsReturn="True" SpellCheck.IsEnabled="True" AcceptsTab="True" />
<StackPanel Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width= "80" Margin="2" Content="{x:Static p:Resources.textOK}" x:Name="buttonOK" Click="buttonOK_Click" />
<Button Width="80" Margin="2" Content="{x:Static p:Resources.textCancel}" x:Name="buttonCancel" Click="buttonCancel_Click"/>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,114 @@
// Copyright (c) 2023 schick Informatik
// Description: Single dialog to edit times for all participant types
// (we might use different controls at a later time)
//
using BreCalClient.misc.Model;
using System.Windows;
namespace BreCalClient
{
/// <summary>
/// Interaction logic for EditTimesControl.xaml
/// </summary>
public partial class EditTimesControl : Window
{
#region Construction
public EditTimesControl()
{
InitializeComponent();
}
#endregion
#region Properties
public Times Times { get; set; } = new();
internal Extensions.ParticipantType ParticipantType { get; set; } = Extensions.ParticipantType.NONE;
#endregion
#region event handler
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.CopyToControls();
// enable controls according to participant type
this.datePickerETABerth.IsEnabled = App.Participant.IsFlagSet(Extensions.ParticipantType.AGENCY) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.MOORING) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.PILOT) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.TUG);
this.checkBoxEtaBerthFixed.IsEnabled = this.datePickerETABerth.IsEnabled;
this.datePickerETDBerth.IsEnabled = this.datePickerETABerth.IsEnabled;
this.checkBoxEtDBerthFixed.IsEnabled = this.datePickerETABerth.IsEnabled;
this.datePickerLockTime.IsEnabled = App.Participant.IsFlagSet(Extensions.ParticipantType.AGENCY) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.MOORING) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION);
this.checkBoxLockTimeFixed.IsEnabled = this.datePickerLockTime.IsEnabled;
this.datePickerZoneEntry.IsEnabled = App.Participant.IsFlagSet(Extensions.ParticipantType.AGENCY) ||
App.Participant.IsFlagSet(Extensions.ParticipantType.PILOT);
this.checkBoxZoneEntryFixed.IsEnabled = this.datePickerZoneEntry.IsEnabled;
this.datePickerOperationStart.IsEnabled = App.Participant.IsFlagSet(Extensions.ParticipantType.TERMINAL);
this.datePickerOperationEnd.IsEnabled = App.Participant.IsFlagSet(Extensions.ParticipantType.TERMINAL);
}
private void buttonOK_Click(object sender, RoutedEventArgs e)
{
this.CopyToModel();
this.DialogResult = true;
this.Close();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
#endregion
#region private methods
private void CopyToModel()
{
this.Times.Remarks = this.textBoxRemarks.Text.Trim().Truncate(512);
this.Times.EtaBerth = this.datePickerETABerth.Value;
this.Times.EtdBerth = this.datePickerETDBerth.Value;
this.Times.LockTime = this.datePickerLockTime.Value;
this.Times.ZoneEntry = this.datePickerZoneEntry.Value;
this.Times.OperationsStart = this.datePickerOperationStart.Value;
this.Times.OperationsEnd = this.datePickerOperationEnd.Value;
this.Times.EtaBerthFixed = this.checkBoxEtaBerthFixed.IsChecked;
this.Times.EtdBerthFixed = this.checkBoxEtDBerthFixed.IsChecked;
this.Times.LockTimeFixed = this.checkBoxLockTimeFixed.IsChecked;
this.Times.ZoneEntryFixed = this.checkBoxZoneEntryFixed.IsChecked;
}
private void CopyToControls()
{
this.textBoxRemarks.Text = this.Times.Remarks;
this.datePickerETABerth.Value = this.Times.EtaBerth;
this.datePickerETDBerth.Value = this.Times.EtdBerth;
this.datePickerLockTime.Value = this.Times.LockTime;
this.datePickerZoneEntry.Value = this.Times.ZoneEntry;
this.datePickerOperationStart.Value = this.Times.OperationsStart;
this.datePickerOperationEnd.Value = this.Times.OperationsEnd;
this.checkBoxEtaBerthFixed.IsChecked = this.Times.EtaBerthFixed;
this.checkBoxEtDBerthFixed.IsChecked = this.Times.EtdBerthFixed;
this.checkBoxLockTimeFixed.IsChecked = this.Times.LockTimeFixed;
this.checkBoxZoneEntryFixed.IsChecked = this.Times.ZoneEntryFixed;
}
#endregion
}
}

View File

@ -66,6 +66,12 @@ namespace BreCalClient
else participant.Type &= (int)~flag;
}
public static string Truncate(this string value, int maxLength)
{
if (string.IsNullOrEmpty(value)) return value;
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
}
#endregion
}

View File

@ -337,11 +337,41 @@ namespace BreCalClient
}
}
private void Sc_EditTimesRequested(ShipcallControl obj, Times times)
private async void Sc_EditTimesRequested(ShipcallControl obj, Times? times)
{
// show a dialog that lets the user create / update times for the given shipcall
EditTimesControl etc = new();
bool wasEdit = false;
if (times != null)
{
etc.Times = times;
wasEdit = true;
}
if(etc.ShowDialog() ?? false)
{
try
{
if (wasEdit)
{
await _api.TimesPutAsync(etc.Times);
}
else
{
etc.Times.ParticipantId = App.Participant.Id;
if ((obj.ShipcallControlModel != null) && (obj.ShipcallControlModel.Shipcall != null))
{
etc.Times.ShipcallId = obj.ShipcallControlModel.Shipcall.Id;
}
await _api.TimesPostAsync(etc.Times);
obj.ShipcallControlModel?.Times.Add(etc.Times);
}
obj.RefreshData();
}
catch (Exception ex)
{
ShowErrorDialog(ex.Message, "Error saving times");
}
}
}
private void ShowErrorDialog(string message, string caption)

View File

@ -333,6 +333,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Edit times.
/// </summary>
public static string textEditTimes {
get {
return ResourceManager.GetString("textEditTimes", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enter keyword.
/// </summary>
@ -342,6 +351,24 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to ETA berth.
/// </summary>
public static string textETABerth {
get {
return ResourceManager.GetString("textETABerth", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ETD berth.
/// </summary>
public static string textETDBerth {
get {
return ResourceManager.GetString("textETDBerth", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Exit.
/// </summary>
@ -351,6 +378,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Fixed.
/// </summary>
public static string textFixed {
get {
return ResourceManager.GetString("textFixed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to from.
/// </summary>
@ -378,6 +414,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Lock time.
/// </summary>
public static string textLockTime {
get {
return ResourceManager.GetString("textLockTime", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Login.
/// </summary>
@ -450,6 +495,24 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Operations end.
/// </summary>
public static string textOperationsEnd {
get {
return ResourceManager.GetString("textOperationsEnd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Operations start.
/// </summary>
public static string textOperationsStart {
get {
return ResourceManager.GetString("textOperationsStart", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Participants.
/// </summary>
@ -513,6 +576,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Remarks.
/// </summary>
public static string textRemarks {
get {
return ResourceManager.GetString("textRemarks", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Repeat new password.
/// </summary>
@ -666,6 +738,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Zone entry.
/// </summary>
public static string textZoneEntryTime {
get {
return ResourceManager.GetString("textZoneEntryTime", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>

View File

@ -196,6 +196,15 @@
<data name="textEditShipcall" xml:space="preserve">
<value>Schiffsanlauf bearbeiten</value>
</data>
<data name="textEditTimes" xml:space="preserve">
<value>Zeiten bearbeiten</value>
</data>
<data name="textETABerth" xml:space="preserve">
<value>ETA Liegeplatz</value>
</data>
<data name="textETDBerth" xml:space="preserve">
<value>ETD Liegeplatz</value>
</data>
<data name="textEnterKeyword" xml:space="preserve">
<value>Suchbegriff eingeben</value>
</data>
@ -214,6 +223,18 @@
<data name="textLogin" xml:space="preserve">
<value>Anmelden</value>
</data>
<data name="textFixed" xml:space="preserve">
<value>Fest</value>
</data>
<data name="textLockTime" xml:space="preserve">
<value>Zeit Schleuse</value>
</data>
<data name="textOperationsEnd" xml:space="preserve">
<value>Operation Ende</value>
</data>
<data name="textOperationsStart" xml:space="preserve">
<value>Operation Start</value>
</data>
<data name="textMooredLock" xml:space="preserve">
<value>Festmacher in Schleuse</value>
</data>
@ -229,6 +250,9 @@
<data name="textNotRotated" xml:space="preserve">
<value>Ungedreht</value>
</data>
<data name="textZoneEntryTime" xml:space="preserve">
<value>Reviereintritt</value>
</data>
<data name="textOK" xml:space="preserve">
<value>OK</value>
</data>

View File

@ -205,12 +205,24 @@
<data name="textEditShipcall" xml:space="preserve">
<value>Edit ship call</value>
</data>
<data name="textEditTimes" xml:space="preserve">
<value>Edit times</value>
</data>
<data name="textEnterKeyword" xml:space="preserve">
<value>Enter keyword</value>
</data>
<data name="textETABerth" xml:space="preserve">
<value>ETA berth</value>
</data>
<data name="textETDBerth" xml:space="preserve">
<value>ETD berth</value>
</data>
<data name="textExit" xml:space="preserve">
<value>Exit</value>
</data>
<data name="textFixed" xml:space="preserve">
<value>Fixed</value>
</data>
<data name="textFrom" xml:space="preserve">
<value>from</value>
</data>
@ -220,6 +232,9 @@
<data name="textLengthWidth" xml:space="preserve">
<value>L/W</value>
</data>
<data name="textLockTime" xml:space="preserve">
<value>Lock time</value>
</data>
<data name="textLogin" xml:space="preserve">
<value>Login</value>
</data>
@ -244,6 +259,12 @@
<data name="textOldPassword" xml:space="preserve">
<value>Old password</value>
</data>
<data name="textOperationsEnd" xml:space="preserve">
<value>Operations end</value>
</data>
<data name="textOperationsStart" xml:space="preserve">
<value>Operations start</value>
</data>
<data name="textParticipants" xml:space="preserve">
<value>Participants</value>
</data>
@ -265,6 +286,9 @@
<data name="textRecommendedTugs" xml:space="preserve">
<value>Recommended tugs</value>
</data>
<data name="textRemarks" xml:space="preserve">
<value>Remarks</value>
</data>
<data name="textRepeatNewPassword" xml:space="preserve">
<value>Repeat new password</value>
</data>
@ -316,6 +340,9 @@
<data name="textVoyage" xml:space="preserve">
<value>Voyage</value>
</data>
<data name="textZoneEntryTime" xml:space="preserve">
<value>Zone entry</value>
</data>
<data name="trafficlight_green" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>trafficlight_green.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>

View File

@ -30,7 +30,7 @@ namespace BreCalClient
public event Action<ShipcallControl>? EditRequested;
public event Action<ShipcallControl, Times>? EditTimesRequested;
public event Action<ShipcallControl, Times?>? EditTimesRequested;
public event Action<ShipcallControl>? OpenExtraRequested;
@ -162,10 +162,7 @@ namespace BreCalClient
if (App.Participant.IsFlagSet(Extensions.ParticipantType.AGENCY))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
this.EditTimesRequested?.Invoke(this, times);
}
}
@ -174,10 +171,7 @@ namespace BreCalClient
if (App.Participant.IsFlagSet(Extensions.ParticipantType.MOORING))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING);
if(times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
this.EditTimesRequested?.Invoke(this, times);
}
}
@ -186,10 +180,7 @@ namespace BreCalClient
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);
}
this.EditTimesRequested?.Invoke(this, times);
}
}
@ -198,10 +189,7 @@ namespace BreCalClient
if (App.Participant.IsFlagSet(Extensions.ParticipantType.PILOT))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
this.EditTimesRequested?.Invoke(this, times);
}
}
@ -210,10 +198,7 @@ namespace BreCalClient
if (App.Participant.IsFlagSet(Extensions.ParticipantType.TUG))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
this.EditTimesRequested?.Invoke(this, times);
}
}
@ -222,10 +207,7 @@ namespace BreCalClient
if (App.Participant.IsFlagSet(Extensions.ParticipantType.TERMINAL))
{
Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL);
if (times != null)
{
this.EditTimesRequested?.Invoke(this, times);
}
this.EditTimesRequested?.Invoke(this, times);
}
}

View File

@ -59,6 +59,10 @@ def PostShipcalls(schemaModel):
continue
if key == "participants":
continue
if key == "created":
continue
if key == "modified":
continue
if isNotFirst:
query += ","
isNotFirst = True
@ -70,6 +74,10 @@ def PostShipcalls(schemaModel):
continue
if key == "participants":
continue
if key == "created":
continue
if key == "modified":
continue
if isNotFirst:
query += ","
isNotFirst = True
@ -125,6 +133,10 @@ def PutShipcalls(schemaModel):
continue
if key == "participants":
continue
if key == "created":
continue
if key == "modified":
continue
if isNotFirst:
query += ", "
isNotFirst = True

View File

@ -53,6 +53,10 @@ def PostTimes(schemaModel):
for key in schemaModel.keys():
if key == "id":
continue
if key == "created":
continue
if key == "modified":
continue
if isNotFirst:
query += ","
isNotFirst = True
@ -62,6 +66,10 @@ def PostTimes(schemaModel):
for key in schemaModel.keys():
if key == "id":
continue
if key == "created":
continue
if key == "modified":
continue
if isNotFirst:
query += ","
isNotFirst = True
@ -100,6 +108,10 @@ def PutTimes(schemaModel):
for key in schemaModel.keys():
if key == "id":
continue
if key == "created":
continue
if key == "modified":
continue
if isNotFirst:
query += ", "
isNotFirst = True

View File

@ -130,21 +130,21 @@ class TimesSchema(Schema):
pass
id = fields.Int(Required=False)
eta_berth = fields.DateTime(Required = False)
eta_berth_fixed = fields.Bool(Required = False)
etd_berth = fields.DateTime(Required = False)
etd_berth_fixed = fields.Bool(Required = False)
lock_time = fields.DateTime(Required = False)
lock_time_fixed = fields.Bool(Required = False)
zone_entry = fields.DateTime(Required = False)
zone_entry_fixed = fields.Bool(Required = False)
operations_start = fields.DateTime(Required = False)
operations_end = fields.DateTime(Required = False)
remarks = fields.String(Required = False)
eta_berth = fields.DateTime(Required = False, allow_none=True)
eta_berth_fixed = fields.Bool(Required = False, allow_none=True)
etd_berth = fields.DateTime(Required = False, allow_none=True)
etd_berth_fixed = fields.Bool(Required = False, allow_none=True)
lock_time = fields.DateTime(Required = False, allow_none=True)
lock_time_fixed = fields.Bool(Required = False, allow_none=True)
zone_entry = fields.DateTime(Required = False, allow_none=True)
zone_entry_fixed = fields.Bool(Required = False, allow_none=True)
operations_start = fields.DateTime(Required = False, allow_none=True)
operations_end = fields.DateTime(Required = False, allow_none=True)
remarks = fields.String(Required = False, allow_none=True)
participant_id = fields.Int(Required = True)
shipcall_id = fields.Int(Required = True)
created = fields.DateTime(Required = False)
modified = fields.DateTime(Required = False)
created = fields.DateTime(Required = False, allow_none=True)
modified = fields.DateTime(Required = False, allow_none=True)
# deserialize PUT object target