From 6b5d876cd5befc7783446b9e5bb8a0610aa20cc0 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 5 Nov 2024 13:26:53 +0100 Subject: [PATCH] added -1 day time logic to client --- src/BreCalClient/EditShipcallControl.xaml.cs | 18 ++++---- .../EditTimesAgencyIncomingControl.xaml.cs | 8 ++-- .../EditTimesAgencyOutgoingControl.xaml.cs | 8 ++-- .../EditTimesAgencyShiftingControl.xaml.cs | 12 +++--- src/BreCalClient/EditTimesControl.xaml.cs | 42 +++++++++---------- .../EditTimesTerminalControl.xaml.cs | 8 ++-- src/BreCalClient/Extensions.cs | 8 ++++ 7 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs index fd42086..8609f0a 100644 --- a/src/BreCalClient/EditShipcallControl.xaml.cs +++ b/src/BreCalClient/EditShipcallControl.xaml.cs @@ -204,26 +204,22 @@ namespace BreCalClient { case ShipcallType.Departure: isEnabled &= this.comboBoxDepartureBerth.SelectedItem != null; - isEnabled &= this.datePickerETD.Value.HasValue; - if(this.datePickerETD.Value.HasValue) - isEnabled &= (this.datePickerETD.Value.Value > DateTime.Now); + isEnabled &= this.datePickerETD.Value.HasValue; + isEnabled &= !(this.datePickerETD.Value.IsTooOld() && this.datePickerETD.Value != this.ShipcallModel.Shipcall?.Etd); isEnabled &= !this.datePickerETD.Value.IsTooFar(); break; case ShipcallType.Arrival: isEnabled &= this.comboBoxArrivalBerth.SelectedItem != null; - isEnabled &= this.datePickerETA.Value.HasValue; - if(this.datePickerETA.Value.HasValue) - isEnabled &= (this.datePickerETA.Value.Value > DateTime.Now); + isEnabled &= this.datePickerETA.Value.HasValue; + isEnabled &= !(this.datePickerETA.Value.IsTooOld() && this.datePickerETA.Value != this.ShipcallModel.Shipcall?.Eta); isEnabled &= !this.datePickerETA.Value.IsTooFar(); break; case ShipcallType.Shifting: isEnabled &= ((this.comboBoxDepartureBerth.SelectedItem != null) && (this.comboBoxArrivalBerth.SelectedItem != null)); isEnabled &= this.datePickerETD.Value.HasValue; - isEnabled &= this.datePickerETA.Value.HasValue; - if (this.datePickerETD.Value.HasValue) - isEnabled &= (this.datePickerETD.Value.Value > DateTime.Now); - if (this.datePickerETA.Value.HasValue) - isEnabled &= (this.datePickerETA.Value.Value > DateTime.Now); + isEnabled &= this.datePickerETA.Value.HasValue; + isEnabled &= !(this.datePickerETD.Value.IsTooOld() && this.datePickerETD.Value != this.ShipcallModel.Shipcall?.Etd); + isEnabled &= !(this.datePickerETA.Value.IsTooOld() && this.datePickerETA.Value != this.ShipcallModel.Shipcall?.Eta); if (this.datePickerETA.Value.HasValue && this.datePickerETD.Value.HasValue) isEnabled &= (this.datePickerETA.Value.Value > this.datePickerETD.Value.Value); isEnabled &= !this.datePickerETD.Value.IsTooFar(); diff --git a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs index 8d85d68..47b5cab 100644 --- a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs @@ -97,13 +97,13 @@ namespace BreCalClient { 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; 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; return false; @@ -115,13 +115,13 @@ namespace BreCalClient 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; 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; return false; diff --git a/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs index c850ed8..7721819 100644 --- a/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs @@ -107,13 +107,13 @@ namespace BreCalClient { 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; 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; return false; @@ -125,13 +125,13 @@ namespace BreCalClient 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; 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; return false; diff --git a/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs index 9307943..08cc2ca 100644 --- a/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs @@ -97,13 +97,13 @@ namespace BreCalClient { 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; 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; return false; @@ -115,13 +115,13 @@ namespace BreCalClient 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; 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; return false; @@ -133,13 +133,13 @@ namespace BreCalClient 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; 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; return false; diff --git a/src/BreCalClient/EditTimesControl.xaml.cs b/src/BreCalClient/EditTimesControl.xaml.cs index 079d9ab..89bdd8d 100644 --- a/src/BreCalClient/EditTimesControl.xaml.cs +++ b/src/BreCalClient/EditTimesControl.xaml.cs @@ -1,7 +1,7 @@ // 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; @@ -40,7 +40,7 @@ namespace BreCalClient #region event handler private void Window_Loaded(object sender, RoutedEventArgs e) - { + { this.EnableControls(); this.CopyToControls(); } @@ -49,7 +49,7 @@ namespace BreCalClient { 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); } else @@ -58,7 +58,7 @@ namespace BreCalClient this.DialogResult = true; this.Close(); } - } + } private void buttonCancel_Click(object sender, RoutedEventArgs e) { @@ -99,13 +99,13 @@ namespace BreCalClient 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; 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; return false; @@ -117,13 +117,13 @@ namespace BreCalClient 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; 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; return false; @@ -135,13 +135,13 @@ namespace BreCalClient 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; 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; return false; @@ -218,13 +218,13 @@ namespace BreCalClient { this.labelETA.Content = string.Format("ETA {0}", BreCalLists.TimeRefs[displayIndex]); this.labelETD.Content = string.Format("ETD {0}", BreCalLists.TimeRefs[displayIndex]); - } + } else { this.labelETA.Content = BreCalClient.Resources.Resources.textETABerth; this.labelETD.Content = BreCalClient.Resources.Resources.textETDBerth; } - } + } this.SetLockButton(this.Times.EtaBerthFixed ?? false); } @@ -290,11 +290,11 @@ namespace BreCalClient case Extensions.ParticipantType.PORT_ADMINISTRATION: this.datePickerLockTime.IsEnabled = true; break; - case Extensions.ParticipantType.TUG: - case Extensions.ParticipantType.PILOT: - this.datePickerZoneEntry.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival); + case Extensions.ParticipantType.TUG: + case Extensions.ParticipantType.PILOT: + this.datePickerZoneEntry.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival); break; - } + } } 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.buttonFixedOrder.ToolTip = BreCalClient.Resources.Resources.textTooltipSetFixedOrder; } - } + } #endregion @@ -335,17 +335,17 @@ namespace BreCalClient private void contextMenuItemClearZoneEntry_Click(object sender, RoutedEventArgs e) { this.datePickerZoneEntry.Value = null; - } + } private void contextMenuItemClearATA_Click(object sender, RoutedEventArgs e) { this.datePickerATA.Value = null; - } + } private void contextMenuItemClearATD_Click(object sender, RoutedEventArgs e) { this.datePickerATD.Value = null; - } + } private void contextMenuItemClearETA_End_Click(object sender, RoutedEventArgs e) { @@ -358,6 +358,6 @@ namespace BreCalClient } #endregion - + } } diff --git a/src/BreCalClient/EditTimesTerminalControl.xaml.cs b/src/BreCalClient/EditTimesTerminalControl.xaml.cs index e980c9e..fe9e363 100644 --- a/src/BreCalClient/EditTimesTerminalControl.xaml.cs +++ b/src/BreCalClient/EditTimesTerminalControl.xaml.cs @@ -108,13 +108,13 @@ namespace BreCalClient 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; 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; return false; @@ -126,13 +126,13 @@ namespace BreCalClient 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; 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; return false; diff --git a/src/BreCalClient/Extensions.cs b/src/BreCalClient/Extensions.cs index 54fedb3..f4ba524 100644 --- a/src/BreCalClient/Extensions.cs +++ b/src/BreCalClient/Extensions.cs @@ -69,6 +69,14 @@ namespace BreCalClient 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) { return (participant.Type & (uint)flag) != 0;