Multi-Edit from Grid for CREWA/D und PASA/D

This commit is contained in:
Daniel Schick 2024-08-26 11:08:36 +02:00
parent 5085b82a13
commit 5d02cf1cfa
6 changed files with 421 additions and 6 deletions

View File

@ -56,6 +56,7 @@ namespace ENI2.Controls
// das hier bildet 1:1 das Kontext-Menü des ANSW ab
public event Action<DatabaseEntity> EditRequested;
public event Action<List<DatabaseEntity>> MultiEditRequested;
public event Action<DatabaseEntity> DeleteRequested;
public event Action CreateRequested;
public event Action RefreshGrid;
@ -206,6 +207,14 @@ namespace ENI2.Controls
if (this.SelectedItems[0] is DatabaseEntity selectedEntity)
this.EditRequested?.Invoke(selectedEntity);
}
if((this.SelectedItems != null) && (this.SelectedItems.Count > 1) && !this.IsReadOnly)
{
List<DatabaseEntity> databaseEntities = new List<DatabaseEntity>();
foreach(DatabaseEntity databaseEntity in this.SelectedItems)
databaseEntities.Add(databaseEntity);
this.MultiEditRequested?.Invoke(databaseEntities);
}
}
protected void printItem(object sender, RoutedEventArgs e)

View File

@ -63,10 +63,17 @@ namespace ENI2.Controls
get { var addButton = (Button)Template.FindName("buttonAdd", this); return addButton.Visibility == Visibility.Visible; }
set
{
var addButton = (Button)Template.FindName("buttonAdd", this); addButton.Visibility = value ? Visibility.Visible : Visibility.Hidden;
var addButton = (Button)Template.FindName("buttonAdd", this);
if (addButton != null)
{
addButton.Visibility = value ? Visibility.Visible : Visibility.Hidden;
}
var okButton = (Button)Template.FindName("buttonOK", this);
if (okButton.Visibility == Visibility.Hidden)
okButton.Width = 1; // we are in a DockPanel, try to collapse okButton to place addButton more to the right
if (okButton != null)
{
if (okButton.Visibility == Visibility.Hidden)
okButton.Width = 1; // we are in a DockPanel, try to collapse okButton to place addButton more to the right
}
}
}

View File

