From 02705f26771e25f604d11704cbe5cf2cb8d1adf9 Mon Sep 17 00:00:00 2001 From: puls200 Date: Tue, 10 Oct 2023 11:50:43 +0200 Subject: [PATCH] allow read-only views of not-assigned participants of any data --- .../EditTimesAgencyIncomingControl.xaml.cs | 43 ++++++++++++++++ .../EditTimesAgencyOutgoingControl.xaml.cs | 39 +++++++++++++++ .../EditTimesAgencyShiftingControl.xaml.cs | 41 ++++++++++++++++ src/BreCalClient/EditTimesControl.xaml.cs | 29 +++++------ .../EditTimesTerminalControl.xaml.cs | 9 ++++ src/BreCalClient/MainWindow.xaml.cs | 24 ++++++++- src/BreCalClient/ShipcallControl.xaml.cs | 49 ++++++------------- 7 files changed, 180 insertions(+), 54 deletions(-) diff --git a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs index f7fee41..1efebed 100644 --- a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs @@ -44,6 +44,23 @@ namespace BreCalClient 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) @@ -220,6 +237,32 @@ namespace BreCalClient } } + private void EnableControls(bool isEnabled) + { + this.datePickerETA.IsEnabled = isEnabled; + this.comboBoxArrivalBerth.IsEnabled = isEnabled; + this.comboBoxPierside.IsEnabled = isEnabled; + this.textBoxBerthRemarks.IsEnabled = isEnabled; + this.doubleUpDownDraft.IsEnabled = isEnabled; + this.datePickerTidalWindowFrom.IsEnabled = isEnabled; + this.datePickerTidalWindowTo.IsEnabled = isEnabled; + this.checkBoxCanceled.IsEnabled = isEnabled; + + this.checkBoxAnchored.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.checkBoxBunkering.IsEnabled = isEnabled; + this.checkBoxReplenishingTerminal.IsEnabled = isEnabled; + this.checkBoxReplenishingLock.IsEnabled = isEnabled; + this.textBoxRemarks.IsEnabled = isEnabled; + } + #endregion #region context menu handlers diff --git a/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs index 3ad2bf5..eca4860 100644 --- a/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs @@ -45,6 +45,22 @@ namespace BreCalClient this.comboBoxDepartureBerth.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) @@ -210,6 +226,29 @@ namespace BreCalClient } } + private void EnableControls(bool isEnabled) + { + this.datePickerETD.IsEnabled = isEnabled; + this.comboBoxDepartureBerth.IsEnabled = isEnabled; + this.comboBoxPierside.IsEnabled = isEnabled; + this.textBoxBerthRemarks.IsEnabled = isEnabled; + this.doubleUpDownDraft.IsEnabled = isEnabled; + this.datePickerTidalWindowFrom.IsEnabled = isEnabled; + this.datePickerTidalWindowTo.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; + } + #endregion #region context menu handlers diff --git a/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs index 022e338..93fdbfa 100644 --- a/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs @@ -46,6 +46,22 @@ namespace BreCalClient 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) @@ -226,6 +242,31 @@ namespace BreCalClient } } + 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; + } + #endregion #region context menu handlers diff --git a/src/BreCalClient/EditTimesControl.xaml.cs b/src/BreCalClient/EditTimesControl.xaml.cs index c15f1a1..94c26dc 100644 --- a/src/BreCalClient/EditTimesControl.xaml.cs +++ b/src/BreCalClient/EditTimesControl.xaml.cs @@ -36,26 +36,19 @@ namespace BreCalClient private void Window_Loaded(object sender, RoutedEventArgs e) { this.CopyToControls(); - // enable controls according to participant type - this.datePickerETABerth.IsEnabled = App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG); + bool enableControls = this.Times.ParticipantId == App.Participant.Id; - - this.checkBoxEtaBerthFixed.IsEnabled = this.datePickerETABerth.IsEnabled; - this.datePickerETDBerth.IsEnabled = this.datePickerETABerth.IsEnabled; - this.checkBoxEtDBerthFixed.IsEnabled = this.datePickerETABerth.IsEnabled; + this.datePickerETABerth.IsEnabled = enableControls; + this.checkBoxEtaBerthFixed.IsEnabled = enableControls; + this.datePickerETDBerth.IsEnabled = enableControls; + this.checkBoxEtDBerthFixed.IsEnabled = enableControls; + this.datePickerLockTime.IsEnabled = enableControls; + this.checkBoxLockTimeFixed.IsEnabled = enableControls; + this.datePickerZoneEntry.IsEnabled = enableControls; + this.checkBoxZoneEntryFixed.IsEnabled = enableControls; + this.textBoxRemarks.IsEnabled = enableControls; + this.buttonOK.IsEnabled = enableControls; - this.datePickerLockTime.IsEnabled = App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION); - this.checkBoxLockTimeFixed.IsEnabled = this.datePickerLockTime.IsEnabled; - - this.datePickerZoneEntry.IsEnabled = App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) || - App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT); - this.checkBoxZoneEntryFixed.IsEnabled = this.datePickerZoneEntry.IsEnabled; } private void buttonOK_Click(object sender, RoutedEventArgs e) diff --git a/src/BreCalClient/EditTimesTerminalControl.xaml.cs b/src/BreCalClient/EditTimesTerminalControl.xaml.cs index 1f626a1..3f2e939 100644 --- a/src/BreCalClient/EditTimesTerminalControl.xaml.cs +++ b/src/BreCalClient/EditTimesTerminalControl.xaml.cs @@ -29,6 +29,15 @@ namespace BreCalClient { this.comboBoxBerth.ItemsSource = BreCalLists.Berths; this.CopyToControls(); + + bool enableControls = this.Times.ParticipantId == App.Participant.Id; + this.datePickerOperationStart.IsEnabled = enableControls; + this.datePickerOperationEnd.IsEnabled = enableControls; + this.comboBoxBerth.IsEnabled = enableControls; + this.comboBoxPierside.IsEnabled = enableControls; + this.textBoxRemarks.IsEnabled = enableControls; + this.textBoxBerthRemarks.IsEnabled = enableControls; + this.buttonOK.IsEnabled = enableControls; } private void contextMenuItemClearOperationStart_Click(object sender, RoutedEventArgs e) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 8f4e568..3f7e095 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -560,8 +560,13 @@ namespace BreCalClient private async void Sc_EditTimesRequested(ShipcallControl obj, Times? times, Extensions.ParticipantType participantType) { + + if( obj.ShipcallControlModel == null) { return; } + if (!obj.ShipcallControlModel.AssignedParticipants.ContainsKey(participantType)) return; // no assigment means no dialog my friend + // show a dialog that lets the user create / update times for the given shipcall - IEditTimesControl etc = (participantType == ParticipantType.TERMINAL) ? new EditTimesTerminalControl() : new EditTimesControl(); + IEditTimesControl etc = (participantType == ParticipantType.TERMINAL) ? new EditTimesTerminalControl() : new EditTimesControl(); + bool wasEdit = false; if (times != null) @@ -569,6 +574,13 @@ namespace BreCalClient etc.Times = times; wasEdit = true; } + else + { + if(obj.ShipcallControlModel.AssignedParticipants[participantType].ParticipantId == App.Participant.Id) + { + etc.Times.ParticipantId = App.Participant.Id; // this is my record, so the Participant Id is set that allows editing + } + } // actually we should only do this on create but we have existing data etc.Times.ParticipantType = (int) participantType; @@ -632,7 +644,15 @@ namespace BreCalClient { try { - editControl.Times.ParticipantId = App.Participant.Id; + // always try to be the agent, even if we are BSMD + if (editControl.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY)) + { + editControl.Times.ParticipantId = editControl.ShipcallModel.AssignedParticipants[ParticipantType.AGENCY].ParticipantId; + } + else + { + editControl.Times.ParticipantId = App.Participant.Id; + } if (wasEdit) { diff --git a/src/BreCalClient/ShipcallControl.xaml.cs b/src/BreCalClient/ShipcallControl.xaml.cs index 22e274d..00b541c 100644 --- a/src/BreCalClient/ShipcallControl.xaml.cs +++ b/src/BreCalClient/ShipcallControl.xaml.cs @@ -270,13 +270,13 @@ namespace BreCalClient private void UserControl_Loaded(object sender, RoutedEventArgs e) { - + // TBD } private void buttonEditShipcall_Click(object? sender, RoutedEventArgs? e) { if(App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD)) - this.EditRequested?.Invoke(this); + this.EditRequested?.Invoke(this); } private void Image_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) @@ -285,58 +285,39 @@ namespace BreCalClient } private void labelAgent_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) - { - if ((App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == _agency?.Id)) || - (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) && (_agency != null) && _agency.IsFlagSet(Extensions.ParticipantFlag.ALLOW_BSMD))) - { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY); - this.EditAgencyRequested?.Invoke(this, times); - } + { + Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY); + this.EditAgencyRequested?.Invoke(this, times); } private void labelMooring_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == _mooring?.Id)) - { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING); - this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.MOORING); - } + Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.MOORING); + this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.MOORING); } private void labelPortAuthority_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == _port_administration?.Id)) - { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION); - this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PORT_ADMINISTRATION); - } + Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PORT_ADMINISTRATION); + this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PORT_ADMINISTRATION); } private void labelPilot_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == _pilot?.Id)) - { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT); - this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PILOT); - } + Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.PILOT); + this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.PILOT); } private void labelTug_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == _tug?.Id)) - { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG); - this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TUG); - } + Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TUG); + this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TUG); } private void labelTerminal_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == _terminal?.Id)) - { - Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL); - this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TERMINAL); - } + Times? times = this.ShipcallControlModel?.GetTimesForParticipantType(Extensions.ParticipantType.TERMINAL); + this.EditTimesRequested?.Invoke(this, times, Extensions.ParticipantType.TERMINAL); } #endregion