273 lines
10 KiB
C#
273 lines
10 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)
|
|
{
|
|
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 datePickerETABerth_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
private void datePickerETDBerth_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
#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.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.datePickerETABerth.Value = this.AgencyTimes.EtaBerth;
|
|
WatermarkTextBox? tb = this.datePickerETABerth.Template.FindName("PART_TextBox", this.datePickerETABerth) as WatermarkTextBox;
|
|
if (tb != null) { 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.datePickerETDBerth.Value = this.AgencyTimes.EtdBerth;
|
|
WatermarkTextBox? tb = this.datePickerETDBerth.Template.FindName("PART_TextBox", this.datePickerETDBerth) as WatermarkTextBox;
|
|
if (tb != null) 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;
|
|
this.datePickerETDBerth_End.Value = this.Times.EtdIntervalEnd;
|
|
|
|
this.labelETA.Content = string.Format("ETA {0}", BreCalLists.TimeRefs[this.ShipcallModel.Shipcall?.TimeRefPoint ?? 0]);
|
|
this.labelETD.Content = string.Format("ETD {0}", BreCalLists.TimeRefs[this.ShipcallModel.Shipcall?.TimeRefPoint ?? 0]);
|
|
|
|
switch (ShipcallModel.Shipcall?.Type)
|
|
{
|
|
case ShipcallType.Arrival:
|
|
this.labelETA.FontWeight = FontWeights.Bold;
|
|
this.datePickerETABerth.ContextMenu.IsEnabled = false;
|
|
break;
|
|
case ShipcallType.Departure:
|
|
case ShipcallType.Shifting:
|
|
this.labelETD.FontWeight = FontWeights.Bold;
|
|
this.datePickerETDBerth.ContextMenu.IsEnabled = false;
|
|
break;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
// setting en/dis-abled
|
|
|
|
if (this.Times.ParticipantId != App.Participant.Id)
|
|
{
|
|
this.buttonFixedOrder.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;
|
|
|
|
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;
|
|
}
|
|
|
|
CheckOKButton();
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
private void CheckOKButton()
|
|
{
|
|
Extensions.ParticipantType pType = (Extensions.ParticipantType)this.Times.ParticipantType;
|
|
if (pType != Extensions.ParticipantType.PORT_ADMINISTRATION)
|
|
this.buttonOK.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival) ?
|
|
this.datePickerETABerth.Value.HasValue : this.datePickerETDBerth.Value.HasValue;
|
|
else
|
|
this.buttonOK.IsEnabled = true;
|
|
}
|
|
|
|
#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
|
|
|
|
}
|
|
}
|