Update on Save event
Save Event in AircraftDetails.cs
bool isFavorite;
//btnSave
private void btnSave_Click(object sender, EventArgs e)
{
var textBoxes = new Dictionary<Control, string>()
{
{txtType, "Type" },
{txtEngines, "Engines" },
{txtSeats, "Seats" },
{txtSpecialLivery, "Special Livery" }
};
// Check for empty values
var emptyFields = new List<string>();
foreach (var kvp in textBoxes)
{
if (kvp.Key is TextBox textBox)
{
if (string.IsNullOrWhiteSpace(textBox.Text) && (textBox.Visible || kvp.Value != "Special Livery"))
{
emptyFields.Add(kvp.Value);
}
}
}
// Message for empty values
if (emptyFields.Any())
{
string message = "Please fill out the following fields:\n- " + string.Join("\n- ", emptyFields);
MessageBox.Show(message);
foreach (var kvp in textBoxes)
{
if ((kvp.Key is TextBox textBox && string.IsNullOrWhiteSpace(textBox.Text)))
{
kvp.Key.Focus();
break;
}
}
return; // Beende, wenn es leere Felder gibt
}
// Check for changes and only update changed values
string updatedType = currentAircraft.Type;
int updatedSeats = currentAircraft.Seats;
string updatedEngines = currentAircraft.Engines;
DateTime updatedFirstFlight = currentAircraft.FirstFlight;
string updatedSpecialLivery = currentAircraft.SpecialLivery;
string airline = currentAircraft.Airline;
bool updatedIsFavorite;
if(btnSetFavorite.Visible == true)
{
updatedIsFavorite = false;
}
else
{
updatedIsFavorite = true;
}
// Flag, um zu überprüfen, ob alle Daten korrekt sind
bool isValid = true;bool isFavorite;
//btnSave
private void btnSave_Click(object sender, EventArgs e)
{
var textBoxes = new Dictionary<Control, string>()
{
{txtType, "Type" },
{txtEngines, "Engines" },
{txtSeats, "Seats" },
{txtSpecialLivery, "Special Livery" }
};
// Check for empty values
var emptyFields = new List<string>();
foreach (var kvp in textBoxes)
{
if (kvp.Key is TextBox textBox)
{
if (string.IsNullOrWhiteSpace(textBox.Text) && (textBox.Visible || kvp.Value != "Special Livery"))
{
emptyFields.Add(kvp.Value);
}
}
}
// Message for empty values
if (emptyFields.Any())
{
string message = "Please fill out the following fields:\n- " + string.Join("\n- ", emptyFields);
MessageBox.Show(message);
foreach (var kvp in textBoxes)
{
if ((kvp.Key is TextBox textBox && string.IsNullOrWhiteSpace(textBox.Text)))
{
kvp.Key.Focus();
break;
}
}
return; // Beende, wenn es leere Felder gibt
}
// Check for changes and only update changed values
string updatedType = currentAircraft.Type;
int updatedSeats = currentAircraft.Seats;
string updatedEngines = currentAircraft.Engines;
DateTime updatedFirstFlight = currentAircraft.FirstFlight;
string updatedSpecialLivery = currentAircraft.SpecialLivery;
string airline = currentAircraft.Airline;
bool updatedIsFavorite;
if(btnSetFavorite.Visible == true)
{
updatedIsFavorite = false;
}
else
{
updatedIsFavorite = true;
}
// Flag, um zu überprüfen, ob alle Daten korrekt sind
bool isValid = true;