@ -114,6 +114,7 @@ namespace ENI2.DetailViewControls
this.dataGridCrewList.DeleteRequested += DataGridCrewList_DeleteRequested;
this.dataGridCrewList.CreateRequested += DataGridCrewList_CreateRequested;
this.dataGridCrewList.RefreshGrid += DataGridCrewList_RefreshGrid;
this.dataGridCrewList.MultiEditRequested += DataGridCrewList_MultiEditRequested;
if(this._crewMessage.Elements.Count > 0)
{
@ -150,6 +151,7 @@ namespace ENI2.DetailViewControls
this.dataGridCrewListDeparture.DeleteRequested += DataGridCrewListDeparture_DeleteRequested;
this.dataGridCrewListDeparture.CreateRequested += DataGridCrewListDeparture_CreateRequested;
this.dataGridCrewListDeparture.RefreshGrid += DataGridCrewListDeparture_RefreshGrid;
this.dataGridCrewListDeparture.MultiEditRequested += DataGridCrewListDeparture_MultiEditRequested;
if (this._crewdMessage.Elements.Count > 0)
{
@ -186,6 +188,7 @@ namespace ENI2.DetailViewControls
this.dataGridPassengerList.DeleteRequested += DataGridPassengerList_DeleteRequested;
this.dataGridPassengerList.CreateRequested += DataGridPassengerList_CreateRequested;
this.dataGridPassengerList.RefreshGrid += DataGridPassengerList_RefreshGrid;
this.dataGridPassengerList.MultiEditRequested += DataGridPassengerList_MultiEditRequested;
if (this._pasMessage.Elements.Count > 0)
{
@ -222,6 +225,7 @@ namespace ENI2.DetailViewControls
this.dataGridPassengerListDeparture.DeleteRequested += DataGridPassengerListDeparture_DeleteRequested;
this.dataGridPassengerListDeparture.CreateRequested += DataGridPassengerListDeparture_CreateRequested;
this.dataGridPassengerListDeparture.RefreshGrid += DataGridPassengerListDeparture_RefreshGrid;
this.dataGridPassengerListDeparture.MultiEditRequested += DataGridPassengerListDeparture_MultiEditRequested;
if (this._pasdMessage.Elements.Count > 0)
{
@ -630,6 +634,28 @@ namespace ENI2.DetailViewControls
this.DataGridPassengerList_CreateRequested();
}
private void DataGridPassengerList_MultiEditRequested(List<DatabaseEntity> databaseEntities)
{
List<PAS> pasList = new List<PAS>();
foreach (PAS apas in databaseEntities.Cast<PAS>())
pasList.Add(apas);
// write common values of all PAS entities to template entity
PAS pas = PAS.CreateCommon(pasList);
EditPASDialog dialog = new EditPASDialog();
dialog.PAS = pas;
dialog.AddVisible = false;
if (dialog.ShowDialog() ?? false)
{
// write back changed values from pas to all entities and mark them as changed
PAS.WriteTemplateToList(pas, pasList);
this.SublistElementChanged(Message.NotificationClass.PASA);
this.dataGridPassengerList.Items.Refresh();
}
}
#endregion
#region passenger grid departure
@ -734,6 +760,28 @@ namespace ENI2.DetailViewControls
this.DataGridPassengerListDeparture_CreateRequested();
}
private void DataGridPassengerListDeparture_MultiEditRequested(List<DatabaseEntity> databaseEntities)
{
List<PAS> pasList = new List<PAS>();
foreach (PAS apas in databaseEntities.Cast<PAS>())
pasList.Add(apas);
// write common values of all PAS entities to template entity
PAS pas = PAS.CreateCommon(pasList);
EditPASDialog dialog = new EditPASDialog();
dialog.PAS = pas;
dialog.AddVisible = false;
if (dialog.ShowDialog() ?? false)
{
// write back changed values from pas to all entities and mark them as changed
PAS.WriteTemplateToList(pas, pasList);
this.SublistElementChanged(Message.NotificationClass.PASD);
this.dataGridPassengerListDeparture.Items.Refresh();
}
}
#endregion
#region crew grid arrival
@ -835,6 +883,28 @@ namespace ENI2.DetailViewControls
this.DataGridCrewList_CreateRequested();
}
private void DataGridCrewList_MultiEditRequested(List<DatabaseEntity> databaseEntities)
{
List<CREW> crewList = new List<CREW>();
foreach (CREW acrew in databaseEntities.Cast<CREW>())
crewList.Add(acrew);
// write common values of all CREW entities to template entity
CREW crew = CREW.CreateCommon(crewList);
EditCREWDialog dialog = new EditCREWDialog();
dialog.CREW = crew;
dialog.AddVisible = false;
if(dialog.ShowDialog() ?? false)
{
// write back changed values from crew to all entities and mark them as changed
CREW.WriteTemplateToList(crew, crewList);
this.SublistElementChanged(Message.NotificationClass.CREWA);
this.dataGridCrewList.Items.Refresh();
}
}
#endregion
#region crew grid departure
@ -939,6 +1009,28 @@ namespace ENI2.DetailViewControls
this.DataGridCrewListDeparture_CreateRequested();
}
private void DataGridCrewListDeparture_MultiEditRequested(List<DatabaseEntity> databaseEntities)
{
List<CREW> crewList = new List<CREW>();
foreach (CREW acrew in databaseEntities.Cast<CREW>())
crewList.Add(acrew);
// write common values of all CREW entities to template entity
CREW crew = CREW.CreateCommon(crewList);
EditCREWDialog dialog = new EditCREWDialog();
dialog.CREW = crew;
dialog.AddVisible = false;
if (dialog.ShowDialog() ?? false)
{
// write back changed values from crew to all entities and mark them as changed
CREW.WriteTemplateToList(crew, crewList);
this.SublistElementChanged(Message.NotificationClass.CREWD);
this.dataGridCrewListDeparture.Items.Refresh();
}
}
#endregion
#region Excel import

