diff --git a/ENI-2/ENI2/ENI2/AnmeldungenControl.xaml.cs b/ENI-2/ENI2/ENI2/AnmeldungenControl.xaml.cs index ba54757b..24e4d7a5 100644 --- a/ENI-2/ENI2/ENI2/AnmeldungenControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/AnmeldungenControl.xaml.cs @@ -42,7 +42,7 @@ namespace ENI2 if(sender != null) { DataGrid grid = sender as DataGrid; - if((grid != null) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1)) + if(grid?.SelectedItems?.Count == 1) { DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow; MessageCore selectedCore = grid.SelectedItem as MessageCore; diff --git a/ENI-2/ENI2/ENI2/Controls/EditWindowBase.cs b/ENI-2/ENI2/ENI2/Controls/EditWindowBase.cs index 71aacd43..47853a0e 100644 --- a/ENI-2/ENI2/ENI2/Controls/EditWindowBase.cs +++ b/ENI-2/ENI2/ENI2/Controls/EditWindowBase.cs @@ -37,15 +37,12 @@ namespace ENI2.Controls var okButton = (Button)Template.FindName("buttonOK", this); var cancelButton = (Button)Template.FindName("buttonCancel", this); var addButton = (Button)Template.FindName("buttonAdd", this); - okButton.Click += (s, e) => { if (IsModal) DialogResult = true; OKClicked?.Invoke(); this.Close(); }; - cancelButton.Click += (s, e) => { if (IsModal) DialogResult = false; CancelClicked?.Invoke(); this.Close(); }; - addButton.Click += (s, e) => { AddClicked?.Invoke(); }; + okButton.Click += (s, e) => { if (this.IsModal()) DialogResult = true; OKClicked?.Invoke(); this.Close(); }; + cancelButton.Click += (s, e) => { if (this.IsModal()) DialogResult = false; CancelClicked?.Invoke(); this.Close(); }; + addButton.Click += (s, e) => AddClicked?.Invoke(); }; - this.IsModal = true; // default } - public bool IsModal { get; set; } - public bool AddVisible { get { var addButton = (Button)Template.FindName("buttonAdd", this); return addButton.Visibility == Visibility.Visible; } diff --git a/ENI-2/ENI2/ENI2/Controls/ReportingPartyControl.xaml.cs b/ENI-2/ENI2/ENI2/Controls/ReportingPartyControl.xaml.cs index cdebb1dd..368ac39b 100644 --- a/ENI-2/ENI2/ENI2/Controls/ReportingPartyControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/Controls/ReportingPartyControl.xaml.cs @@ -46,10 +46,9 @@ namespace ENI2.Controls private void ResetItem_Click(object sender, RoutedEventArgs e) { - if ((this.dataGridReportingParties.SelectedItems != null) && (this.dataGridReportingParties.SelectedItems.Count == 1) && !this.dataGridReportingParties.IsReadOnly) + if ((this.dataGridReportingParties.SelectedItems?.Count == 1) && !this.dataGridReportingParties.IsReadOnly) { - ReportingParty selectedParty = this.dataGridReportingParties.SelectedItems[0] as ReportingParty; - if (selectedParty != null) + if (this.dataGridReportingParties.SelectedItems[0] is ReportingParty selectedParty) { string confirmText = string.Format(Properties.Resources.textConfirmPasswordReset, selectedParty.Logon); MessageBoxResult result = MessageBox.Show(confirmText, Properties.Resources.textCaptionDeleteConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question); @@ -59,7 +58,7 @@ namespace ENI2.Controls selectedParty.Salt = null; DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Save(selectedParty); } - } + } } } @@ -67,8 +66,7 @@ namespace ENI2.Controls private void DataGridReportingParties_DeleteRequested(DatabaseEntity obj) { - ReportingParty rp = obj as ReportingParty; - if (rp != null) + if (obj is ReportingParty rp) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(rp); @@ -79,15 +77,14 @@ namespace ENI2.Controls private void DataGridReportingParties_EditRequested(DatabaseEntity obj) { - ReportingParty rp = obj as ReportingParty; - if (rp != null) + if (obj is ReportingParty rp) { EditReportingPartyDialog eld = new EditReportingPartyDialog(); - eld.ReportingParty = rp; + eld.ReportingParty = rp; if (eld.ShowDialog() ?? false) { - this.dataGridReportingParties.Items.Refresh(); + this.dataGridReportingParties.Items.Refresh(); } } } diff --git a/ENI-2/ENI2/ENI2/Controls/StatusWindowBase.cs b/ENI-2/ENI2/ENI2/Controls/StatusWindowBase.cs index 12ae90e3..205c4af9 100644 --- a/ENI-2/ENI2/ENI2/Controls/StatusWindowBase.cs +++ b/ENI-2/ENI2/ENI2/Controls/StatusWindowBase.cs @@ -32,14 +32,11 @@ namespace ENI2.Controls var closeButton = (Button)Template.FindName("buttonClose", this); var refreshButton = (Button)Template.FindName("buttonRefresh", this); - closeButton.Click += (s, e) => { if (IsModal) DialogResult = true; CloseClicked?.Invoke(); this.Close(); }; + closeButton.Click += (s, e) => { if (this.IsModal()) DialogResult = true; CloseClicked?.Invoke(); this.Close(); }; refreshButton.Click += (s, e) => { RefreshClicked?.Invoke(); }; - }; - this.IsModal = true; // default - } - - public bool IsModal { get; set; } + }; + } public bool RefreshVisible { diff --git a/ENI-2/ENI2/ENI2/DetailBaseControl.cs b/ENI-2/ENI2/ENI2/DetailBaseControl.cs index a3633167..762ba8b5 100644 --- a/ENI-2/ENI2/ENI2/DetailBaseControl.cs +++ b/ENI-2/ENI2/ENI2/DetailBaseControl.cs @@ -29,10 +29,9 @@ namespace ENI2 private DependencyPropertyDescriptor _dpComboboxValue; private DependencyPropertyDescriptor _dpNumericUpdown; private DependencyPropertyDescriptor _dpIntUpdown; - private Dictionary _controlClassDict = new Dictionary(); - private Dictionary _typeMessageDict = new Dictionary(); - private List _controlMessages = new List(); - + private readonly Dictionary _controlClassDict = new Dictionary(); + private readonly Dictionary _typeMessageDict = new Dictionary(); + #endregion @@ -109,7 +108,7 @@ namespace ENI2 /// /// particular messages that are edited on this page /// - public List ControlMessages { get { return this._controlMessages; } } + public List ControlMessages { get; } = new List(); public bool LockedByOtherUser { get; set; } diff --git a/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs b/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs index 44ae9619..420847a9 100644 --- a/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/DetailRootControl.xaml.cs @@ -203,8 +203,7 @@ namespace ENI2 MessageCore newCore = new MessageCore(); cdd.NewCore = newCore; cdd.OldCore = this.Core; - - cdd.IsModal = false; + cdd.Closed += (senderDialog, closeArgs) => { CopyDeclarationDialog closedDialog = senderDialog as CopyDeclarationDialog; @@ -734,9 +733,8 @@ namespace ENI2 this._errorListDialog.Closed += (o, e) => this._errorListDialog = null; this._errorListDialog.Loaded += (o, e) => this._errorListDialog.RefreshVisible = true; this._errorListDialog.ErrorSelected += _errorListDialog_ErrorSelected; - this._errorListDialog.RefreshClicked += _errorListDialog_RefreshClicked; - this._errorListDialog.IsModal = false; - this._errorListDialog.Show(); + this._errorListDialog.RefreshClicked += _errorListDialog_RefreshClicked; + this._errorListDialog.ShowDialog(); } this._errorListDialog.Errors = vErrors; } @@ -749,8 +747,7 @@ namespace ENI2 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.IsModal = false; + this._violationListDialog.RefreshClicked += _errorListDialog_RefreshClicked; this._violationListDialog.Show(); } _violationListDialog.Violations = vViolations; diff --git a/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs b/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs index 832e27c0..082b613c 100644 --- a/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/DetailViewControls/OverViewDetailControl.xaml.cs @@ -146,6 +146,15 @@ namespace ENI2.DetailViewControls pdfItem.Click += this.buttonCreatePDF_Click; this.dataGridMessages.ContextMenu.Items.Add(pdfItem); + MenuItem historyItem = new MenuItem + { + Header = Properties.Resources.textHistoryItems, + Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/clock_history.png")) } + }; + historyItem.Click += HistoryItem_Click; + this.dataGridMessages.ContextMenu.Items.Add(historyItem); + historyItem.IsEnabled = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsAdmin; // TODO: rechtzeitig wieder entfernen! + #endregion #region lokale Meldeklassen @@ -442,7 +451,7 @@ namespace ENI2.DetailViewControls { if ((sender is DataGrid grid) && (grid.SelectedItems?.Count == 1)) { - DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow; + // DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow; Message selectedMessage = grid.SelectedItem as Message; this.jumpToMessage(selectedMessage); } @@ -466,6 +475,18 @@ namespace ENI2.DetailViewControls #region Command button event handler + private void HistoryItem_Click(object sender, RoutedEventArgs e) + { + if(this.dataGridMessages.SelectedItems.Count > 0) + { + Message historyMessage = this.dataGridMessages.SelectedItems[0] as Message; + MessageHistoryDialog mhd = new MessageHistoryDialog(); + mhd.Messages = this.Messages; + mhd.MessageHistories = DBManager.Instance.GetMessageHistories(historyMessage.Id.Value); + mhd.Show(); + } + } + private void contextSendMessage(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show(Properties.Resources.textConfirmSend, Properties.Resources.textConfirm, MessageBoxButton.YesNo, MessageBoxImage.Question); @@ -550,9 +571,7 @@ namespace ENI2.DetailViewControls { if(this.Core.InitialHIS != _message.HIS) { - MessageBoxResult noMatchResult = MessageBox.Show(Properties.Resources.textHISNotMatching, Properties.Resources.textConfirm, - MessageBoxButton.OK, MessageBoxImage.Exclamation); - // todo: Hier den "Egal!" Fall berücksichtigen? + MessageBox.Show(Properties.Resources.textHISNotMatching, Properties.Resources.textConfirm, MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } @@ -634,8 +653,7 @@ namespace ENI2.DetailViewControls { MessageCore reloadedCore = DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).GetMessageCoreById(this.Core.Id.Value); CoreStatusInfoDialog csid = new CoreStatusInfoDialog - { - IsModal = false, + { Core = reloadedCore }; csid.Show(); @@ -661,8 +679,7 @@ namespace ENI2.DetailViewControls private void buttonInfoCore_Click(object sender, RoutedEventArgs e) { SimplePropertyViewDialog spvd = new SimplePropertyViewDialog - { - IsModal = false, + { DisplayObject = this.Core }; spvd.Show(); diff --git a/ENI-2/ENI2/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs b/ENI-2/ENI2/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs index f518efcf..dd09672b 100644 --- a/ENI-2/ENI2/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/DetailViewControls/SecurityDetailControl.xaml.cs @@ -163,7 +163,8 @@ namespace ENI2.DetailViewControls // are you sure dialog is in base class _sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Remove(s2s); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(s2s); - DatabaseEntity.ResetIdentifiers(_sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled); + List tmpList = new List(_sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled); + DatabaseEntity.ResetIdentifiers(tmpList); this.SublistElementChanged(Message.NotificationClass.SEC); this.dataGridShip2ShipActivities.Items.Refresh(); } @@ -246,7 +247,8 @@ namespace ENI2.DetailViewControls // are you sure dialog is in base class _sec.LastTenPortFacilitesCalled.Remove(l10c); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(l10c); - DatabaseEntity.ResetIdentifiers(_sec.LastTenPortFacilitesCalled); + List tmpList = new List(_sec.LastTenPortFacilitesCalled); + DatabaseEntity.ResetIdentifiers(tmpList);// ); this.SublistElementChanged(Message.NotificationClass.SEC); this.dataGridLast10PortFacilities.Items.Refresh(); } diff --git a/ENI-2/ENI2/ENI2/ENI2.csproj b/ENI-2/ENI2/ENI2/ENI2.csproj index ac2d14ca..c7543676 100644 --- a/ENI-2/ENI2/ENI2/ENI2.csproj +++ b/ENI-2/ENI2/ENI2/ENI2.csproj @@ -300,6 +300,9 @@ ErrorListDialog.xaml + + MessageHistoryDialog.xaml + NewWithIdDialog.xaml @@ -535,6 +538,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -675,6 +682,9 @@ + + + Always diff --git a/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml b/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml new file mode 100644 index 00000000..653770cc --- /dev/null +++ b/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + diff --git a/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs b/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs new file mode 100644 index 00000000..7b926d41 --- /dev/null +++ b/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs @@ -0,0 +1,129 @@ +// Copyright (c) 2017 schick Informatik +// Description: Übersicht Speicherreihenfolge zu diesem Objekt +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using bsmd.database; +using ENI2.Controls; +using log4net; + +namespace ENI2.EditControls +{ + /// + /// Interaction logic for MessageHistoryDialog.xaml + /// + public partial class MessageHistoryDialog : StatusWindowBase + { + + private static readonly ILog _log = LogManager.GetLogger(typeof(MessageHistoryDialog)); + + public MessageHistoryDialog() + { + InitializeComponent(); + Loaded += (o, e) => + { + this.dataGridMessageHistories.ItemsSource = this.MessageHistories; + + this.dataGridMessageHistories.ContextMenu = new ContextMenu(); + + MenuItem showDetailItem = new MenuItem + { + Header = Properties.Resources.textShowData, + Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/document_view.png")) } + }; + showDetailItem.Click += ShowDetailItem_Click; + this.dataGridMessageHistories.ContextMenu.Items.Add(showDetailItem); + + MenuItem copyDataItem = new MenuItem + { + Header = Properties.Resources.textCopyData, + Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/document_down.png")) } + }; + copyDataItem.Click += CopyDataItem_Click; + this.dataGridMessageHistories.ContextMenu.Items.Add(copyDataItem); + }; + } + + #region Properties + + public List MessageHistories { get; set; } + + public List Messages { get; set; } + + #endregion + + #region event handler + + private void ShowDetailItem_Click(object sender, RoutedEventArgs e) + { + this.DataGridViolations_MouseDoubleClick(sender, null); + } + + private void DataGridViolations_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + if (this.dataGridMessageHistories.SelectedItem is MessageHistory selectedHistory) + { + SimplePropertyViewDialog spvd = new SimplePropertyViewDialog(); + spvd.Title = "Message history"; + spvd.DisplayObject = selectedHistory.CreateObjectFromValues(); + spvd.Show(); + } + } + + private void CopyDataItem_Click(object sender, RoutedEventArgs e) + { + if (this.dataGridMessageHistories.SelectedItem is MessageHistory selectedHistory) + { + if (MessageBox.Show("Overwrite data selected message class?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) + { + Message targetMessage = null; + foreach (Message aMessage in this.Messages) + { + if (aMessage.MessageNotificationClassDisplay.Equals(selectedHistory.EntityName)) + { + targetMessage = aMessage; + break; + } + } + if (targetMessage != null) + { + _log.InfoFormat("Message {0} Id {1} will be restored from {2}", selectedHistory.EntityName, targetMessage.Id, selectedHistory.Created); + DatabaseEntity selectedItem = selectedHistory.CreateObjectFromValues() as DatabaseEntity; + // Fallunterscheidung: a) ISublistElement oder nicht? Falls ja müssen die anderen Elemente zusammengesucht werden + if(Message.IsListClass(targetMessage.MessageNotificationClass)) // Meldeklasse ist also z.B. LADG, CREW, PAS.. + { + foreach (DatabaseEntity oldElement in targetMessage.Elements) + DBManager.Instance.Delete(oldElement); + foreach (DatabaseEntity element in selectedHistory.GetGroup(this.MessageHistories)) + targetMessage.Elements.Add(element); + } + else + { + targetMessage.Elements[0].OverwriteWith(selectedItem); + } + DBManager.Instance.Save(targetMessage); + } + else + { + _log.WarnFormat("Cannot find message {0} to restore history element with id {1}", selectedHistory.EntityName, selectedHistory.Id); + } + } + } + } + + #endregion + + } +} diff --git a/ENI-2/ENI2/ENI2/MainWindow.xaml.cs b/ENI-2/ENI2/ENI2/MainWindow.xaml.cs index 550535ce..65845a3c 100644 --- a/ENI-2/ENI2/ENI2/MainWindow.xaml.cs +++ b/ENI-2/ENI2/ENI2/MainWindow.xaml.cs @@ -38,7 +38,7 @@ namespace ENI2 private ServerStatusControl statusControl; private readonly SucheControl sucheControl; - private readonly List anmeldungen = new List(); + // private readonly List anmeldungen = new List(); private bool efMode = false; private bool dbConnected; private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0); @@ -336,8 +336,7 @@ namespace ENI2 MessageCore newCore = new MessageCore(); VisitIdDialog visitIdDialog = new VisitIdDialog(); - visitIdDialog.Core = newCore; - visitIdDialog.IsModal = false; + visitIdDialog.Core = newCore; visitIdDialog.Closed += (senderDialog, closeArgs) => { VisitIdDialog closedDialog = senderDialog as VisitIdDialog; @@ -370,8 +369,7 @@ namespace ENI2 /// private void buttonNewWithIdClick(object sender, RoutedEventArgs e) { - NewWithIdDialog newWithIdDialog = new NewWithIdDialog(); - newWithIdDialog.IsModal = false; + NewWithIdDialog newWithIdDialog = new NewWithIdDialog(); newWithIdDialog.OKClicked += new Action(() => { @@ -444,8 +442,8 @@ namespace ENI2 TabItem tabitem = this.openTabs[changedCore.Id.Value]; this.Dispatcher.BeginInvoke(new Action(() => { - if (tabitem is ClosableTabItem) - ((ClosableTabItem)tabitem).IsHighlighted = true; + if (tabitem is ClosableTabItem closableTabItem) + (closableTabItem).IsHighlighted = true; })); } } diff --git a/ENI-2/ENI2/ENI2/Properties/Resources.Designer.cs b/ENI-2/ENI2/ENI2/Properties/Resources.Designer.cs index 0c3ec203..d9046a93 100644 --- a/ENI-2/ENI2/ENI2/Properties/Resources.Designer.cs +++ b/ENI-2/ENI2/ENI2/Properties/Resources.Designer.cs @@ -220,6 +220,26 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap clock_history { + get { + object obj = ResourceManager.GetObject("clock_history", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + public static System.Drawing.Icon clock_historyIcon { + get { + object obj = ResourceManager.GetObject("clock_historyIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -260,6 +280,16 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap document_down { + get { + object obj = ResourceManager.GetObject("document_down", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -1457,6 +1487,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Copy to current message (overwrite). + /// + public static string textCopyToMessageClass { + get { + return ResourceManager.GetString("textCopyToMessageClass", resourceCulture); + } + } + /// /// Looks up a localized string similar to Copy TOWA to TOWD. /// @@ -2213,6 +2252,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Show item history. + /// + public static string textHistoryItems { + get { + return ResourceManager.GetString("textHistoryItems", resourceCulture); + } + } + /// /// Looks up a localized string similar to IBC item. /// @@ -2897,6 +2945,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Message history. + /// + public static string textMessageHistory { + get { + return ResourceManager.GetString("textMessageHistory", resourceCulture); + } + } + /// /// Looks up a localized string similar to Message reset at {0}. /// @@ -4022,6 +4079,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Show data. + /// + public static string textShowData { + get { + return ResourceManager.GetString("textShowData", resourceCulture); + } + } + /// /// Looks up a localized string similar to Sick animals or pets on board?. /// @@ -4265,6 +4331,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Timestamp. + /// + public static string textTimestamp { + get { + return ResourceManager.GetString("textTimestamp", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show message core database fields (Detail). /// @@ -4364,6 +4439,15 @@ namespace ENI2.Properties { } } + /// + /// Looks up a localized string similar to Type. + /// + public static string textType { + get { + return ResourceManager.GetString("textType", resourceCulture); + } + } + /// /// Looks up a localized string similar to Type for Locode.... /// diff --git a/ENI-2/ENI2/ENI2/Properties/Resources.resx b/ENI-2/ENI2/ENI2/Properties/Resources.resx index 0533b26d..6eff215c 100644 --- a/ENI-2/ENI2/ENI2/Properties/Resources.resx +++ b/ENI-2/ENI2/ENI2/Properties/Resources.resx @@ -1663,4 +1663,31 @@ Reset "Cancelled" flag in database + + Show item history + + + Message history + + + ..\Resources\clock_history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\clock_history.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Timestamp + + + Type + + + ..\Resources\document_down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Copy to current message (overwrite) + + + Show data + \ No newline at end of file diff --git a/ENI-2/ENI2/ENI2/Resources/clock_history.ico b/ENI-2/ENI2/ENI2/Resources/clock_history.ico new file mode 100644 index 00000000..976a44bd Binary files /dev/null and b/ENI-2/ENI2/ENI2/Resources/clock_history.ico differ diff --git a/ENI-2/ENI2/ENI2/Resources/clock_history.png b/ENI-2/ENI2/ENI2/Resources/clock_history.png new file mode 100644 index 00000000..9e1f6c0a Binary files /dev/null and b/ENI-2/ENI2/ENI2/Resources/clock_history.png differ diff --git a/ENI-2/ENI2/ENI2/Resources/document_down.png b/ENI-2/ENI2/ENI2/Resources/document_down.png new file mode 100644 index 00000000..5c724f62 Binary files /dev/null and b/ENI-2/ENI2/ENI2/Resources/document_down.png differ diff --git a/ENI-2/ENI2/ENI2/SucheControl.xaml.cs b/ENI-2/ENI2/ENI2/SucheControl.xaml.cs index 68f264b5..36ce6af9 100644 --- a/ENI-2/ENI2/ENI2/SucheControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/SucheControl.xaml.cs @@ -22,8 +22,8 @@ namespace ENI2 public partial class SucheControl : UserControl { private List anmeldungen = new List(); - private object searchLock = new object(); - private ILog _log = LogManager.GetLogger("SucheControl"); + private readonly object searchLock = new object(); + private readonly ILog _log = LogManager.GetLogger("SucheControl"); private MenuItem cancelItem; #region Construction @@ -42,7 +42,7 @@ namespace ENI2 MenuItem addItem = new MenuItem(); addItem.Header = Properties.Resources.textCopyClip; addItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; - addItem.Click += new RoutedEventHandler(this.copyID); + addItem.Click += this.copyID; this.dataGrid.ContextMenu.Items.Add(addItem); cancelItem = new MenuItem(); cancelItem.Header = Properties.Resources.textUndoCancel; @@ -186,7 +186,7 @@ namespace ENI2 // ergebnis anzeigen this.dataGrid.ItemsSource = this.anmeldungen; - this.searchResultLabel.Content = ((expectedResultNum ?? 0) > 0) ? string.Format("{0} results found, {1} displayed.", (expectedResultNum ?? 0), this.anmeldungen.Count) : "no results"; + this.searchResultLabel.Content = ((expectedResultNum ?? 0) > 0) ? string.Format("{0} results found, {1} displayed.", expectedResultNum ?? 0, this.anmeldungen.Count) : "no results"; if((expectedResultNum ?? 0) > 100) { @@ -234,7 +234,7 @@ namespace ENI2 if (sender != null) { DataGrid grid = sender as DataGrid; - if ((grid != null) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1)) + if (grid?.SelectedItems?.Count == 1) { DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow; MessageCore selectedCore = grid.SelectedItem as MessageCore; @@ -258,10 +258,9 @@ namespace ENI2 private void copyID(object sender, RoutedEventArgs e) { - MessageCore selectedCore = dataGrid.SelectedItem as MessageCore; - if(selectedCore != null) + if (dataGrid.SelectedItem is MessageCore selectedCore) { - if(selectedCore.DisplayId != null) + if (selectedCore.DisplayId != null) { Clipboard.SetText(selectedCore.DisplayId); } diff --git a/ENI-2/ENI2/ENI2/Util/UIHelper.cs b/ENI-2/ENI2/ENI2/Util/UIHelper.cs index e85faea6..34f56f5b 100644 --- a/ENI-2/ENI2/ENI2/Util/UIHelper.cs +++ b/ENI-2/ENI2/ENI2/Util/UIHelper.cs @@ -4,6 +4,7 @@ // https://stackoverflow.com/a/7482321 using System; +using System.Reflection; using System.Windows; using System.Windows.Input; using System.Windows.Threading; @@ -32,8 +33,6 @@ namespace ENI2.Util { new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, Application.Current.Dispatcher); } - - } private static void dispatcherTimer_Tick(object sender, EventArgs e) @@ -45,5 +44,11 @@ namespace ENI2.Util timer.Stop(); } } + + public static bool IsModal(this Window window) + { + return (bool)typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(window); + } + } } diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 7c0a29d1..94193187 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs index d1893e97..82c17e0e 100644 --- a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs +++ b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs @@ -150,6 +150,7 @@ namespace bsmd.ExcelReadService if (reportingPartyDict[rpKey].UserEMail.IsNullOrEmpty()) continue; if (reportingPartyDict[rpKey].UserEMail.Equals(mailSender, StringComparison.OrdinalIgnoreCase)) { + ReportingParty.CurrentReportingParty = reportingPartyDict[rpKey]; importHeader.ReportingPartyId = rpKey; foundReportingParty = true; break; @@ -158,6 +159,7 @@ namespace bsmd.ExcelReadService if (!foundReportingParty) { _log.WarnFormat("Sender {0} is an unknown reporting party", mailSender); + ReportingParty.CurrentReportingParty = null; } DBManager.Instance.Save(importHeader); diff --git a/nsw/Source/bsmd.database/BPOL.cs b/nsw/Source/bsmd.database/BPOL.cs index 4d70b5a7..37ff34fa 100644 --- a/nsw/Source/bsmd.database/BPOL.cs +++ b/nsw/Source/bsmd.database/BPOL.cs @@ -103,6 +103,28 @@ namespace bsmd.database #endregion + #region overrides + + public override void OverwriteWith(DatabaseEntity otherEntity) + { + if (otherEntity is BPOL otherBPOL) + { + base.OverwriteWith(otherEntity); + foreach (PortOfItinerary poi in this.PortOfItineraries) + DBManager.Instance.Delete(poi); + this.PortOfItineraries.Clear(); + foreach (PortOfItinerary poi in otherBPOL.PortOfItineraries) + { + PortOfItinerary newPOI = poi.Clone() as PortOfItinerary; + newPOI.BPOL = this; + DBManager.Instance.Save(newPOI); + this.PortOfItineraries.Add(newPOI); + } + } + } + + #endregion + #region ISublistContainer implementation public ISublistElement GetSublistElementWithIdentifier(string identifier) diff --git a/nsw/Source/bsmd.database/DBManager.cs b/nsw/Source/bsmd.database/DBManager.cs index 435a6a4f..bc5631b9 100644 --- a/nsw/Source/bsmd.database/DBManager.cs +++ b/nsw/Source/bsmd.database/DBManager.cs @@ -650,6 +650,25 @@ namespace bsmd.database return result; } + public List GetMessageHistories(Guid messageId) + { + try + { + SqlCommand cmd = new SqlCommand(); + cmd.CommandText = MessageHistory.GetLoadCommand(); + cmd.Parameters.AddWithValue("@ENTITYID", messageId); + IDataReader reader = this.PerformCommand(cmd); + List result = MessageHistory.LoadList(reader); + reader.Close(); + return result; + } + catch(Exception ex) + { + _log.ErrorFormat("Error loadin message history: {0}", ex.Message); + return null; + } + } + #endregion #region internal/private funcs diff --git a/nsw/Source/bsmd.database/DatabaseEntity.cs b/nsw/Source/bsmd.database/DatabaseEntity.cs index bfc94d46..af047ad0 100644 --- a/nsw/Source/bsmd.database/DatabaseEntity.cs +++ b/nsw/Source/bsmd.database/DatabaseEntity.cs @@ -183,7 +183,40 @@ namespace bsmd.database public virtual ValidationBlock GetValidationBlock() { return ValidationBlock.BLOCK1; - } + } + + /// + /// Diese Methode überschreibt die Properties dieses Objekts mit den (gleichnamigen) Properties eines + /// anderen Objekts. Vorausgesetzt wird, dass die beiden Objekte vom selben Typ sind. Properties, die mit + /// "JSONIgnore" dekoriert sind werden dabei übersprungen + /// + /// Quell-Objekt + public virtual void OverwriteWith(DatabaseEntity otherEntity) + { + try + { + DatabaseEntity.CopyProperties(this, otherEntity); + } + catch(Exception ex) + { + _log.ErrorFormat("Error copying properties: {0}", ex.Message); + } + } + + public static void CopyProperties(DatabaseEntity entityTarget, DatabaseEntity entitySource) + { + foreach (PropertyInfo propertyInfo in entityTarget.GetType().GetProperties()) + { + bool hasJsonIgnoreAttribute = (propertyInfo.GetCustomAttribute(typeof(JsonIgnoreAttribute)) != null); + if (!hasJsonIgnoreAttribute) + { + PropertyInfo otherProperty = entitySource.GetType().GetProperty(propertyInfo.Name); + propertyInfo.SetValue(entityTarget, otherProperty.GetValue(entitySource)); + } + } + + DBManager.Instance.Save(entityTarget); + } #endregion diff --git a/nsw/Source/bsmd.database/HAZ.cs b/nsw/Source/bsmd.database/HAZ.cs index 5af2d278..0f5062b6 100644 --- a/nsw/Source/bsmd.database/HAZ.cs +++ b/nsw/Source/bsmd.database/HAZ.cs @@ -238,6 +238,89 @@ namespace bsmd.database #endregion + #region Overrides + + public override void OverwriteWith(DatabaseEntity otherEntity) + { + if (otherEntity is HAZ otherHAZ) + { + base.OverwriteWith(otherEntity); + + // overwrite IMGD + + foreach (IMDGPosition imdg in this.IMDGPositions) + DBManager.Instance.Delete(imdg); + this.IMDGPositions.Clear(); + + foreach (IMDGPosition imdg in otherHAZ.IMDGPositions) + { + IMDGPosition newIMDG = imdg.Clone() as IMDGPosition; + newIMDG.HAZ = this; + DBManager.Instance.Save(newIMDG); + this.IMDGPositions.Add(newIMDG); + } + + // overwrite IBC + + foreach (IBCPosition ibc in this.IBCPositions) + DBManager.Instance.Delete(ibc); + this.IBCPositions.Clear(); + + foreach (IBCPosition ibc in otherHAZ.IBCPositions) + { + IBCPosition newIBC = ibc.Clone() as IBCPosition; + newIBC.HAZ = this; + DBManager.Instance.Save(newIBC); + this.IBCPositions.Add(newIBC); + } + + // overwrite IGC + + foreach (IGCPosition igc in this.IGCPositions) + DBManager.Instance.Delete(igc); + this.IGCPositions.Clear(); + + foreach (IGCPosition igc in otherHAZ.IGCPositions) + { + IGCPosition newIGC = igc.Clone() as IGCPosition; + newIGC.HAZ = this; + DBManager.Instance.Save(newIGC); + this.IGCPositions.Add(newIGC); + } + + // IMSBC + + foreach (IMSBCPosition imsbc in this.IMSBCPositions) + DBManager.Instance.Delete(imsbc); + this.IMSBCPositions.Clear(); + + foreach (IMSBCPosition imsbc in otherHAZ.IMSBCPositions) + { + IMSBCPosition newIMSBC = imsbc.Clone() as IMSBCPosition; + newIMSBC.HAZ = this; + DBManager.Instance.Save(newIMSBC); + this.IMSBCPositions.Add(newIMSBC); + } + + // Marpol + + foreach (MARPOL_Annex_I_Position marpol in this.MARPOLPositions) + DBManager.Instance.Delete(marpol); + this.MARPOLPositions.Clear(); + + foreach (MARPOL_Annex_I_Position marpol in otherHAZ.MARPOLPositions) + { + MARPOL_Annex_I_Position newMarpol = marpol.Clone() as MARPOL_Annex_I_Position; + newMarpol.HAZ = this; + DBManager.Instance.Save(newMarpol); + this.MARPOLPositions.Add(newMarpol); + } + + } + } + + #endregion + #region ISublistContainer implementation public ISublistElement GetSublistElementWithIdentifier(string identifier) diff --git a/nsw/Source/bsmd.database/LADG.cs b/nsw/Source/bsmd.database/LADG.cs index 37968986..61c133cc 100644 --- a/nsw/Source/bsmd.database/LADG.cs +++ b/nsw/Source/bsmd.database/LADG.cs @@ -19,7 +19,7 @@ namespace bsmd.database #region static definition - private static Lazy> laCodes = + private static readonly Lazy> laCodes = new Lazy>(() => new Dictionary { { 10, "unverpacktes Flüssiggut" }, @@ -43,8 +43,6 @@ namespace bsmd.database { 67, "Reisezugwagen und Triebwagen" } }); - private static Dictionary _cargoHandlingDict = new Dictionary(); - #endregion public LADG() @@ -66,8 +64,8 @@ namespace bsmd.database get { if(this.CargoHandlingType.HasValue) { - if (_cargoHandlingDict.ContainsKey(this.CargoHandlingType.Value)) - return _cargoHandlingDict[this.CargoHandlingType.Value]; + if (CargoHandlingDict.ContainsKey(this.CargoHandlingType.Value)) + return CargoHandlingDict[this.CargoHandlingType.Value]; return string.Empty; } return string.Empty; @@ -117,12 +115,9 @@ namespace bsmd.database public static Dictionary CargoCodesNST { get; set; } public static List> CargoCodesNST3 { get; set; } - - public static Dictionary CargoHandlingDict - { - get { return _cargoHandlingDict; } - } + + public static Dictionary CargoHandlingDict { get; } = new Dictionary(); #endregion @@ -162,7 +157,7 @@ namespace bsmd.database } else { - scmd.Parameters.AddWithValue(@"ID", this.Id); + scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET CargoHandlingType = @P2, CargoCodeNST = @P3, CargoNumberOfItems = @P4, " + "CargoGrossQuantity_TNE = @P5, PortOfLoading = @P6, PortOfDischarge = @P7, CargoLACode = @P9, CargoCodeNST_3 = @P10, " + "Identifier = @P8 WHERE Id = @ID", this.Tablename); diff --git a/nsw/Source/bsmd.database/MDH.cs b/nsw/Source/bsmd.database/MDH.cs index 8dcaffef..5ee04790 100644 --- a/nsw/Source/bsmd.database/MDH.cs +++ b/nsw/Source/bsmd.database/MDH.cs @@ -17,15 +17,6 @@ namespace bsmd.database { public class MDH : DatabaseEntity, ISublistContainer { - - private ObservableCollection portOfCallLast30Days = new ObservableCollection(); - - private ObservableCollection sanitaryMeasuresDetails = new ObservableCollection(); - - private ObservableCollection stowawaysJoiningLocations = new ObservableCollection(); - - private ObservableCollection infectedAreas = new ObservableCollection(); - public MDH() { this.tablename = "[dbo].[MDH]"; @@ -34,13 +25,13 @@ namespace bsmd.database #region Properties - public ObservableCollection PortOfCallLast30Days { get { return this.portOfCallLast30Days; } } + public ObservableCollection PortOfCallLast30Days { get; private set; } = new ObservableCollection(); - public ObservableCollection SanitaryMeasuresDetails { get { return this.sanitaryMeasuresDetails; } } + public ObservableCollection SanitaryMeasuresDetails { get; private set; } = new ObservableCollection(); - public ObservableCollection StowawaysJoiningLocations { get { return this.stowawaysJoiningLocations; } } + public ObservableCollection StowawaysJoiningLocations { get; private set; } = new ObservableCollection(); - public ObservableCollection InfectedAreas { get { return this.infectedAreas; } } + public ObservableCollection InfectedAreas { get; private set; } = new ObservableCollection(); [ShowReport] [Validation1(ValidationCode.NOT_NULL)] @@ -400,6 +391,71 @@ namespace bsmd.database #endregion + #region overrides + + public override void OverwriteWith(DatabaseEntity otherEntity) + { + if (otherEntity is MDH otherMDH) + { + base.OverwriteWith(otherEntity); + + // PortOfCallLast30Days + + foreach (PortOfCallLast30Days poc in this.PortOfCallLast30Days) + DBManager.Instance.Delete(poc); + this.PortOfCallLast30Days.Clear(); + foreach (PortOfCallLast30Days poc in otherMDH.PortOfCallLast30Days) + { + PortOfCallLast30Days newPOC = poc.Clone() as PortOfCallLast30Days; + newPOC.MDH = this; + DBManager.Instance.Save(newPOC); + this.PortOfCallLast30Days.Add(newPOC); + } + + // SanitaryMeasuresDetails + + foreach (SanitaryMeasuresDetail san in this.SanitaryMeasuresDetails) + DBManager.Instance.Delete(san); + this.SanitaryMeasuresDetails.Clear(); + foreach (SanitaryMeasuresDetail san in otherMDH.SanitaryMeasuresDetails) + { + SanitaryMeasuresDetail newSAN = san.Clone() as SanitaryMeasuresDetail; + newSAN.MDH = this; + DBManager.Instance.Save(newSAN); + this.SanitaryMeasuresDetails.Add(newSAN); + } + + // StowawaysJoiningLocations + + foreach (StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) + DBManager.Instance.Delete(sjl); + this.StowawaysJoiningLocations.Clear(); + foreach (StowawaysJoiningLocation sjl in otherMDH.StowawaysJoiningLocations) + { + StowawaysJoiningLocation newSJL = sjl.Clone() as StowawaysJoiningLocation; + newSJL.MDH = this; + DBManager.Instance.Save(newSJL); + this.StowawaysJoiningLocations.Add(newSJL); + } + + // InfectedAreas + + foreach (InfectedArea ia in this.InfectedAreas) + DBManager.Instance.Delete(ia); + this.InfectedAreas.Clear(); + foreach (InfectedArea ia in otherMDH.InfectedAreas) + { + InfectedArea newIA = ia.Clone() as InfectedArea; + newIA.MDH = this; + DBManager.Instance.Save(newIA); + this.InfectedAreas.Add(newIA); + } + + } + } + + #endregion + #region ISublistContainer implementation public ISublistElement GetSublistElementWithIdentifier(string identifier) @@ -429,7 +485,7 @@ namespace bsmd.database DBManager.Instance.Save(smd); } - foreach(StowawaysJoiningLocation sjl in this.stowawaysJoiningLocations) + foreach(StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) { DBManager.Instance.Save(sjl); } @@ -453,9 +509,9 @@ namespace bsmd.database { DBManager.Instance.Delete(smd); } - this.sanitaryMeasuresDetails.Clear(); + this.SanitaryMeasuresDetails.Clear(); - foreach (StowawaysJoiningLocation sjl in this.stowawaysJoiningLocations) + foreach (StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) { DBManager.Instance.Delete(sjl); } @@ -470,21 +526,21 @@ namespace bsmd.database public SanitaryMeasuresDetail GetSanitaryMeasuresDetailWithIdentifier(string identifier) { - foreach (SanitaryMeasuresDetail sd in this.sanitaryMeasuresDetails) + foreach (SanitaryMeasuresDetail sd in this.SanitaryMeasuresDetails) if (sd.Identifier.Equals(identifier)) return sd; return null; } public StowawaysJoiningLocation GetStowawaysJoiningLocationWithIdentifier(string identifier) { - foreach (StowawaysJoiningLocation sj in this.stowawaysJoiningLocations) + foreach (StowawaysJoiningLocation sj in this.StowawaysJoiningLocations) if (sj.Identifier.Equals(identifier)) return sj; return null; } public InfectedArea GetInfectedAreaWithIdentifier(string identifier) { - foreach (InfectedArea ia in this.infectedAreas) + foreach (InfectedArea ia in this.InfectedAreas) if (ia.Identifier.Equals(identifier)) return ia; return null; } @@ -553,12 +609,12 @@ namespace bsmd.database if ((this.DateOfIssue.HasValue) && (this.DateOfIssue.Value < DateTime.Today.AddMonths(-6))) violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Date of issue might be too old", null, this.Title, null, this.Tablename)); - if (this.portOfCallLast30Days.Count == 0) + if (this.PortOfCallLast30Days.Count == 0) { errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, "Port of Call last 30 day list is EMPTY", null, this.Title, null, this.Tablename)); } - foreach (PortOfCallLast30Days poc30d in this.portOfCallLast30Days) + foreach (PortOfCallLast30Days poc30d in this.PortOfCallLast30Days) { RuleEngine.ValidateProperties(poc30d, errors, violations); poc30d.Validate(errors, violations); @@ -574,10 +630,10 @@ namespace bsmd.database { MDH mdh = this.MemberwiseClone() as MDH; mdh.id = null; - mdh.infectedAreas = new ObservableCollection(); - mdh.portOfCallLast30Days = new ObservableCollection(); - mdh.sanitaryMeasuresDetails = new ObservableCollection(); - mdh.stowawaysJoiningLocations = new ObservableCollection(); + mdh.InfectedAreas = new ObservableCollection(); + mdh.PortOfCallLast30Days = new ObservableCollection(); + mdh.SanitaryMeasuresDetails = new ObservableCollection(); + mdh.StowawaysJoiningLocations = new ObservableCollection(); foreach (InfectedArea ia in this.InfectedAreas) { @@ -593,7 +649,7 @@ namespace bsmd.database mdh.PortOfCallLast30Days.Add(clonedPOC); } - foreach (SanitaryMeasuresDetail smd in this.sanitaryMeasuresDetails) + foreach (SanitaryMeasuresDetail smd in this.SanitaryMeasuresDetails) { SanitaryMeasuresDetail clonedSMD = smd.Clone() as SanitaryMeasuresDetail; clonedSMD.MDH = mdh; diff --git a/nsw/Source/bsmd.database/MessageHistory.cs b/nsw/Source/bsmd.database/MessageHistory.cs index 1c37624b..881d1db4 100644 --- a/nsw/Source/bsmd.database/MessageHistory.cs +++ b/nsw/Source/bsmd.database/MessageHistory.cs @@ -1,6 +1,7 @@ // Copyright (c) 2015-2017 schick Informatik // Description: +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; @@ -35,6 +36,88 @@ namespace bsmd.database public DateTime Created { get; private set; } + /// + /// ENI Grid helper property + /// + public string ReportingPartyName + { + get + { + Dictionary repPartyDict = DBManager.Instance.GetReportingPartyDict(); + if (ReportingPartyId.HasValue && repPartyDict.ContainsKey(ReportingPartyId.Value)) + return repPartyDict[ReportingPartyId.Value].Logon; + return ""; + } + } + + #endregion + + #region public methods + + internal static string GetLoadCommand() + { + return "SELECT Id, ReportingPartyId, EntityId, EntityType, EntityName, EntityValues, Timestamp FROM MessageHistory WHERE EntityId=@ENTITYID ORDER BY Timestamp"; + } + + public object CreateObjectFromValues() + { + if(!this.EntityType.IsNullOrEmpty()) + { + Type objectType = Type.GetType(this.EntityType); + if(objectType != null) + return JsonConvert.DeserializeObject(this.EntityValues, objectType); + } + return null; + } + + /// + /// Liefert alle History-Elemente zu dem Parameter Bezugselement, wenn es ISublistElement Objekte sind + /// Die Elemente werden über den Index gefunden.. also alles was von 1..n geht in dem Abschnitt, in dem der Benutzer + /// einen Eintrag ausgewählt hat. + /// + /// + /// + public List GetGroup(List allHistories) + { + + LinkedList tmpResult = new LinkedList(); + DatabaseEntity refEntity = this.CreateObjectFromValues() as DatabaseEntity; + + if (refEntity is ISublistElement sublistElement) + { + List tmpList = new List(allHistories); + // Alle History-Elemente einer anderen Meldeklasse ausfiltern + tmpList.RemoveAll(aMessageHistory => !aMessageHistory.EntityId.Equals(this.EntityId)); + + int selIndex = tmpList.IndexOf(this); + tmpResult.AddLast(refEntity); + int myIdentifier = Int32.Parse((sublistElement).Identifier); + + // Elemente vor dem ausgewählten Element der Linked List hinzufügen + int indexIdentifier = myIdentifier; + + for (int tmpIndex = selIndex - 1; (indexIdentifier != 1) && (tmpIndex >= 0); tmpIndex--) + { + DatabaseEntity prevEntity = tmpList[tmpIndex].CreateObjectFromValues() as DatabaseEntity; + indexIdentifier = Int32.Parse(((ISublistElement)prevEntity).Identifier); + tmpResult.AddFirst(prevEntity); + } + + // Elemente nach dem ausgewählten Element hinzufügen (wenn sie zur gleichen Gruppe gehören) + indexIdentifier = myIdentifier; + for(int tmpIndex = selIndex + 1; (indexIdentifier != 1) && (tmpIndex < tmpList.Count); tmpIndex++) + { + DatabaseEntity nextEntity = tmpList[tmpIndex].CreateObjectFromValues() as DatabaseEntity; + indexIdentifier = Int32.Parse(((ISublistElement)nextEntity).Identifier); + tmpResult.AddLast(nextEntity); + } + + } + + return new List(tmpResult); + } + + #endregion #region IDatabaseEntity implementation @@ -62,9 +145,9 @@ namespace bsmd.database SqlCommand scmd = cmd as SqlCommand; scmd.CommandText = string.Format("DELETE FROM {0} WHERE Id = @ID", Tablename); scmd.Parameters.AddWithValue("@ID", this.Id); - } + } - public List LoadList(IDataReader reader) + internal static List LoadList(IDataReader reader) { List result = new List(); diff --git a/nsw/Source/bsmd.database/NOA_NOD.cs b/nsw/Source/bsmd.database/NOA_NOD.cs index 3b459ca3..7a0b54b8 100644 --- a/nsw/Source/bsmd.database/NOA_NOD.cs +++ b/nsw/Source/bsmd.database/NOA_NOD.cs @@ -153,6 +153,28 @@ namespace bsmd.database #endregion + #region overrides + + public override void OverwriteWith(DatabaseEntity otherEntity) + { + if (otherEntity is NOA_NOD otherNOA_NOD) + { + base.OverwriteWith(otherEntity); + foreach (CallPurpose cp in this.CallPurposes) + DBManager.Instance.Delete(cp); + this.CallPurposes.Clear(); + foreach (CallPurpose cp in otherNOA_NOD.CallPurposes) + { + CallPurpose newCP = cp.Clone() as CallPurpose; + newCP.NOA_NOD = this; + DBManager.Instance.Save(newCP); + this.CallPurposes.Add(newCP); + } + } + } + + #endregion + #region ISublistContainer implementation public ISublistElement GetSublistElementWithIdentifier(string identifier) diff --git a/nsw/Source/bsmd.database/SEC.cs b/nsw/Source/bsmd.database/SEC.cs index 615a443c..ff01aa3a 100644 --- a/nsw/Source/bsmd.database/SEC.cs +++ b/nsw/Source/bsmd.database/SEC.cs @@ -17,11 +17,6 @@ namespace bsmd.database { public class SEC : DatabaseEntity, ISublistContainer { - - private ObservableCollection ltpfc = new ObservableCollection(); - - private ObservableCollection lsts = new ObservableCollection(); - public SEC() { this.tablename = "[dbo].[SEC]"; @@ -155,9 +150,9 @@ namespace bsmd.database public DateTime? KielCanalPassagePlannedOutgoing { get; set; } [Validation2(ValidationCode.LIST_EMPTY)] - public ObservableCollection LastTenPortFacilitesCalled { get { return this.ltpfc; } } + public ObservableCollection LastTenPortFacilitesCalled { get; private set; } = new ObservableCollection(); - public ObservableCollection ShipToShipActivitiesDuringLastTenPortFacilitiesCalled { get { return this.lsts; } } + public ObservableCollection ShipToShipActivitiesDuringLastTenPortFacilitiesCalled { get; private set; } = new ObservableCollection(); #endregion @@ -282,11 +277,46 @@ namespace bsmd.database #endregion + #region overrides + + public override void OverwriteWith(DatabaseEntity otherEntity) + { + if (otherEntity is SEC otherSEC) + { + base.OverwriteWith(otherEntity); + + foreach (LastTenPortFacilitiesCalled lc in this.LastTenPortFacilitesCalled) + DBManager.Instance.Delete(lc); + this.LastTenPortFacilitesCalled.Clear(); + foreach (LastTenPortFacilitiesCalled lc in otherSEC.LastTenPortFacilitesCalled) + { + LastTenPortFacilitiesCalled newLC = lc.Clone() as LastTenPortFacilitiesCalled; + newLC.SEC = this; + DBManager.Instance.Save(newLC); + this.LastTenPortFacilitesCalled.Add(newLC); + } + + foreach (ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2s in this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) + DBManager.Instance.Delete(s2s); + this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Clear(); + foreach (ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2s in otherSEC.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) + { + ShipToShipActivitiesDuringLastTenPortFacilitiesCalled newS2S = s2s.Clone() as ShipToShipActivitiesDuringLastTenPortFacilitiesCalled; + newS2S.SEC = this; + DBManager.Instance.Save(newS2S); + this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Add(newS2S); + } + + } + } + + #endregion + #region sublist lookup implementation public LastTenPortFacilitiesCalled GetPortFacilityWithIdentifier(string identifier) { - foreach(ISublistElement lp in this.ltpfc) { + foreach(ISublistElement lp in this.LastTenPortFacilitesCalled) { if (lp.Identifier.Equals(identifier)) return lp as LastTenPortFacilitiesCalled; } @@ -295,7 +325,7 @@ namespace bsmd.database public ShipToShipActivitiesDuringLastTenPortFacilitiesCalled GetShipToShipWithIdentifier(string identifier) { - foreach (ISublistElement lp in this.lsts) + foreach (ISublistElement lp in this.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled) { if (lp.Identifier.Equals(identifier)) return lp as ShipToShipActivitiesDuringLastTenPortFacilitiesCalled; @@ -437,8 +467,8 @@ namespace bsmd.database SEC sec = this.MemberwiseClone() as SEC; sec.id = null; - sec.lsts = new ObservableCollection(); - sec.ltpfc = new ObservableCollection(); + sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled = new ObservableCollection(); + sec.LastTenPortFacilitesCalled = new ObservableCollection(); foreach (LastTenPortFacilitiesCalled ltp in this.LastTenPortFacilitesCalled) { diff --git a/nsw/Source/bsmd.database/WAS.cs b/nsw/Source/bsmd.database/WAS.cs index 42af6299..6d0664b2 100644 --- a/nsw/Source/bsmd.database/WAS.cs +++ b/nsw/Source/bsmd.database/WAS.cs @@ -17,11 +17,6 @@ namespace bsmd.database { public class WAS : DatabaseEntity, ISublistContainer { - - private ObservableCollection wdsp = new ObservableCollection(); - - private ObservableCollection waste = new ObservableCollection(); - public WAS() { this.tablename = "[dbo].[WAS]"; @@ -70,9 +65,9 @@ namespace bsmd.database [ENI2Validation] public bool? ConfirmationOfSufficiency { get; set; } - public ObservableCollection Waste { get { return this.waste; } } + public ObservableCollection Waste { get; private set; } = new ObservableCollection(); - public ObservableCollection WasteDisposalServiceProvider { get { return this.wdsp; } } + public ObservableCollection WasteDisposalServiceProvider { get; private set; } = new ObservableCollection(); /// /// Hilfsproperty, um eine kommaseparierte Liste von WasteDisposalServiceProvider (analog ANSW) im ENI-2 anzuzeigen, @@ -227,6 +222,41 @@ namespace bsmd.database #endregion + #region overrides + + public override void OverwriteWith(DatabaseEntity otherEntity) + { + if (otherEntity is WAS otherWAS) + { + base.OverwriteWith(otherEntity); + + foreach (Waste w in this.Waste) + DBManager.Instance.Delete(w); + this.Waste.Clear(); + foreach (Waste w in otherWAS.Waste) + { + Waste newW = w.Clone() as Waste; + newW.WAS = this; + DBManager.Instance.Save(newW); + this.Waste.Add(newW); + } + + foreach (WasteDisposalServiceProvider ws in this.WasteDisposalServiceProvider) + DBManager.Instance.Delete(ws); + this.WasteDisposalServiceProvider.Clear(); + foreach (WasteDisposalServiceProvider ws in otherWAS.WasteDisposalServiceProvider) + { + WasteDisposalServiceProvider newWS = ws.Clone() as WasteDisposalServiceProvider; + newWS.WAS = this; + DBManager.Instance.Save(newWS); + this.WasteDisposalServiceProvider.Add(newWS); + } + + } + } + + #endregion + #region ISublistContainer implementation public ISublistElement GetSublistElementWithIdentifier(string identifier) @@ -460,8 +490,8 @@ namespace bsmd.database { WAS was = this.MemberwiseClone() as WAS; was.id = null; - was.waste = new ObservableCollection(); - was.wdsp = new ObservableCollection(); + was.Waste = new ObservableCollection(); + was.WasteDisposalServiceProvider = new ObservableCollection(); foreach (Waste waste in this.Waste) {