From f9f8980e09addc3e4f2ccd0288dd155e6d47ad71 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 23 Jul 2024 08:48:27 +0200 Subject: [PATCH] completely reload core after copy operation --- ENI2/DetailRootControl.xaml.cs | 69 +++++++++++++++++----------------- bsmd.database/DBManager.cs | 17 ++++++--- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/ENI2/DetailRootControl.xaml.cs b/ENI2/DetailRootControl.xaml.cs index cd52b04e..80ea49e1 100644 --- a/ENI2/DetailRootControl.xaml.cs +++ b/ENI2/DetailRootControl.xaml.cs @@ -31,7 +31,7 @@ namespace ENI2 private readonly List _listBoxList = new List(); private List _messages; private readonly Dictionary controlCache = new Dictionary(); - // private readonly Dictionary messageClassControlDict = new Dictionary(); + // private readonly Dictionary messageClassControlDict = new Dictionary(); private readonly object messageListLock = new object(); private readonly HighlightService highlightService = new HighlightService(); @@ -65,7 +65,7 @@ namespace ENI2 get { // Bedingung: - // wenn in einer Meldeklasse zwar Daten vorhanden sind, eingespielt durch Excel import oder + // wenn in einer Meldeklasse zwar Daten vorhanden sind, eingespielt durch Excel import oder // Handeingabe, diese aber NICHT gesendet wurden. // TODO: Hier wird noch ein Flag benötigt, dass die erfolgte Anzeige des Warndialogs speichert List result = new List(); @@ -74,7 +74,7 @@ namespace ENI2 { if (((aMessage.InternalStatus == Message.BSMDStatus.UPDATED) || (aMessage.InternalStatus == Message.BSMDStatus.SAVED)) && // || - // (aMessage.InternalStatus == Message.BSMDStatus.EXCEL)) && + // (aMessage.InternalStatus == Message.BSMDStatus.EXCEL)) && !aMessage.UnsentMessageWarningShown) { aMessage.UnsentMessageWarningShown = true; @@ -82,7 +82,7 @@ namespace ENI2 result.Add(aMessage.MessageNotificationClassDisplay); } } - + return result; } } @@ -140,7 +140,7 @@ namespace ENI2 shipNameLabel.Text = aCore.Shipname; shipEMailLabel.Text = aCore.HerbergEmailContactReportingVessel; displayIdLabel.Text = aCore.DisplayId; - + // Listbox befüllen this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textOverview, MessageGroupControlType = typeof(OverViewDetailControl), ImagePath = "Resources/documents.png" }); @@ -153,7 +153,7 @@ namespace ENI2 this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textMDH, MessageGroupControlType = typeof(MaritimeHealthDeclarationDetailControl), ImagePath = "Resources/medical_bag.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textDepartureNotification, MessageGroupControlType = typeof(DepartureNotificationDetailControl), ImagePath = "Resources/arrow_up_right_green.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textShipData, MessageGroupControlType = typeof(ShipDataDetailControl), ImagePath = "Resources/containership.png" }); - this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textBorderPolice, MessageGroupControlType = typeof(BorderPoliceDetailControl), ImagePath = "Resources/policeman_german.png" }); + this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textBorderPolice, MessageGroupControlType = typeof(BorderPoliceDetailControl), ImagePath = "Resources/policeman_german.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textDGArrival, MessageGroupControlType = typeof(DangerousGoodsDetailControl), ImagePath = "Resources/sign_warning_radiation.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textDGDeparture, MessageGroupControlType = typeof(DangerousGoodsDetailControl), ImagePath = "Resources/sign_warning_radiation.png" }); this._listBoxList.Add(new MessageGroup() { MessageGroupName = Properties.Resources.textTowage, MessageGroupControlType = typeof(TowageDetailControl), ImagePath = "Resources/ship2.png" }); @@ -264,7 +264,7 @@ namespace ENI2 detailControl.SetEnabled(isEnabled); if (!isEnabled && (detailControl is OverViewDetailControl control) && !(Core.Cancelled ?? false)) - control.ShowLockedBy(this.LockedBy); + control.ShowLockedBy(this.LockedBy); controlCache.Add(mg.MessageGroupName, detailControl); this.buttonSave.Visibility = Visibility.Hidden; @@ -298,7 +298,7 @@ namespace ENI2 MessageCore newCore = new MessageCore(); cdd.NewCore = newCore; cdd.OldCore = this.Core; - + cdd.Closed += (senderDialog, closeArgs) => { CopyDeclarationDialog closedDialog = senderDialog as CopyDeclarationDialog; @@ -331,19 +331,19 @@ namespace ENI2 if(existingCore != null) { - if(MessageBox.Show(Properties.Resources.textDeclarationAlreadyExists, Properties.Resources.textCaptionExists, + if(MessageBox.Show(Properties.Resources.textDeclarationAlreadyExists, Properties.Resources.textCaptionExists, MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { List existingMessages = DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessagesForCore(existingCore, DBManager.MessageLoad.ALL); foreach(Message existingMessage in existingMessages) { - if((existingMessage.InternalStatus == Message.BSMDStatus.SENT) && + if((existingMessage.InternalStatus == Message.BSMDStatus.SENT) && (existingMessage.MessageNotificationClass != Message.NotificationClass.VISIT) && (existingMessage.MessageNotificationClass != Message.NotificationClass.TRANSIT)) { MessageBox.Show(Properties.Resources.textMessagesAlreadySent, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Stop); return; - } + } } // delete all existing data of core @@ -357,7 +357,7 @@ namespace ENI2 // Bearbeitungsinformationen für bestehende ID-Beantragung beibehalten, falls bereits vorhanden if(existingCore.IsTransit && - (existingMessage.MessageNotificationClass == Message.NotificationClass.TRANSIT) && + (existingMessage.MessageNotificationClass == Message.NotificationClass.TRANSIT) && (existingMessage.InternalStatus == Message.BSMDStatus.CONFIRMED)) { skipCopyTransit = true; @@ -389,7 +389,7 @@ namespace ENI2 DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(newCore); - // Meldeklassen für neuen Anlauf erzeugen + // Meldeklassen für neuen Anlauf erzeugen List newMessages = new List(); foreach (Message oldMessage in this._messages) { @@ -417,6 +417,7 @@ namespace ENI2 newMessage.SaveElements(); } + DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).LoadXtraData(newCore); // reload data from DB and set all rel properites this.OnOpenNewCoreRequested(newCore); } }; @@ -427,7 +428,7 @@ namespace ENI2 { this.LockedByOtherUser = true; // fake flag - // clear existing controls + // clear existing controls this.detailView.Children.Clear(); this.controlCache.Clear(); @@ -444,7 +445,7 @@ namespace ENI2 private void buttonSave_Click(object sender, RoutedEventArgs e) { - MessageBoxResult result = MessageBox.Show(Properties.Resources.textQuestionSavePage, Properties.Resources.textConfirmation, + MessageBoxResult result = MessageBox.Show(Properties.Resources.textQuestionSavePage, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { @@ -495,7 +496,7 @@ namespace ENI2 if(message.MessageNotificationClass == Message.NotificationClass.ATA) { - DetailBaseControl currentControl = this.detailView.Children[0] as DetailBaseControl; + DetailBaseControl currentControl = this.detailView.Children[0] as DetailBaseControl; // ggf. hat sich die Ticketnr geändert.. DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(currentControl.Core); } @@ -512,7 +513,7 @@ namespace ENI2 private void buttonSaveAll_Click(object sender, RoutedEventArgs e) { - MessageBoxResult result = MessageBox.Show(Properties.Resources.textQuestionSaveAll, Properties.Resources.textConfirmation, + MessageBoxResult result = MessageBox.Show(Properties.Resources.textQuestionSaveAll, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { @@ -708,16 +709,16 @@ namespace ENI2 { vViolations = new List(); vErrors = new List(); - + // TODO: clear highlighting Util.UIHelper.SetBusyState(); RuleEngine ruleEngine = new RuleEngine(); foreach (Message aMessage in _messages) - { + { if (!aMessage.EvaluateForValidation(this.Core.IsTransit)) continue; - + List errors = new List(); List violations = new List(); ruleEngine.ValidateMessage(aMessage, out errors, out violations); @@ -793,7 +794,7 @@ namespace ENI2 #region CREW/PAS Schengen Plausibility - // Wir können davon ausgehen, dass bei allen Unterelementen die Flags gleich gesetzt sind. Das wird im Import und BorderPoliceDetailControl sichergestellt. + // Wir können davon ausgehen, dass bei allen Unterelementen die Flags gleich gesetzt sind. Das wird im Import und BorderPoliceDetailControl sichergestellt. if(crewaMessage.Elements.Count > 0) { @@ -802,7 +803,7 @@ namespace ENI2 if (!((crewaFirst.NotificationPAX ?? false) || crewaIsSchengen)) // mindestens eins der beiden { vErrors.Add(RuleEngine.CreateError(ValidationCode.V181, "Pax / Schengen: one must be set", null, Properties.Resources.textOverview, null, "CREWA")); ; - } + } } if (crewdMessage != null) @@ -814,7 +815,7 @@ namespace ENI2 if (!((crewdFirst.NotificationPAX ?? false) || crewdIsSchengen)) // mindestens eins der beiden { vErrors.Add(RuleEngine.CreateError(ValidationCode.V181, "Pax / Schengen: one must be set", null, Properties.Resources.textOverview, null, "CREWD")); ; - } + } } } @@ -826,7 +827,7 @@ namespace ENI2 if (!(pasIsPAX || pasIsSchengen)) // mindestens eins der beiden { vErrors.Add(RuleEngine.CreateError (ValidationCode.V201, "Pax / Schengen: one must be set", null, Properties.Resources.textOverview, null, "PASA")); - } + } } if (pasdMessage != null) @@ -839,7 +840,7 @@ namespace ENI2 if (!(pasdIsPAX || pasdIsSchengen)) // mindestens eins der beiden { vErrors.Add(RuleEngine.CreateError(ValidationCode.V201, "Pax / Schengen: one must be set", null, Properties.Resources.textOverview, null, "PASD")); - } + } } } @@ -855,7 +856,7 @@ namespace ENI2 MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.NO_PAX, "No PAX set (PASA > 12)", null, Properties.Resources.textOverview, null, "PASA"); vViolations.Add(mv); } - + if((crewaMessage != null) && (crewaMessage.Elements.Count > 0)) { CREW firstCREW = crewaMessage.Elements[0] as CREW; @@ -897,8 +898,8 @@ namespace ENI2 crewaMessage.ViolationList.Remove(mv); } - if(crewdMessage != null) - { + if(crewdMessage != null) + { MessageViolation mvd = crewdMessage.ViolationList.Find((x) => x.PropertyName.Equals("Effects") && (x.ViolationCode == (int)ValidationCode.TRUNCATE)); if ((mvd != null) && !Core.IsDK) crewdMessage.ViolationList.Remove(mvd); @@ -1043,7 +1044,7 @@ namespace ENI2 { if (poc30d.PortOfCallLast30DaysDateOfDeparture.HasValue && !poc30d.PortOfCallLast30DaysLocode.IsNullOrEmpty()) { - if((poc30d.PortOfCallLast30DaysDateOfDeparture.Value.Date == l10c.PortFacilityDateOfDeparture.Value.Date) && + if((poc30d.PortOfCallLast30DaysDateOfDeparture.Value.Date == l10c.PortFacilityDateOfDeparture.Value.Date) && poc30d.PortOfCallLast30DaysLocode.Equals(l10c.PortFacilityPortLoCode, StringComparison.OrdinalIgnoreCase)) { matchIsFound = true; @@ -1098,7 +1099,7 @@ namespace ENI2 MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.LIST_EMPTY, "No entry for SERV found", null, "SERV service provider", null, "SERV"); mv.MessageGroupName = Properties.Resources.textPortNotification; vViolations.Add(mv); - } + } } #endregion @@ -1154,8 +1155,8 @@ namespace ENI2 this._errorListDialog.Loaded += (o, e) => this._errorListDialog.RefreshVisible = true; this._errorListDialog.ErrorSelected += _errorListDialog_ErrorSelected; this._errorListDialog.RefreshClicked += _errorListDialog_RefreshClicked; - this._errorListDialog.Show(); - } + this._errorListDialog.Show(); + } else { this._errorListDialog.BringUp(); @@ -1167,12 +1168,12 @@ namespace ENI2 { if(this._violationListDialog == null) { - this._violationListDialog = new ViolationListDialog(); + this._violationListDialog = new ViolationListDialog(); this._violationListDialog.Closed += (o, e) => this._violationListDialog = null; this._violationListDialog.Loaded += (o, e) => this._violationListDialog.RefreshVisible = true; this._violationListDialog.ViolationSelected += _errorListDialog_ErrorSelected; this._violationListDialog.RefreshClicked += _errorListDialog_RefreshClicked; - this._violationListDialog.Show(); + this._violationListDialog.Show(); } else { diff --git a/bsmd.database/DBManager.cs b/bsmd.database/DBManager.cs index b13f2a8e..ced838c5 100644 --- a/bsmd.database/DBManager.cs +++ b/bsmd.database/DBManager.cs @@ -295,12 +295,7 @@ namespace bsmd.database List result = new List(); foreach (MessageCore core in cores.Cast()) { - this.LoadCustomer(core); - this.LoadSTATShipName(core); - this.LoadETA_ETD(core); - this.LoadATA(core); - this.LoadATD(core); - this.LoadNumberSent(core); + LoadXtraData(core); result.Add(core); } @@ -310,6 +305,16 @@ namespace bsmd.database return result; } + public void LoadXtraData(MessageCore core) + { + this.LoadCustomer(core); + this.LoadSTATShipName(core); + this.LoadETA_ETD(core); + this.LoadATA(core); + this.LoadATD(core); + this.LoadNumberSent(core); + } + /// /// Lädt MessageCore (=Schiffsanlauf) einer EU-NOAD Nachricht vom Fleettracker / Herberg ///