git_bsmd/ENI2/EditControls/VisitIdDialog.xaml.cs

140 lines
5.0 KiB
C#

// Copyright (c) 2017 schick Informatik
// Description: Mit diesem Dialog können neue Visit/Transit-Id's beantragt werden (DE only)
//
using System.Collections.Generic;
using System.Windows;
using ENI2.Controls;
using ENI2.Locode;
using bsmd.database;
namespace ENI2.EditControls
{
/// <summary>
/// Interaction logic for VisitIdDialog.xaml
/// </summary>
public partial class VisitIdDialog : EditWindowBase
{
private bool _isOK;
public VisitIdDialog()
{
InitializeComponent();
Loaded += VisitIdDialog_Loaded;
}
private void VisitIdDialog_Loaded(object sender, RoutedEventArgs e)
{
this.OKClicked += VisitIdDialog_OKClicked;
List<KeyValuePair<Message.NSWProvider, string>> comboDataSource = new List<KeyValuePair<Message.NSWProvider, string>>()
{
new KeyValuePair<Message.NSWProvider, string>( Message.NSWProvider.DUDR, "HIS-Nord" ),
new KeyValuePair<Message.NSWProvider, string>( Message.NSWProvider.DBH, "DBH" ),
new KeyValuePair<Message.NSWProvider, string>(Message.NSWProvider.DBH_MAERSK, "DBH / Maersk")
};
this.comboBoxInitialHIS.ItemsSource = comboDataSource;
this.comboBoxInitialHIS.SelectedIndex = 1;
this.EnableOK(false);
this.locodePoC.PropertyChanged += LocodePoC_PropertyChanged;
}
private void VisitIdDialog_OKClicked()
{
// Validate entries, write back to model etc pp
if(this.locodePoC.LocodeValue == "ZZNOK")
{
this.Core.IsTransit = true;
this.Core.ETAKielCanal = this.datePickerETA.SelectedDate;
}
else
{
this.Core.IsTransit = false;
this.Core.ETA = this.datePickerETA.SelectedDate;
}
if (this.doubleUpDownIMO.Value.HasValue)
this.Core.IMO = this.doubleUpDownIMO.Value.Value.ToString("0000000");
if (this.doubleUpDownENI.Value.HasValue)
this.Core.ENI = this.doubleUpDownENI.Value.Value.ToString("00000000");
this.Core.PoC = this.locodePoC.LocodeValue;
this.Core.Portname = LocodeDB.PortNameFromLocode(this.Core.PoC);
this.Core.InitialHIS = (Message.NSWProvider) this.comboBoxInitialHIS.SelectedValue;
this._isOK = true;
}
public MessageCore Core { get; set; }
public bool IsOK { get { return this._isOK; } }
#region event handler
private void doubleUpDownIMO_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
bool hasValue = (doubleUpDownIMO.Value.HasValue && doubleUpDownIMO.Value > 0);
doubleUpDownENI.IsReadOnly = hasValue;
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 doubleUpDownENI_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
bool hasValue = (doubleUpDownENI.Value.HasValue && doubleUpDownENI.Value > 0);
doubleUpDownIMO.IsReadOnly = hasValue;
this.CheckComplete();
}
private void LocodePoC_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
this.CheckComplete();
}
private void datePickerETA_SelectedDateChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
this.CheckComplete();
}
private void comboBoxInitialHIS_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
this.CheckComplete();
}
#endregion
#region input validation
private void CheckComplete()
{
bool isComplete = true;
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;
string locode = this.locodePoC.LocodeValue;
bool validLocode = (locode != null) && (locode.Length == 5) && (locode.StartsWith("DE") || locode.StartsWith("DK") || locode.Equals("ZZNOK"));
isComplete &= validLocode;
isComplete &= (comboBoxInitialHIS.SelectedValue != null);
this.EnableOK(isComplete);
}
#endregion
}
}