Copy HAZA/HAZD in beide Richtungen

This commit is contained in:
Daniel Schick 2022-05-26 10:26:16 +02:00
parent c35ce294c5
commit 7a5442f2bd

View File

@ -22,9 +22,11 @@ namespace ENI2.DetailViewControls
public partial class DangerousGoodsDetailControl : DetailBaseControl public partial class DangerousGoodsDetailControl : DetailBaseControl
{ {
private Message _hazMessage; private Message _hazaMessage;
private HAZ haz; private Message _hazdMessage;
private HAZ hazd; // referenz auf HAZD, falls das hier HAZA ist und wir Positionen kopieren wollen
private HAZ haza;
private HAZ hazd;
public DangerousGoodsDetailControl() public DangerousGoodsDetailControl()
{ {
@ -40,6 +42,9 @@ namespace ENI2.DetailViewControls
this.RegisterComboboxIndexChange(this.comboBoxVesselClass, this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.RegisterComboboxIndexChange(this.comboBoxVesselClass, this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
} }
/// <summary>
/// Flag if this control is used for arrival or departure
/// </summary>
public bool IsDeparture { get; set; } public bool IsDeparture { get; set; }
public override void Initialize() public override void Initialize()
@ -48,21 +53,11 @@ namespace ENI2.DetailViewControls
foreach (Message aMessage in this.Messages) foreach (Message aMessage in this.Messages)
{ {
if (IsDeparture)
{
if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) { this._hazMessage = aMessage; this.ControlMessages.Add(aMessage); }
}
else
{
if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA)
{
this._hazMessage = aMessage;
this.ControlMessages.Add(aMessage);
}
if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD) if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZD)
{ {
if (aMessage != null) this._hazdMessage = aMessage;
{ this.ControlMessages.Add(aMessage);
if (aMessage.Elements.Count > 0) if (aMessage.Elements.Count > 0)
this.hazd = aMessage.Elements[0] as HAZ; this.hazd = aMessage.Elements[0] as HAZ;
if (this.hazd == null) if (this.hazd == null)
@ -74,41 +69,35 @@ namespace ENI2.DetailViewControls
aMessage.Elements.Add(this.hazd); aMessage.Elements.Add(this.hazd);
SublistElementChanged(Message.NotificationClass.HAZD); SublistElementChanged(Message.NotificationClass.HAZD);
} }
}
if (aMessage.MessageNotificationClass == Message.NotificationClass.HAZA)
{
this._hazaMessage = aMessage;
this.ControlMessages.Add(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"; this.textBlockMessageClass.Text = IsDeparture ? "HAZD" : "HAZA";
} }
#region HAZ #region HAZ
if (this._hazMessage == null)
{
this._hazMessage = this.Core.CreateMessage(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.Messages.Add(this._hazMessage);
}
HAZ haz = null;
if (this._hazMessage.Elements.Count > 0)
haz = this._hazMessage.Elements[0] as HAZ;
if (haz == null)
{
haz = new HAZ();
haz.MessageCore = this.Core;
haz.MessageHeader = this._hazMessage;
haz.IsDeparture = this.IsDeparture;
_hazMessage.Elements.Add(haz);
}
this.haz = haz;
this.comboBoxVesselClass.ItemsSource = GlobalStructures.vesselClasses; this.comboBoxVesselClass.ItemsSource = GlobalStructures.vesselClasses;
this.groupBoxHAZ.DataContext = haz; this.groupBoxHAZ.DataContext = this.IsDeparture ? hazd : haza;
this.dataGridIMDGItems.Initialize(); this.dataGridIMDGItems.Initialize();
this.dataGridIMDGItems.ItemsSource = this.haz.IMDGPositions; this.dataGridIMDGItems.ItemsSource = this.IsDeparture ? this.hazd.IMDGPositions : this.haza.IMDGPositions;
CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIMDGItems.Items); CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIMDGItems.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged;
this.dataGridIMDGItems.CreateRequested += DataGridIMDGItems_CreateRequested; this.dataGridIMDGItems.CreateRequested += DataGridIMDGItems_CreateRequested;
@ -117,7 +106,7 @@ namespace ENI2.DetailViewControls
this.dataGridIMDGItems.DeleteRequested += DataGridIMDGItems_DeleteRequested; this.dataGridIMDGItems.DeleteRequested += DataGridIMDGItems_DeleteRequested;
this.dataGridIBCItems.Initialize(); this.dataGridIBCItems.Initialize();
this.dataGridIBCItems.ItemsSource = this.haz.IBCPositions; this.dataGridIBCItems.ItemsSource = this.IsDeparture ? this.hazd.IBCPositions : this.haza.IBCPositions;
myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIBCItems.Items); myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIBCItems.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged;
this.dataGridIBCItems.CreateRequested += DataGridIBCItems_CreateRequested; this.dataGridIBCItems.CreateRequested += DataGridIBCItems_CreateRequested;
@ -126,7 +115,7 @@ namespace ENI2.DetailViewControls
this.dataGridIBCItems.DeleteRequested += DataGridIBCItems_DeleteRequested; this.dataGridIBCItems.DeleteRequested += DataGridIBCItems_DeleteRequested;
this.dataGridIGCItems.Initialize(); this.dataGridIGCItems.Initialize();
this.dataGridIGCItems.ItemsSource = this.haz.IGCPositions; this.dataGridIGCItems.ItemsSource = this.IsDeparture ? this.hazd.IGCPositions : this.haza.IGCPositions;
myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIGCItems.Items); myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIGCItems.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged;
this.dataGridIGCItems.CreateRequested += DataGridIGCItems_CreateRequested; this.dataGridIGCItems.CreateRequested += DataGridIGCItems_CreateRequested;
@ -135,7 +124,7 @@ namespace ENI2.DetailViewControls
this.dataGridIGCItems.DeleteRequested += DataGridIGCItems_DeleteRequested; this.dataGridIGCItems.DeleteRequested += DataGridIGCItems_DeleteRequested;
this.dataGridIMSBCItems.Initialize(); this.dataGridIMSBCItems.Initialize();
this.dataGridIMSBCItems.ItemsSource = this.haz.IMSBCPositions; this.dataGridIMSBCItems.ItemsSource = this.IsDeparture ? this.hazd.IMSBCPositions : this.haza.IMSBCPositions;
myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIMSBCItems.Items); myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridIMSBCItems.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged;
this.dataGridIMSBCItems.CreateRequested += DataGridIMSBCItems_CreateRequested; this.dataGridIMSBCItems.CreateRequested += DataGridIMSBCItems_CreateRequested;
@ -144,7 +133,7 @@ namespace ENI2.DetailViewControls
this.dataGridIMSBCItems.DeleteRequested += DataGridIMSBCItems_DeleteRequested; this.dataGridIMSBCItems.DeleteRequested += DataGridIMSBCItems_DeleteRequested;
this.dataGridMARPOLItems.Initialize(); this.dataGridMARPOLItems.Initialize();
this.dataGridMARPOLItems.ItemsSource = this.haz.MARPOLPositions; this.dataGridMARPOLItems.ItemsSource = this.IsDeparture ? this.hazd.MARPOLPositions : this.haza.MARPOLPositions;
myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridMARPOLItems.Items); myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(dataGridMARPOLItems.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged; ((INotifyCollectionChanged)myCollectionView).CollectionChanged += DangerousGoodsDetailControl_CollectionChanged;
this.dataGridMARPOLItems.CreateRequested += DataGridMARPOLItems_CreateRequested; this.dataGridMARPOLItems.CreateRequested += DataGridMARPOLItems_CreateRequested;
@ -156,49 +145,45 @@ namespace ENI2.DetailViewControls
#endregion #endregion
if (!this.haz.IsDeparture) #region Extra Menüpunkte um Positionen zwischen HAZA / HAZD zu kopieren
{
#region Extra Menüpunkte um Positionen nach HAZD zu kopieren
this.dataGridIBCItems.ContextMenu.Items.Add(new Separator()); this.dataGridIBCItems.ContextMenu.Items.Add(new Separator());
MenuItem copyIBCItem = new MenuItem(); MenuItem copyIBCItem = new MenuItem();
copyIBCItem.Header = Properties.Resources.textCopyToHAZD; 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.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) };
copyIBCItem.Click += new RoutedEventHandler(this.copyIBC); copyIBCItem.Click += new RoutedEventHandler(this.copyIBC);
this.dataGridIBCItems.ContextMenu.Items.Add(copyIBCItem); this.dataGridIBCItems.ContextMenu.Items.Add(copyIBCItem);
this.dataGridIGCItems.ContextMenu.Items.Add(new Separator()); this.dataGridIGCItems.ContextMenu.Items.Add(new Separator());
MenuItem copyItemIGC = new MenuItem(); MenuItem copyItemIGC = new MenuItem();
copyItemIGC.Header = Properties.Resources.textCopyToHAZD; 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.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) };
copyItemIGC.Click += new RoutedEventHandler(this.copyIGC); copyItemIGC.Click += new RoutedEventHandler(this.copyIGC);
this.dataGridIGCItems.ContextMenu.Items.Add(copyItemIGC); this.dataGridIGCItems.ContextMenu.Items.Add(copyItemIGC);
this.dataGridIMDGItems.ContextMenu.Items.Add(new Separator()); this.dataGridIMDGItems.ContextMenu.Items.Add(new Separator());
MenuItem copyItemIMDG = new MenuItem(); MenuItem copyItemIMDG = new MenuItem();
copyItemIMDG.Header = Properties.Resources.textCopyToHAZD; 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.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) };
copyItemIMDG.Click += new RoutedEventHandler(this.copyIMDG); copyItemIMDG.Click += new RoutedEventHandler(this.copyIMDG);
this.dataGridIMDGItems.ContextMenu.Items.Add(copyItemIMDG); this.dataGridIMDGItems.ContextMenu.Items.Add(copyItemIMDG);
this.dataGridIMSBCItems.ContextMenu.Items.Add(new Separator()); this.dataGridIMSBCItems.ContextMenu.Items.Add(new Separator());
MenuItem copyItemIMSBC = new MenuItem(); MenuItem copyItemIMSBC = new MenuItem();
copyItemIMSBC.Header = Properties.Resources.textCopyToHAZD; 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.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) };
copyItemIMSBC.Click += new RoutedEventHandler(this.copyIMSBC); copyItemIMSBC.Click += new RoutedEventHandler(this.copyIMSBC);
this.dataGridIMSBCItems.ContextMenu.Items.Add(copyItemIMSBC); this.dataGridIMSBCItems.ContextMenu.Items.Add(copyItemIMSBC);
this.dataGridMARPOLItems.ContextMenu.Items.Add(new Separator()); this.dataGridMARPOLItems.ContextMenu.Items.Add(new Separator());
MenuItem copyItemMARPOL = new MenuItem(); MenuItem copyItemMARPOL = new MenuItem();
copyItemMARPOL.Header = Properties.Resources.textCopyToHAZD; 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.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) };
copyItemMARPOL.Click += new RoutedEventHandler(this.copyMARPOL); copyItemMARPOL.Click += new RoutedEventHandler(this.copyMARPOL);
this.dataGridMARPOLItems.ContextMenu.Items.Add(copyItemMARPOL); this.dataGridMARPOLItems.ContextMenu.Items.Add(copyItemMARPOL);
#endregion #endregion
}
this._initialized = true; this._initialized = true;
} }
@ -226,17 +211,18 @@ namespace ENI2.DetailViewControls
// aus dem aktuell selektierten MARPOL Element ein neues MARPOL Element machen und nach HAZD kopieren // aus dem aktuell selektierten MARPOL Element ein neues MARPOL Element machen und nach HAZD kopieren
if (this.dataGridMARPOLItems.SelectedItems != null) if (this.dataGridMARPOLItems.SelectedItems != null)
{ {
HAZ target_haz = this.IsDeparture ? this.haza : this.hazd;
foreach (MARPOL_Annex_I_Position selectedMARPOL in this.dataGridMARPOLItems.SelectedItems) foreach (MARPOL_Annex_I_Position selectedMARPOL in this.dataGridMARPOLItems.SelectedItems)
{ {
MARPOL_Annex_I_Position copyMARPOL = new MARPOL_Annex_I_Position(); MARPOL_Annex_I_Position copyMARPOL = new MARPOL_Annex_I_Position();
copyMARPOL.MessageHeader = this.hazd.MessageHeader; copyMARPOL.MessageHeader = target_haz.MessageHeader;
copyMARPOL.HAZ = this.hazd; copyMARPOL.HAZ = target_haz;
copyMARPOL.CopyFromMARPOL(selectedMARPOL); copyMARPOL.CopyFromMARPOL(selectedMARPOL);
copyMARPOL.Identifier = DatabaseEntity.GetNewIdentifier(this.hazd.MARPOLPositions, "MARPOL-"); copyMARPOL.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.MARPOLPositions, "MARPOL-");
this.hazd.MARPOLPositions.Add(copyMARPOL); target_haz.MARPOLPositions.Add(copyMARPOL);
this.SublistElementChanged(Message.NotificationClass.HAZD); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD);
this.OnControlCacheReset(Properties.Resources.textDGDeparture); this.OnControlCacheReset(Properties.Resources.textDGDeparture);
this.SetHAZGlobalFlags(this.hazd); this.SetHAZGlobalFlags();
} }
} }
} }
@ -246,17 +232,18 @@ namespace ENI2.DetailViewControls
// aus dem aktuell selektierten IMBSC Element ein neues IMBSC Element machen und nach HAZD kopieren // aus dem aktuell selektierten IMBSC Element ein neues IMBSC Element machen und nach HAZD kopieren
if (this.dataGridIMSBCItems.SelectedItems != null) if (this.dataGridIMSBCItems.SelectedItems != null)
{ {
HAZ target_haz = this.IsDeparture ? this.haza : this.hazd;
foreach (IMSBCPosition selectedIMSBC in this.dataGridIMSBCItems.SelectedItems) foreach (IMSBCPosition selectedIMSBC in this.dataGridIMSBCItems.SelectedItems)
{ {
IMSBCPosition copyIMSBC = new IMSBCPosition(); IMSBCPosition copyIMSBC = new IMSBCPosition();
copyIMSBC.MessageHeader = this.hazd.MessageHeader; copyIMSBC.MessageHeader = target_haz.MessageHeader;
copyIMSBC.HAZ = this.hazd; copyIMSBC.HAZ = target_haz;
copyIMSBC.CopyFromIMSBC(selectedIMSBC); copyIMSBC.CopyFromIMSBC(selectedIMSBC);
copyIMSBC.Identifier = DatabaseEntity.GetNewIdentifier(this.hazd.IMSBCPositions, "IMSBC-"); copyIMSBC.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IMSBCPositions, "IMSBC-");
this.hazd.IMSBCPositions.Add(copyIMSBC); target_haz.IMSBCPositions.Add(copyIMSBC);
this.SublistElementChanged(Message.NotificationClass.HAZD); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD);
this.OnControlCacheReset(Properties.Resources.textDGDeparture); this.OnControlCacheReset(Properties.Resources.textDGDeparture);
this.SetHAZGlobalFlags(this.hazd); this.SetHAZGlobalFlags();
} }
} }
} }
@ -266,17 +253,18 @@ namespace ENI2.DetailViewControls
// aus dem aktuell selektierten IMDG Element ein neues IMDG Element machen und nach HAZD kopieren // aus dem aktuell selektierten IMDG Element ein neues IMDG Element machen und nach HAZD kopieren
if (this.dataGridIMDGItems.SelectedItems != null) if (this.dataGridIMDGItems.SelectedItems != null)
{ {
HAZ target_haz = this.IsDeparture ? this.haza : this.hazd;
foreach (IMDGPosition selectedIMDG in this.dataGridIMDGItems.SelectedItems) foreach (IMDGPosition selectedIMDG in this.dataGridIMDGItems.SelectedItems)
{ {
IMDGPosition copyIMDG = new IMDGPosition(); IMDGPosition copyIMDG = new IMDGPosition();
copyIMDG.MessageHeader = this.hazd.MessageHeader; copyIMDG.MessageHeader = target_haz.MessageHeader;
copyIMDG.HAZ = this.hazd; copyIMDG.HAZ = target_haz;
copyIMDG.CopyFromIMDG(selectedIMDG); copyIMDG.CopyFromIMDG(selectedIMDG);
copyIMDG.Identifier = DatabaseEntity.GetNewIdentifier(this.hazd.IMDGPositions, "IMDG-"); copyIMDG.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IMDGPositions, "IMDG-");
this.hazd.IMDGPositions.Add(copyIMDG); target_haz.IMDGPositions.Add(copyIMDG);
this.SublistElementChanged(Message.NotificationClass.HAZD); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD);
this.OnControlCacheReset(Properties.Resources.textDGDeparture); this.OnControlCacheReset(Properties.Resources.textDGDeparture);
this.SetHAZGlobalFlags(this.hazd); this.SetHAZGlobalFlags();
} }
} }
} }
@ -286,17 +274,18 @@ namespace ENI2.DetailViewControls
// aus dem aktuell selektierten IGC Element ein neues IGC Element machen und nach HAZD kopieren // aus dem aktuell selektierten IGC Element ein neues IGC Element machen und nach HAZD kopieren
if (this.dataGridIGCItems.SelectedItems != null) if (this.dataGridIGCItems.SelectedItems != null)
{ {
HAZ target_haz = this.IsDeparture ? this.haza : this.hazd;
foreach (IGCPosition selectedIGC in this.dataGridIGCItems.SelectedItems) foreach (IGCPosition selectedIGC in this.dataGridIGCItems.SelectedItems)
{ {
IGCPosition copyIGC = new IGCPosition(); IGCPosition copyIGC = new IGCPosition();
copyIGC.MessageHeader = this.hazd.MessageHeader; copyIGC.MessageHeader = target_haz.MessageHeader;
copyIGC.HAZ = this.hazd; copyIGC.HAZ = target_haz;
copyIGC.CopyFromIGC(selectedIGC); copyIGC.CopyFromIGC(selectedIGC);
copyIGC.Identifier = DatabaseEntity.GetNewIdentifier(this.hazd.IGCPositions, "IGC-"); copyIGC.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IGCPositions, "IGC-");
this.hazd.IGCPositions.Add(copyIGC); target_haz.IGCPositions.Add(copyIGC);
this.SublistElementChanged(Message.NotificationClass.HAZD); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD);
this.OnControlCacheReset(Properties.Resources.textDGDeparture); this.OnControlCacheReset(Properties.Resources.textDGDeparture);
this.SetHAZGlobalFlags(this.hazd); this.SetHAZGlobalFlags();
} }
} }
} }
@ -306,19 +295,20 @@ namespace ENI2.DetailViewControls
// aus dem aktuell selektierten IBC Element ein neues IBC Element machen und nach HAZD kopieren // aus dem aktuell selektierten IBC Element ein neues IBC Element machen und nach HAZD kopieren
if (this.dataGridIBCItems.SelectedItems != null) if (this.dataGridIBCItems.SelectedItems != null)
{ {
HAZ target_haz = this.IsDeparture ? this.haza : this.hazd;
foreach (IBCPosition selectedIBC in this.dataGridIBCItems.SelectedItems) foreach (IBCPosition selectedIBC in this.dataGridIBCItems.SelectedItems)
{ {
if (selectedIBC != null) if (selectedIBC != null)
{ {
IBCPosition copyIBC = new IBCPosition(); IBCPosition copyIBC = new IBCPosition();
copyIBC.MessageHeader = this.hazd.MessageHeader; copyIBC.MessageHeader = target_haz.MessageHeader;
copyIBC.HAZ = this.hazd; copyIBC.HAZ = target_haz;
copyIBC.CopyFromIBC(selectedIBC); copyIBC.CopyFromIBC(selectedIBC);
copyIBC.Identifier = DatabaseEntity.GetNewIdentifier(this.hazd.IBCPositions, "IBC-"); copyIBC.Identifier = DatabaseEntity.GetNewIdentifier(target_haz.IBCPositions, "IBC-");
this.hazd.IBCPositions.Add(copyIBC); target_haz.IBCPositions.Add(copyIBC);
this.SublistElementChanged(Message.NotificationClass.HAZD); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZA : Message.NotificationClass.HAZD);
this.OnControlCacheReset(Properties.Resources.textDGDeparture); this.OnControlCacheReset(Properties.Resources.textDGDeparture);
this.SetHAZGlobalFlags(this.hazd); this.SetHAZGlobalFlags();
} }
} }
} }
@ -329,22 +319,22 @@ namespace ENI2.DetailViewControls
/// <summary> /// <summary>
/// Beim Hinzufügen der allerersten Gefahrgutposition sollen die Flags vorbelegt werden /// Beim Hinzufügen der allerersten Gefahrgutposition sollen die Flags vorbelegt werden
/// </summary> /// </summary>
void SetHAZGlobalFlags(HAZ theHAZ) void SetHAZGlobalFlags()
{ {
int totalCount = theHAZ.MARPOLPositions.Count + theHAZ.IMDGPositions.Count + theHAZ.IGCPositions.Count + theHAZ.IBCPositions.Count + theHAZ.IMSBCPositions.Count; 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(totalCount == 1)
{ {
if (theHAZ == this.haz) if (!this.IsDeparture)
{ {
if (!(this.checkBoxDangerousGoodsOnBoard.IsChecked ?? false)) this.checkBoxDangerousGoodsOnBoard.IsChecked = true; if (!(this.checkBoxDangerousGoodsOnBoard.IsChecked ?? false)) this.checkBoxDangerousGoodsOnBoard.IsChecked = true;
// if (!(this.checkBoxDGManifestOnBoard.IsChecked ?? false)) this.checkBoxDGManifestOnBoard.IsChecked = true;
if (this.checkBoxMoUBaltic.IsChecked ?? true) this.checkBoxMoUBaltic.IsChecked = false; if (this.checkBoxMoUBaltic.IsChecked ?? true) this.checkBoxMoUBaltic.IsChecked = false;
} }
else else
{ {
theHAZ.NoDPGOnBoardOnArrival = false; haz.NoDPGOnBoardOnArrival = false;
// theHAZ.DPGManifestOnBoardOnArrival = true; // theHAZ.DPGManifestOnBoardOnArrival = true;
theHAZ.MOUBaltic = false; haz.MOUBaltic = false;
} }
} }
} }
@ -354,11 +344,12 @@ namespace ENI2.DetailViewControls
private void DataGridMARPOLItems_DeleteRequested(DatabaseEntity obj) private void DataGridMARPOLItems_DeleteRequested(DatabaseEntity obj)
{ {
MARPOL_Annex_I_Position marpol = obj as MARPOL_Annex_I_Position; MARPOL_Annex_I_Position marpol = obj as MARPOL_Annex_I_Position;
HAZ haz = this.IsDeparture ? hazd : haza;
if (marpol != null) if (marpol != null)
{ {
// are you sure dialog is in base class // are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(marpol); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(marpol);
this.haz.MARPOLPositions.Remove(marpol); haz.MARPOLPositions.Remove(marpol);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.MARPOLPositions)); DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.MARPOLPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridMARPOLItems.Items.Refresh(); this.dataGridMARPOLItems.Items.Refresh();
@ -369,6 +360,7 @@ namespace ENI2.DetailViewControls
{ {
EditMarpolDialog eld = new EditMarpolDialog(); EditMarpolDialog eld = new EditMarpolDialog();
eld.MARPOL = obj as MARPOL_Annex_I_Position; eld.MARPOL = obj as MARPOL_Annex_I_Position;
HAZ haz = this.IsDeparture ? hazd : haza;
eld.AddClicked += () => eld.AddClicked += () =>
{ {
@ -378,9 +370,9 @@ namespace ENI2.DetailViewControls
this.dataGridMARPOLItems.Items.Refresh(); this.dataGridMARPOLItems.Items.Refresh();
eld.MARPOL = new MARPOL_Annex_I_Position(); eld.MARPOL = new MARPOL_Annex_I_Position();
eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-");
eld.MARPOL.HAZ = this.haz; eld.MARPOL.HAZ = haz;
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
}; };
if (eld.ShowDialog() ?? false) if (eld.ShowDialog() ?? false)
@ -400,10 +392,11 @@ namespace ENI2.DetailViewControls
private void DataGridMARPOLItems_CreateRequested() private void DataGridMARPOLItems_CreateRequested()
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditMarpolDialog ebd = new EditMarpolDialog(); EditMarpolDialog ebd = new EditMarpolDialog();
ebd.MARPOL = new MARPOL_Annex_I_Position(); ebd.MARPOL = new MARPOL_Annex_I_Position();
ebd.MARPOL.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.MARPOLPositions, "MARPOL-"); ebd.MARPOL.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-");
ebd.MARPOL.HAZ = this.haz; ebd.MARPOL.HAZ = haz;
ebd.AddClicked += () => ebd.AddClicked += () =>
{ {
@ -412,10 +405,10 @@ namespace ENI2.DetailViewControls
haz.MARPOLPositions.Add(ebd.MARPOL); haz.MARPOLPositions.Add(ebd.MARPOL);
this.dataGridMARPOLItems.Items.Refresh(); this.dataGridMARPOLItems.Items.Refresh();
ebd.MARPOL = new MARPOL_Annex_I_Position(); ebd.MARPOL = new MARPOL_Annex_I_Position();
ebd.MARPOL.HAZ = this.haz; ebd.MARPOL.HAZ = haz;
ebd.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.MARPOLPositions, "MARPOL-"); ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-");
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
}; };
if (ebd.ShowDialog() ?? false) if (ebd.ShowDialog() ?? false)
@ -424,7 +417,7 @@ namespace ENI2.DetailViewControls
haz.MARPOLPositions.Add(ebd.MARPOL); haz.MARPOLPositions.Add(ebd.MARPOL);
this.dataGridMARPOLItems.Items.Refresh(); this.dataGridMARPOLItems.Items.Refresh();
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
} }
} }
@ -434,12 +427,13 @@ namespace ENI2.DetailViewControls
private void DataGridIMSBCItems_DeleteRequested(DatabaseEntity obj) private void DataGridIMSBCItems_DeleteRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
IMSBCPosition imsbc = obj as IMSBCPosition; IMSBCPosition imsbc = obj as IMSBCPosition;
if (imsbc != null) if (imsbc != null)
{ {
// are you sure dialog is in base class // are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imsbc); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imsbc);
this.haz.IMSBCPositions.Remove(imsbc); haz.IMSBCPositions.Remove(imsbc);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IMSBCPositions)); DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IMSBCPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIMSBCItems.Items.Refresh(); this.dataGridIMSBCItems.Items.Refresh();
@ -448,6 +442,7 @@ namespace ENI2.DetailViewControls
private void DataGridIMSBCItems_EditRequested(DatabaseEntity obj) private void DataGridIMSBCItems_EditRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIMSBCDialog eld = new EditIMSBCDialog(); EditIMSBCDialog eld = new EditIMSBCDialog();
eld.IMSBC = obj as IMSBCPosition; eld.IMSBC = obj as IMSBCPosition;
@ -458,10 +453,10 @@ namespace ENI2.DetailViewControls
haz.IMSBCPositions.Add(eld.IMSBC); haz.IMSBCPositions.Add(eld.IMSBC);
this.dataGridIMSBCItems.Items.Refresh(); this.dataGridIMSBCItems.Items.Refresh();
eld.IMSBC = new IMSBCPosition(); eld.IMSBC = new IMSBCPosition();
eld.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IMSBCPositions, "IMSBC-"); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-");
eld.IMSBC.HAZ = this.haz; eld.IMSBC.HAZ = haz;
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
}; };
if (eld.ShowDialog() ?? false) if (eld.ShowDialog() ?? false)
@ -480,22 +475,23 @@ namespace ENI2.DetailViewControls
private void DataGridIMSBCItems_CreateRequested() private void DataGridIMSBCItems_CreateRequested()
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIMSBCDialog ebd = new EditIMSBCDialog(); EditIMSBCDialog ebd = new EditIMSBCDialog();
ebd.IMSBC = new IMSBCPosition(); ebd.IMSBC = new IMSBCPosition();
ebd.IMSBC.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IMSBCPositions, "IMSBC-"); ebd.IMSBC.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-");
ebd.IMSBC.HAZ = this.haz; ebd.IMSBC.HAZ = haz;
ebd.AddClicked += () => ebd.AddClicked += () =>
{ {
ebd.CopyValuesToEntity(); ebd.CopyValuesToEntity();
if (!haz.IMSBCPositions.Contains(ebd.IMSBC)) if (!haz.IMSBCPositions.Contains(ebd.IMSBC))
this.haz.IMSBCPositions.Add(ebd.IMSBC); haz.IMSBCPositions.Add(ebd.IMSBC);
this.dataGridIMSBCItems.Items.Refresh(); this.dataGridIMSBCItems.Items.Refresh();
ebd.IMSBC = new IMSBCPosition(); ebd.IMSBC = new IMSBCPosition();
ebd.IMSBC.HAZ = this.haz; ebd.IMSBC.HAZ = haz;
ebd.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IMSBCPositions, "IMSBC-"); ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-");
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
}; };
if (ebd.ShowDialog() ?? false) if (ebd.ShowDialog() ?? false)
@ -504,7 +500,7 @@ namespace ENI2.DetailViewControls
haz.IMSBCPositions.Add(ebd.IMSBC); haz.IMSBCPositions.Add(ebd.IMSBC);
this.dataGridIMSBCItems.Items.Refresh(); this.dataGridIMSBCItems.Items.Refresh();
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
} }
} }
@ -514,12 +510,13 @@ namespace ENI2.DetailViewControls
private void DataGridIGCItems_DeleteRequested(DatabaseEntity obj) private void DataGridIGCItems_DeleteRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
IGCPosition igc = obj as IGCPosition; IGCPosition igc = obj as IGCPosition;
if (igc != null) if (igc != null)
{ {
// are you sure dialog is in base class // are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(igc); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(igc);
this.haz.IGCPositions.Remove(igc); haz.IGCPositions.Remove(igc);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IGCPositions)); DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IGCPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIGCItems.Items.Refresh(); this.dataGridIGCItems.Items.Refresh();
@ -528,6 +525,7 @@ namespace ENI2.DetailViewControls
private void DataGridIGCItems_EditRequested(DatabaseEntity obj) private void DataGridIGCItems_EditRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIGCDialog eld = new EditIGCDialog(); EditIGCDialog eld = new EditIGCDialog();
eld.IGC = obj as IGCPosition; eld.IGC = obj as IGCPosition;
@ -538,10 +536,10 @@ namespace ENI2.DetailViewControls
haz.IGCPositions.Add(eld.IGC); haz.IGCPositions.Add(eld.IGC);
this.dataGridIGCItems.Items.Refresh(); this.dataGridIGCItems.Items.Refresh();
eld.IGC = new IGCPosition(); eld.IGC = new IGCPosition();
eld.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IGCPositions, "IGC-"); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-");
eld.IGC.HAZ = this.haz; eld.IGC.HAZ = haz;
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
}; };
if (eld.ShowDialog() ?? false) if (eld.ShowDialog() ?? false)
@ -560,30 +558,31 @@ namespace ENI2.DetailViewControls
private void DataGridIGCItems_CreateRequested() private void DataGridIGCItems_CreateRequested()
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIGCDialog ebd = new EditIGCDialog(); EditIGCDialog ebd = new EditIGCDialog();
ebd.IGC = new IGCPosition(); ebd.IGC = new IGCPosition();
ebd.IGC.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IGCPositions, "IGC-"); ebd.IGC.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-");
ebd.IGC.HAZ = this.haz; ebd.IGC.HAZ = haz;
ebd.AddClicked += () => ebd.AddClicked += () =>
{ {
ebd.CopyValuesToEntity(); ebd.CopyValuesToEntity();
if(!this.haz.IGCPositions.Contains(ebd.IGC)) if(!haz.IGCPositions.Contains(ebd.IGC))
this.haz.IGCPositions.Add(ebd.IGC); haz.IGCPositions.Add(ebd.IGC);
this.dataGridIGCItems.Items.Refresh(); this.dataGridIGCItems.Items.Refresh();
ebd.IGC = new IGCPosition(); ebd.IGC = new IGCPosition();
ebd.IGC.HAZ = this.haz; ebd.IGC.HAZ = haz;
ebd.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IGCPositions, "IGC-"); ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IGCPositions, "IGC-");
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
}; };
if (ebd.ShowDialog() ?? false) if (ebd.ShowDialog() ?? false)
{ {
if(!this.haz.IGCPositions.Contains(ebd.IGC)) if(!haz.IGCPositions.Contains(ebd.IGC))
haz.IGCPositions.Add(ebd.IGC); haz.IGCPositions.Add(ebd.IGC);
this.dataGridIGCItems.Items.Refresh(); this.dataGridIGCItems.Items.Refresh();
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
} }
} }
@ -593,12 +592,13 @@ namespace ENI2.DetailViewControls
private void DataGridIBCItems_DeleteRequested(DatabaseEntity obj) private void DataGridIBCItems_DeleteRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
IBCPosition ibc = obj as IBCPosition; IBCPosition ibc = obj as IBCPosition;
if (ibc != null) if (ibc != null)
{ {
// are you sure dialog is in base class // are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ibc); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ibc);
this.haz.IBCPositions.Remove(ibc); haz.IBCPositions.Remove(ibc);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IBCPositions)); DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IBCPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIBCItems.Items.Refresh(); this.dataGridIBCItems.Items.Refresh();
@ -607,6 +607,7 @@ namespace ENI2.DetailViewControls
private void DataGridIBCItems_EditRequested(DatabaseEntity obj) private void DataGridIBCItems_EditRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIBCDialog eld = new EditIBCDialog(); EditIBCDialog eld = new EditIBCDialog();
eld.IBC = obj as IBCPosition; eld.IBC = obj as IBCPosition;
@ -617,10 +618,10 @@ namespace ENI2.DetailViewControls
haz.IBCPositions.Add(eld.IBC); haz.IBCPositions.Add(eld.IBC);
this.dataGridIBCItems.Items.Refresh(); this.dataGridIBCItems.Items.Refresh();
eld.IBC = new IBCPosition(); eld.IBC = new IBCPosition();
eld.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IBCPositions, "IBC-"); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-");
eld.IBC.HAZ = this.haz; eld.IBC.HAZ = haz;
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
}; };
if (eld.ShowDialog() ?? false) if (eld.ShowDialog() ?? false)
@ -639,30 +640,31 @@ namespace ENI2.DetailViewControls
private void DataGridIBCItems_CreateRequested() private void DataGridIBCItems_CreateRequested()
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIBCDialog ebd = new EditIBCDialog(); EditIBCDialog ebd = new EditIBCDialog();
ebd.IBC = new IBCPosition(); ebd.IBC = new IBCPosition();
ebd.IBC.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IBCPositions, "IBC-"); ebd.IBC.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-");
ebd.IBC.HAZ = this.haz; ebd.IBC.HAZ = haz;
ebd.AddClicked += () => ebd.AddClicked += () =>
{ {
ebd.CopyValuesToEntity(); ebd.CopyValuesToEntity();
if(!this.haz.IBCPositions.Contains(ebd.IBC)) if(!haz.IBCPositions.Contains(ebd.IBC))
this.haz.IBCPositions.Add(ebd.IBC); haz.IBCPositions.Add(ebd.IBC);
this.dataGridIBCItems.Items.Refresh(); this.dataGridIBCItems.Items.Refresh();
ebd.IBC = new IBCPosition(); ebd.IBC = new IBCPosition();
ebd.IBC.HAZ = this.haz; ebd.IBC.HAZ = haz;
ebd.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IBCPositions, "IBC-"); ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-");
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
}; };
if (ebd.ShowDialog() ?? false) if (ebd.ShowDialog() ?? false)
{ {
if(!this.haz.IBCPositions.Contains(ebd.IBC)) if(!haz.IBCPositions.Contains(ebd.IBC))
haz.IBCPositions.Add(ebd.IBC); haz.IBCPositions.Add(ebd.IBC);
this.dataGridIBCItems.Items.Refresh(); this.dataGridIBCItems.Items.Refresh();
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
} }
} }
@ -672,12 +674,13 @@ namespace ENI2.DetailViewControls
private void DataGridIMDGItems_DeleteRequested(DatabaseEntity obj) private void DataGridIMDGItems_DeleteRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
IMDGPosition imdg = obj as IMDGPosition; IMDGPosition imdg = obj as IMDGPosition;
if (imdg != null) if (imdg != null)
{ {
// are you sure dialog is in base class // are you sure dialog is in base class
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imdg); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(imdg);
this.haz.IMDGPositions.Remove(imdg); haz.IMDGPositions.Remove(imdg);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IMDGPositions)); DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(haz.IMDGPositions));
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.dataGridIMDGItems.Items.Refresh(); this.dataGridIMDGItems.Items.Refresh();
@ -686,6 +689,7 @@ namespace ENI2.DetailViewControls
private void DataGridIMDGItems_EditRequested(DatabaseEntity obj) private void DataGridIMDGItems_EditRequested(DatabaseEntity obj)
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIMDGDialog eld = new EditIMDGDialog(); EditIMDGDialog eld = new EditIMDGDialog();
eld.IMDG = obj as IMDGPosition; eld.IMDG = obj as IMDGPosition;
@ -696,8 +700,8 @@ namespace ENI2.DetailViewControls
haz.IMDGPositions.Add(eld.IMDG); haz.IMDGPositions.Add(eld.IMDG);
this.dataGridIMDGItems.Items.Refresh(); this.dataGridIMDGItems.Items.Refresh();
eld.IMDG = new IMDGPosition(); eld.IMDG = new IMDGPosition();
eld.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IMDGPositions, "IMDG-"); eld.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMDGPositions, "IMDG-");
eld.IMDG.HAZ = this.haz; eld.IMDG.HAZ = haz;
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
}; };
@ -707,7 +711,7 @@ namespace ENI2.DetailViewControls
haz.IMDGPositions.Add(eld.IMDG); haz.IMDGPositions.Add(eld.IMDG);
this.dataGridIMDGItems.Items.Refresh(); this.dataGridIMDGItems.Items.Refresh();
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
} }
} }
@ -718,20 +722,21 @@ namespace ENI2.DetailViewControls
private void DataGridIMDGItems_CreateRequested() private void DataGridIMDGItems_CreateRequested()
{ {
HAZ haz = this.IsDeparture ? hazd : haza;
EditIMDGDialog ebd = new EditIMDGDialog(); EditIMDGDialog ebd = new EditIMDGDialog();
ebd.IMDG = new IMDGPosition(); ebd.IMDG = new IMDGPosition();
ebd.IMDG.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IMDGPositions, "IMDG-"); ebd.IMDG.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMDGPositions, "IMDG-");
ebd.IMDG.HAZ = this.haz; ebd.IMDG.HAZ = haz;
ebd.AddClicked += () => ebd.AddClicked += () =>
{ {
ebd.CopyValuesToEntity(); ebd.CopyValuesToEntity();
if(!this.haz.IMDGPositions.Contains(ebd.IMDG)) if(!haz.IMDGPositions.Contains(ebd.IMDG))
this.haz.IMDGPositions.Add(ebd.IMDG); haz.IMDGPositions.Add(ebd.IMDG);
this.dataGridIMDGItems.Items.Refresh(); this.dataGridIMDGItems.Items.Refresh();
ebd.IMDG = new IMDGPosition(); ebd.IMDG = new IMDGPosition();
ebd.IMDG.HAZ = this.haz; ebd.IMDG.HAZ = haz;
ebd.Identifier = DatabaseEntity.GetNewIdentifier(this.haz.IMDGPositions, "IMDG-"); ebd.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMDGPositions, "IMDG-");
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
}; };
@ -741,7 +746,7 @@ namespace ENI2.DetailViewControls
haz.IMDGPositions.Add(ebd.IMDG); haz.IMDGPositions.Add(ebd.IMDG);
this.dataGridIMDGItems.Items.Refresh(); this.dataGridIMDGItems.Items.Refresh();
this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA); this.SublistElementChanged(this.IsDeparture ? Message.NotificationClass.HAZD : Message.NotificationClass.HAZA);
this.SetHAZGlobalFlags(this.haz); this.SetHAZGlobalFlags();
} }
} }
@ -751,20 +756,24 @@ namespace ENI2.DetailViewControls
public override void HighlightErrorMessageContainer() public override void HighlightErrorMessageContainer()
{ {
if (this._hazMessage.HasErrors) Message hazMessage = this.IsDeparture ? _hazdMessage : _hazaMessage;
if (hazMessage.HasErrors)
{ {
HighlightService.HighlightControl(this.groupBoxHAZ, HighlightService.HighlightStyle.ERROR, this._hazMessage); HighlightService.HighlightControl(this.groupBoxHAZ, HighlightService.HighlightStyle.ERROR, hazMessage);
} }
} }
public override void HighlightViolationMessageContainer() public override void HighlightViolationMessageContainer()
{ {
if (this._hazMessage.HasViolations) Message hazMessage = this.IsDeparture ? _hazdMessage : _hazaMessage;
HighlightService.HighlightControl(this.groupBoxHAZ, HighlightService.HighlightStyle.VIOLATION, this._hazMessage); if (hazMessage.HasViolations)
HighlightService.HighlightControl(this.groupBoxHAZ, HighlightService.HighlightStyle.VIOLATION, hazMessage);
} }
#endregion #endregion
#region handle tab header info
private void DangerousGoodsDetailControl_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void DangerousGoodsDetailControl_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
this.RefreshTabHeaders(); this.RefreshTabHeaders();
@ -772,31 +781,34 @@ namespace ENI2.DetailViewControls
private void RefreshTabHeaders() private void RefreshTabHeaders()
{ {
if (this.haz.IMDGPositions.Count > 0) HAZ haz = this.IsDeparture ? hazd : haza;
this.tabIMDGItems.Header = string.Format("{0} ({1})", Properties.Resources.textIMDGItems, this.haz.IMDGPositions.Count); if (haz.IMDGPositions.Count > 0)
this.tabIMDGItems.Header = string.Format("{0} ({1})", Properties.Resources.textIMDGItems, haz.IMDGPositions.Count);
else else
this.tabIMDGItems.Header = Properties.Resources.textIMDGItems; this.tabIMDGItems.Header = Properties.Resources.textIMDGItems;
if (this.haz.IBCPositions.Count > 0) if (haz.IBCPositions.Count > 0)
this.tabIBCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIBCItems, this.haz.IBCPositions.Count); this.tabIBCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIBCItems, haz.IBCPositions.Count);
else else
this.tabIBCItems.Header = Properties.Resources.textIBCItems; this.tabIBCItems.Header = Properties.Resources.textIBCItems;
if (this.haz.IGCPositions.Count > 0) if (haz.IGCPositions.Count > 0)
this.tabIGCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIGCItems, this.haz.IGCPositions.Count); this.tabIGCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIGCItems, haz.IGCPositions.Count);
else else
this.tabIGCItems.Header = Properties.Resources.textIGCItems; this.tabIGCItems.Header = Properties.Resources.textIGCItems;
if (this.haz.IMSBCPositions.Count > 0) if (haz.IMSBCPositions.Count > 0)
this.tabIMSBCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIMSBCItems, this.haz.IMSBCPositions.Count); this.tabIMSBCItems.Header = string.Format("{0} ({1})", Properties.Resources.textIMSBCItems, haz.IMSBCPositions.Count);
else else
this.tabIMSBCItems.Header = Properties.Resources.textIMSBCItems; this.tabIMSBCItems.Header = Properties.Resources.textIMSBCItems;
if (this.haz.MARPOLPositions.Count > 0) if (haz.MARPOLPositions.Count > 0)
this.tabMarpolItems.Header = string.Format("{0} ({1})", Properties.Resources.textMARPOLItems, this.haz.MARPOLPositions.Count); this.tabMarpolItems.Header = string.Format("{0} ({1})", Properties.Resources.textMARPOLItems, haz.MARPOLPositions.Count);
else else
this.tabMarpolItems.Header = Properties.Resources.textMARPOLItems; this.tabMarpolItems.Header = Properties.Resources.textMARPOLItems;
} }
#endregion
} }
} }