162 lines
6.0 KiB
C#
162 lines
6.0 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Terminals have all different fields so a different dialog
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System.Windows;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for EditTimesTerminalControl.xaml
|
|
/// </summary>
|
|
public partial class EditTimesTerminalControl : Window, IEditTimesControl
|
|
{
|
|
public EditTimesTerminalControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#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.comboBoxBerth.ItemsSource = BreCalLists.Berths;
|
|
this.CopyToControls();
|
|
this.EnableControls();
|
|
}
|
|
|
|
private void contextMenuItemClearOperationStart_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerOperationStart.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemClearOperationEnd_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerOperationEnd.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemClearOperationStart_End_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerOperationStart_End.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemClearOperationEnd_End_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.datePickerOperationEnd_End.Value = null;
|
|
}
|
|
|
|
private void contextMenuItemBerth_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxBerth.SelectedIndex -= 1;
|
|
}
|
|
|
|
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 contextMenuItemClearPierside_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxPierside.SelectedIndex = -1;
|
|
}
|
|
|
|
private void datePickerOperationStart_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
this.CheckOKButton();
|
|
}
|
|
|
|
private void datePickerOperationEnd_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
this.CheckOKButton();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private methods
|
|
|
|
private void CopyToModel()
|
|
{
|
|
this.Times.PierSide = this.comboBoxPierside.SelectedIndex switch
|
|
{
|
|
0 => true,
|
|
1 => false,
|
|
_ => null,
|
|
};
|
|
this.Times.OperationsStart = this.datePickerOperationStart.Value;
|
|
this.Times.OperationsEnd = this.datePickerOperationEnd.Value;
|
|
this.Times.EtaIntervalEnd = this.datePickerOperationStart_End.Value;
|
|
this.Times.EtdIntervalEnd = this.datePickerOperationEnd_End.Value;
|
|
this.Times.BerthId = (this.comboBoxBerth.SelectedItem != null) ? ((Berth)this.comboBoxBerth.SelectedItem).Id : null;
|
|
this.Times.Remarks = this.textBoxRemarks.Text.Trim();
|
|
this.Times.BerthInfo = this.textBoxBerthRemarks.Text.Trim();
|
|
}
|
|
|
|
private void CopyToControls()
|
|
{
|
|
this.datePickerOperationStart.Value = this.Times.OperationsStart;
|
|
this.datePickerOperationEnd.Value = this.Times.OperationsEnd;
|
|
this.datePickerOperationStart_End.Value = this.Times.EtaIntervalEnd;
|
|
this.datePickerOperationEnd_End.Value = this.Times.EtdIntervalEnd;
|
|
if(this.Times.PierSide == null) { this.comboBoxPierside.SelectedIndex = -1; }
|
|
else this.comboBoxPierside.SelectedIndex = (this.Times.PierSide ?? false) ? 0 : 1;
|
|
this.comboBoxBerth.SelectedValue = this.Times.BerthId;
|
|
this.textBoxRemarks.Text = this.Times.Remarks;
|
|
this.textBoxBerthRemarks.Text = this.Times.BerthInfo;
|
|
|
|
switch (ShipcallModel.Shipcall?.Type)
|
|
{
|
|
case ShipcallType.Arrival:
|
|
this.labelStart.FontWeight = FontWeights.Bold;
|
|
this.datePickerOperationStart.ContextMenu.IsEnabled = false;
|
|
break;
|
|
case ShipcallType.Departure:
|
|
case ShipcallType.Shifting:
|
|
this.labelEnd.FontWeight = FontWeights.Bold;
|
|
this.datePickerOperationEnd.ContextMenu.IsEnabled = false;
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
private void EnableControls()
|
|
{
|
|
if (this.Times.ParticipantId != App.Participant.Id) return;
|
|
|
|
this.datePickerOperationStart.IsEnabled = ShipcallModel.Shipcall?.Type == ShipcallType.Arrival;
|
|
this.datePickerOperationStart_End.IsEnabled = ShipcallModel.Shipcall?.Type == ShipcallType.Arrival;
|
|
this.datePickerOperationEnd.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Departure) || (ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.datePickerOperationEnd_End.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Departure) || (ShipcallModel.Shipcall?.Type == ShipcallType.Shifting);
|
|
this.comboBoxBerth.IsEnabled = ShipcallModel.Shipcall?.Type == ShipcallType.Arrival;
|
|
this.comboBoxPierside.IsEnabled = ShipcallModel.Shipcall?.Type == ShipcallType.Arrival;
|
|
this.textBoxBerthRemarks.IsEnabled = ShipcallModel.Shipcall?.Type == ShipcallType.Arrival;
|
|
this.textBoxRemarks.IsEnabled = true;
|
|
this.CheckOKButton();
|
|
}
|
|
|
|
private void CheckOKButton()
|
|
{
|
|
this.buttonOK.IsEnabled = (ShipcallModel.Shipcall?.Type == ShipcallType.Arrival) ? this.datePickerOperationStart.Value.HasValue :
|
|
this.datePickerOperationEnd.Value.HasValue;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|