// Copyright (c) 2017 schick Informatik // Description: Detailansicht Gruppe Port Notification // using System; using System.Collections; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using ENI2.EditControls; using ENI2.Util; using bsmd.database; namespace ENI2.DetailViewControls { /// /// Interaction logic for PortNotificationDetailControl.xaml /// public partial class PortNotificationDetailControl : DetailBaseControl { private Message _nameMessage; private Message _infoMessage; private Message _servMessage; private Message _ladgMessage; private static readonly string[] shippingAreas = { Properties.Resources.textShippingAreaNORTHBALTIC, Properties.Resources.textShippingAreaEUROPE, Properties.Resources.textShippingAreaOverseas }; public PortNotificationDetailControl() { InitializeComponent(); this.Loaded += PortNotificationDetailControl_Loaded; } private void PortNotificationDetailControl_Loaded(object sender, RoutedEventArgs e) { this.RegisterTextboxChange(this.textBox_NameMaster, Message.NotificationClass.NAME); this.RegisterComboboxIndexChange(this.comboBoxShippingArea, Message.NotificationClass.INFO); this.RegisterComboboxValueChange(this.comboBoxPortArea, Message.NotificationClass.INFO); this.RegisterTextboxChange(this.textRequestedPostionInPortOfCall, Message.NotificationClass.INFO); this.RegisterTextboxChange(this.textBowThrusterPower, Message.NotificationClass.INFO); this.RegisterTextboxChange(this.textSternThrusterPower, Message.NotificationClass.INFO); this.RegisterCheckboxChange(this.checkBoxFumigatedBulkCargo, Message.NotificationClass.INFO); this.RegisterDoubleUpDownChange(this.doubleUpDownDisplacementSummerDraught, Message.NotificationClass.INFO); this.RegisterTextboxChange(this.textSpecialRequirements, Message.NotificationClass.INFO); this.RegisterTextboxChange(this.textConstructionCharacteristics, Message.NotificationClass.INFO); } public override void Initialize() { base.Initialize(); foreach (Message aMessage in this.Messages) { if (aMessage.MessageNotificationClass == Message.NotificationClass.NAME) { this._nameMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.INFO) { this._infoMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.SERV) { this._servMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.LADG) { this._ladgMessage = aMessage; this.ControlMessages.Add(aMessage); } } #region init NAME if (this._nameMessage == null) { this._nameMessage = this.Core.CreateMessage(Message.NotificationClass.NAME); this.Messages.Add(this._nameMessage); } NAME name = null; if(this._nameMessage.Elements.Count > 0) name = this._nameMessage.Elements[0] as NAME; if (name == null) { name = new NAME(); name.MessageCore = this.Core; name.MessageHeader = this._nameMessage; _nameMessage.Elements.Add(name); } this.textBox_NameMaster.DataContext = name; #endregion #region init INFO if(this._infoMessage == null) { this._infoMessage = this.Core.CreateMessage(Message.NotificationClass.INFO); this.Messages.Add(this._infoMessage); } INFO info = null; if(this._infoMessage.Elements.Count > 0) info = this._infoMessage.Elements[0] as INFO; if(info == null) { info = new INFO(); info.MessageCore = this.Core; info.MessageHeader = this._infoMessage; _infoMessage.Elements.Add(info); } Dictionary portAreas = LocalizedLookup.getPortAreasForLocode(this.Core.PoC); this.comboBoxPortArea.ItemsSource = portAreas; this.comboBoxShippingArea.ItemsSource = shippingAreas; this.infoGroupBox.DataContext = info; #endregion #region init SERV if(this._servMessage == null) { this._servMessage = this.Core.CreateMessage(Message.NotificationClass.SERV); this.Messages.Add(this._servMessage); } this.dataGridSERV.Initialize(); this.dataGridSERV.ItemsSource = this._servMessage.Elements; this.dataGridSERV.AddingNewItem += DataGridSERV_AddingNewItem; this.dataGridSERV.EditRequested += DataGridSERV_EditRequested; this.dataGridSERV.DeleteRequested += DataGridSERV_DeleteRequested; this.dataGridSERV.CreateRequested += DataGridSERV_CreateRequested; #endregion #region init LADG if(this._ladgMessage == null) { this._ladgMessage = this.Core.CreateMessage(Message.NotificationClass.LADG); this.Messages.Add(this._ladgMessage); } this.dataGridLADG.Initialize(); this.dataGridLADG.ItemsSource = this._ladgMessage.Elements; this.dataGridLADG.AddingNewItem += DataGridLADG_AddingNewItem; this.dataGridLADG.EditRequested += DataGridLADG_EditRequested; this.dataGridLADG.DeleteRequested += DataGridLADG_DeleteRequested; this.dataGridLADG.CreateRequested += DataGridLADG_CreateRequested; #endregion #region init helper Maersk / SeaGo Field if (this.Core.IsFlagSet(MessageCore.CoreFlags.MAERSK_BHV)) this.comboBoxGroup.SelectedIndex = 1; if (this.Core.IsFlagSet(MessageCore.CoreFlags.SEAGO_BHV)) this.comboBoxGroup.SelectedIndex = 2; if (this.Core.IsFlagSet(MessageCore.CoreFlags.SEAGO_WHV)) this.comboBoxGroup.SelectedIndex = 3; if (this.Core.IsFlagSet(MessageCore.CoreFlags.HOEGH)) this.comboBoxGroup.SelectedIndex = 4; #endregion } #region datagrid LADG private void DataGridLADG_CreateRequested() { EditLADGDialog eld = new EditLADGDialog(); eld.LADG = new LADG(); eld.LADG.MessageHeader = _ladgMessage; eld.LADG.Identifier = LADG.GetNewIdentifier(_ladgMessage.Elements); eld.Core = this.Core; eld.AddClicked += () => { eld.CopyValuesToEntity(); if (!this._ladgMessage.Elements.Contains(eld.LADG)) this._ladgMessage.Elements.Add(eld.LADG); this.dataGridLADG.Items.Refresh(); eld.LADG = new LADG(); eld.LADG.MessageHeader = _ladgMessage; eld.LADG.Identifier = LADG.GetNewIdentifier(_ladgMessage.Elements); this.SublistElementChanged(Message.NotificationClass.LADG); }; if (eld.ShowDialog() ?? false) { if(!_ladgMessage.Elements.Contains(eld.LADG)) _ladgMessage.Elements.Add(eld.LADG); this.dataGridLADG.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.LADG); } } private void DataGridLADG_DeleteRequested(DatabaseEntity obj) { if (obj is LADG ladg) { // are you sure dialog is in base class this._ladgMessage.Elements.Remove(ladg); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ladg); DatabaseEntity.ResetIdentifiers(_ladgMessage.Elements); this.SublistElementChanged(Message.NotificationClass.LADG); this.dataGridLADG.Items.Refresh(); } } private void DataGridLADG_EditRequested(DatabaseEntity obj) { LADG ladg = obj as LADG; EditLADGDialog eld = new EditLADGDialog(); eld.Core = this.Core; eld.LADG = ladg; eld.AddClicked += () => { eld.CopyValuesToEntity(); if(!_ladgMessage.Elements.Contains(eld.LADG)) _ladgMessage.Elements.Add(eld.LADG); this.dataGridLADG.Items.Refresh(); eld.LADG = new LADG(); eld.LADG.Identifier = LADG.GetNewIdentifier(_ladgMessage.Elements); eld.LADG.MessageHeader = _ladgMessage; this.SublistElementChanged(Message.NotificationClass.LADG); }; if (eld.ShowDialog() ?? false) { if (!_ladgMessage.Elements.Contains(eld.LADG)) _ladgMessage.Elements.Add(eld.LADG); this.dataGridLADG.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.LADG); } } private void DataGridLADG_AddingNewItem(object sender, AddingNewItemEventArgs e) { this.DataGridLADG_CreateRequested(); } #endregion #region datagrid SERV private void DataGridSERV_CreateRequested() { EditSERVDialog esd = new EditSERVDialog(); esd.SERV = new SERV(); esd.SERV.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); esd.SERV.MessageHeader = _servMessage; esd.AddClicked += () => { esd.CopyValuesToEntity(); if(!_servMessage.Elements.Contains(esd.SERV)) _servMessage.Elements.Add(esd.SERV); this.dataGridSERV.Items.Refresh(); esd.SERV = new SERV(); esd.SERV.MessageHeader = _servMessage; esd.SERV.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); this.SublistElementChanged(Message.NotificationClass.SERV); }; if(esd.ShowDialog() ?? false) { if(!_servMessage.Elements.Contains(esd.SERV)) _servMessage.Elements.Add(esd.SERV); this.dataGridSERV.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.SERV); } } private void DataGridSERV_DeleteRequested(DatabaseEntity obj) { if (obj is SERV serv) { // are you sure dialog is in base class _servMessage.Elements.Remove(serv); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(serv); DatabaseEntity.ResetIdentifiers(_servMessage.Elements); this.SublistElementChanged(Message.NotificationClass.SERV); this.dataGridSERV.Items.Refresh(); } } private void DataGridSERV_EditRequested(DatabaseEntity obj) { EditSERVDialog esd = new EditSERVDialog(); esd.SERV = obj as SERV; esd.AddClicked += () => { esd.CopyValuesToEntity(); if(!_servMessage.Elements.Contains(esd.SERV)) _servMessage.Elements.Add(esd.SERV); this.dataGridSERV.Items.Refresh(); esd.SERV = new SERV(); esd.SERV.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); esd.SERV.MessageHeader = _servMessage; this.SublistElementChanged(Message.NotificationClass.SERV); }; if (esd.ShowDialog() ?? false) { if (!_servMessage.Elements.Contains(esd.SERV)) _servMessage.Elements.Add(esd.SERV); this.dataGridSERV.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.SERV); } } private void DataGridSERV_AddingNewItem(object sender, AddingNewItemEventArgs e) { this.DataGridSERV_CreateRequested(); } #endregion #region Highlighting public override void HighlightErrorMessageContainer() { if (this._nameMessage.HasErrors) HighlightService.HighlightControl(this.nameGroupBox, HighlightService.HighlightStyle.ERROR, this._nameMessage); if (this._infoMessage.HasErrors) HighlightService.HighlightControl(this.infoGroupBox, HighlightService.HighlightStyle.ERROR, this._infoMessage); if (this._servMessage.HasErrors) HighlightService.HighlightControl(this.servGroupBox, HighlightService.HighlightStyle.ERROR, this._servMessage); if (this._ladgMessage.HasErrors) HighlightService.HighlightControl(this.ladgGroupBox, HighlightService.HighlightStyle.ERROR, this._ladgMessage); } public override void HighlightViolationMessageContainer() { if (this._nameMessage.HasViolations) HighlightService.HighlightControl(this.nameGroupBox, HighlightService.HighlightStyle.VIOLATION, this._nameMessage); if (this._infoMessage.HasViolations) HighlightService.HighlightControl(this.infoGroupBox, HighlightService.HighlightStyle.VIOLATION, this._infoMessage); if (this._servMessage.HasViolations) HighlightService.HighlightControl(this.servGroupBox, HighlightService.HighlightStyle.VIOLATION, this._servMessage); if (this._ladgMessage.HasViolations) HighlightService.HighlightControl(this.ladgGroupBox, HighlightService.HighlightStyle.VIOLATION, this._ladgMessage); } #endregion #region mouse wheel private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) { ScrollViewer scv = (ScrollViewer)sender; scv.ScrollToVerticalOffset(scv.VerticalOffset - e.Delta); e.Handled = true; } #endregion #region Spezialbalkon für die Gruppenauswahl im Core (Maersk BHV / Seago usw.) private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e) { // clear all this.Core.SetFlag(false, MessageCore.CoreFlags.MAERSK_BHV); this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_BHV); this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_WHV); this.Core.SetFlag(false, MessageCore.CoreFlags.HOEGH); DictionaryEntry selectedItem = (DictionaryEntry) this.comboBoxGroup.SelectedItem; if(Int32.TryParse((string)selectedItem.Value, out int selectedValue)) { if (selectedValue == (int)MessageCore.CoreFlags.MAERSK_BHV) CheckServiceEntryMaerskBHV(); if (selectedValue == (int)MessageCore.CoreFlags.SEAGO_BHV) CheckServiceEntrySeaGoBHV(); if (selectedValue == (int)MessageCore.CoreFlags.HOEGH) CheckServiceEntryHoegh(); this.Core.SetFlag(true, (MessageCore.CoreFlags)selectedValue); DBManager.Instance.Save(this.Core); } } #endregion #region special entry ship service check private void CheckServiceEntryMaerskBHV() { bool found = false; foreach(SERV serv in this._servMessage.Elements) { if (serv.ServiceBeneficiary.Equals("Maersk A/S, Esplanaden 50, DK-1263 Copenhagen K, VAT-ID: DK53139655")) found = true; } if(!found) { SERV newServ = new SERV(); newServ.ServiceBeneficiary = "Maersk A/S, Esplanaden 50, DK-1263 Copenhagen K, VAT-ID: DK53139655"; newServ.ServiceInvoiceRecipient = "Maersk Deutschland A/S & Co.KG, Ericusspitze 2-4, 20457 Hamburg"; newServ.ServiceName = "Maersk BHV"; newServ.MessageHeader = this._servMessage; newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); this._servMessage.Elements.Add(newServ); this.dataGridSERV.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.SERV); } } private void CheckServiceEntrySeaGoBHV() { bool found = false; foreach (SERV serv in this._servMessage.Elements) { if (serv.ServiceBeneficiary.Equals("Sealand Europe A/S, Dampfaergevej 10, 3.tv, DK- 2100 Copenhagen, VAT-ID: DK53139655")) found = true; } if (!found) { SERV newServ = new SERV(); newServ.ServiceBeneficiary = "Sealand Europe A/S, Dampfaergevej 10, 3.tv, DK- 2100 Copenhagen, VAT-ID: DK53139655"; newServ.ServiceInvoiceRecipient = "Sealand Europe Deutschland A/S & Co. KG, Ericusspitze 2-4, 20457 Hamburg"; newServ.ServiceName = "SeaGo BHV"; newServ.MessageHeader = this._servMessage; newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); this._servMessage.Elements.Add(newServ); this.dataGridSERV.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.SERV); } } private void CheckServiceEntryHoegh() { bool found = false; foreach (SERV serv in this._servMessage.Elements) { if (serv.ServiceBeneficiary.Equals("Höegh Autoliners AS, Oslo, Norway")) found = true; } if (!found) { SERV newServ = new SERV(); newServ.ServiceBeneficiary = "Höegh Autoliners AS, Oslo, Norway"; newServ.ServiceInvoiceRecipient = " PWL Port Services GmbH & Co. KG"; newServ.ServiceName = "HOEGH BHV"; newServ.MessageHeader = this._servMessage; newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements); this._servMessage.Elements.Add(newServ); this.dataGridSERV.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.SERV); } } #endregion } }