View File

@ -459,6 +459,135 @@ namespace bsmd.database
#endregion
#region public static helper funcs
public static CREW CreateCommon(List<CREW> crewList)
{
CREW crew = new CREW(); // template entity
if(crewList.IsNullOrEmpty())
return crew;
string crewMemberLastName = crewList[0].CrewMemberLastName;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberLastName, crewMemberLastName)))
crew.CrewMemberLastName = crewMemberLastName;
string crewMemberFirstName = crewList[0].CrewMemberFirstName;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberFirstName, crewMemberFirstName)))
crew.CrewMemberFirstName = crewMemberFirstName;
string crewMemberPlaceOfBirth = crewList[0].CrewMemberPlaceOfBirth;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberPlaceOfBirth, crewMemberPlaceOfBirth)))
crew.CrewMemberPlaceOfBirth = crewMemberPlaceOfBirth;
string crewMemberCountryOfBirth = crewList[0].CrewMemberCountryOfBirth;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberPlaceOfBirth, crewMemberCountryOfBirth)))
crew.CrewMemberCountryOfBirth = crewMemberCountryOfBirth;
DateTime? crewMemberDateOfBirth = crewList[0].CrewMemberDateOfBirth;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberDateOfBirth, crewMemberDateOfBirth)))
crew.CrewMemberDateOfBirth = crewMemberDateOfBirth;
byte? crewMemberGender = crewList[0].CrewMemberGender;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberGender, crewMemberGender)))
crew.CrewMemberGender = crewMemberGender;
string crewMemberNationality = crewList[0].CrewMemberNationality;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberNationality, crewMemberNationality)))
crew.CrewMemberNationality = crewMemberNationality;
byte? crewMemberIdentityDocumentType = crewList[0].CrewMemberIdentityDocumentType;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberIdentityDocumentType, crewMemberIdentityDocumentType)))
crew.CrewMemberIdentityDocumentType = crewMemberIdentityDocumentType;
string crewMemberIdentityDocumentId = crewList[0].CrewMemberIdentityDocumentId;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberIdentityDocumentId, crewMemberIdentityDocumentId)))
crew.CrewMemberIdentityDocumentId = crewMemberIdentityDocumentId;
string crewMemberVisaNumber = crewList[0].CrewMemberVisaNumber;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberVisaNumber, crewMemberVisaNumber)))
crew.CrewMemberVisaNumber = crewMemberVisaNumber;
string crewMemberDuty = crewList[0].CrewMemberDuty;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberDuty, crewMemberDuty)))
crew.CrewMemberDuty = crewMemberDuty;
string crewMemberIdentityDocumentIssuingState = crewList[0].CrewMemberIdentityDocumentIssuingState;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberIdentityDocumentIssuingState, crewMemberIdentityDocumentIssuingState)))
crew.CrewMemberIdentityDocumentIssuingState = crewMemberIdentityDocumentIssuingState;
DateTime? crewMemberIdentityDocumentExpiryDate = crewList[0].CrewMemberIdentityDocumentExpiryDate;
if (crewList.All(x => Extensions.AreEqual(x.CrewMemberIdentityDocumentExpiryDate, crewMemberIdentityDocumentExpiryDate)))
crew.CrewMemberIdentityDocumentExpiryDate = crewMemberIdentityDocumentExpiryDate;
string effects = crewList[0].Effects;
if (crewList.All(x => Extensions.AreEqual(x.Effects, effects)))
crew.Effects = effects;
bool? notificationPax = crewList[0].NotificationPAX;
if (crewList.All(x => Extensions.AreEqual(x.NotificationPAX, notificationPax)))
crew.NotificationPAX = notificationPax;
bool? notificationSchengen = crewList[0].NotificationSchengen;
if (crewList.All(x => Extensions.AreEqual(x.NotificationSchengen, notificationSchengen)))
crew.NotificationSchengen = notificationSchengen;
return crew;
}
public static void WriteTemplateToList(CREW crew, List<CREW> crewList)
{
if (!crew.CrewMemberLastName.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberLastName = crew.CrewMemberLastName);
if (!crew.CrewMemberFirstName.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberFirstName = crew.CrewMemberFirstName);
if (!crew.CrewMemberPlaceOfBirth.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberPlaceOfBirth = crew.CrewMemberPlaceOfBirth);
if (!crew.CrewMemberCountryOfBirth.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberCountryOfBirth = crew.CrewMemberCountryOfBirth);
if (crew.CrewMemberDateOfBirth != null)
crewList.ForEach(x => x.CrewMemberDateOfBirth = crew.CrewMemberDateOfBirth);
if (crew.CrewMemberGender != null)
crewList.ForEach(x => x.CrewMemberGender = crew.CrewMemberGender);
if (!crew.CrewMemberNationality.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberNationality = crew.CrewMemberNationality);
if (crew.CrewMemberIdentityDocumentType != null)
crewList.ForEach(x => x.CrewMemberIdentityDocumentType = crew.CrewMemberIdentityDocumentType);
if (!crew.CrewMemberIdentityDocumentId.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberIdentityDocumentId = crew.CrewMemberIdentityDocumentId);
if (!crew.CrewMemberVisaNumber.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberVisaNumber = crew.CrewMemberVisaNumber);
if (!crew.CrewMemberDuty.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberDuty = crew.CrewMemberDuty);
if (!crew.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty())
crewList.ForEach(x => x.CrewMemberIdentityDocumentIssuingState = crew.CrewMemberIdentityDocumentIssuingState);
if (crew.CrewMemberIdentityDocumentExpiryDate != null)
crewList.ForEach(x => x.CrewMemberIdentityDocumentExpiryDate = crew.CrewMemberIdentityDocumentExpiryDate);
if (!crew.Effects.IsNullOrEmpty())
crewList.ForEach(x => x.Effects = crew.Effects);
if (crew.NotificationPAX != null)
crewList.ForEach(x => x.NotificationPAX = crew.NotificationPAX);
if (crew.NotificationSchengen != null)
crewList.ForEach(x => x.NotificationSchengen = crew.NotificationSchengen);
}
#endregion
}
#region CREWD

