// Copyright (c) 2017 schick Informatik // Description: Für Arrival / Departure // using System.Windows; using bsmd.database; using ENI2.EditControls; using ENI2.Util; using System.Windows.Controls; using System.Windows.Media.Imaging; using System; using System.Collections.Generic; using System.Windows.Data; using System.Collections.Specialized; namespace ENI2.DetailViewControls { /// /// Interaction logic for DangerousGoodsDetailControl.xaml /// public partial class DangerousGoodsDetailControl : DetailBaseControl { #region fields private Message _hazaMessage; private Message _hazdMessage; private HAZ haza; private HAZ hazd; private NewDGItemDialog newDGDialog = null; #endregion #region Construction public DangerousGoodsDetailControl() { InitializeComponent(); this.Loaded += DangerousGoodsDetailControl_Loaded; } #endregion private void DangerousGoodsDetailControl_Loaded(object sender, RoutedEventArgs e) { this.RegisterCheckboxChange(this.checkBoxDangerousGoodsOnBoard, this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.RegisterCheckboxChange(this.checkBoxDGManifestOnBoard, this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.RegisterCheckboxChange(this.checkBoxMoUBaltic, this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.RegisterComboboxIndexChange(this.comboBoxVesselClass, this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); } /// /// Flag if this control is used for arrival or departure /// public bool IsDeparture { get; set; } public override void Initialize() { base.Initialize(); foreach (Message aMessage in this.Messages) { if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) { this._hazdMessage = aMessage; this.ControlMessages.Add(aMessage); if (aMessage.Elements.Count > 0) this.hazd = aMessage.Elements[0] as HAZ; if (this.hazd == null) { this.hazd = new HAZ(); this.hazd.MessageCore = this.Core; this.hazd.MessageHeader = aMessage; this.hazd.IsDeparture = true; aMessage.Elements.Add(this.hazd); SublistElementChanged(Message.NotificationClass.HAZD); } } if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA) { this._hazaMessage = aMessage; this.ControlMessages.Add(aMessage); if (aMessage.Elements.Count > 0) this.haza = aMessage.Elements[0] as HAZ; if (this.haza == null) { this.haza = new HAZ(); this.haza.MessageCore = this.Core; this.haza.MessageHeader = aMessage; this.haza.IsDeparture = true; aMessage.Elements.Add(this.haza); SublistElementChanged(Message.NotificationClass.HAZA); } } this.textBlockMessageClass.Text = IsDeparture ? "HAZD" : "HAZA"; } #region HAZ this.comboBoxVesselClass.ItemsSource = GlobalStructures.vesselClasses; this.groupBoxHAZ.DataContext = this.IsDeparture ? hazd : haza; this.dataGridIMDGItems.Initialize(); this.dataGridIMDGItems.ItemsSource = this.IsDeparture ? this.hazd.IMDGPositions : this.haza.IMDGPositions; CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIMDGItems.Items); ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; this.dataGridIMDGItems.CreateRequested += DataGridIMDGItems_CreateRequested; this.dataGridIMDGItems.AddingNewItem += DataGridIMDGItems_AddingNewItem; this.dataGridIMDGItems.EditRequested += DataGridIMDGItems_EditRequested; this.dataGridIMDGItems.DeleteRequested += DataGridIMDGItems_DeleteRequested; this.dataGridIBCItems.Initialize(); this.dataGridIBCItems.ItemsSource = this.IsDeparture ? this.hazd.IBCPositions : this.haza.IBCPositions; myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIBCItems.Items); ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; this.dataGridIBCItems.CreateRequested += DataGridIBCItems_CreateRequested; this.dataGridIBCItems.AddingNewItem += DataGridIBCItems_AddingNewItem; this.dataGridIBCItems.EditRequested += DataGridIBCItems_EditRequested; this.dataGridIBCItems.DeleteRequested += DataGridIBCItems_DeleteRequested; this.dataGridIGCItems.Initialize(); this.dataGridIGCItems.ItemsSource = this.IsDeparture ? this.hazd.IGCPositions : this.haza.IGCPositions; myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIGCItems.Items); ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; this.dataGridIGCItems.CreateRequested += DataGridIGCItems_CreateRequested; this.dataGridIGCItems.AddingNewItem += DataGridIGCItems_AddingNewItem; this.dataGridIGCItems.EditRequested += DataGridIGCItems_EditRequested; this.dataGridIGCItems.DeleteRequested += DataGridIGCItems_DeleteRequested; this.dataGridIMSBCItems.Initialize(); this.dataGridIMSBCItems.ItemsSource = this.IsDeparture ? this.hazd.IMSBCPositions : this.haza.IMSBCPositions; myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIMSBCItems.Items); ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; this.dataGridIMSBCItems.CreateRequested += DataGridIMSBCItems_CreateRequested; this.dataGridIMSBCItems.AddingNewItem += DataGridIMSBCItems_AddingNewItem; this.dataGridIMSBCItems.EditRequested += DataGridIMSBCItems_EditRequested; this.dataGridIMSBCItems.DeleteRequested += DataGridIMSBCItems_DeleteRequested; this.dataGridMARPOLItems.Initialize(); this.dataGridMARPOLItems.ItemsSource = this.IsDeparture ? this.hazd.MARPOLPositions : this.haza.MARPOLPositions; myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridMARPOLItems.Items); ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; this.dataGridMARPOLItems.CreateRequested += DataGridMARPOLItems_CreateRequested; this.dataGridMARPOLItems.AddingNewItem += DataGridMARPOLItems_AddingNewItem; this.dataGridMARPOLItems.EditRequested += DataGridMARPOLItems_EditRequested; this.dataGridMARPOLItems.DeleteRequested += DataGridMARPOLItems_DeleteRequested; this.RefreshTabHeaders(); #endregion #region Extra Menüpunkte um Positionen zwischen HAZA / HAZD zu kopieren this.dataGridIBCItems.ContextMenu.Items.Add(new Separator()); MenuItem copyIBCItem = new MenuItem(); copyIBCItem.Header = string.Format(Properties.Resources.textCopyTo, this.IsDeparture ? "HAZA" : "HAZD"); copyIBCItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; copyIBCItem.Click += new RoutedEventHandler(this.copyIBC); this.dataGridIBCItems.ContextMenu.Items.Add(copyIBCItem); this.dataGridIGCItems.ContextMenu.Items.Add(new Separator()); MenuItem copyItemIGC = new MenuItem(); copyItemIGC.Header = string.Format(Properties.Resources.textCopyTo, this.IsDeparture ? "HAZA" : "HAZD"); copyItemIGC.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; copyItemIGC.Click += new RoutedEventHandler(this.copyIGC); this.dataGridIGCItems.ContextMenu.Items.Add(copyItemIGC); this.dataGridIMDGItems.ContextMenu.Items.Add(new Separator()); MenuItem copyItemIMDG = new MenuItem(); copyItemIMDG.Header = string.Format(Properties.Resources.textCopyTo, this.IsDeparture ? "HAZA" : "HAZD"); copyItemIMDG.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; copyItemIMDG.Click += new RoutedEventHandler(this.copyIMDG); this.dataGridIMDGItems.ContextMenu.Items.Add(copyItemIMDG); this.dataGridIMSBCItems.ContextMenu.Items.Add(new Separator()); MenuItem copyItemIMSBC = new MenuItem(); copyItemIMSBC.Header = string.Format(Properties.Resources.textCopyTo, this.IsDeparture ? "HAZA" : "HAZD"); copyItemIMSBC.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; copyItemIMSBC.Click += new RoutedEventHandler(this.copyIMSBC); this.dataGridIMSBCItems.ContextMenu.Items.Add(copyItemIMSBC); this.dataGridMARPOLItems.ContextMenu.Items.Add(new Separator()); MenuItem copyItemMARPOL = new MenuItem(); copyItemMARPOL.Header = string.Format(Properties.Resources.textCopyTo, this.IsDeparture ? "HAZA" : "HAZD"); copyItemMARPOL.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; copyItemMARPOL.Click += new RoutedEventHandler(this.copyMARPOL); this.dataGridMARPOLItems.ContextMenu.Items.Add(copyItemMARPOL); #endregion 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) { this.dataGridIBCItems.IsEnabled = enabled; this.checkBoxDangerousGoodsOnBoard.IsEnabled = enabled; this.checkBoxDGManifestOnBoard.IsEnabled = enabled; this.checkBoxMoUBaltic.IsEnabled = enabled; this.dataGridIBCItems.IsEnabled = enabled; this.dataGridIMDGItems.IsEnabled = enabled; this.dataGridIGCItems.IsEnabled = enabled; this.dataGridIMSBCItems.IsEnabled = enabled; this.dataGridMARPOLItems.IsEnabled = enabled; } #endregion #region Copy event handler private void copyMARPOL(object sender, RoutedEventArgs e) { // aus dem aktuell selektierten MARPOL Element ein neues MARPOL Element machen und nach HAZD kopieren if (this.dataGridMARPOLItems.SelectedItems != null) { HAZ target_haz = this.IsDeparture ? this.haza : this.hazd; foreach (MARPOL_Annex_I_Position selectedMARPOL in this.dataGridMARPOLItems.SelectedItems) { MARPOL_Annex_I_Position copyMARPOL = new MARPOL_Annex_I_Position(); copyMARPOL.MessageHeader = target_haz.MessageHeader; copyMARPOL.HAZ = target_haz; copyMARPOL.CopyFromMARPOL(selectedMARPOL); copyMARPOL.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.MARPOLPositions, "MARPOL-"); target_haz.MARPOLPositions.Add(copyMARPOL); target_haz.NoDPGOnBoardOnArrival = false; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD); this.OnControlCacheReset(this.IsDeparture ? Properties.Resources.textDGArrival : Properties.Resources.textDGDeparture); } } } private void copyIMSBC(object sender, RoutedEventArgs e) { // aus dem aktuell selektierten IMBSC Element ein neues IMBSC Element machen und nach HAZD kopieren if (this.dataGridIMSBCItems.SelectedItems != null) { HAZ target_haz = this.IsDeparture ? this.haza : this.hazd; foreach (IMSBCPosition selectedIMSBC in this.dataGridIMSBCItems.SelectedItems) { IMSBCPosition copyIMSBC = new IMSBCPosition(); copyIMSBC.MessageHeader = target_haz.MessageHeader; copyIMSBC.HAZ = target_haz; copyIMSBC.CopyFromIMSBC(selectedIMSBC); copyIMSBC.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IMSBCPositions, "IMSBC-"); target_haz.IMSBCPositions.Add(copyIMSBC); target_haz.NoDPGOnBoardOnArrival = false; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD); this.OnControlCacheReset(this.IsDeparture ? Properties.Resources.textDGArrival : Properties.Resources.textDGDeparture); } } } private void copyIMDG(object sender, RoutedEventArgs e) { // aus dem aktuell selektierten IMDG Element ein neues IMDG Element machen und nach HAZD kopieren if (this.dataGridIMDGItems.SelectedItems != null) { HAZ target_haz = this.IsDeparture ? this.haza : this.hazd; foreach (IMDGPosition selectedIMDG in this.dataGridIMDGItems.SelectedItems) { IMDGPosition copyIMDG = new IMDGPosition(); copyIMDG.MessageHeader = target_haz.MessageHeader; copyIMDG.HAZ = target_haz; copyIMDG.CopyFromIMDG(selectedIMDG); copyIMDG.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IMDGPositions, "IMDG-"); target_haz.IMDGPositions.Add(copyIMDG); target_haz.NoDPGOnBoardOnArrival = false; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD); this.OnControlCacheReset(this.IsDeparture ? Properties.Resources.textDGArrival : Properties.Resources.textDGDeparture); } } } private void copyIGC(object sender, RoutedEventArgs e) { // aus dem aktuell selektierten IGC Element ein neues IGC Element machen und nach HAZD kopieren if (this.dataGridIGCItems.SelectedItems != null) { HAZ target_haz = this.IsDeparture ? this.haza : this.hazd; foreach (IGCPosition selectedIGC in this.dataGridIGCItems.SelectedItems) { IGCPosition copyIGC = new IGCPosition(); copyIGC.MessageHeader = target_haz.MessageHeader; copyIGC.HAZ = target_haz; copyIGC.CopyFromIGC(selectedIGC); copyIGC.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IGCPositions, "IGC-"); target_haz.IGCPositions.Add(copyIGC); target_haz.NoDPGOnBoardOnArrival = false; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD); this.OnControlCacheReset(this.IsDeparture ? Properties.Resources.textDGArrival : Properties.Resources.textDGDeparture); } } } private void copyIBC(object sender, RoutedEventArgs e) { // aus dem aktuell selektierten IBC Element ein neues IBC Element machen und nach HAZD kopieren if (this.dataGridIBCItems.SelectedItems != null) { HAZ target_haz = this.IsDeparture ? this.haza : this.hazd; foreach (IBCPosition selectedIBC in this.dataGridIBCItems.SelectedItems) { if (selectedIBC != null) { IBCPosition copyIBC = new IBCPosition(); copyIBC.MessageHeader = target_haz.MessageHeader; copyIBC.HAZ = target_haz; copyIBC.CopyFromIBC(selectedIBC); copyIBC.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IBCPositions, "IBC-"); target_haz.IBCPositions.Add(copyIBC); target_haz.NoDPGOnBoardOnArrival = false; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD); this.OnControlCacheReset(this.IsDeparture ? Properties.Resources.textDGArrival : Properties.Resources.textDGDeparture); } } } } #endregion #region MARPOL datagrid handlers private void DataGridMARPOLItems_DeleteRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; if (obj is MARPOL_Annex_I_Position marpol) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(marpol); haz.MARPOLPositions.Remove(marpol); DatabaseEntity.ResetIdentifiers(new List(haz.MARPOLPositions)); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.dataGridMARPOLItems.Items.Refresh(); } } private void DataGridMARPOLItems_EditRequested(DatabaseEntity obj) { EditMarpolDialog eld = new EditMarpolDialog(); eld.MARPOL = obj as MARPOL_Annex_I_Position; HAZ haz = this.IsDeparture ? hazd : haza; eld.AddClicked += () => { eld.CopyValuesToEntity(); if (!haz.MARPOLPositions.Contains(eld.MARPOL)) haz.MARPOLPositions.Add(eld.MARPOL); this.dataGridMARPOLItems.Items.Refresh(); eld.MARPOL = new MARPOL_Annex_I_Position(); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); eld.MARPOL.HAZ = haz; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); }; if (eld.ShowDialog() ?? false) { if (!haz.MARPOLPositions.Contains(eld.MARPOL)) haz.MARPOLPositions.Add(eld.MARPOL); this.dataGridMARPOLItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); } } private void DataGridMARPOLItems_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e) { this.DataGridMARPOLItems_CreateRequested(); } private void DataGridMARPOLItems_CreateRequested() { HAZ haz = this.IsDeparture ? hazd : haza; EditMarpolDialog ebd = new EditMarpolDialog(); ebd.MARPOL = new MARPOL_Annex_I_Position(); ebd.MARPOL.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); ebd.MARPOL.HAZ = haz; ebd.AddClicked += () => { ebd.CopyValuesToEntity(); if (!haz.MARPOLPositions.Contains(ebd.MARPOL)) haz.MARPOLPositions.Add(ebd.MARPOL); this.dataGridMARPOLItems.Items.Refresh(); ebd.MARPOL = new MARPOL_Annex_I_Position(); ebd.MARPOL.HAZ = haz; ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); }; if (ebd.ShowDialog() ?? false) { if (!haz.MARPOLPositions.Contains(ebd.MARPOL)) haz.MARPOLPositions.Add(ebd.MARPOL); this.dataGridMARPOLItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); } } #endregion #region IMSBC datagrid handlers private void DataGridIMSBCItems_DeleteRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; if (obj is IMSBCPosition imsbc) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imsbc); haz.IMSBCPositions.Remove(imsbc); DatabaseEntity.ResetIdentifiers(new List(haz.IMSBCPositions)); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.dataGridIMSBCItems.Items.Refresh(); } } private void DataGridIMSBCItems_EditRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; EditIMSBCDialog eld = new EditIMSBCDialog(); eld.IMSBC = obj as IMSBCPosition; eld.AddClicked += () => { eld.CopyValuesToEntity(); if (!haz.IMSBCPositions.Contains(eld.IMSBC)) haz.IMSBCPositions.Add(eld.IMSBC); this.dataGridIMSBCItems.Items.Refresh(); eld.IMSBC = new IMSBCPosition(); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-"); eld.IMSBC.HAZ = haz; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); }; if (eld.ShowDialog() ?? false) { if (!haz.IMSBCPositions.Contains(eld.IMSBC)) haz.IMSBCPositions.Add(eld.IMSBC); this.dataGridIMSBCItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); } } private void DataGridIMSBCItems_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e) { this.DataGridIMSBCItems_CreateRequested(); } private void DataGridIMSBCItems_CreateRequested() { HAZ haz = this.IsDeparture ? hazd : haza; EditIMSBCDialog ebd = new EditIMSBCDialog(); ebd.IMSBC = new IMSBCPosition(); ebd.IMSBC.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-"); ebd.IMSBC.HAZ = haz; ebd.AddClicked += () => { ebd.CopyValuesToEntity(); if (!haz.IMSBCPositions.Contains(ebd.IMSBC)) haz.IMSBCPositions.Add(ebd.IMSBC); this.dataGridIMSBCItems.Items.Refresh(); ebd.IMSBC = new IMSBCPosition(); ebd.IMSBC.HAZ = haz; ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-"); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); }; if (ebd.ShowDialog() ?? false) { if (!haz.IMSBCPositions.Contains(ebd.IMSBC)) haz.IMSBCPositions.Add(ebd.IMSBC); this.dataGridIMSBCItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); } } #endregion #region IGC datagrid handlers private void DataGridIGCItems_DeleteRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; if (obj is IGCPosition igc) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(igc); haz.IGCPositions.Remove(igc); DatabaseEntity.ResetIdentifiers(new List(haz.IGCPositions)); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.dataGridIGCItems.Items.Refresh(); } } private void DataGridIGCItems_EditRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; EditIGCDialog eld = new EditIGCDialog(); eld.IGC = obj as IGCPosition; eld.AddClicked += () => { eld.CopyValuesToEntity(); if(!haz.IGCPositions.Contains(eld.IGC)) haz.IGCPositions.Add(eld.IGC); this.dataGridIGCItems.Items.Refresh(); eld.IGC = new IGCPosition(); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-"); eld.IGC.HAZ = haz; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); }; if (eld.ShowDialog() ?? false) { if (!haz.IGCPositions.Contains(eld.IGC)) haz.IGCPositions.Add(eld.IGC); this.dataGridIGCItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); } } private void DataGridIGCItems_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e) { this.DataGridIGCItems_CreateRequested(); } private void DataGridIGCItems_CreateRequested() { HAZ haz = this.IsDeparture ? hazd : haza; EditIGCDialog ebd = new EditIGCDialog(); ebd.IGC = new IGCPosition(); ebd.IGC.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-"); ebd.IGC.HAZ = haz; ebd.AddClicked += () => { ebd.CopyValuesToEntity(); if(!haz.IGCPositions.Contains(ebd.IGC)) haz.IGCPositions.Add(ebd.IGC); this.dataGridIGCItems.Items.Refresh(); ebd.IGC = new IGCPosition(); ebd.IGC.HAZ = haz; ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-"); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); }; if (ebd.ShowDialog() ?? false) { if(!haz.IGCPositions.Contains(ebd.IGC)) haz.IGCPositions.Add(ebd.IGC); this.dataGridIGCItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); } } #endregion #region IBC datagrid handlers private void DataGridIBCItems_DeleteRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; if (obj is IBCPosition ibc) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ibc); haz.IBCPositions.Remove(ibc); DatabaseEntity.ResetIdentifiers(new List(haz.IBCPositions)); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.dataGridIBCItems.Items.Refresh(); } } private void DataGridIBCItems_EditRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; EditIBCDialog eld = new EditIBCDialog(); eld.IBC = obj as IBCPosition; eld.AddClicked += () => { eld.CopyValuesToEntity(); if(!haz.IBCPositions.Contains(eld.IBC)) haz.IBCPositions.Add(eld.IBC); this.dataGridIBCItems.Items.Refresh(); eld.IBC = new IBCPosition(); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-"); eld.IBC.HAZ = haz; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); }; if (eld.ShowDialog() ?? false) { if (!haz.IBCPositions.Contains(eld.IBC)) haz.IBCPositions.Add(eld.IBC); this.dataGridIBCItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); } } private void DataGridIBCItems_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e) { this.DataGridIBCItems_CreateRequested(); } private void DataGridIBCItems_CreateRequested() { HAZ haz = this.IsDeparture ? hazd : haza; EditIBCDialog ebd = new EditIBCDialog(); ebd.IBC = new IBCPosition(); ebd.IBC.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-"); ebd.IBC.HAZ = haz; ebd.AddClicked += () => { ebd.CopyValuesToEntity(); if(!haz.IBCPositions.Contains(ebd.IBC)) haz.IBCPositions.Add(ebd.IBC); this.dataGridIBCItems.Items.Refresh(); ebd.IBC = new IBCPosition(); ebd.IBC.HAZ = haz; ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-"); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); }; if (ebd.ShowDialog() ?? false) { if(!haz.IBCPositions.Contains(ebd.IBC)) haz.IBCPositions.Add(ebd.IBC); this.dataGridIBCItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); } } #endregion #region IMDG datagrid handlers private void DataGridIMDGItems_DeleteRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; if (obj is IMDGPosition imdg) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imdg); haz.IMDGPositions.Remove(imdg); DatabaseEntity.ResetIdentifiers(new List(haz.IMDGPositions)); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.dataGridIMDGItems.Items.Refresh(); } } private void DataGridIMDGItems_EditRequested(DatabaseEntity obj) { HAZ haz = this.IsDeparture ? hazd : haza; EditIMDGDialog eld = new EditIMDGDialog(); eld.IMDG = obj as IMDGPosition; eld.AddClicked += () => { eld.CopyValuesToEntity(); if(!haz.IMDGPositions.Contains(eld.IMDG)) haz.IMDGPositions.Add(eld.IMDG); this.dataGridIMDGItems.Items.Refresh(); eld.IMDG = new IMDGPosition(); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMDGPositions, "IMDG-"); eld.IMDG.HAZ = haz; this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); }; if (eld.ShowDialog() ?? false) { if (!haz.IMDGPositions.Contains(eld.IMDG)) haz.IMDGPositions.Add(eld.IMDG); this.dataGridIMDGItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); } } private void DataGridIMDGItems_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e) { this.DataGridIMDGItems_CreateRequested(); } private void DataGridIMDGItems_CreateRequested() { HAZ haz = this.IsDeparture ? hazd : haza; EditIMDGDialog ebd = new EditIMDGDialog(); ebd.IMDG = new IMDGPosition(); ebd.IMDG.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMDGPositions, "IMDG-"); ebd.IMDG.HAZ = haz; ebd.AddClicked += () => { ebd.CopyValuesToEntity(); if(!haz.IMDGPositions.Contains(ebd.IMDG)) haz.IMDGPositions.Add(ebd.IMDG); this.dataGridIMDGItems.Items.Refresh(); ebd.IMDG = new IMDGPosition(); ebd.IMDG.HAZ = haz; ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMDGPositions, "IMDG-"); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); }; if (ebd.ShowDialog() ?? false) { if(!haz.IMDGPositions.Contains(ebd.IMDG)) haz.IMDGPositions.Add(ebd.IMDG); this.dataGridIMDGItems.Items.Refresh(); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SetHAZGlobalFlags(); } } #endregion #region Highlighting public override void HighlightErrorMessageContainer() { Message hazMessage = this.IsDeparture ? _hazdMessage : _hazaMessage; if (hazMessage.HasErrors) { HighlightService.HighlightControl(this.groupBoxHAZ, HighlightService.HighlightStyle.ERROR, hazMessage); } } public override void HighlightViolationMessageContainer() { Message hazMessage = this.IsDeparture ? _hazdMessage : _hazaMessage; if (hazMessage.HasViolations) HighlightService.HighlightControl(this.groupBoxHAZ, HighlightService.HighlightStyle.VIOLATION, hazMessage); } #endregion #region handle tab header info private void DangerousGoodsDetailControl_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { this.RefreshTabHeaders(); } private void RefreshTabHeaders() { HAZ haz = this.IsDeparture ? hazd : haza; if (haz.IMDGPositions.Count > 0) this.tabIMDGItems.Header = string.Format("{0} ({1})", Properties.Resources.textIMDGItems, haz.IMDGPositions.Count); else this.tabIMDGItems.Header = Properties.Resources.textIMDGItems; if (haz.IBCPositions.Count > 0) this.tabIBCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIBCItems, haz.IBCPositions.Count); else this.tabIBCItems.Header = Properties.Resources.textIBCItems; if (haz.IGCPositions.Count > 0) this.tabIGCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIGCItems, haz.IGCPositions.Count); else this.tabIGCItems.Header = Properties.Resources.textIGCItems; if (haz.IMSBCPositions.Count > 0) this.tabIMSBCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIMSBCItems, haz.IMSBCPositions.Count); else this.tabIMSBCItems.Header = Properties.Resources.textIMSBCItems; if (haz.MARPOLPositions.Count > 0) this.tabMarpolItems.Header = string.Format("{0} ({1})", Properties.Resources.textMARPOLItems, haz.MARPOLPositions.Count); else this.tabMarpolItems.Header = Properties.Resources.textMARPOLItems; } #endregion #region new sublist item button handler private void buttonNewItem_Click(object sender, RoutedEventArgs e) { if (newDGDialog != null) { newDGDialog.Activate(); } else { newDGDialog = new NewDGItemDialog(); newDGDialog.Closed += NewDGDialog_Closed; newDGDialog.OKClicked += NewDGDialog_OKClicked; newDGDialog.AddClicked += NewDGDialog_OKClicked; newDGDialog.Show(); } } private void NewDGDialog_Closed(object sender, EventArgs e) { newDGDialog = null; } private void NewDGDialog_OKClicked() { HAZ haz = this.IsDeparture ? hazd : haza; HAZPosTemplate selectedTemplate = this.newDGDialog.SelectedTemplate; if (selectedTemplate != null) { // create new DG position based on template switch (selectedTemplate.TemplateType) { case HAZPosTemplate.SublistType.IBC: this.tabControlPositions.SelectedIndex = 1; IBCPosition ibcPos = new IBCPosition(); ibcPos.FlashpointInformation = selectedTemplate.Flashpoint; ibcPos.Flashpoint_CEL = selectedTemplate.FP_IBC; ibcPos.SpecRef15_19 = selectedTemplate.SpecRef15_19; ibcPos.Hazards = selectedTemplate.Hazard; ibcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-"); ibcPos.PollutionCategory = selectedTemplate.PollutionCategory; ibcPos.HAZ = haz; haz.IBCPositions.Add(ibcPos); this.dataGridIBCItems.Items.Refresh(); this.DataGridIBCItems_EditRequested(ibcPos); break; case HAZPosTemplate.SublistType.IGC: this.tabControlPositions.SelectedIndex = 2; IGCPosition igcPos = new IGCPosition(); igcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-"); igcPos.UNNumber = selectedTemplate.UNNr; igcPos.IMOClass = selectedTemplate.IMOClass; igcPos.HAZ = haz; haz.IGCPositions.Add(igcPos); this.dataGridIGCItems.Items.Refresh(); this.DataGridIGCItems_EditRequested(igcPos); break; case HAZPosTemplate.SublistType.IMSBC: this.tabControlPositions.SelectedIndex = 3; IMSBCPosition imsbcPos = new IMSBCPosition(); imsbcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-"); imsbcPos.IMOHazardClass = selectedTemplate.IMSBC_HAZ; imsbcPos.UNNumber = selectedTemplate.UNNr; imsbcPos.IMOClass = selectedTemplate.IMOClass; imsbcPos.MHB = selectedTemplate.MHB ?? false; imsbcPos.HAZ = haz; haz.IMSBCPositions.Add(imsbcPos); this.dataGridIMSBCItems.Items.Refresh(); this.DataGridIMSBCItems_EditRequested(imsbcPos); break; case HAZPosTemplate.SublistType.MARPOL: this.tabControlPositions.SelectedIndex = 4; MARPOL_Annex_I_Position marpolPos = new MARPOL_Annex_I_Position(); marpolPos.FlashpointInformation = selectedTemplate.Flashpoint; marpolPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); marpolPos.HAZ = haz; haz.MARPOLPositions.Add(marpolPos); this.dataGridMARPOLItems.Items.Refresh(); this.DataGridMARPOLItems_EditRequested(marpolPos); break; } this.SetHAZGlobalFlags(); } } #endregion #region private methods /// /// Beim Hinzufügen der allerersten Gefahrgutposition sollen die Flags vorbelegt werden /// void SetHAZGlobalFlags() { HAZ haz = this.IsDeparture ? this.hazd : this.haza; int totalCount = haz.MARPOLPositions.Count + haz.IMDGPositions.Count + haz.IGCPositions.Count + haz.IBCPositions.Count + haz.IMSBCPositions.Count; if (totalCount == 1) { if (!(this.checkBoxDangerousGoodsOnBoard.IsChecked ?? false)) this.checkBoxDangerousGoodsOnBoard.IsChecked = true; if (this.checkBoxMoUBaltic.IsChecked ?? true) this.checkBoxMoUBaltic.IsChecked = false; haz.NoDPGOnBoardOnArrival = false; haz.MOUBaltic = false; } } #endregion } }