// Copyright (c) 2023 schick Informatik // Description: Input control for incoming shipcalls // using BreCalClient.misc.Model; using System; using System.Collections.Generic; using System.Linq; using System.Windows; namespace BreCalClient { /// /// Interaction logic for EditTimesAgencyIncomingControl.xaml /// public partial class EditTimesAgencyIncomingControl : Window, IEditShipcallTimesControl { #region Construction public EditTimesAgencyIncomingControl() { 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.comboBoxArrivalBerth.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.EtaBerth = this.datePickerETA.Value; if (this.comboBoxPierside.SelectedIndex >= 0) { this.ShipcallModel.Shipcall.PierSide = (this.comboBoxPierside.SelectedIndex == 0) ? true : false; } this.Times.BerthInfo = this.textBoxBerthRemarks.Text.Trim(); if((this.comboBoxArrivalBerth.SelectedValue != null) && ((int?)this.comboBoxArrivalBerth.SelectedValue != this.ShipcallModel.Shipcall.ArrivalBerthId)) { 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.Anchored = this.checkBoxAnchored.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.Bunkering = this.checkBoxBunkering.IsChecked; this.ShipcallModel.Shipcall.ReplenishingTerminal = this.checkBoxReplenishingTerminal.IsChecked; this.ShipcallModel.Shipcall.ReplenishingLock = this.checkBoxReplenishingLock.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 participantAssignment = new() { ParticipantId = participant.Id, Type = (int)Extensions.ParticipantType.MOORING }; this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.MOORING] = participantAssignment; } participant = (Participant?)this.comboBoxPilot.SelectedItem; if (participant != null) { ParticipantAssignment participantAssignment = new() { ParticipantId = participant.Id, Type = (int)Extensions.ParticipantType.PILOT }; this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.PILOT] = participantAssignment; } participant = (Participant?)this.comboBoxTerminal.SelectedItem; if (participant != null) { ParticipantAssignment participantAssignment = new() { ParticipantId = participant.Id, Type = (int)Extensions.ParticipantType.TERMINAL }; this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TERMINAL] = participantAssignment; } participant = (Participant?)this.comboBoxTug.SelectedItem; if (participant != null) { ParticipantAssignment participantAssignment = new() { ParticipantId = participant.Id, Type = (int)Extensions.ParticipantType.TUG }; this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.TUG] = participantAssignment; } } } 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 (Times.BerthId.HasValue) this.comboBoxArrivalBerth.SelectedValue = Times.BerthId; else if (this.ShipcallModel.Shipcall.ArrivalBerthId.HasValue) this.comboBoxArrivalBerth.SelectedValue = this.ShipcallModel.Shipcall.ArrivalBerthId; 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 ?? false; this.checkBoxAnchored.IsChecked = this.ShipcallModel.Shipcall.Anchored ?? false; this.checkBoxTugRequired.IsChecked = this.ShipcallModel.Shipcall.TugRequired ?? false; this.integerUpDownRecommendedTugs.Value = this.ShipcallModel.Shipcall.RecommendedTugs; this.checkBoxPilotRequired.IsChecked = this.ShipcallModel.Shipcall.PilotRequired ?? false; this.checkBoxMooredLock.IsChecked = this.ShipcallModel.Shipcall.MooredLock ?? false; this.checkBoxBunkering.IsChecked = this.ShipcallModel.Shipcall.Bunkering ?? false; this.checkBoxReplenishingLock.IsChecked = this.ShipcallModel.Shipcall.ReplenishingLock ?? false; this.checkBoxReplenishingTerminal.IsChecked = this.ShipcallModel.Shipcall.ReplenishingTerminal ?? false; if(!string.IsNullOrEmpty(this.Times.Remarks)) this.textBoxRemarks.Text = this.Times.Remarks; foreach (ParticipantAssignment participantAssignment in this.ShipcallModel.Shipcall.Participants) { if (((List)this.comboBoxMooring.ItemsSource).Any(x => x.Id == participantAssignment.ParticipantId)) this.comboBoxMooring.SelectedValue = participantAssignment.ParticipantId; if (((List)this.comboBoxPilot.ItemsSource).Any(x => x.Id == participantAssignment.ParticipantId)) this.comboBoxPilot.SelectedValue = participantAssignment.ParticipantId; if (((List)this.comboBoxTerminal.ItemsSource).Any(x => x.Id == participantAssignment.ParticipantId)) this.comboBoxTerminal.SelectedValue = participantAssignment.ParticipantId; if (((List)this.comboBoxTug.ItemsSource).Any(x => x.Id == participantAssignment.ParticipantId)) this.comboBoxTug.SelectedValue = participantAssignment.ParticipantId; } } } #endregion #region context menu handlers 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); } #endregion } }