474 lines
20 KiB
C#
474 lines
20 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Input control for shifting operations
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Documents;
|
|
using static BreCalClient.Extensions;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for EditTimesAgencyShiftingControl.xaml
|
|
/// </summary>
|
|
public partial class EditTimesAgencyShiftingControl : Window, IEditTimesControl
|
|
{
|
|
#region Fields
|
|
|
|
bool _editing = false;
|
|
|
|
#endregion
|
|
|
|
#region Construction
|
|
|
|
public EditTimesAgencyShiftingControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public ShipcallControlModel ShipcallModel { get; set; } = new();
|
|
|
|
public Times Times { get; set; } = new();
|
|
|
|
#endregion
|
|
|
|
#region event handler
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
if ((this.ShipcallModel != null) && (this.ShipcallModel.Shipcall != null))
|
|
{
|
|
int portId = this.ShipcallModel.Shipcall.PortId;
|
|
List<Berth> availableBerths = BreCalLists.GetBerthsByPort(portId);
|
|
this.comboBoxArrivalBerth.ItemsSource = availableBerths;
|
|
this.comboBoxDepartureBerth.ItemsSource = availableBerths;
|
|
this.comboBoxMooring.ItemsSource = BreCalLists.GetParticipants(portId, ParticipantType.MOORING);
|
|
this.comboBoxPilot.ItemsSource = BreCalLists.GetParticipants(portId, ParticipantType.PILOT);
|
|
this.comboBoxTug.ItemsSource = BreCalLists.GetParticipants(portId, ParticipantType.TUG);
|
|
this.comboBoxTerminal.ItemsSource = BreCalLists.GetParticipants(portId, ParticipantType.TERMINAL);
|
|
}
|
|
|
|
this.CopyToControls();
|
|
|
|
Participant? p = null;
|
|
|
|
if (this.ShipcallModel != null)
|
|
{
|
|
this.Title = this.ShipcallModel.Title;
|
|
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY))
|
|
p = BreCalLists.Participants.Find(x => x.Id == this.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId);
|
|
}
|
|
|
|
bool allowBSMD = false;
|
|
if (p != null)
|
|
{
|
|
allowBSMD = p.IsFlagSet(ParticipantFlag.ALLOW_BSMD);
|
|
}
|
|
|
|
_editing = (this.Times.ParticipantId == App.Participant.Id) ||
|
|
(App.Participant.IsTypeFlagSet(ParticipantType.BSMD) && allowBSMD);
|
|
|
|
this.EnableControls();
|
|
|
|
}
|
|
|
|
private void buttonOK_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!CheckValues(out string message))
|
|
{
|
|
System.Windows.MessageBox.Show(message, "Warning", 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();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private methods
|
|
|
|
private bool CheckValues(out string message)
|
|
{
|
|
message = "";
|
|
|
|
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.IsTooOld() && (this.datePickerETA_End.Value != this.Times.EtaIntervalEnd))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textETAInThePast;
|
|
return false;
|
|
}
|
|
|
|
if (this.datePickerETA.Value.HasValue && this.datePickerETA_End.Value.HasValue && this.datePickerETA.Value > this.datePickerETA_End.Value)
|
|
{
|
|
message = BreCalClient.Resources.Resources.textEndValueBeforeStartValue;
|
|
return false;
|
|
}
|
|
|
|
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.IsTooOld() && (this.datePickerETD_End.Value != this.Times.EtdIntervalEnd))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textETDInThePast;
|
|
return false;
|
|
}
|
|
|
|
if (this.datePickerETD.Value.HasValue && this.datePickerETD_End.Value.HasValue && this.datePickerETD.Value > this.datePickerETD_End.Value)
|
|
{
|
|
message = BreCalClient.Resources.Resources.textEndValueBeforeStartValue;
|
|
return false;
|
|
}
|
|
|
|
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.IsTooOld() && (this.datePickerTidalWindowTo.Value != this.ShipcallModel.Shipcall?.TidalWindowTo))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textTideTimesInThePast;
|
|
return false;
|
|
}
|
|
|
|
if (this.datePickerTidalWindowFrom.Value.HasValue && this.datePickerTidalWindowTo.Value.HasValue && this.datePickerTidalWindowFrom.Value > this.datePickerTidalWindowTo.Value)
|
|
{
|
|
message = BreCalClient.Resources.Resources.textEndValueBeforeStartValue;
|
|
return false;
|
|
}
|
|
|
|
if ((this.datePickerTidalWindowFrom.Value.HasValue && !this.datePickerTidalWindowTo.Value.HasValue) || (!this.datePickerTidalWindowFrom.Value.HasValue && this.datePickerTidalWindowTo.Value.HasValue))
|
|
{
|
|
message = BreCalClient.Resources.Resources.textTidalBothValues;
|
|
return false;
|
|
}
|
|
|
|
if (this.datePickerETA.Value.IsTooFar() || this.datePickerETA_End.Value.IsTooFar() || this.datePickerTidalWindowFrom.Value.IsTooFar() || this.datePickerTidalWindowTo.Value.IsTooFar() ||
|
|
this.datePickerETD.Value.IsTooFar() || this.datePickerETD_End.Value.IsTooFar())
|
|
{
|
|
message = BreCalClient.Resources.Resources.textTooFarInTheFuture;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void CopyToModel()
|
|
{
|
|
if (this.ShipcallModel.Shipcall != null)
|
|
{
|
|
this.Times.EtdBerth = this.datePickerETD.Value;
|
|
this.Times.EtaBerth = this.datePickerETA.Value;
|
|
this.Times.EtaIntervalEnd = this.datePickerETA_End.Value;
|
|
this.Times.EtdIntervalEnd = this.datePickerETD_End.Value;
|
|
|
|
this.ShipcallModel.Shipcall.DepartureBerthId = (int)this.comboBoxDepartureBerth.SelectedValue;
|
|
if (this.comboBoxPiersideArrival.SelectedIndex >= 0)
|
|
{
|
|
this.ShipcallModel.Shipcall.PierSide = (this.comboBoxPiersideArrival.SelectedIndex == 0);
|
|
}
|
|
else
|
|
{
|
|
this.ShipcallModel.Shipcall.PierSide = null;
|
|
}
|
|
|
|
this.Times.BerthInfo = this.textBoxBerthRemarksArrival.Text.Trim();
|
|
this.Times.BerthId = (int?)this.comboBoxArrivalBerth.SelectedValue;
|
|
|
|
this.ShipcallModel.Shipcall.Draft = (float?)this.doubleUpDownDraft.Value;
|
|
this.ShipcallModel.Shipcall.TidalWindowFrom = this.datePickerTidalWindowFrom.Value;
|
|
this.ShipcallModel.Shipcall.TidalWindowTo = this.datePickerTidalWindowTo.Value;
|
|
this.ShipcallModel.Shipcall.Canceled = this.checkBoxCanceled.IsChecked;
|
|
|
|
|
|
|
|
this.ShipcallModel.Shipcall.RecommendedTugs = this.integerUpDownRecommendedTugs.Value;
|
|
|
|
this.ShipcallModel.Shipcall.MooredLock = this.checkBoxMooredLock.IsChecked;
|
|
this.ShipcallModel.Shipcall.RainSensitiveCargo = this.checkBoxRainsensitiveCargo.IsChecked;
|
|
if(!string.IsNullOrEmpty(this.textBoxRemarks.Text.Trim()))
|
|
this.Times.Remarks = this.textBoxRemarks.Text.Trim();
|
|
|
|
Participant? participant = (Participant?)this.comboBoxMooring.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
ParticipantAssignment pa = new()
|
|
{
|
|
ParticipantId = participant.Id,
|
|
Type = (int)Extensions.ParticipantType.MOORING
|
|
};
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.MOORING] = pa;
|
|
}
|
|
participant = (Participant?)this.comboBoxPilot.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
ParticipantAssignment pa = new()
|
|
{
|
|
ParticipantId = participant.Id,
|
|
Type = (int)Extensions.ParticipantType.PILOT
|
|
};
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.PILOT] = pa;
|
|
}
|
|
participant = (Participant?)this.comboBoxTerminal.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
ParticipantAssignment pa = new()
|
|
{
|
|
ParticipantId = participant.Id,
|
|
Type = (int)Extensions.ParticipantType.TERMINAL
|
|
};
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TERMINAL] = pa;
|
|
}
|
|
participant = (Participant?)this.comboBoxTug.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
ParticipantAssignment pa = new()
|
|
{
|
|
ParticipantId = participant.Id,
|
|
Type = (int)Extensions.ParticipantType.TUG
|
|
};
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TUG] = pa;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CopyToControls()
|
|
{
|
|
if (this.ShipcallModel == null) return;
|
|
if (this.ShipcallModel.Shipcall != null)
|
|
{
|
|
if (this.Times.EtaBerth.HasValue)
|
|
{
|
|
this.datePickerETA.Value = this.Times.EtaBerth.Value;
|
|
}
|
|
else
|
|
{
|
|
// if not set through times use value of BSMD entry
|
|
if (this.ShipcallModel.Shipcall.Eta != DateTime.MinValue)
|
|
this.datePickerETA.Value = this.ShipcallModel.Shipcall.Eta;
|
|
}
|
|
if(this.Times.EtdBerth.HasValue)
|
|
{
|
|
this.datePickerETD.Value = this.Times.EtdBerth.Value;
|
|
}
|
|
else
|
|
{
|
|
if (this.ShipcallModel.Shipcall.Etd != DateTime.MinValue)
|
|
this.datePickerETD.Value = this.ShipcallModel.Shipcall.Etd;
|
|
}
|
|
|
|
this.datePickerETA_End.Value = this.Times.EtaIntervalEnd;
|
|
this.datePickerETD_End.Value = this.Times.EtdIntervalEnd;
|
|
|
|
if (this.Times.BerthId.HasValue)
|
|
this.comboBoxArrivalBerth.SelectedValue = this.Times.BerthId;
|
|
else if (this.ShipcallModel.Shipcall.ArrivalBerthId.HasValue)
|
|
this.comboBoxArrivalBerth.SelectedValue = this.ShipcallModel.Shipcall.ArrivalBerthId;
|
|
|
|
if (this.ShipcallModel.Shipcall.DepartureBerthId.HasValue)
|
|
this.comboBoxDepartureBerth.SelectedValue = this.ShipcallModel.Shipcall.DepartureBerthId;
|
|
|
|
if (this.ShipcallModel.Shipcall.PierSide.HasValue)
|
|
{
|
|
if (this.ShipcallModel.Shipcall.PierSide.Value) this.comboBoxPiersideArrival.SelectedIndex = 0;
|
|
else this.comboBoxPiersideArrival.SelectedIndex = 1;
|
|
}
|
|
this.textBoxBerthRemarksArrival.Text = this.Times.BerthInfo;
|
|
this.doubleUpDownDraft.Value = this.ShipcallModel.Shipcall.Draft;
|
|
this.datePickerTidalWindowFrom.Value = this.ShipcallModel.Shipcall.TidalWindowFrom;
|
|
this.datePickerTidalWindowTo.Value = this.ShipcallModel.Shipcall.TidalWindowTo;
|
|
this.checkBoxCanceled.IsChecked = this.ShipcallModel.Shipcall.Canceled ?? false;
|
|
|
|
this.integerUpDownRecommendedTugs.Value = this.ShipcallModel.Shipcall.RecommendedTugs;
|
|
|
|
|
|
this.checkBoxMooredLock.IsChecked = this.ShipcallModel.Shipcall.MooredLock ?? false;
|
|
this.checkBoxRainsensitiveCargo.IsChecked = this.ShipcallModel.Shipcall.RainSensitiveCargo ?? false;
|
|
|
|
if (!string.IsNullOrEmpty(this.Times.Remarks))
|
|
this.textBoxRemarks.Text = this.Times.Remarks;
|
|
|
|
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.MOORING))
|
|
{
|
|
if (BreCalLists.ParticipantLookupDict.ContainsKey(this.ShipcallModel.AssignedParticipants[ParticipantType.MOORING].ParticipantId))
|
|
{
|
|
this.comboBoxMooring.SelectedValue = this.ShipcallModel.AssignedParticipants[ParticipantType.MOORING].ParticipantId;
|
|
}
|
|
}
|
|
|
|
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.PILOT))
|
|
{
|
|
if (BreCalLists.ParticipantLookupDict.ContainsKey(this.ShipcallModel.AssignedParticipants[ParticipantType.PILOT].ParticipantId))
|
|
{
|
|
this.comboBoxPilot.SelectedValue = this.ShipcallModel.AssignedParticipants[ParticipantType.PILOT].ParticipantId;
|
|
}
|
|
}
|
|
|
|
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.TERMINAL))
|
|
{
|
|
if (BreCalLists.ParticipantLookupDict.ContainsKey(this.ShipcallModel.AssignedParticipants[ParticipantType.TERMINAL].ParticipantId))
|
|
{
|
|
this.comboBoxTerminal.SelectedValue = this.ShipcallModel.AssignedParticipants[ParticipantType.TERMINAL].ParticipantId;
|
|
}
|
|
}
|
|
|
|
if (this.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.TUG))
|
|
{
|
|
if (BreCalLists.ParticipantLookupDict.ContainsKey(this.ShipcallModel.AssignedParticipants[ParticipantType.TUG].ParticipantId))
|
|
{
|
|
this.comboBoxTug.SelectedValue = this.ShipcallModel.AssignedParticipants[ParticipantType.TUG].ParticipantId;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void EnableControls()
|
|
{
|
|
this.datePickerETD_End.IsEnabled = _editing;
|
|
this.datePickerETA_End.IsEnabled = _editing;
|
|
this.datePickerETD.IsEnabled = _editing;
|
|
this.comboBoxArrivalBerth.IsEnabled = _editing;
|
|
this.doubleUpDownDraft.IsEnabled = _editing;
|
|
this.datePickerTidalWindowFrom.IsEnabled = _editing;
|
|
this.datePickerTidalWindowTo.IsEnabled = _editing;
|
|
this.datePickerETA.IsEnabled = _editing;
|
|
this.comboBoxDepartureBerth.IsEnabled = _editing;
|
|
this.comboBoxPiersideArrival.IsEnabled = _editing;
|
|
this.textBoxBerthRemarksArrival.IsReadOnly = !_editing;
|
|
this.checkBoxCanceled.IsEnabled = _editing;
|
|
|
|
|
|
this.comboBoxTug.IsEnabled = _editing;
|
|
this.integerUpDownRecommendedTugs.IsEnabled = _editing;
|
|
this.comboBoxPilot.IsEnabled = _editing;
|
|
this.comboBoxMooring.IsEnabled = _editing;
|
|
this.checkBoxMooredLock.IsEnabled = _editing;
|
|
this.comboBoxTerminal.IsEnabled = _editing;
|
|
this.checkBoxRainsensitiveCargo.IsEnabled = _editing;
|
|
this.textBoxRemarks.IsReadOnly = !_editing;
|
|
|
|
CheckOKButton();
|
|
}
|
|
|
|
private bool RequiredFieldsSet()
|
|
{
|
|
bool areSet = this.datePickerETA.Value.HasValue &&
|
|
this.datePickerETD.Value.HasValue &&
|
|
this.doubleUpDownDraft.Value.HasValue &&
|
|
(this.comboBoxArrivalBerth.SelectedIndex >= 0) &&
|
|
(this.comboBoxDepartureBerth.SelectedIndex >= 0);
|
|
|
|
if (this.datePickerETA_End.Value.HasValue)
|
|
areSet &= (this.datePickerETA_End.Value > this.datePickerETA.Value);
|
|
|
|
if (this.datePickerETD_End.Value.HasValue)
|
|
areSet &= (this.datePickerETD_End.Value > this.datePickerETD.Value);
|
|
|
|
return areSet;
|
|
}
|
|
|
|
private void CheckOKButton()
|
|
{
|
|
this.buttonOK.IsEnabled = _editing && RequiredFieldsSet();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region event handlers
|
|
|
|
private void contextMenuItemDepartureBerth_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxDepartureBerth.SelectedIndex = -1;
|
|
this.ShipcallModel.Berth = "";
|
|
}
|
|
|
|
private void contextMenuItemArrivalBerth_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxArrivalBerth.SelectedIndex = -1;
|
|
this.ShipcallModel.Berth = "";
|
|
}
|
|
|
|
private void contextMenuItemClearTug_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxTug.SelectedIndex = -1;
|
|
this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.TUG);
|
|
}
|
|
|
|
private void contextMenuItemClearPilot_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxPilot.SelectedIndex = -1;
|
|
this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.PILOT);
|
|
}
|
|
|
|
private void contextMenuItemClearMooring_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxMooring.SelectedIndex = -1;
|
|
this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.MOORING);
|
|
}
|
|
|
|
private void contextMenuItemClearTerminal_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxTerminal.SelectedIndex = -1;
|
|
this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.TERMINAL);
|
|
}
|
|
|
|
private void contextMenuItemClearPierside_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxPiersideArrival.SelectedIndex = -1;
|
|
}
|
|
|
|
private void datePickerETD_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
private void comboBoxDepartureBerth_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
private void doubleUpDownDraft_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
private void datePickerETA_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
private void comboBoxArrivalBerth_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|
{
|
|
CheckOKButton();
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|