git_bsmd/ENI2/EditControls/EditLADGDialog.xaml.cs

117 lines
4.7 KiB
C#

// Copyright (c) 2017 schick Informatik
// Description: LADG Bearbeitungsdialog
//
using System.Windows;
using System.Collections.Generic;
using bsmd.database;
using ENI2.Controls;
using System.Collections.ObjectModel;
using System.Windows.Data;
namespace ENI2.EditControls
{
/// <summary>
/// Interaction logic for EditLADGDialog.xaml
/// </summary>
public partial class EditLADGDialog : EditWindowBase
{
private static readonly string[] handlingTypeList =
{
Properties.Resources.textLoading,
Properties.Resources.textDischarge,
Properties.Resources.textTransit
};
private static readonly string[] handlinTypeListDE =
{
Properties.Resources.textLoading,
Properties.Resources.textDischarge
};
public EditLADGDialog()
{
InitializeComponent();
Loaded += EditLADGDialog_Loaded;
}
public LADG LADG { get; set; }
public MessageCore Core { get; set; }
#region event handler
private void EditLADGDialog_Loaded(object sender, RoutedEventArgs e)
{
this.OKClicked += EditLADGDialog_OKClicked;
if (this.Core.IsDK)
this.comboBoxHandlingType.ItemsSource = handlingTypeList;
else
this.comboBoxHandlingType.ItemsSource = handlinTypeListDE;
//this.comboBoxHandlingType.KeyUp += ComboBox_KeyUp;
if (this.LADG.CargoHandlingType.HasValue)
this.comboBoxHandlingType.SelectedIndex = this.LADG.CargoHandlingType.Value;
this.comboBoxLACodes.ItemsSource = LADG.LACodes;
this.comboBoxLACodes.SelectedValue = this.LADG.CargoLACode;
this.integerUpDownNumberOfItems.Value = this.LADG.CargoNumberOfItems;
this.doubleUpDownGrossQuantity.Value = this.LADG.CargoGrossQuantity_TNE;
this.locodeControl_PortOfLoading.LocodeValue = this.LADG.PortOfLoading;
this.locodeControl_PortOfDischarge.LocodeValue = this.LADG.PortOfDischarge;
this.comboBoxLACodes.SelectedValue = this.LADG.CargoLACode;
this.comboBoxNSTCode.ItemsSource = LADG.CargoCodesNST;
this.comboBoxNSTCode.SelectedValue = this.LADG.CargoCodeNST;
this.comboBoxNSTCode.SelectionChanged += ComboBoxNSTCode_SelectionChanged;
this.comboBoxNST3Code.ItemsSource = LADG.CargoCodesNST3;
this.ComboBoxNSTCode_SelectionChanged(null, null);
this.comboBoxNST3Code.SelectedValue = this.LADG.CargoCodeNST_3;
this.AddVisible = true;
}
public void CopyValuesToEntity()
{
this.LADG.CargoHandlingType = (this.comboBoxHandlingType.SelectedIndex < 0) ? null : (byte?)this.comboBoxHandlingType.SelectedIndex;
this.LADG.CargoNumberOfItems = this.integerUpDownNumberOfItems.Value;
this.LADG.CargoGrossQuantity_TNE = this.doubleUpDownGrossQuantity.Value;
this.LADG.PortOfLoading = this.locodeControl_PortOfLoading.LocodeValue;
this.LADG.PortOfDischarge = this.locodeControl_PortOfDischarge.LocodeValue;
this.LADG.CargoLACode = (this.comboBoxLACodes.SelectedValue == null) ? null : ((int?)this.comboBoxLACodes.SelectedValue);
this.LADG.CargoCodeNST = (string)this.comboBoxNSTCode.SelectedValue;
this.LADG.CargoCodeNST_3 = (string)this.comboBoxNST3Code.SelectedValue;
}
private void ComboBoxNSTCode_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (this.comboBoxNSTCode.SelectedItem == null) return;
// filter ItemsSource von NST3
KeyValuePair<string, string> selectedItem = (KeyValuePair < string, string> ) this.comboBoxNSTCode.SelectedItem;
string key = selectedItem.Key;
if (key.Length == 1) key = "0" + key;
List<KeyValuePair<string, string>> filteredItemsSource = new List<KeyValuePair<string, string>>();
foreach(KeyValuePair<string, string> aPair in LADG.CargoCodesNST3)
{
if (aPair.Value.StartsWith(key))
filteredItemsSource.Add(aPair);
}
this.comboBoxNST3Code.ItemsSource = filteredItemsSource;
}
private void EditLADGDialog_OKClicked()
{
this.CopyValuesToEntity();
}
#endregion
}
}