git_bsmd/ENI2/EditControls/EditCREWDialog.xaml.cs

105 lines
5.1 KiB
C#

// Copyright (c) 2017 schick Informatik
// Description: CREW Bearbeitungsdialog
//
using System;
using System.Windows;
using bsmd.database;
using ENI2.Controls;
using ENI2.Util;
namespace ENI2.EditControls
{
/// <summary>
/// Interaction logic for EditCREWDialog.xaml
/// </summary>
public partial class EditCREWDialog : EditWindowBase
{
public EditCREWDialog()
{
InitializeComponent();
Loaded += EditCREWDialog_Loaded;
AddClicked += () => { this.textBoxDuty.Focus(); };
}
public CREW CREW { get; set; }
private void EditCREWDialog_Loaded(object sender, RoutedEventArgs e)
{
// copy into fields
this.textBoxDuty.Text = this.CREW.CrewMemberDuty;
this.textBoxLastName.Text = this.CREW.CrewMemberLastName;
this.textBoxFirstName.Text = this.CREW.CrewMemberFirstName;
this.comboBoxGender.ItemsSource = GlobalStructures.GenderDict;
this.comboBoxGender.SelectedValue = this.CREW.CrewMemberGender?.ToString();
this.textBoxPlaceOfBirth.Text = this.CREW.CrewMemberPlaceOfBirth;
this.comboBoxNationality.ItemsSource = bsmd.database.CREW.NationalityDict;
this.comboBoxNationality.SelectedValue = this.CREW.CrewMemberNationality;
if (this.CREW.CrewMemberDateOfBirth > CREW.CLAMPMAXDATE)
{
this.datePickerDateOfBirth.SelectedDate = CREW.CLAMPMAXDATE;
}
else if (this.CREW.CrewMemberDateOfBirth < CREW.CLAMPMINDATE)
{
this.datePickerDateOfBirth.SelectedDate = CREW.CLAMPMINDATE;
}
else
{
this.datePickerDateOfBirth.SelectedDate = this.CREW.CrewMemberDateOfBirth;
}
this.comboBoxIdDocType.ItemsSource = GlobalStructures.IDDocTypeDict;
this.comboBoxIdDocType.SelectedValue = this.CREW.CrewMemberIdentityDocumentType?.ToString();
this.textBoxIdDocNumber.Text = this.CREW.CrewMemberIdentityDocumentId;
this.textBoxVisaNumber.Text = this.CREW.CrewMemberVisaNumber;
this.comboBoxIssuingState.ItemsSource = bsmd.database.CREW.NationalityDict;
this.comboBoxIssuingState.SelectedValue = this.CREW.CrewMemberIdentityDocumentIssuingState;
if (this.CREW.CrewMemberIdentityDocumentExpiryDate > CREW.CLAMPMAXDATE)
{
this.datePickerExpiryDate.SelectedDate = CREW.CLAMPMAXDATE;
}
else if(this.CREW.CrewMemberDateOfBirth < CREW.CLAMPMINDATE)
{
this.datePickerExpiryDate.SelectedDate = CREW.CLAMPMINDATE;
}
else
{
this.datePickerExpiryDate.SelectedDate = this.CREW.CrewMemberIdentityDocumentExpiryDate;
}
this.comboBoxCountryOfBirth.ItemsSource = bsmd.database.CREW.NationalityDict;
this.comboBoxCountryOfBirth.SelectedValue = this.CREW.CrewMemberCountryOfBirth;
// this.textBoxEffects.Text = this.CREW.Effects;
this.OKClicked += EditCREWDialog_OKClicked;
this.AddVisible = true;
}
public void CopyValuesToEntity()
{
// copy back
this.CREW.CrewMemberDuty = this.textBoxDuty.Text.Trim();
if (this.CREW.CrewMemberDuty.IsNullOrEmpty()) this.CREW.CrewMemberDuty = "unknown";
this.CREW.CrewMemberLastName = this.textBoxLastName.Text.Trim();
this.CREW.CrewMemberFirstName = this.textBoxFirstName.Text.Trim();
this.CREW.CrewMemberGender = (this.comboBoxGender.SelectedIndex == -1) ? null : (byte?) byte.Parse((string) this.comboBoxGender.SelectedValue);
this.CREW.CrewMemberPlaceOfBirth = this.textBoxPlaceOfBirth.Text.Trim();
this.CREW.CrewMemberNationality = (this.comboBoxNationality.SelectedValue == null) ? "" : (string) this.comboBoxNationality.SelectedValue;
this.CREW.CrewMemberDateOfBirth = this.datePickerDateOfBirth.SelectedDate;
this.CREW.CrewMemberIdentityDocumentType = (this.comboBoxIdDocType.SelectedIndex == -1) ? null : (byte?) byte.Parse((string)this.comboBoxIdDocType.SelectedValue);
this.CREW.CrewMemberIdentityDocumentId = this.textBoxIdDocNumber.Text.Trim();
this.CREW.CrewMemberVisaNumber = this.textBoxVisaNumber.Text.Trim();
this.CREW.CrewMemberIdentityDocumentIssuingState = (this.comboBoxIssuingState.SelectedValue == null) ? "" : (string) this.comboBoxIssuingState.SelectedValue;
this.CREW.CrewMemberIdentityDocumentExpiryDate = this.datePickerExpiryDate.SelectedDate;
this.CREW.CrewMemberCountryOfBirth = (this.comboBoxCountryOfBirth.SelectedValue == null) ? "" : (string)this.comboBoxCountryOfBirth.SelectedValue;
// this.CREW.Effects = this.textBoxEffects.Text.Trim();
}
private void EditCREWDialog_OKClicked()
{
this.CopyValuesToEntity();
}
}
}