[#56] Windows: Fail gracefully while saving
All checks were successful
Test / Run tests (push) Successful in 2m11s

This commit is contained in:
2024-09-23 22:51:01 +02:00
parent 94a6dd5312
commit ce39797d8b
8 changed files with 141 additions and 65 deletions

View File

@ -494,7 +494,6 @@ namespace Elwig.Services {
WeighingReason = vm.ManualWeighingReason, WeighingReason = vm.ManualWeighingReason,
}; };
try {
if (oldDelivery != null && ctx.Entry(oldDelivery) is EntityEntry<Delivery> entry) { if (oldDelivery != null && ctx.Entry(oldDelivery) is EntityEntry<Delivery> entry) {
entry.State = EntityState.Detached; entry.State = EntityState.Detached;
} }
@ -524,11 +523,6 @@ namespace Elwig.Services {
} }
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
} catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Lieferung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
}
return p; return p;
} }

View File

@ -226,14 +226,22 @@ namespace Elwig.Windows {
} }
private async void AreaCommitmentSaveButton_Click(object? sender, RoutedEventArgs? evt) { private async void AreaCommitmentSaveButton_Click(object? sender, RoutedEventArgs? evt) {
int? fbnr = null; AreaCommitmentSaveButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting;
int fbnr;
try { try {
fbnr = await ViewModel.UpdateAreaCommitment((AreaCommitmentList.SelectedItem as AreaCom)?.FbNr); fbnr = await ViewModel.UpdateAreaCommitment((AreaCommitmentList.SelectedItem as AreaCom)?.FbNr);
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Flächenbindung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Flächenbindung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
AreaCommitmentSaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null;
} }
IsEditing = false; IsEditing = false;
IsCreating = false; IsCreating = false;
AreaCommitmentList.IsEnabled = true; AreaCommitmentList.IsEnabled = true;

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input;
namespace Elwig.Windows { namespace Elwig.Windows {
public partial class BaseDataWindow : AdministrationWindow { public partial class BaseDataWindow : AdministrationWindow {
@ -316,12 +317,19 @@ namespace Elwig.Windows {
} }
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) { private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
SaveButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting;
try { try {
await Save(); await Save();
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Stammdaten aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Stammdaten aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
SaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null;
} }
IsEditing = false; IsEditing = false;

View File

@ -661,6 +661,9 @@ namespace Elwig.Windows {
} }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { private async void SaveButton_Click(object sender, RoutedEventArgs e) {
SaveButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting;
try { try {
using (var ctx = new AppDbContext()) { using (var ctx = new AppDbContext()) {
var origData = BillingData.FromJson(PaymentVar.Data); var origData = BillingData.FromJson(PaymentVar.Data);
@ -677,7 +680,12 @@ namespace Elwig.Windows {
var str = "Der Eintrag konnte nicht in der Datenbank gespeichert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank gespeichert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Auszahlungsvariante speichern", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Auszahlungsvariante speichern", MessageBoxButton.OK, MessageBoxImage.Error);
SaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null;
} }
LockContext = true; LockContext = true;
SetHasChanged(false); SetHasChanged(false);
} }

View File

@ -694,7 +694,10 @@ namespace Elwig.Windows {
NewDeliveryPartButton.IsEnabled = false; NewDeliveryPartButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
DeliveryPartList.IsEnabled = false; DeliveryPartList.IsEnabled = false;
var p = await ViewModel.UpdateDeliveryPart(
DeliveryPart? p;
try {
p = await ViewModel.UpdateDeliveryPart(
(DeliveryList.SelectedItem as Delivery)?.Year, (DeliveryList.SelectedItem as Delivery)?.Year,
(DeliveryList.SelectedItem as Delivery)?.DId, (DeliveryList.SelectedItem as Delivery)?.DId,
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr, (DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
@ -702,6 +705,17 @@ namespace Elwig.Windows {
InputHasChanged(TimeInput), InputHasChanged(TimeInput),
!InputIsNotDefault(TimeInput) !InputIsNotDefault(TimeInput)
); );
} catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Lieferung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
FinishButton.IsEnabled = true;
SaveButton.IsEnabled = true;
Mouse.OverrideCursor = null;
DeliveryPartList.IsEnabled = true;
return;
}
EmptyScale(); EmptyScale();
await RefreshList(); await RefreshList();
await RefreshDeliveryParts(); await RefreshDeliveryParts();
@ -718,7 +732,10 @@ namespace Elwig.Windows {
NewDeliveryPartButton.IsEnabled = false; NewDeliveryPartButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
DeliveryPartList.IsEnabled = false; DeliveryPartList.IsEnabled = false;
var p = await ViewModel.UpdateDeliveryPart(
DeliveryPart? p;
try {
p = await ViewModel.UpdateDeliveryPart(
(DeliveryList.SelectedItem as Delivery)?.Year, (DeliveryList.SelectedItem as Delivery)?.Year,
(DeliveryList.SelectedItem as Delivery)?.DId, (DeliveryList.SelectedItem as Delivery)?.DId,
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr, (DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
@ -726,6 +743,17 @@ namespace Elwig.Windows {
InputHasChanged(TimeInput), InputHasChanged(TimeInput),
!InputIsNotDefault(TimeInput) !InputIsNotDefault(TimeInput)
); );
} catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Lieferung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
FinishButton.IsEnabled = true;
SaveButton.IsEnabled = true;
Mouse.OverrideCursor = null;
DeliveryPartList.IsEnabled = true;
return;
}
EmptyScale(); EmptyScale();
await RefreshList(); await RefreshList();
await RefreshDeliveryParts(); await RefreshDeliveryParts();
@ -743,6 +771,7 @@ namespace Elwig.Windows {
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
} }
} }
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;
DeliveryList.SelectedItem = null; DeliveryList.SelectedItem = null;
await RenewContext(); await RenewContext();
@ -940,12 +969,9 @@ namespace Elwig.Windows {
SaveButton.IsEnabled = false; SaveButton.IsEnabled = false;
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
IsEditing = false; DeliveryPart? p;
IsCreating = false; try {
DeliveryList.IsEnabled = true; p = await ViewModel.UpdateDeliveryPart(
DeliveryPartList.IsEnabled = true;
var p = await ViewModel.UpdateDeliveryPart(
(DeliveryList.SelectedItem as Delivery)?.Year, (DeliveryList.SelectedItem as Delivery)?.Year,
(DeliveryList.SelectedItem as Delivery)?.DId, (DeliveryList.SelectedItem as Delivery)?.DId,
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr, (DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
@ -953,8 +979,20 @@ namespace Elwig.Windows {
InputHasChanged(TimeInput), InputHasChanged(TimeInput),
!InputIsNotDefault(TimeInput) !InputIsNotDefault(TimeInput)
); );
} catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Lieferung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
SaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;
}
IsEditing = false;
IsCreating = false;
DeliveryList.IsEnabled = true;
DeliveryPartList.IsEnabled = true;
HideSaveResetCancelButtons(); HideSaveResetCancelButtons();
ShowNewEditDeleteButtons(); ShowNewEditDeleteButtons();

View File

@ -341,6 +341,8 @@ namespace Elwig.Windows {
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) { private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
SaveButton.IsEnabled = false;
int year = -1, dsnr = -1, mgnr = -1; int year = -1, dsnr = -1, mgnr = -1;
string? sortid = null; string? sortid = null;
try { try {
@ -350,8 +352,12 @@ namespace Elwig.Windows {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Anmeldung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Anmeldung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
} SaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;
}
IsEditing = false; IsEditing = false;
IsCreating = false; IsCreating = false;
DeliveryAncmtList.IsEnabled = true; DeliveryAncmtList.IsEnabled = true;

View File

@ -201,14 +201,20 @@ namespace Elwig.Windows {
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) { private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
SaveButton.IsEnabled = false;
try { try {
await ViewModel.UpdateDeliverySchedule(ViewModel.SelectedDeliverySchedule?.Year, ViewModel.SelectedDeliverySchedule?.DsNr); await ViewModel.UpdateDeliverySchedule(ViewModel.SelectedDeliverySchedule?.Year, ViewModel.SelectedDeliverySchedule?.DsNr);
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Leseplan aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Leseplan aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
} SaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;
}
IsEditing = false; IsEditing = false;
IsCreating = false; IsCreating = false;
DeliveryScheduleList.IsEnabled = true; DeliveryScheduleList.IsEnabled = true;

View File

@ -391,14 +391,22 @@ namespace Elwig.Windows {
} }
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) { private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
int? mgnr = null; Mouse.OverrideCursor = Cursors.AppStarting;
SaveButton.IsEnabled = false;
int mgnr;
try { try {
mgnr = await ViewModel.UpdateMember(ViewModel.SelectedMember?.MgNr); mgnr = await ViewModel.UpdateMember(ViewModel.SelectedMember?.MgNr);
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
SaveButton.IsEnabled = true;
return;
} finally {
Mouse.OverrideCursor = null;
} }
IsEditing = false; IsEditing = false;
IsCreating = false; IsCreating = false;
MemberList.IsEnabled = true; MemberList.IsEnabled = true;