// Copyright (c) 2023 schick Informatik // Description: Input control for shifting operations // using BreCalClient.misc.Model; using System; using System.Windows; using static BreCalClient.Extensions; namespace BreCalClient { /// /// Interaction logic for EditTimesAgencyShiftingControl.xaml /// public partial class EditTimesAgencyShiftingControl : Window, IEditShipcallTimesControl { #region Construction public EditTimesAgencyShiftingControl() { InitializeComponent(); } #endregion #region Properties public ShipcallControlModel ShipcallModel { get; set; } = new(); public Times Times { get; set; } = new(); public Extensions.TypeEnum CallType { get; set; } #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.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths; this.CopyToControls(); Participant? p = null; 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); } bool enableControls = (this.Times.ParticipantId == App.Participant.Id) || (App.Participant.IsTypeFlagSet(ParticipantType.BSMD) && allowBSMD); this.EnableControls(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(); } #endregion #region private methods private void CopyToModel() { if (this.ShipcallModel.Shipcall != null) { this.Times.EtdBerth = this.datePickerETD.Value; this.Times.EtaBerth = this.datePickerETA.Value; this.ShipcallModel.Shipcall.DepartureBerthId = (int)this.comboBoxDepartureBerth.SelectedValue; if (this.comboBoxPiersideArrival.SelectedIndex >= 0) { this.ShipcallModel.Shipcall.PierSide = (this.comboBoxPiersideArrival.SelectedIndex == 0) ? true : false; } 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.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) { 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; } 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.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.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(bool isEnabled) { this.datePickerETD.IsEnabled = isEnabled; this.comboBoxArrivalBerth.IsEnabled = isEnabled; this.doubleUpDownDraft.IsEnabled = isEnabled; this.datePickerTidalWindowFrom.IsEnabled = isEnabled; this.datePickerTidalWindowTo.IsEnabled = isEnabled; this.datePickerETA.IsEnabled = isEnabled; this.comboBoxDepartureBerth.IsEnabled = isEnabled; this.comboBoxPiersideArrival.IsEnabled = isEnabled; this.textBoxBerthRemarksArrival.IsEnabled = isEnabled; this.checkBoxCanceled.IsEnabled = isEnabled; this.checkBoxTugRequired.IsEnabled = isEnabled; this.comboBoxTug.IsEnabled = isEnabled; this.integerUpDownRecommendedTugs.IsEnabled = isEnabled; this.checkBoxPilotRequired.IsEnabled = isEnabled; this.comboBoxPilot.IsEnabled = isEnabled; this.comboBoxMooring.IsEnabled = isEnabled; this.checkBoxMooredLock.IsEnabled = isEnabled; this.comboBoxTerminal.IsEnabled = isEnabled; this.checkBoxRainsensitiveCargo.IsEnabled = isEnabled; this.textBoxRemarks.IsEnabled = isEnabled; this.buttonOK.IsEnabled = isEnabled; } #endregion #region context menu 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); } #endregion } }