// Copyright (c) 2017 schick Informatik // Description: Detailansicht für ATA, TIEFA, POBA, BKRA // using System.Windows; using bsmd.database; using ENI2.EditControls; using System.Windows.Media; using System.Windows.Controls; using System.Windows.Media.Imaging; using System; namespace ENI2.DetailViewControls { /// /// Interaction logic for ArrivalNotificationDetailControl.xaml /// public partial class ArrivalNotificationDetailControl : DetailBaseControl { bool startupComplete = false; private Message _ataMessage; private Message _tiefaMessage; private Message _pobaMessage; private Message _bkraMessage; private Message _brkdMessage; public ArrivalNotificationDetailControl() { InitializeComponent(); this.Loaded += ArrivalNotificationDetailControl_Loaded; } private void ArrivalNotificationDetailControl_Loaded(object sender, RoutedEventArgs e) { this.RegisterDateTimePickerChange(this.dateTimePickerATA, Message.NotificationClass.ATA); this.RegisterDoubleUpDownChange(this.doubleUpDownDraught, Message.NotificationClass.TIEFA); this.RegisterIntegerUpDownChange(this.integerUpDownCrewMemberOnBoard, Message.NotificationClass.POBA); this.RegisterIntegerUpDownChange(this.integerUpDownPassengersOnBoard, Message.NotificationClass.POBA); this.RegisterIntegerUpDownChange(this.integerUpDownPersonsOnBoard, Message.NotificationClass.POBA); this.RegisterIntegerUpDownChange(this.integerUpDownStowawaysOnBoard, Message.NotificationClass.POBA); startupComplete = true; } public override void Initialize() { base.Initialize(); foreach (Message aMessage in this.Messages) { if (aMessage.MessageNotificationClass == Message.NotificationClass.ATA) { this._ataMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.TIEFA) { this._tiefaMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.POBA) { this._pobaMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.BKRA) { this._bkraMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.BKRD) { this._brkdMessage = aMessage; this.ControlMessages.Add(aMessage); } } #region ATA if (this._ataMessage == null) { this._ataMessage = this.Core.CreateMessage(Message.NotificationClass.ATA); this.Messages.Add(this._ataMessage); } ATA ata = null; if (this._ataMessage.Elements.Count > 0) ata = this._ataMessage.Elements[0] as ATA; if (ata == null) { ata = new ATA(); ata.MessageCore = this.Core; ata.MessageHeader = this._ataMessage; _ataMessage.Elements.Add(ata); } this.ataGroupBox.DataContext = ata; // Diese Lösung wurde nicht für gut befunden. Dadurch wird zwar der gültige Bereich hübsch im Control angezeigt, // allerdings kann man kein Datum außerhalb des Bereichs angeben, der Wert springt dann wieder zurück. Das wäre doch doofererer und // fehleranfällig (Feb 2021) //if (!ata.ATAPortOfCall.HasValue) //{ // this.dateTimePickerATA.Minimum = DateTime.Now.AddDays(-14); // this.dateTimePickerATA.Maximum = DateTime.Now.AddDays(14); // this.dateTimePickerATA.ClipValueToMinMax = true; //} #endregion #region TIEFA if (this._tiefaMessage == null) { this._tiefaMessage = this.Core.CreateMessage(Message.NotificationClass.TIEFA); this.Messages.Add(this._tiefaMessage); } TIEFA tiefa = null; if (this._tiefaMessage.Elements.Count > 0) tiefa = this._tiefaMessage.Elements[0] as TIEFA; if (tiefa == null) { tiefa = new TIEFA(); tiefa.MessageCore = this.Core; tiefa.MessageHeader = this._tiefaMessage; _tiefaMessage.Elements.Add(tiefa); } this.tiefaGroupBox.DataContext = tiefa; #endregion #region POBA if (this._pobaMessage == null) { this._pobaMessage = this.Core.CreateMessage(Message.NotificationClass.POBA); this.Messages.Add(this._pobaMessage); } POBA poba = null; if (this._pobaMessage.Elements.Count > 0) poba = this._pobaMessage.Elements[0] as POBA; if (poba == null) { poba = new POBA(); poba.MessageCore = this.Core; poba.MessageHeader = this._pobaMessage; _pobaMessage.Elements.Add(poba); } this.pobaGroupBox.DataContext = poba; #endregion #region BKRA if (this._bkraMessage == null) { this._bkraMessage = this.Core.CreateMessage(Message.NotificationClass.BKRA); this.Messages.Add(this._bkraMessage); } this.dataGridBKRA.Initialize(); this.dataGridBKRA.ItemsSource = this._bkraMessage.Elements; this.dataGridBKRA.AddingNewItem += DataGridBKRA_AddingNewItem; this.dataGridBKRA.EditRequested += DataGridBKRA_EditRequested; this.dataGridBKRA.DeleteRequested += DataGridBKRA_DeleteRequested; this.dataGridBKRA.CreateRequested += DataGridBKRA_CreateRequested; // Extra Menüpunkt um alle Bunker Positionen nach BKRD zu kopieren this.dataGridBKRA.ContextMenu.Items.Add(new Separator()); MenuItem copyBKRItem = new MenuItem(); copyBKRItem.Header = Properties.Resources.textCopyToBKRD; copyBKRItem.Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Resources/documents.png")) }; copyBKRItem.Click += this.copyBKR; this.dataGridBKRA.ContextMenu.Items.Add(copyBKRItem); #endregion } private void copyBKR(object sender, RoutedEventArgs e) { if (this.dataGridBKRA.SelectedItems != null) { foreach (BRKA brka in this.dataGridBKRA.SelectedItems) { BRKD copyBRKD = new BRKD(); copyBRKD.MessageHeader = this._brkdMessage; copyBRKD.CopyFromBKRA(brka); copyBRKD.Identifier = DatabaseEntity.GetNewIdentifier(this._brkdMessage.Elements); this._brkdMessage.Elements.Add(copyBRKD); this.SublistElementChanged(Message.NotificationClass.BKRD); } } } #region BKRA grid events private void DataGridBKRA_CreateRequested() { EditBKRDialog ebd = new EditBKRDialog(); ebd.BRKA = new BRKA(); ebd.BRKA.Identifier = BRKA.GetNewIdentifier(this._bkraMessage.Elements); ebd.BRKA.MessageHeader = _bkraMessage; ebd.IsDeparture = false; ebd.AddClicked += () => { ebd.CopyValuesToEntity(); if(!this._bkraMessage.Elements.Contains(ebd.BRKA)) this._bkraMessage.Elements.Add(ebd.BRKA); this.dataGridBKRA.Items.Refresh(); ebd.BRKA = new BRKA(); ebd.BRKA.Identifier = BRKA.GetNewIdentifier(this._bkraMessage.Elements); ebd.BRKA.MessageHeader = _bkraMessage; this.SublistElementChanged(Message.NotificationClass.BKRA); }; if (ebd.ShowDialog() ?? false) { if(!_bkraMessage.Elements.Contains(ebd.BRKA)) _bkraMessage.Elements.Add(ebd.BRKA); this.dataGridBKRA.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.BKRA); } } private void DataGridBKRA_DeleteRequested(DatabaseEntity obj) { if (obj is BRKA brka) { // are you sure dialog is in base class DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(brka); this._bkraMessage.Elements.Remove(brka); DatabaseEntity.ResetIdentifiers(this._bkraMessage.Elements); this.SublistElementChanged(Message.NotificationClass.BKRA); this.dataGridBKRA.Items.Refresh(); } } private void DataGridBKRA_EditRequested(DatabaseEntity obj) { EditBKRDialog eld = new EditBKRDialog(); eld.IsDeparture = false; eld.BRKA = obj as BRKA; eld.AddClicked += () => { eld.CopyValuesToEntity(); if(!_bkraMessage.Elements.Contains(eld.BRKA)) _bkraMessage.Elements.Add(eld.BRKA); this.dataGridBKRA.Items.Refresh(); eld.BRKA = new BRKA(); eld.BRKA.Identifier = BRKA.GetNewIdentifier(this._bkraMessage.Elements); eld.BRKA.MessageHeader = _bkraMessage; this.SublistElementChanged(Message.NotificationClass.BKRA); }; if (eld.ShowDialog() ?? false) { if (!_bkraMessage.Elements.Contains(eld.BRKA)) _bkraMessage.Elements.Add(eld.BRKA); this.dataGridBKRA.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.BKRA); } } private void DataGridBKRA_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e) { this.DataGridBKRA_CreateRequested(); } #endregion #region Highlighting public override void HighlightErrorMessageContainer() { if (this._ataMessage.HasErrors) this.ataGroupBox.BorderBrush = Brushes.Red; if (this._bkraMessage.HasErrors) this.bkraGroupBox.BorderBrush = Brushes.Red; if (this._pobaMessage.HasErrors) this.pobaGroupBox.BorderBrush = Brushes.Red; if (this._tiefaMessage.HasErrors) this.tiefaGroupBox.BorderBrush = Brushes.Red; } public override void HighlightViolationMessageContainer() { if (this._ataMessage.HasViolations) this.ataGroupBox.BorderBrush = Brushes.Yellow; if (this._bkraMessage.HasViolations) this.bkraGroupBox.BorderBrush = Brushes.Yellow; if (this._pobaMessage.HasViolations) this.pobaGroupBox.BorderBrush = Brushes.Yellow; if (this._tiefaMessage.HasViolations) this.tiefaGroupBox.BorderBrush = Brushes.Yellow; } #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 special datetimepicker validation popup (OMG) private void dateTimePickerATA_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { if(startupComplete && this.dateTimePickerATA.Value.HasValue) { DateTime setTime = this.dateTimePickerATA.Value.Value; if ((setTime > DateTime.Now.AddDays(14)) || (setTime < DateTime.Now.AddDays(-14))) MessageBox.Show("ATA value may be invalid", "Date implausible", MessageBoxButton.OK, MessageBoxImage.Warning); } } #endregion } }