git_bsmd/ENI2/EditControls/CopyDeclarationDialog.xaml.cs

180 lines
6.8 KiB
C#

// 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
{
/// <summary>
/// Interaction logic for CopyDeclarationDialog.xaml
/// </summary>
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<KeyValuePair<bsmd.database.Message.NSWProvider, string>> comboDataSource = new List<KeyValuePair<bsmd.database.Message.NSWProvider, string>>()
{
new KeyValuePair<bsmd.database.Message.NSWProvider, string>( Message.NSWProvider.DBH, "DBH live" ),
new KeyValuePair<bsmd.database.Message.NSWProvider, string>( Message.NSWProvider.DBH_TEST, "DBH Testsystem" ),
new KeyValuePair<bsmd.database.Message.NSWProvider, string>( Message.NSWProvider.DUDR, "HIS-Nord live" ),
new KeyValuePair<bsmd.database.Message.NSWProvider, string>( Message.NSWProvider.DUDR_TEST, "HIS-Nord Testsystem" )
};
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();
}
private void doubleUpDownIMO_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<object> e)
{
bool hasValue = (doubleUpDownIMO.Value.HasValue && doubleUpDownIMO.Value > 0);
doubleUpDownENI.IsReadOnly = hasValue;
this.CheckComplete();
}
private void doubleUpDownENI_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<object> e)
{
bool hasValue = (doubleUpDownENI.Value.HasValue && doubleUpDownENI.Value > 0);
doubleUpDownIMO.IsReadOnly = hasValue;
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();
}
private void textBoxVisitTransitId_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
string newVisitId = this.textBoxVisitTransitId.Text;
// bei Angabe einer gültigen Visit/Transit Id soll
// a) IMO nicht mehr änderbar sein und
// b) der Hafen aus der Visit/Transit Id abgeleitet werden
if (bsmd.database.Util.IsVisitId(newVisitId) || bsmd.database.Util.IsTransitId(newVisitId))
{
this.doubleUpDownIMO.IsEnabled = false;
this.locodePoC.LocodeValue = newVisitId.Substring(0, 5);
this.locodePoC.IsEnabled = false;
}
else
{
this.doubleUpDownIMO.IsEnabled = true;
}
this.CheckComplete();
}
private void VisitIdDialog_OKClicked()
{
if (this.locodePoC.LocodeValue == "ZZNOK")
{
this.NewCore.IsTransit = true;
this.NewCore.ETAKielCanal = this.datePickerETA.SelectedDate;
this.NewCore.TransitId = this.textBoxVisitTransitId.Text.Trim();
}
else
{
this.NewCore.IsTransit = false;
this.NewCore.ETA = this.datePickerETA.SelectedDate;
this.NewCore.VisitId = this.textBoxVisitTransitId.Text.Trim();
}
if (this.doubleUpDownIMO.Value.HasValue)
this.NewCore.IMO = this.doubleUpDownIMO.Value.Value.ToString("0000000");
if (this.doubleUpDownENI.Value.HasValue)
this.NewCore.ENI = this.doubleUpDownENI.Value.Value.ToString("00000000");
this.NewCore.PoC = this.locodePoC.LocodeValue;
this.NewCore.Portname = LocodeDB.PortNameFromLocode(this.NewCore.PoC);
this.NewCore.InitialHIS = (Message.NSWProvider)this.comboBoxInitialHIS.SelectedValue;
this._isOK = true;
}
#endregion
}
}