From d1c131c52b84c16cdaa5a2b2c3746d75e4f13578 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 7 Mar 2025 16:04:53 +0100 Subject: [PATCH] Added logic to return to the previously selected tab page on a detail control, but only if the control has a tab control and the save button was hit. In this case a complete reload happens. --- ENI2/DetailBaseControl.cs | 8 ++-- ENI2/DetailRootControl.xaml.cs | 39 +++++++++++++++++-- .../BorderPoliceDetailControl.xaml.cs | 8 +++- .../DangerousGoodsDetailControl.xaml.cs | 6 +++ ...timeHealthDeclarationDetailControl.xaml.cs | 6 +++ .../SecurityDetailControl.xaml.cs | 6 +++ .../WasteDetailControl.xaml.cs | 6 +++ ENI2/SheetDisplayControls/PortControl.xaml | 2 +- ENI2/SheetDisplayControls/PortControl.xaml.cs | 21 ++++++---- .../SheetDisplayControls/ShipDataControl.xaml | 2 +- .../ShipDataControl.xaml.cs | 6 +++ ENI2/SheetDisplayControls/VoyageControl.xaml | 2 +- .../VoyageControl.xaml.cs | 6 +++ 13 files changed, 99 insertions(+), 19 deletions(-) diff --git a/ENI2/DetailBaseControl.cs b/ENI2/DetailBaseControl.cs index f8142630..88b5c7dc 100644 --- a/ENI2/DetailBaseControl.cs +++ b/ENI2/DetailBaseControl.cs @@ -192,6 +192,10 @@ namespace ENI2 e.Handled = true; } + public virtual int SelectedTabIndex { get; set; } = -1; + + #endregion + #region event handling for control content changes (signal dirty etc) protected void RegisterTextboxChange(TextBox textBox, Message.NotificationClass notificationClass) @@ -345,9 +349,7 @@ namespace ENI2 GlobalStructures.FilterCombobox(cmb, e.Key); } - #endregion - - #endregion + #endregion #region IHighlightControlContainer implementation diff --git a/ENI2/DetailRootControl.xaml.cs b/ENI2/DetailRootControl.xaml.cs index e4ff3bd8..2a1f9841 100644 --- a/ENI2/DetailRootControl.xaml.cs +++ b/ENI2/DetailRootControl.xaml.cs @@ -485,6 +485,7 @@ namespace ENI2 { Util.UIHelper.SetBusyState(); + int currentMainTabIndex = -1; if (this.detailView.Children[0] is DetailBaseControl currentControl) { @@ -499,10 +500,24 @@ namespace ENI2 // ggf. hat sich die Ticketnr geändert.. DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(currentControl.Core); } - } - } - this.DetailControl_RequestReload(this.Core.Id.Value); + currentMainTabIndex = currentControl.SelectedTabIndex; + } + + this.DetailControl_RequestReload(this.Core.Id.Value); + + System.Action SetTabAction = (int x) => + { + // this hopefully happens *after* the view was completely reloaded + if (this.detailView.Children[0] is DetailBaseControl currentNewControl) + { + currentNewControl.SelectedTabIndex = x; + } + }; + + if (currentMainTabIndex >= 0) + Dispatcher.BeginInvoke(SetTabAction, currentMainTabIndex); + } } private void SaveMessage(Message message) @@ -553,6 +568,7 @@ namespace ENI2 { Util.UIHelper.SetBusyState(); + int currentMainTabIndex = -1; foreach (Message message in this._messages) { @@ -564,12 +580,27 @@ namespace ENI2 { // ggf. hat sich die Ticketnr geändert.. DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(currentControl.Core); + currentMainTabIndex = currentControl.SelectedTabIndex; } this.buttonSaveAll.Visibility = Visibility.Hidden; this.buttonSave.Visibility = Visibility.Hidden; + + this.DetailControl_RequestReload(this.Core.Id.Value); + + System.Action SetTabAction = (int x) => + { + // this hopefully happens *after* the view was completely reloaded + if (this.detailView.Children[0] is DetailBaseControl currentNewControl) + { + currentNewControl.SelectedTabIndex = x; + } + }; + + if(currentMainTabIndex >= 0) + Dispatcher.BeginInvoke(SetTabAction, currentMainTabIndex); } - this.DetailControl_RequestReload(this.Core.Id.Value); + } private void DetailControl_NotificationClassChanged(Message.NotificationClass? notificationClass) diff --git a/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs b/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs index cf3138b4..7aecb28e 100644 --- a/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs @@ -244,7 +244,13 @@ namespace ENI2.DetailViewControls } #endregion - } + } + + public override int SelectedTabIndex + { + get { return this.mainFrame.SelectedIndex; } + set { this.mainFrame.SelectedIndex = value; } + } #region Grid copy handlers diff --git a/ENI2/DetailViewControls/DangerousGoodsDetailControl.xaml.cs b/ENI2/DetailViewControls/DangerousGoodsDetailControl.xaml.cs index 6da66a77..a25253a0 100644 --- a/ENI2/DetailViewControls/DangerousGoodsDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/DangerousGoodsDetailControl.xaml.cs @@ -197,6 +197,12 @@ namespace ENI2.DetailViewControls this._initialized = true; } + public override int SelectedTabIndex + { + get { return this.tabControlPositions.SelectedIndex; } + set { this.tabControlPositions.SelectedIndex = value; } + } + #region SetEnabled public override void SetEnabled(bool enabled) diff --git a/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs b/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs index 71634ab1..d5d719b3 100644 --- a/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs @@ -130,6 +130,12 @@ namespace ENI2.DetailViewControls } + public override int SelectedTabIndex + { + get { return this.mainFrame.SelectedIndex; } + set { this.mainFrame.SelectedIndex = value; } + } + #region SetEnabled public override void SetEnabled(bool enabled) diff --git a/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs b/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs index ca76db9c..28e45fb4 100644 --- a/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs @@ -116,6 +116,12 @@ namespace ENI2.DetailViewControls } + public override int SelectedTabIndex + { + get { return this.mainFrame.SelectedIndex; } + set { this.mainFrame.SelectedIndex = value; } + } + #region SetEnabled public override void SetEnabled(bool enabled) diff --git a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs index d2eaac69..696c94c8 100644 --- a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs @@ -187,6 +187,12 @@ namespace ENI2.DetailViewControls } + public override int SelectedTabIndex + { + get { return this.mainFrame.SelectedIndex; } + set { this.mainFrame.SelectedIndex = value; } + } + #region Waste receipt grid event handler private async void DataGridWasteReceipt_CreateRequested() diff --git a/ENI2/SheetDisplayControls/PortControl.xaml b/ENI2/SheetDisplayControls/PortControl.xaml index 5202b86d..387783a2 100644 --- a/ENI2/SheetDisplayControls/PortControl.xaml +++ b/ENI2/SheetDisplayControls/PortControl.xaml @@ -24,7 +24,7 @@ - + diff --git a/ENI2/SheetDisplayControls/PortControl.xaml.cs b/ENI2/SheetDisplayControls/PortControl.xaml.cs index 7f6636dc..13491d60 100644 --- a/ENI2/SheetDisplayControls/PortControl.xaml.cs +++ b/ENI2/SheetDisplayControls/PortControl.xaml.cs @@ -204,15 +204,10 @@ namespace ENI2.SheetDisplayControls } - private void CheckBoxValidExemption_Checked(object sender, RoutedEventArgs e) + public override int SelectedTabIndex { - bool on = !(this.checkBoxValidExemption.IsChecked ?? false); - this.checkBoxAccurateCorrectDetails.IsEnabled = on; - this.locodeCtrlLastWastePort.IsEnabled = on; - this.datePickerDateLastDisposal.IsEnabled = on; - this.textBoxWasteDisposalServiceProviders.IsEnabled = on; - this.gridWasteControls.IsEnabled = on; - this.dataGridWaste.IsEnabled = on; + get { return this.mainTabControl.SelectedIndex; } + set { this.mainTabControl.SelectedIndex = value; } } public override void SetEnabled(bool enabled) @@ -270,7 +265,17 @@ namespace ENI2.SheetDisplayControls this.RegisterTextboxChange(this.textBoxWasteDisposalServiceProviders, Message.NotificationClass.WAS); this.RegisterDatePickerChange(this.datePickerDateLastDisposal, Message.NotificationClass.WAS); + } + private void CheckBoxValidExemption_Checked(object sender, RoutedEventArgs e) + { + bool on = !(this.checkBoxValidExemption.IsChecked ?? false); + this.checkBoxAccurateCorrectDetails.IsEnabled = on; + this.locodeCtrlLastWastePort.IsEnabled = on; + this.datePickerDateLastDisposal.IsEnabled = on; + this.textBoxWasteDisposalServiceProviders.IsEnabled = on; + this.gridWasteControls.IsEnabled = on; + this.dataGridWaste.IsEnabled = on; } private void buttonSearchPortArea_Click(object sender, RoutedEventArgs e) diff --git a/ENI2/SheetDisplayControls/ShipDataControl.xaml b/ENI2/SheetDisplayControls/ShipDataControl.xaml index dbbff450..c5b402d6 100644 --- a/ENI2/SheetDisplayControls/ShipDataControl.xaml +++ b/ENI2/SheetDisplayControls/ShipDataControl.xaml @@ -12,7 +12,7 @@ mc:Ignorable="d" d:DesignHeight="1050" d:DesignWidth="800"> - + diff --git a/ENI2/SheetDisplayControls/ShipDataControl.xaml.cs b/ENI2/SheetDisplayControls/ShipDataControl.xaml.cs index 39c2beab..aedda13e 100644 --- a/ENI2/SheetDisplayControls/ShipDataControl.xaml.cs +++ b/ENI2/SheetDisplayControls/ShipDataControl.xaml.cs @@ -123,6 +123,12 @@ namespace ENI2.SheetDisplayControls this.shipDataGroupBox.IsEnabled = enabled; } + public override int SelectedTabIndex + { + get { return this.mainTabControl.SelectedIndex; } + set { this.mainTabControl.SelectedIndex = value; } + } + #endregion #region event handler diff --git a/ENI2/SheetDisplayControls/VoyageControl.xaml b/ENI2/SheetDisplayControls/VoyageControl.xaml index e44e3624..d08e6aa4 100644 --- a/ENI2/SheetDisplayControls/VoyageControl.xaml +++ b/ENI2/SheetDisplayControls/VoyageControl.xaml @@ -13,7 +13,7 @@ d:DesignHeight="1150" d:DesignWidth="800"> - + diff --git a/ENI2/SheetDisplayControls/VoyageControl.xaml.cs b/ENI2/SheetDisplayControls/VoyageControl.xaml.cs index b652fe95..be9d4eec 100644 --- a/ENI2/SheetDisplayControls/VoyageControl.xaml.cs +++ b/ENI2/SheetDisplayControls/VoyageControl.xaml.cs @@ -199,6 +199,12 @@ namespace ENI2.SheetDisplayControls this.voyageGroupBox.IsEnabled = enabled; } + public override int SelectedTabIndex + { + get { return this.mainTabControl.SelectedIndex; } + set { this.mainTabControl.SelectedIndex = value; } + } + #endregion #region event handler