209 lines
9.2 KiB
C#
209 lines
9.2 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Input control for outgoing shipcalls
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for EditTimesAgencyOutgoingControl.xaml
|
|
/// </summary>
|
|
public partial class EditTimesAgencyOutgoingControl : Window, IEditShipcallTimesControl
|
|
{
|
|
|
|
#region Construction
|
|
|
|
public EditTimesAgencyOutgoingControl()
|
|
{
|
|
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)
|
|
{
|
|
this.comboBoxMooring.ItemsSource = BreCalLists.Participants_Mooring;
|
|
this.comboBoxPilot.ItemsSource = BreCalLists.Participants_Pilot;
|
|
this.comboBoxTug.ItemsSource = BreCalLists.Participants_Tug;
|
|
this.comboBoxTerminal.ItemsSource = BreCalLists.Participants_Terminal;
|
|
|
|
this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths;
|
|
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();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private methods
|
|
|
|
private void CopyToModel()
|
|
{
|
|
if (this.ShipcallModel.Shipcall != null)
|
|
{
|
|
this.Times.EtdBerth = this.datePickerETD.Value;
|
|
if (this.comboBoxPierside.SelectedIndex >= 0)
|
|
{
|
|
this.ShipcallModel.Shipcall.PierSide = (this.comboBoxPierside.SelectedIndex == 0) ? true : false;
|
|
}
|
|
if ((this.comboBoxDepartureBerth.SelectedValue != null) && ((int?)this.comboBoxDepartureBerth.SelectedValue != this.ShipcallModel.Shipcall.DepartureBerthId))
|
|
{
|
|
this.Times.BerthId = (int?)this.comboBoxDepartureBerth.SelectedValue;
|
|
}
|
|
this.Times.BerthInfo = this.textBoxBerthRemarks.Text.Trim();
|
|
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.TugRequired = this.checkBoxTugRequired.IsChecked;
|
|
this.ShipcallModel.Shipcall.RecommendedTugs = this.integerUpDownRecommendedTugs.Value;
|
|
this.ShipcallModel.Shipcall.PilotRequired = this.checkBoxPilotRequired.IsChecked;
|
|
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)
|
|
{
|
|
this.ShipcallModel.Shipcall.Participants.Add(participant.Id);
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.MOORING] = participant;
|
|
}
|
|
participant = (Participant?)this.comboBoxPilot.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
this.ShipcallModel.Shipcall.Participants.Add(participant.Id);
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.PILOT] = participant;
|
|
}
|
|
participant = (Participant?)this.comboBoxTerminal.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
this.ShipcallModel.Shipcall.Participants.Add(participant.Id);
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TERMINAL] = participant;
|
|
}
|
|
participant = (Participant?)this.comboBoxTug.SelectedItem;
|
|
if (participant != null)
|
|
{
|
|
this.ShipcallModel.Shipcall.Participants.Add(participant.Id);
|
|
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TUG] = participant;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CopyToControls()
|
|
{
|
|
if (this.ShipcallModel == null) return;
|
|
if (this.ShipcallModel.Shipcall != null)
|
|
{
|
|
if (this.Times.EtdBerth.HasValue)
|
|
{
|
|
this.datePickerETD.Value = this.Times.EtdBerth.Value;
|
|
}
|
|
else
|
|
{
|
|
// if not set through times use value of BSMD entry
|
|
if (this.ShipcallModel.Shipcall.Etd != DateTime.MinValue)
|
|
this.datePickerETD.Value = this.ShipcallModel.Shipcall.Etd;
|
|
}
|
|
|
|
if (this.Times.BerthId.HasValue)
|
|
this.comboBoxDepartureBerth.SelectedValue = this.Times.BerthId;
|
|
else 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.comboBoxPierside.SelectedIndex = 0;
|
|
else this.comboBoxPierside.SelectedIndex = 1;
|
|
}
|
|
this.textBoxBerthRemarks.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;
|
|
|
|
this.checkBoxTugRequired.IsChecked = this.ShipcallModel.Shipcall.TugRequired;
|
|
this.integerUpDownRecommendedTugs.Value = this.ShipcallModel.Shipcall.RecommendedTugs;
|
|
this.checkBoxPilotRequired.IsChecked = this.ShipcallModel.Shipcall.PilotRequired;
|
|
|
|
this.checkBoxMooredLock.IsChecked = this.ShipcallModel.Shipcall.MooredLock;
|
|
this.checkBoxRainsensitiveCargo.IsChecked = this.ShipcallModel.Shipcall.RainSensitiveCargo;
|
|
if(!string.IsNullOrEmpty(this.Times.Remarks))
|
|
this.textBoxRemarks.Text = this.Times.Remarks;
|
|
|
|
foreach (int participant_id in this.ShipcallModel.Shipcall.Participants)
|
|
{
|
|
if (((List<Participant>)this.comboBoxMooring.ItemsSource).Any(x => x.Id == participant_id)) this.comboBoxMooring.SelectedValue = participant_id;
|
|
if (((List<Participant>)this.comboBoxPilot.ItemsSource).Any(x => x.Id == participant_id)) this.comboBoxPilot.SelectedValue = participant_id;
|
|
if (((List<Participant>)this.comboBoxTerminal.ItemsSource).Any(x => x.Id == participant_id)) this.comboBoxTerminal.SelectedValue = participant_id;
|
|
if (((List<Participant>)this.comboBoxTug.ItemsSource).Any(x => x.Id == participant_id)) this.comboBoxTug.SelectedValue = participant_id;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region context menu handlers
|
|
|
|
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 contextMenuItemDepartureBerth_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxDepartureBerth.SelectedIndex = -1;
|
|
this.ShipcallModel.Berth = "";
|
|
}
|
|
|
|
private void contextMenuItemClearTerminal_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.comboBoxTerminal.SelectedIndex = -1;
|
|
this.ShipcallModel.AssignedParticipants.Remove(Extensions.ParticipantType.TERMINAL);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|