356 lines
15 KiB
C#
356 lines
15 KiB
C#
// 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;
|
|
using System.Windows;
|
|
using System.Windows.Media.Imaging;
|
|
using Xceed.Wpf.Toolkit;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for EditTimesControl.xaml
|
|
/// </summary>
|
|
public partial class EditTimesControl : Window, IEditTimesControl
|
|
{
|
|
|
|
#region Construction
|
|
|
|
public EditTimesControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public Times Times { get; set; } = new();
|
|
|
|
public Times? AgencyTimes { get; set; } = new();
|
|
|
|
public ShipcallControlModel ShipcallModel { get; set; } = new();
|
|
|
|
#endregion
|
|
|
|
#region event handler
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
this.EnableControls();
|
|
this.CopyToControls();
|
|
}
|
|
|
|
private void buttonOK_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!CheckValues(out string message))
|
|
{
|
|
System.Windows.MessageBox.Show(message, BreCalClient.Resources.Resources.textWarning,
|
|
MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
}
|
|
else
|
|
{
|
|
this.CopyToModel();
|
|
this.DialogResult = true;
|
|
this.Close();
|
|
}
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.DialogResult = false;
|
|
this.Close();
|
|
}
|
|
|
|
private void buttonFixedOrder_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
bool newValue = true;
|
|
if (this.Times.EtaBerthFixed ?? false)
|
|
newValue = false;
|
|
SetLockButton(newValue);
|
|
}
|
|
|
|
private void buttonClearAll_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (System.Windows.MessageBox.Show(BreCalClient.Resources.Resources.textClearAll, BreCalClient.Resources.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
|
|
{
|
|
this.datePickerETABerth.Value = null;
|
|
this.datePickerETABerth_End.Value = null;
|
|
this.datePickerETDBerth.Value = null;
|
|
this.datePickerETDBerth_End.Value = null;
|
|
this.datePickerATA.Value = null;
|
|
this.datePickerATD.Value = null;
|
|
this.datePickerLockTime.Value = null;
|
|
this.datePickerZoneEntry.Value = null;
|
|
this.textBoxRemarks.Text = null;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private methods
|
|
|
|
private bool CheckValues(out string message)
|
|
{
|
|
|
|
message = "";
|
|
|
|
if ((this.datePickerETABerth.Value != this.Times.EtaBerth) || (this.datePickerETABerth_End.Value != this.Times.EtaIntervalEnd))
|
|
{
|
|
if (this.datePickerETABerth.Value.IsTooOld() || this.datePickerETABerth_End.Value.IsTooOld())
|
|
{
|
|
message = BreCalClient.Resources.Resources.textETAInThePast;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (this.datePickerETABerth.Value.HasValue && this.datePickerETABerth_End.Value.HasValue && this.datePickerETABerth.Value > this.datePickerETABerth_End.Value)
|
|
{
|
|
message = BreCalClient.Resources.Resources.textEndValueBeforeStartValue;
|
|
return false;
|
|
}
|
|
|
|
if((this.datePickerETDBerth.Value != this.Times.EtdBerth) || (this.datePickerETDBerth_End.Value != this.Times.EtdIntervalEnd))
|
|
{
|
|
if(this.datePickerETDBerth.Value.IsTooOld() || this.datePickerETDBerth_End.Value.IsTooOld())
|
|
{
|
|
message = BreCalClient.Resources.Resources.textETDInThePast;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (this.datePickerETDBerth.Value.HasValue && this.datePickerETDBerth_End.Value.HasValue && this.datePickerETDBerth.Value > this.datePickerETDBerth_End.Value)
|
|
{
|
|
message = BreCalClient.Resources.Resources.textEndValueBeforeStartValue;
|
|
return false;
|
|
}
|
|
|
|
if (this.datePickerLockTime.Value.IsTooOld() && (this.datePickerLockTime.Value != this.Times.LockTime))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textLockTimeInThePast;
|
|
return false;
|
|
}
|
|
|
|
if (this.datePickerZoneEntry.Value.IsTooOld() && (this.datePickerZoneEntry.Value != this.Times.ZoneEntry))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textZoneEntryInThePast;
|
|
return false;
|
|
}
|
|
|
|
if(this.datePickerATA.Value.IsTooFar() || this.datePickerATD.Value.IsTooFar() || this.datePickerETABerth.Value.IsTooFar() || this.datePickerETABerth_End.Value.IsTooFar() ||
|
|
this.datePickerETDBerth.Value.IsTooFar() || this.datePickerETDBerth_End.Value.IsTooFar() || this.datePickerLockTime.Value.IsTooFar() || this.datePickerZoneEntry.Value.IsTooFar())
|
|
{
|
|
message = BreCalClient.Resources.Resources.textTooFarInTheFuture;
|
|
return false;
|
|
}
|
|
|
|
if((this.datePickerETABerth_End.Value.HasValue && !this.datePickerETABerth.Value.HasValue) || (this.datePickerETDBerth_End.Value.HasValue && !this.datePickerETDBerth.Value.HasValue))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textStartTimeMissing;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
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.EtaIntervalEnd = this.datePickerETABerth_End.Value;
|
|
this.Times.EtdIntervalEnd = this.datePickerETDBerth_End.Value;
|
|
this.Times.LockTime = this.datePickerLockTime.Value;
|
|
this.Times.ZoneEntry = this.datePickerZoneEntry.Value;
|
|
this.Times.Ata = this.datePickerATA.Value;
|
|
this.Times.Atd = this.datePickerATD.Value;
|
|
}
|
|
|
|
private void CopyToControls()
|
|
{
|
|
this.textBoxRemarks.Text = this.Times.Remarks;
|
|
this.datePickerETABerth.Value = this.Times.EtaBerth;
|
|
if(this.datePickerETABerth.IsEnabled && (this.Times.EtaBerth == null) && (this.AgencyTimes?.EtaBerth != null) && (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival) && (this.AgencyTimes?.EtaBerth > DateTime.Now.AddDays(-1)))
|
|
{
|
|
this.datePickerETABerth.Value = this.AgencyTimes.EtaBerth;
|
|
if (this.datePickerETABerth.Template.FindName("PART_TextBox", this.datePickerETABerth) is WatermarkTextBox tb) { tb.Focus(); tb.SelectAll(); }
|
|
}
|
|
this.datePickerETDBerth.Value = this.Times.EtdBerth;
|
|
if(this.datePickerETDBerth.IsEnabled && (this.Times.EtdBerth == null) && (this.AgencyTimes?.EtdBerth != null) && ((ShipcallModel.Shipcall?.Type == ShipcallType.Departure) || (ShipcallModel.Shipcall?.Type == ShipcallType.Shifting)) && (this.AgencyTimes?.EtdBerth > DateTime.Now.AddDays(-1)))
|
|
{
|
|
this.datePickerETDBerth.Value = this.AgencyTimes.EtdBerth;
|
|
if (this.datePickerETDBerth.Template.FindName("PART_TextBox", this.datePickerETDBerth) is WatermarkTextBox tb) tb.SelectAll();
|
|
}
|
|
|
|
this.datePickerLockTime.Value = this.Times.LockTime;
|
|
this.datePickerZoneEntry.Value = this.Times.ZoneEntry;
|
|
this.datePickerATA.Value = this.Times.Ata;
|
|
this.datePickerATD.Value = this.Times.Atd;
|
|
this.datePickerETABerth_End.Value = this.Times.EtaIntervalEnd;
|
|
if (this.datePickerETABerth_End.IsEnabled && (this.Times.EtaIntervalEnd == null) && (this.Times.EtaBerth == null) && (this.AgencyTimes?.EtaIntervalEnd != null) && (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival) && (this.AgencyTimes?.EtaBerth > DateTime.Now.AddDays(-1)))
|
|
{
|
|
this.datePickerETABerth_End.Value = this.AgencyTimes.EtaIntervalEnd;
|
|
//if (this.datePickerETABerth_End.Template.FindName("PART_TextBox", this.datePickerETABerth_End) is WatermarkTextBox tb) { tb.Focus(); tb.SelectAll(); }
|
|
}
|
|
|
|
this.datePickerETDBerth_End.Value = this.Times.EtdIntervalEnd;
|
|
if (this.datePickerETDBerth_End.IsEnabled && (this.Times.EtdIntervalEnd == null) && (this.Times.EtdBerth == null) && (this.AgencyTimes?.EtdIntervalEnd != null) && ((ShipcallModel.Shipcall?.Type == ShipcallType.Departure) || (ShipcallModel.Shipcall?.Type == ShipcallType.Shifting)) && (this.AgencyTimes?.EtdBerth > DateTime.Now.AddDays(-1)))
|
|
{
|
|
this.datePickerETDBerth_End.Value = this.AgencyTimes.EtdIntervalEnd;
|
|
//if (this.datePickerETDBerth_End.Template.FindName("PART_TextBox", this.datePickerETDBerth_End) is WatermarkTextBox tb) { tb.Focus(); tb.SelectAll(); }
|
|
}
|
|
|
|
if (this.ShipcallModel.Shipcall?.Type != ShipcallType.Shifting)
|
|
{
|
|
int displayIndex = this.ShipcallModel.Shipcall?.TimeRefPoint ?? 0;
|
|
if (displayIndex > 0)
|
|
{
|
|
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);
|
|
}
|
|
|
|
private void EnableControls()
|
|
{
|
|
Extensions.ParticipantType pType = (Extensions.ParticipantType) this.Times.ParticipantType;
|
|
|
|
// setting visibility
|
|
|
|
if (pType != Extensions.ParticipantType.MOORING)
|
|
{
|
|
this.labelATA.Visibility = Visibility.Hidden;
|
|
this.datePickerATA.Visibility = Visibility.Hidden;
|
|
this.labelATD.Visibility = Visibility.Hidden;
|
|
this.datePickerATD.Visibility = Visibility.Hidden;
|
|
}
|
|
else
|
|
{
|
|
if(ShipcallModel.Shipcall?.Type == ShipcallType.Arrival)
|
|
{
|
|
this.labelATD.Visibility = Visibility.Hidden;
|
|
this.datePickerATD.Visibility = Visibility.Hidden;
|
|
}
|
|
if (ShipcallModel.Shipcall?.Type == ShipcallType.Departure)
|
|
{
|
|
this.labelATA.Visibility = Visibility.Hidden;
|
|
this.datePickerATA.Visibility = Visibility.Hidden;
|
|
}
|
|
}
|
|
|
|
if (ShipcallModel.Shipcall?.Type != ShipcallType.Arrival)
|
|
{
|
|
this.rowETA.Height = new(0);
|
|
}
|
|
else
|
|
{
|
|
this.rowETD.Height = new(0);
|
|
}
|
|
|
|
// setting en/dis-abled
|
|
|
|
if ((this.Times.ParticipantId != App.Participant.Id) || (this.ShipcallModel.Shipcall?.Canceled ?? false))
|
|
{
|
|
this.buttonFixedOrder.IsEnabled = false;
|
|
this.buttonOK.IsEnabled = false;
|
|
return; // if this is not "my" entry, there is no editing!
|
|
}
|
|
|
|
this.datePickerETABerth.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival);
|
|
this.datePickerETABerth_End.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival);
|
|
this.datePickerETDBerth.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Departure || ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.datePickerETDBerth_End.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Departure || ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.textBoxRemarks.IsReadOnly = false;
|
|
this.buttonClearAll.IsEnabled = true;
|
|
|
|
switch (pType)
|
|
{
|
|
case Extensions.ParticipantType.MOORING:
|
|
this.datePickerATA.IsEnabled = true;
|
|
this.datePickerATD.IsEnabled = true;
|
|
break;
|
|
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);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void SetLockButton(bool newValue)
|
|
{
|
|
if (newValue)
|
|
{
|
|
this.Times.EtaBerthFixed = true;
|
|
this.imageFixedOrder.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/lock.png", UriKind.RelativeOrAbsolute));
|
|
this.buttonFixedOrder.ToolTip = BreCalClient.Resources.Resources.textTooltipUnSetFixedOrder;
|
|
}
|
|
else
|
|
{
|
|
this.Times.EtaBerthFixed = false;
|
|
this.imageFixedOrder.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/lock_open.png", UriKind.RelativeOrAbsolute));
|
|
this.buttonFixedOrder.ToolTip = BreCalClient.Resources.Resources.textTooltipSetFixedOrder;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region clear value event handler
|
|
|
|
private void contextMenuItemClearETA_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerETABerth.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemClearETD_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerETDBerth.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemClearLockTime_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerLockTime.Value = null;
|
|
}
|
|
|
|
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)
|
|
{
|
|
this.datePickerETABerth_End.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemClearETD_End_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerETDBerth_End.Value = null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|