From ffca8e5bddefcc0d6d1b91b4b3ceeb9912bdcb8f Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 24 Jul 2025 16:16:28 +0200 Subject: [PATCH] Preview for send all functionality --- .../OverViewDetailControl.xaml.cs | 106 ++++++++++++------ ENI2/Properties/Resources.Designer.cs | 2 +- ENI2/Properties/Resources.resx | 2 +- 3 files changed, 73 insertions(+), 37 deletions(-) diff --git a/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs b/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs index 11506cc7..8362dc24 100644 --- a/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs @@ -433,44 +433,50 @@ namespace ENI2.DetailViewControls MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmSend, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { - bool somethingsNotSaved = false; - foreach (Message selectedMessage in this.dataGridMessages.SelectedItems) + this.SendMessages((IList)this.dataGridMessages.SelectedItems); + } + } + + private void SendMessages(IList messages) + { + bool somethingsNotSaved = false; + + foreach (Message selectedMessage in messages) + { + if (selectedMessage.IsDirty) somethingsNotSaved = true; + } + + if (somethingsNotSaved) + { + if (MessageBox.Show(Properties.Resources.textUnsavedChangesSendAnyWay, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No) + return; + } + + List watchList = new List(); + foreach (Message selectedMessage in messages) + { + if (selectedMessage.Reset) selectedMessage.Reset = false; // "nochmal" Versenden ist möglich + selectedMessage.InternalStatus = Message.BSMDStatus.TOSEND; + string userName = "?"; + if (App.UserId.HasValue && DBManager.Instance.GetReportingPartyDict().ContainsKey(App.UserId.Value)) { - if (selectedMessage.IsDirty) somethingsNotSaved = true; + userName = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].Logon; } + selectedMessage.ChangedBy = string.Format("{0} at {1} (Send)", userName, DateTime.Now); + selectedMessage.StatusInfo = string.Format(Properties.Resources.textMessageSentAt, DateTime.Now); + DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedMessage); + watchList.Add(selectedMessage); + } - if(somethingsNotSaved) - { - if (MessageBox.Show(Properties.Resources.textUnsavedChangesSendAnyWay, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No) - return; - } + // komplette Anmeldung auf "zu versenden" stellen + this.Core.BSMDStatusInternal = MessageCore.BSMDStatus.TOSEND; + this.Core.DefaultReportingPartyId = App.UserId; - List watchList = new List(); - foreach (Message selectedMessage in this.dataGridMessages.SelectedItems) - { - if (selectedMessage.Reset) selectedMessage.Reset = false; // "nochmal" Versenden ist möglich - selectedMessage.InternalStatus = Message.BSMDStatus.TOSEND; - string userName = "?"; - if (App.UserId.HasValue && DBManager.Instance.GetReportingPartyDict().ContainsKey(App.UserId.Value)) - { - userName = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].Logon; - } - selectedMessage.ChangedBy = string.Format("{0} at {1} (Send)", userName, DateTime.Now); - selectedMessage.StatusInfo = string.Format(Properties.Resources.textMessageSentAt, DateTime.Now); - DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedMessage); - watchList.Add(selectedMessage); - } + DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core); // löst auch den Watchdog aus + this.OnRequestSendValidation(); + this.dataGridMessages.Items.Refresh(); - // komplette Anmeldung auf "zu versenden" stellen - this.Core.BSMDStatusInternal = MessageCore.BSMDStatus.TOSEND; - this.Core.DefaultReportingPartyId = App.UserId; - - DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(this.Core); // löst auch den Watchdog aus - this.OnRequestSendValidation(); - this.dataGridMessages.Items.Refresh(); - - - /* + /* if (this.mssd == null) { this.mssd = new MessageSendStatusDialog(this.Core); @@ -490,7 +496,6 @@ namespace ENI2.DetailViewControls this.mssd.Activate(); // bring to foreground this.mssd.AddMessages(watchList); */ - } } private void contextResetMessage(object sender, RoutedEventArgs e) @@ -828,7 +833,38 @@ namespace ENI2.DetailViewControls private void buttonSendAll_Click(object sender, RoutedEventArgs e) { - // TBD + SelectImportClassesDialog sicd = new SelectImportClassesDialog(); + List readyToSendMessages = new List(); + + foreach (Message message in this.Messages) + { + if (message.MessageNotificationClass == NotificationClass.STO) continue; + // other filters? + + if (((message.ViolationCount ?? 0) > 0) || ((message.ErrorCount ?? 0) > 0)) continue; // these need more work + readyToSendMessages.Add(message); + } + + sicd.Messages = readyToSendMessages; + sicd.IsTransit = this.Core.IsTransit; + + if ((sicd.ShowDialog() ?? false) && (sicd.SelectedClasses.Count > 0)) + { + // now send all selected messages + List toSendMessages = new List(); + foreach(NotificationClass notificationClass in sicd.SelectedClasses) + { + Message selectedMessage = readyToSendMessages.Find(x => x.MessageNotificationClass == notificationClass); + if (selectedMessage != null) + { + toSendMessages.Add(selectedMessage); + } + } + if (toSendMessages.Count > 0) + { + this.SendMessages(toSendMessages); + } + } } #endregion diff --git a/ENI2/Properties/Resources.Designer.cs b/ENI2/Properties/Resources.Designer.cs index 24ce9ab7..cfca18fc 100644 --- a/ENI2/Properties/Resources.Designer.cs +++ b/ENI2/Properties/Resources.Designer.cs @@ -5306,7 +5306,7 @@ namespace ENI2.Properties { } /// - /// Looks up a localized string similar to Select classes to import. + /// Looks up a localized string similar to Select message classes. /// public static string textSelectImportClasses { get { diff --git a/ENI2/Properties/Resources.resx b/ENI2/Properties/Resources.resx index 4aef90f8..bdca0024 100644 --- a/ENI2/Properties/Resources.resx +++ b/ENI2/Properties/Resources.resx @@ -1757,7 +1757,7 @@ Select all - Select classes to import + Select message classes Select none