179 lines
6.5 KiB
C#
179 lines
6.5 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;
|
|
|
|
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 ShipcallControlModel ShipcallModel { get; set; } = new();
|
|
|
|
#endregion
|
|
|
|
#region event handler
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
this.CopyToControls();
|
|
this.EnableControls();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
#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;
|
|
}
|
|
|
|
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.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;
|
|
if (this.Times.ParticipantId != App.Participant.Id)
|
|
{
|
|
this.buttonFixedOrder.IsEnabled = false;
|
|
return; // if this is not "my" entry, there is no editing!
|
|
}
|
|
|
|
switch (pType)
|
|
{
|
|
case Extensions.ParticipantType.MOORING:
|
|
case Extensions.ParticipantType.PORT_ADMINISTRATION:
|
|
case Extensions.ParticipantType.TUG:
|
|
this.datePickerETABerth.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival);
|
|
this.datePickerETDBerth.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Departure || ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.datePickerLockTime.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival || ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.datePickerZoneEntry.IsEnabled = false;
|
|
this.textBoxRemarks.IsEnabled = true;
|
|
break;
|
|
case Extensions.ParticipantType.PILOT:
|
|
this.datePickerETABerth.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival);
|
|
this.datePickerETDBerth.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Departure || ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.datePickerLockTime.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival || ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.datePickerZoneEntry.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival);
|
|
this.textBoxRemarks.IsEnabled = true;
|
|
break;
|
|
}
|
|
this.buttonOK.IsEnabled = true;
|
|
}
|
|
|
|
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));
|
|
}
|
|
else
|
|
{
|
|
this.Times.EtaBerthFixed = false;
|
|
this.imageFixedOrder.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/lock_open.png", UriKind.RelativeOrAbsolute));
|
|
}
|
|
}
|
|
|
|
#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;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|