added -1 day time logic to client

This commit is contained in:
Daniel Schick 2024-11-05 13:26:53 +01:00
parent 2ee9af4b9d
commit 6b5d876cd5
7 changed files with 54 additions and 50 deletions

View File

@ -204,26 +204,22 @@ namespace BreCalClient
{ {
case ShipcallType.Departure: case ShipcallType.Departure:
isEnabled &= this.comboBoxDepartureBerth.SelectedItem != null; isEnabled &= this.comboBoxDepartureBerth.SelectedItem != null;
isEnabled &= this.datePickerETD.Value.HasValue; isEnabled &= this.datePickerETD.Value.HasValue;
if(this.datePickerETD.Value.HasValue) isEnabled &= !(this.datePickerETD.Value.IsTooOld() && this.datePickerETD.Value != this.ShipcallModel.Shipcall?.Etd);
isEnabled &= (this.datePickerETD.Value.Value > DateTime.Now);
isEnabled &= !this.datePickerETD.Value.IsTooFar(); isEnabled &= !this.datePickerETD.Value.IsTooFar();
break; break;
case ShipcallType.Arrival: case ShipcallType.Arrival:
isEnabled &= this.comboBoxArrivalBerth.SelectedItem != null; isEnabled &= this.comboBoxArrivalBerth.SelectedItem != null;
isEnabled &= this.datePickerETA.Value.HasValue; isEnabled &= this.datePickerETA.Value.HasValue;
if(this.datePickerETA.Value.HasValue) isEnabled &= !(this.datePickerETA.Value.IsTooOld() && this.datePickerETA.Value != this.ShipcallModel.Shipcall?.Eta);
isEnabled &= (this.datePickerETA.Value.Value > DateTime.Now);
isEnabled &= !this.datePickerETA.Value.IsTooFar(); isEnabled &= !this.datePickerETA.Value.IsTooFar();
break; break;
case ShipcallType.Shifting: case ShipcallType.Shifting:
isEnabled &= ((this.comboBoxDepartureBerth.SelectedItem != null) && (this.comboBoxArrivalBerth.SelectedItem != null)); isEnabled &= ((this.comboBoxDepartureBerth.SelectedItem != null) && (this.comboBoxArrivalBerth.SelectedItem != null));
isEnabled &= this.datePickerETD.Value.HasValue; isEnabled &= this.datePickerETD.Value.HasValue;
isEnabled &= this.datePickerETA.Value.HasValue; isEnabled &= this.datePickerETA.Value.HasValue;
if (this.datePickerETD.Value.HasValue) isEnabled &= !(this.datePickerETD.Value.IsTooOld() && this.datePickerETD.Value != this.ShipcallModel.Shipcall?.Etd);
isEnabled &= (this.datePickerETD.Value.Value > DateTime.Now); isEnabled &= !(this.datePickerETA.Value.IsTooOld() && this.datePickerETA.Value != this.ShipcallModel.Shipcall?.Eta);
if (this.datePickerETA.Value.HasValue)
isEnabled &= (this.datePickerETA.Value.Value > DateTime.Now);
if (this.datePickerETA.Value.HasValue && this.datePickerETD.Value.HasValue) if (this.datePickerETA.Value.HasValue && this.datePickerETD.Value.HasValue)
isEnabled &= (this.datePickerETA.Value.Value > this.datePickerETD.Value.Value); isEnabled &= (this.datePickerETA.Value.Value > this.datePickerETD.Value.Value);
isEnabled &= !this.datePickerETD.Value.IsTooFar(); isEnabled &= !this.datePickerETD.Value.IsTooFar();

View File

@ -97,13 +97,13 @@ namespace BreCalClient
{ {
message = ""; message = "";
if (this.datePickerETA.Value.HasValue && (this.datePickerETA.Value.Value < DateTime.Now) && (this.datePickerETA_End.Value == null)) if (this.datePickerETA.Value.IsTooOld() && (this.datePickerETA_End.Value == null) && (this.datePickerETA.Value != this.Times.EtaBerth))
{ {
message = BreCalClient.Resources.Resources.textETAInThePast; message = BreCalClient.Resources.Resources.textETAInThePast;
return false; return false;
} }
if(this.datePickerETA_End.Value.HasValue && this.datePickerETA_End.Value < DateTime.Now) if(this.datePickerETA_End.Value.IsTooOld() && (this.datePickerETA_End.Value != this.Times.EtaIntervalEnd))
{ {
message = BreCalClient.Resources.Resources.textETAInThePast; message = BreCalClient.Resources.Resources.textETAInThePast;
return false; return false;
@ -115,13 +115,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerTidalWindowFrom.Value.HasValue && (this.datePickerTidalWindowFrom.Value.Value < DateTime.Now) && (this.datePickerTidalWindowTo.Value == null)) if (this.datePickerTidalWindowFrom.Value.IsTooOld() && (this.datePickerTidalWindowTo.Value == null) && (this.datePickerTidalWindowFrom.Value != this.ShipcallModel.Shipcall?.TidalWindowFrom))
{ {
message = BreCalClient.Resources.Resources.textTideTimesInThePast; message = BreCalClient.Resources.Resources.textTideTimesInThePast;
return false; return false;
} }
if (this.datePickerTidalWindowTo.Value.HasValue && this.datePickerTidalWindowTo.Value < DateTime.Now) if (this.datePickerTidalWindowTo.Value.IsTooOld() && (this.datePickerTidalWindowTo.Value != this.ShipcallModel.Shipcall?.TidalWindowTo))
{ {
message = BreCalClient.Resources.Resources.textTideTimesInThePast; message = BreCalClient.Resources.Resources.textTideTimesInThePast;
return false; return false;

View File

@ -107,13 +107,13 @@ namespace BreCalClient
{ {
message = ""; message = "";
if (this.datePickerETD.Value.HasValue && (this.datePickerETD.Value.Value < DateTime.Now) && (this.datePickerETD_End.Value == null)) if (this.datePickerETD.Value.IsTooOld() && (this.datePickerETD_End.Value == null) && (this.datePickerETD.Value != this.Times.EtdBerth))
{ {
message = BreCalClient.Resources.Resources.textETDInThePast; message = BreCalClient.Resources.Resources.textETDInThePast;
return false; return false;
} }
if (this.datePickerETD_End.Value.HasValue && this.datePickerETD_End.Value < DateTime.Now) if (this.datePickerETD_End.Value.IsTooOld() && (this.datePickerETD_End.Value != this.Times.EtdIntervalEnd))
{ {
message = BreCalClient.Resources.Resources.textETDInThePast; message = BreCalClient.Resources.Resources.textETDInThePast;
return false; return false;
@ -125,13 +125,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerTidalWindowFrom.Value.HasValue && (this.datePickerTidalWindowFrom.Value.Value < DateTime.Now) && (this.datePickerTidalWindowTo.Value == null)) if (this.datePickerTidalWindowFrom.Value.IsTooOld() && (this.datePickerTidalWindowTo.Value == null) && (this.datePickerTidalWindowFrom.Value != this.ShipcallModel.Shipcall?.TidalWindowFrom))
{ {
message = BreCalClient.Resources.Resources.textTideTimesInThePast; message = BreCalClient.Resources.Resources.textTideTimesInThePast;
return false; return false;
} }
if (this.datePickerTidalWindowTo.Value.HasValue && this.datePickerTidalWindowTo.Value < DateTime.Now) if (this.datePickerTidalWindowTo.Value.IsTooOld() && (this.datePickerTidalWindowTo.Value != this.ShipcallModel.Shipcall?.TidalWindowTo))
{ {
message = BreCalClient.Resources.Resources.textTideTimesInThePast; message = BreCalClient.Resources.Resources.textTideTimesInThePast;
return false; return false;

View File

@ -97,13 +97,13 @@ namespace BreCalClient
{ {
message = ""; message = "";
if (this.datePickerETA.Value.HasValue && (this.datePickerETA.Value.Value < DateTime.Now) && (this.datePickerETA_End.Value == null)) if (this.datePickerETA.Value.IsTooOld() && (this.datePickerETA_End.Value == null) && (this.datePickerETA.Value != this.Times.EtaBerth))
{ {
message = BreCalClient.Resources.Resources.textETAInThePast; message = BreCalClient.Resources.Resources.textETAInThePast;
return false; return false;
} }
if (this.datePickerETA_End.Value.HasValue && this.datePickerETA_End.Value < DateTime.Now) if (this.datePickerETA_End.Value.IsTooOld() && (this.datePickerETA_End.Value != this.Times.EtaIntervalEnd))
{ {
message = BreCalClient.Resources.Resources.textETAInThePast; message = BreCalClient.Resources.Resources.textETAInThePast;
return false; return false;
@ -115,13 +115,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerETD.Value.HasValue && (this.datePickerETD.Value.Value < DateTime.Now) && (this.datePickerETD_End.Value == null)) if (this.datePickerETD.Value.IsTooOld() && (this.datePickerETD_End.Value == null) && (this.datePickerETD.Value != this.Times.EtdBerth))
{ {
message = BreCalClient.Resources.Resources.textETDInThePast; message = BreCalClient.Resources.Resources.textETDInThePast;
return false; return false;
} }
if (this.datePickerETD_End.Value.HasValue && this.datePickerETD_End.Value < DateTime.Now) if (this.datePickerETD_End.Value.IsTooOld() && (this.datePickerETD_End.Value != this.Times.EtdIntervalEnd))
{ {
message = BreCalClient.Resources.Resources.textETDInThePast; message = BreCalClient.Resources.Resources.textETDInThePast;
return false; return false;
@ -133,13 +133,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerTidalWindowFrom.Value.HasValue && (this.datePickerTidalWindowFrom.Value.Value < DateTime.Now) && (this.datePickerTidalWindowTo.Value == null)) if (this.datePickerTidalWindowFrom.Value.IsTooOld() && (this.datePickerTidalWindowTo.Value == null) && (this.datePickerTidalWindowFrom.Value != this.ShipcallModel.Shipcall?.TidalWindowFrom))
{ {
message = BreCalClient.Resources.Resources.textTideTimesInThePast; message = BreCalClient.Resources.Resources.textTideTimesInThePast;
return false; return false;
} }
if (this.datePickerTidalWindowTo.Value.HasValue && this.datePickerTidalWindowTo.Value < DateTime.Now) if (this.datePickerTidalWindowTo.Value.IsTooOld() && (this.datePickerTidalWindowTo.Value != this.ShipcallModel.Shipcall?.TidalWindowTo))
{ {
message = BreCalClient.Resources.Resources.textTideTimesInThePast; message = BreCalClient.Resources.Resources.textTideTimesInThePast;
return false; return false;

View File

@ -1,7 +1,7 @@
// Copyright (c) 2023 schick Informatik // Copyright (c) 2023 schick Informatik
// Description: Single dialog to edit times for all participant types // Description: Single dialog to edit times for all participant types
// (we might use different controls at a later time) // (we might use different controls at a later time)
// //
using BreCalClient.misc.Model; using BreCalClient.misc.Model;
using System; using System;
@ -40,7 +40,7 @@ namespace BreCalClient
#region event handler #region event handler
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
this.EnableControls(); this.EnableControls();
this.CopyToControls(); this.CopyToControls();
} }
@ -49,7 +49,7 @@ namespace BreCalClient
{ {
if (!CheckValues(out string message)) if (!CheckValues(out string message))
{ {
System.Windows.MessageBox.Show(message, BreCalClient.Resources.Resources.textWarning, System.Windows.MessageBox.Show(message, BreCalClient.Resources.Resources.textWarning,
MessageBoxButton.OK, MessageBoxImage.Warning); MessageBoxButton.OK, MessageBoxImage.Warning);
} }
else else
@ -58,7 +58,7 @@ namespace BreCalClient
this.DialogResult = true; this.DialogResult = true;
this.Close(); this.Close();
} }
} }
private void buttonCancel_Click(object sender, RoutedEventArgs e) private void buttonCancel_Click(object sender, RoutedEventArgs e)
{ {
@ -99,13 +99,13 @@ namespace BreCalClient
message = ""; message = "";
if (this.datePickerETABerth.Value.HasValue && (this.datePickerETABerth.Value.Value < DateTime.Now) && (this.datePickerETABerth_End.Value == null)) if (this.datePickerETABerth.Value.IsTooOld() && (this.datePickerETABerth_End.Value == null) && (this.datePickerETABerth.Value != this.Times.EtaBerth))
{ {
message = BreCalClient.Resources.Resources.textETAInThePast; message = BreCalClient.Resources.Resources.textETAInThePast;
return false; return false;
} }
if (this.datePickerETABerth_End.Value.HasValue && this.datePickerETABerth_End.Value < DateTime.Now) if (this.datePickerETABerth_End.Value.IsTooOld() && this.datePickerETABerth_End.Value != this.Times.EtaIntervalEnd)
{ {
message = BreCalClient.Resources.Resources.textETAInThePast; message = BreCalClient.Resources.Resources.textETAInThePast;
return false; return false;
@ -117,13 +117,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerETDBerth.Value.HasValue && (this.datePickerETDBerth.Value.Value < DateTime.Now) && (this.datePickerETABerth_End.Value == null)) if (this.datePickerETDBerth.Value.IsTooOld() && (this.datePickerETDBerth_End.Value == null) && (this.datePickerETDBerth.Value != this.Times.EtdBerth))
{ {
message = BreCalClient.Resources.Resources.textETDInThePast; message = BreCalClient.Resources.Resources.textETDInThePast;
return false; return false;
} }
if (this.datePickerETDBerth_End.Value.HasValue && this.datePickerETDBerth_End.Value < DateTime.Now) if (this.datePickerETDBerth_End.Value.IsTooOld() && this.datePickerETDBerth_End.Value != this.Times.EtdIntervalEnd)
{ {
message = BreCalClient.Resources.Resources.textETDInThePast; message = BreCalClient.Resources.Resources.textETDInThePast;
return false; return false;
@ -135,13 +135,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerLockTime.Value.HasValue && (this.datePickerLockTime.Value.Value < DateTime.Now)) if (this.datePickerLockTime.Value.IsTooOld() && (this.datePickerLockTime.Value != this.Times.LockTime))
{ {
message = BreCalClient.Resources.Resources.textLockTimeInThePast; message = BreCalClient.Resources.Resources.textLockTimeInThePast;
return false; return false;
} }
if (this.datePickerZoneEntry.Value.HasValue && this.datePickerZoneEntry.Value < DateTime.Now) if (this.datePickerZoneEntry.Value.IsTooOld() && (this.datePickerZoneEntry.Value != this.Times.ZoneEntry))
{ {
message = BreCalClient.Resources.Resources.textZoneEntryInThePast; message = BreCalClient.Resources.Resources.textZoneEntryInThePast;
return false; return false;
@ -218,13 +218,13 @@ namespace BreCalClient
{ {
this.labelETA.Content = string.Format("ETA {0}", BreCalLists.TimeRefs[displayIndex]); this.labelETA.Content = string.Format("ETA {0}", BreCalLists.TimeRefs[displayIndex]);
this.labelETD.Content = string.Format("ETD {0}", BreCalLists.TimeRefs[displayIndex]); this.labelETD.Content = string.Format("ETD {0}", BreCalLists.TimeRefs[displayIndex]);
} }
else else
{ {
this.labelETA.Content = BreCalClient.Resources.Resources.textETABerth; this.labelETA.Content = BreCalClient.Resources.Resources.textETABerth;
this.labelETD.Content = BreCalClient.Resources.Resources.textETDBerth; this.labelETD.Content = BreCalClient.Resources.Resources.textETDBerth;
} }
} }
this.SetLockButton(this.Times.EtaBerthFixed ?? false); this.SetLockButton(this.Times.EtaBerthFixed ?? false);
} }
@ -290,11 +290,11 @@ namespace BreCalClient
case Extensions.ParticipantType.PORT_ADMINISTRATION: case Extensions.ParticipantType.PORT_ADMINISTRATION:
this.datePickerLockTime.IsEnabled = true; this.datePickerLockTime.IsEnabled = true;
break; break;
case Extensions.ParticipantType.TUG: case Extensions.ParticipantType.TUG:
case Extensions.ParticipantType.PILOT: case Extensions.ParticipantType.PILOT:
this.datePickerZoneEntry.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival); this.datePickerZoneEntry.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival);
break; break;
} }
} }
private void SetLockButton(bool newValue) private void SetLockButton(bool newValue)
@ -311,7 +311,7 @@ namespace BreCalClient
this.imageFixedOrder.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/lock_open.png", UriKind.RelativeOrAbsolute)); this.imageFixedOrder.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/lock_open.png", UriKind.RelativeOrAbsolute));
this.buttonFixedOrder.ToolTip = BreCalClient.Resources.Resources.textTooltipSetFixedOrder; this.buttonFixedOrder.ToolTip = BreCalClient.Resources.Resources.textTooltipSetFixedOrder;
} }
} }
#endregion #endregion
@ -335,17 +335,17 @@ namespace BreCalClient
private void contextMenuItemClearZoneEntry_Click(object sender, RoutedEventArgs e) private void contextMenuItemClearZoneEntry_Click(object sender, RoutedEventArgs e)
{ {
this.datePickerZoneEntry.Value = null; this.datePickerZoneEntry.Value = null;
} }
private void contextMenuItemClearATA_Click(object sender, RoutedEventArgs e) private void contextMenuItemClearATA_Click(object sender, RoutedEventArgs e)
{ {
this.datePickerATA.Value = null; this.datePickerATA.Value = null;
} }
private void contextMenuItemClearATD_Click(object sender, RoutedEventArgs e) private void contextMenuItemClearATD_Click(object sender, RoutedEventArgs e)
{ {
this.datePickerATD.Value = null; this.datePickerATD.Value = null;
} }
private void contextMenuItemClearETA_End_Click(object sender, RoutedEventArgs e) private void contextMenuItemClearETA_End_Click(object sender, RoutedEventArgs e)
{ {
@ -358,6 +358,6 @@ namespace BreCalClient
} }
#endregion #endregion
} }
} }

