// Copyright (c) 2017 schick Informatik
// Description: Dialog, um aus einer alten Anmeldung eine neue zu machen
//
using ENI2.Controls;
using bsmd.database;
using System.Collections.Generic;
using System;
using ENI2.Locode;
using System.ComponentModel;
namespace ENI2.EditControls
{
///
/// Interaction logic for CopyDeclarationDialog.xaml
///
public partial class CopyDeclarationDialog : EditWindowBase
{
private bool _isOK = false;
public CopyDeclarationDialog()
{
InitializeComponent();
Loaded += CopyDeclarationDialog_Loaded;
}
#region Properties
public MessageCore OldCore { get; set; }
public MessageCore NewCore { get; set; }
public bool IsOK { get { return this._isOK; } }
public bool CopyAll { get { return this.radioButtonCopyAll.IsChecked ?? false; } }
#endregion
#region completion logic
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));
if(!this.textBoxVisitTransitId.Text.IsNullOrEmpty())
{
bool isValidId = bsmd.database.Util.IsVisitId(textBoxVisitTransitId.Text) || bsmd.database.Util.IsTransitId(textBoxVisitTransitId.Text);
isComplete &= isValidId;
}
isComplete &= imo_OR_eni;
string locode = this.locodePoC.LocodeValue;
bool validLocode = (locode?.Length == 5) && (locode.StartsWith("DE") || locode.StartsWith("DK") || locode.Equals("ZZNOK"));
isComplete &= validLocode;
isComplete &= (comboBoxInitialHIS.SelectedValue != null);
this.EnableOK(isComplete);
}
#endregion
#region event handler
private void CopyDeclarationDialog_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
this.OKClicked += VisitIdDialog_OKClicked;
List> comboDataSource = new List>()
{
new KeyValuePair( Message.NSWProvider.DBH, "DBH" ),
new KeyValuePair( Message.NSWProvider.DBH_MAERSK, "DBH / Maersk" ),
new KeyValuePair( Message.NSWProvider.DUDR, "HIS-Nord" ),
};
this.comboBoxInitialHIS.ItemsSource = comboDataSource;
this.comboBoxInitialHIS.SelectedIndex = 2;
this.EnableOK(false);
this.locodePoC.PropertyChanged += LocodePoC_PropertyChanged;
if (!this.OldCore.IMO.IsNullOrEmpty()) this.doubleUpDownIMO.Value = Double.Parse(this.OldCore.IMO);
if (!this.OldCore.ENI.IsNullOrEmpty()) this.doubleUpDownENI.Value = Double.Parse(this.OldCore.ENI);
if (!this.OldCore.PoC.IsNullOrEmpty()) this.locodePoC.LocodeValue = this.OldCore.PoC;
if (this.OldCore.ETA.HasValue) this.datePickerETA.SelectedDate = this.OldCore.ETA;
}
private void LocodePoC_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
this.CheckComplete();
string locode = this.locodePoC.LocodeValue;
if ((locode != null) && (locode.Equals("DEBRV") || locode.Equals("DEBRE")))
{
this.comboBoxInitialHIS.SelectedValue = Message.NSWProvider.DBH;
}
else
{
this.comboBoxInitialHIS.SelectedValue = Message.NSWProvider.DUDR;
}
}
private void doubleUpDownIMO_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs