// Copyright (c) 2017 schick Informatik // Description: Simpler Eingabedialog zur Anlage einer Anmeldung mit einer bekannten VIsit/Transit Id // // using System.Windows; using System.Windows.Controls; using ENI2.Controls; using bsmd.database; using System; using System.Collections.Generic; namespace ENI2.EditControls { /// /// Interaction logic for NewWithIdDialog.xaml /// public partial class NewWithIdDialog : EditWindowBase { public NewWithIdDialog() { InitializeComponent(); Loaded += NewWithIdDialog_Loaded; } private void NewWithIdDialog_Loaded(object sender, RoutedEventArgs e) { this.EnableOK(false); List> comboDataSource = new List>() { new KeyValuePair( Message.NSWProvider.DUDR, "HIS-Nord" ), new KeyValuePair(Message.NSWProvider.DBH, "DBH"), new KeyValuePair(Message.NSWProvider.DBH_MAERSK, "DBH / Maersk") }; this.comboBoxInitialHIS.ItemsSource = comboDataSource; this.comboBoxInitialHIS.SelectedIndex = 0; } public bool ValidId { get; set; } public string VisitTransitId { get { return this.textBoxVisitTransitId.Text.Trim(); } } public string IMO { get { if (this.doubleUpDownIMO.Value.HasValue) return this.doubleUpDownIMO.Value.Value.ToString("0000000"); else return null; } } public string ENI { get { if (this.doubleUpDownENI.Value.HasValue) return this.doubleUpDownENI.Value.Value.ToString("00000000"); else return null; } } public DateTime? ETA { get { return this.datePickerETA.SelectedDate; } } public Message.NSWProvider SelectedHIS { get { return (Message.NSWProvider) this.comboBoxInitialHIS.SelectedValue; } } private void textBoxVisitTransitId_TextChanged(object sender, TextChangedEventArgs e) { this.CheckComplete(); if(textBoxVisitTransitId.Text.StartsWith("DEBRE") || textBoxVisitTransitId.Text.StartsWith("DEBRV")) { this.comboBoxInitialHIS.SelectedValue = Message.NSWProvider.DBH; } else { this.comboBoxInitialHIS.SelectedValue = Message.NSWProvider.DUDR; } } private void CheckComplete() { bool isComplete = true; bool isValidId = bsmd.database.Util.IsVisitId(textBoxVisitTransitId.Text) || bsmd.database.Util.IsTransitId(textBoxVisitTransitId.Text); this.okCheckMark.Visibility = isValidId ? Visibility.Visible : Visibility.Hidden; isComplete &= isValidId; isComplete &= this.datePickerETA.SelectedDate.HasValue; // ETA bool imo_OR_eni = ((doubleUpDownIMO.Value.HasValue) && (doubleUpDownIMO.Value >= 1000000) && (doubleUpDownIMO.Value <= 9999999)) || ((doubleUpDownENI.Value.HasValue) && (doubleUpDownENI.Value >= 100000) && (doubleUpDownENI.Value <= 99999999)); isComplete &= imo_OR_eni; bool isHISSelected = (this.comboBoxInitialHIS.SelectedValue != null); isComplete &= isHISSelected; this.EnableOK(isComplete); this.ValidId = isComplete; } private void datePickerETA_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { this.CheckComplete(); } private void doubleUpDownENI_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { this.CheckComplete(); } private void doubleUpDownIMO_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { this.CheckComplete(); if ((this.doubleUpDownIMO.Value > 1000000) && (!bsmd.database.Util.IsIMOValid(this.doubleUpDownIMO.Value.ToString()))) MessageBox.Show("IMO has invalid format!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } private void comboBoxInitialHIS_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.CheckComplete(); } } }