View File

@ -108,13 +108,13 @@ namespace BreCalClient
message = ""; message = "";
if (this.datePickerOperationStart.Value.HasValue && (this.datePickerOperationStart.Value.Value < DateTime.Now) && (this.datePickerOperationStart_End.Value == null)) if (this.datePickerOperationStart.Value.IsTooOld() && (this.datePickerOperationStart_End.Value == null) && (this.datePickerOperationStart.Value != this.Times.OperationsStart))
{ {
message = BreCalClient.Resources.Resources.textOperationStartInThePast; message = BreCalClient.Resources.Resources.textOperationStartInThePast;
return false; return false;
} }
if (this.datePickerOperationStart_End.Value.HasValue && this.datePickerOperationStart_End.Value < DateTime.Now) if (this.datePickerOperationStart_End.Value.IsTooOld() && (this.datePickerOperationStart_End.Value != this.Times.EtaIntervalEnd))
{ {
message = BreCalClient.Resources.Resources.textOperationStartInThePast; message = BreCalClient.Resources.Resources.textOperationStartInThePast;
return false; return false;
@ -126,13 +126,13 @@ namespace BreCalClient
return false; return false;
} }
if (this.datePickerOperationEnd.Value.HasValue && (this.datePickerOperationEnd.Value.Value < DateTime.Now) && (this.datePickerOperationEnd_End.Value == null)) if (this.datePickerOperationEnd.Value.IsTooOld() && (this.datePickerOperationEnd_End.Value == null) && (this.datePickerOperationEnd.Value != this.Times.OperationsEnd))
{ {
message = BreCalClient.Resources.Resources.textOperationEndInThePast; message = BreCalClient.Resources.Resources.textOperationEndInThePast;
return false; return false;
} }
if (this.datePickerOperationEnd_End.Value.HasValue && this.datePickerOperationEnd_End.Value < DateTime.Now) if (this.datePickerOperationEnd_End.Value.IsTooOld() && (this.datePickerOperationEnd_End.Value != this.Times.EtdIntervalEnd))
{ {
message = BreCalClient.Resources.Resources.textOperationEndInThePast; message = BreCalClient.Resources.Resources.textOperationEndInThePast;
return false; return false;

View File

@ -69,6 +69,14 @@ namespace BreCalClient
return datetime > DateTime.Now.AddYears(1); return datetime > DateTime.Now.AddYears(1);
} }
public static bool IsTooOld(this DateTime? datetime)
{
if (datetime == null) return false;
{
return datetime < DateTime.Now.AddDays(-1);
}
}
public static bool IsTypeFlagSet(this Participant participant, ParticipantType flag) public static bool IsTypeFlagSet(this Participant participant, ParticipantType flag)
{ {
return (participant.Type & (uint)flag) != 0; return (participant.Type & (uint)flag) != 0;