add error message to exporter, disable export button on launch

This commit is contained in:
2022-05-16 19:17:17 +02:00
parent 828e6c69fd
commit 961a5274cf

View File

@@ -40,7 +40,7 @@ namespace it_projekt
if (db.Persons == null)
{
Database.resetDatabase();
MessageBox.Show("Connection to Database failed! \nPlease Try again.", "Database Error!");
MessageBox.Show("Verbindung mit der Datenbank fehlgeschlagen :( \nVersuchen Sie es erneut.", "Datenbank Fehler!");
}
else {
foreach (Person person in db.Persons)
@@ -59,6 +59,23 @@ namespace it_projekt
private void export(string Filter, string FileName)
{
List<Person> markedUsers = new List<Person>();
foreach (DataGridViewRow row in dataGrid.Rows)
{
if (row.Cells[6].Value != null)
{
if (row.Cells[6].Value.ToString() == "True")
{
markedUsers.Add(db.Persons.Find(person => person.Id == row.Cells[0].Value.ToString()));
}
}
}
if (markedUsers.Count == 0)
{
MessageBox.Show("Bitte wählen Sie mindestens eine Person zum exportieren aus!", "Exporter Error!");
return;
}
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = Filter;
@@ -69,17 +86,6 @@ namespace it_projekt
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
List<Person> markedUsers = new List<Person>();
foreach (DataGridViewRow row in dataGrid.Rows)
{
if (row.Cells[6].Value != null)
{
if (row.Cells[6].Value.ToString() == "True")
{
markedUsers.Add(db.Persons.Find(person => person.Id == row.Cells[0].Value.ToString()));
}
}
}
StreamWriter sw = new StreamWriter(myStream);
if (FileName.Contains("xml"))
{