View File

@ -36,6 +36,33 @@ namespace bsmd.database
return false;
}
public static bool AreEqual(string a, string b)
{
if (string.IsNullOrEmpty(a)) return string.IsNullOrEmpty(b);
return string.Equals(a, b);
}
public static bool AreEqual(DateTime? a, DateTime? b)
{
if(!a.HasValue) return !b.HasValue;
if(!b.HasValue) return !a.HasValue;
return a.Value.Equals(b.Value);
}
public static bool AreEqual(byte? a, byte? b)
{
if (!a.HasValue) return !b.HasValue;
if (!b.HasValue) return !a.HasValue;
return a.Value.Equals(b.Value);
}
public static bool AreEqual(bool? a, bool? b)
{
if (!a.HasValue) return !b.HasValue;
if (!b.HasValue) return !a.HasValue;
return a.Value == b.Value;
}
public static bool IsNullOrEmpty<T>(this List<T> items)
{
return (items == null) || (items.Count == 0);

View File

@ -521,6 +521,157 @@ namespace bsmd.database
}
#endregion
#region public static helper funcs
public static PAS CreateCommon(List<PAS> pasList)
{
PAS pas = new PAS(); // template entity
//
if (pasList.IsNullOrEmpty())
return pas;
string passengerLastName = pasList[0].PassengerLastName;
if (pasList.All(x => Extensions.AreEqual(x.PassengerLastName, passengerLastName)))
pas.PassengerLastName = passengerLastName;
string passengerFirstName = pasList[0].PassengerFirstName;
if(pasList.All(x => Extensions.AreEqual(x.PassengerFirstName, passengerFirstName)))
pas.PassengerFirstName = passengerFirstName;
string passengerPlaceOfBirth = pasList[0].PassengerPlaceOfBirth;
if(pasList.All(x => Extensions.AreEqual(x.PassengerPlaceOfBirth, passengerPlaceOfBirth)))
pas.PassengerPlaceOfBirth = passengerPlaceOfBirth;
DateTime? passengerDateOfBirth = pasList[0].PassengerDateOfBirth;
if(pasList.All(x => Extensions.AreEqual(x.PassengerDateOfBirth, passengerDateOfBirth)))
pas.PassengerDateOfBirth = passengerDateOfBirth;
byte? passengerGender = pasList[0].PassengerGender;
if(pasList.All(x => Extensions.AreEqual(x.PassengerGender, passengerGender)))
pas.PassengerGender = passengerGender;
string passengerNationality = pasList[0].PassengerNationality;
if(pasList.All(x => Extensions.AreEqual(x.PassengerNationality, passengerNationality)))
pas.PassengerNationality = passengerNationality;
byte? passengerIdentityDocumentType = pasList[0].PassengerIdentityDocumentType;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentType, passengerIdentityDocumentType)))
pas.PassengerIdentityDocumentType = passengerIdentityDocumentType;
string passengerIdentityDocumentId = pasList[0].PassengerIdentityDocumentId;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentId, passengerIdentityDocumentId)))
pas.PassengerIdentityDocumentId = passengerIdentityDocumentId;
string passengerVisaNumber = pasList[0].PassengerVisaNumber;
if(pasList.All(x => Extensions.AreEqual(x.PassengerVisaNumber, passengerVisaNumber)))
pas.PassengerVisaNumber = passengerVisaNumber;
string passengerPortOfEmbarkation = pasList[0].PassengerPortOfEmbarkation;
if (pasList.All(x => Extensions.AreEqual(x.PassengerPortOfEmbarkation, passengerPortOfEmbarkation)))
pas.PassengerPortOfEmbarkation = passengerPortOfEmbarkation;
string passengerPortOfDisembarkation = pasList[0].PassengerPortOfDisembarkation;
if(pasList.All(x => Extensions.AreEqual(x.PassengerPortOfDisembarkation, passengerPortOfDisembarkation)))
pas.PassengerPortOfDisembarkation = passengerPortOfDisembarkation;
bool? passengerInTransit = pasList[0].PassengerInTransit;
if(pasList.All(x => Extensions.AreEqual(x.PassengerInTransit, passengerInTransit)))
pas.PassengerInTransit = passengerInTransit;
string passengerIdentityDocumentIssuingState = pasList[0].PassengerIdentityDocumentIssuingState;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentIssuingState, passengerIdentityDocumentIssuingState)))
pas.PassengerIdentityDocumentIssuingState = passengerIdentityDocumentIssuingState;
DateTime? passengerIdentityDocumentExpiryDate = pasList[0].PassengerIdentityDocumentExpiryDate;
if(pasList.All(x => Extensions.AreEqual(x.PassengerIdentityDocumentExpiryDate, passengerIdentityDocumentExpiryDate)))
pas.PassengerIdentityDocumentExpiryDate = passengerIdentityDocumentExpiryDate;
bool? notificationSchengen = pasList[0].NotificationSchengen;
if(pasList.All(x => Extensions.AreEqual(x.NotificationSchengen, notificationSchengen)))
pas.NotificationSchengen = notificationSchengen;
bool? notificationPAX = pasList[0].NotificationPAX;
if(pasList.All(x => Extensions.AreEqual(x.NotificationPAX, notificationPAX)))
pas.NotificationPAX = notificationPAX;
string passengerCountryOfBirth = pasList[0].PassengerCountryOfBirth;
if(pasList.All(x => Extensions.AreEqual(x.PassengerCountryOfBirth, passengerCountryOfBirth)))
pas.PassengerCountryOfBirth = passengerCountryOfBirth;
string emergencyCare = pasList[0].EmergencyCare;
if(pasList.All(x => Extensions.AreEqual(x.EmergencyCare, emergencyCare)))
pas.EmergencyCare = emergencyCare;
string emergencyContactNumber = pasList[0].EmergencyContactNumber;
if(pasList.All(x => Extensions.AreEqual(x.EmergencyContactNumber, emergencyContactNumber)))
pas.EmergencyContactNumber = emergencyContactNumber;
return pas;
}
public static void WriteTemplateToList(PAS pas, List<PAS> pasList)
{
if (!pas.PassengerLastName.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerLastName = pas.PassengerLastName);
if (!pas.PassengerFirstName.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerFirstName = pas.PassengerFirstName);
if(!pas.PassengerPlaceOfBirth.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerPlaceOfBirth = pas.PassengerPlaceOfBirth);
if(pas.PassengerDateOfBirth.HasValue)
pasList.ForEach(x => x.PassengerDateOfBirth = pas.PassengerDateOfBirth.Value);
if(pas.PassengerGender.HasValue)
pasList.ForEach(x => x.PassengerGender = pas.PassengerGender.Value);
if(!pas.PassengerNationality.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerNationality = pas.PassengerNationality);
if(pas.PassengerIdentityDocumentType.HasValue)
pasList.ForEach(x => x.PassengerIdentityDocumentType = pas.PassengerIdentityDocumentType.Value);
if(!pas.PassengerIdentityDocumentId.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerIdentityDocumentId = pas.PassengerIdentityDocumentId);
if(!pas.PassengerVisaNumber.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerVisaNumber = pas.PassengerVisaNumber);
if(!pas.PassengerPortOfEmbarkation.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerPortOfEmbarkation = pas.PassengerPortOfEmbarkation);
if(!pas.PassengerPortOfDisembarkation.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerPortOfDisembarkation = pas.PassengerPortOfDisembarkation);
if(pas.PassengerInTransit.HasValue)
pasList.ForEach(x => x.PassengerInTransit = pas.PassengerInTransit.Value);
if(!pas.PassengerIdentityDocumentIssuingState.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerIdentityDocumentIssuingState = pas.PassengerIdentityDocumentIssuingState);
if(pas.PassengerIdentityDocumentExpiryDate.HasValue)
pasList.ForEach(x => x.PassengerIdentityDocumentExpiryDate = pas.PassengerIdentityDocumentExpiryDate.Value);
if(pas.NotificationSchengen.HasValue)
pasList.ForEach(x => x.NotificationSchengen = pas.NotificationSchengen.Value);
if(pas.NotificationPAX.HasValue)
pasList.ForEach(x => x.NotificationPAX = pas.NotificationPAX.Value);
if(!pas.PassengerCountryOfBirth.IsNullOrEmpty())
pasList.ForEach(x => x.PassengerCountryOfBirth = pas.PassengerCountryOfBirth);
if(!pas.EmergencyCare.IsNullOrEmpty())
pasList.ForEach(x => x.EmergencyCare = pas.EmergencyCare);
if(!pas.EmergencyContactNumber.IsNullOrEmpty())
pasList.ForEach(x => x.EmergencyContactNumber = pas.EmergencyContactNumber);
}
#endregion
}
#region class PASD