git_bsmd/ENI-2/ENI2/ENI2/EditControls/CopyDeclarationDialog.xaml.cs

156 lines
5.7 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 bsmd.ExcelReadService;
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;
}
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;
}
#region Properties
public MessageCore OldCore { get; set; }
public MessageCore NewCore { get; set; }
public bool IsOK { get { return this._isOK; } }
#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));
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
#region event handler
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)
{
this.CheckComplete();
}
private void VisitIdDialog_OKClicked()
{
if (this.locodePoC.LocodeValue == "ZZNOK")
{
this.NewCore.IsTransit = true;
this.NewCore.ETAKielCanal = this.datePickerETA.SelectedDate;
}
else
{
this.NewCore.IsTransit = false;
this.NewCore.ETA = this.datePickerETA.SelectedDate;
}
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
}
}