[#56] Windows: Fail gracefully while saving
All checks were successful
Test / Run tests (push) Successful in 2m11s
All checks were successful
Test / Run tests (push) Successful in 2m11s
This commit is contained in:
@ -494,41 +494,35 @@ namespace Elwig.Services {
|
||||
WeighingReason = vm.ManualWeighingReason,
|
||||
};
|
||||
|
||||
try {
|
||||
if (oldDelivery != null && ctx.Entry(oldDelivery) is EntityEntry<Delivery> entry) {
|
||||
entry.State = EntityState.Detached;
|
||||
}
|
||||
if (!deliveryNew) {
|
||||
ctx.Update(d);
|
||||
} else {
|
||||
ctx.Add(d);
|
||||
}
|
||||
if (!partNew) {
|
||||
ctx.Update(p);
|
||||
} else {
|
||||
ctx.Add(p);
|
||||
}
|
||||
|
||||
ctx.UpdateDeliveryPartModifiers(p, await ctx.DeliveryPartModifiers
|
||||
.Where(m => m.Year == p.Year && m.DId == p.DId && m.DPNr == p.DPNr)
|
||||
.Select(m => m.Modifier)
|
||||
.ToListAsync(), vm.Modifiers);
|
||||
|
||||
if (originalMgNr != null && originalMgNr.Value != d.MgNr) {
|
||||
// update origin (KgNr), if default is selected
|
||||
var newKgNr = (await ctx.Members.FindAsync(d.MgNr))?.DefaultKgNr;
|
||||
foreach (var part in d.Parts.Where(part => part.DPNr != dpnr && part.KgNr == originalMemberKgNr)) {
|
||||
part.KgNr = newKgNr;
|
||||
ctx.Update(part);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if (oldDelivery != null && ctx.Entry(oldDelivery) is EntityEntry<Delivery> entry) {
|
||||
entry.State = EntityState.Detached;
|
||||
}
|
||||
if (!deliveryNew) {
|
||||
ctx.Update(d);
|
||||
} else {
|
||||
ctx.Add(d);
|
||||
}
|
||||
if (!partNew) {
|
||||
ctx.Update(p);
|
||||
} else {
|
||||
ctx.Add(p);
|
||||
}
|
||||
|
||||
ctx.UpdateDeliveryPartModifiers(p, await ctx.DeliveryPartModifiers
|
||||
.Where(m => m.Year == p.Year && m.DId == p.DId && m.DPNr == p.DPNr)
|
||||
.Select(m => m.Modifier)
|
||||
.ToListAsync(), vm.Modifiers);
|
||||
|
||||
if (originalMgNr != null && originalMgNr.Value != d.MgNr) {
|
||||
// update origin (KgNr), if default is selected
|
||||
var newKgNr = (await ctx.Members.FindAsync(d.MgNr))?.DefaultKgNr;
|
||||
foreach (var part in d.Parts.Where(part => part.DPNr != dpnr && part.KgNr == originalMemberKgNr)) {
|
||||
part.KgNr = newKgNr;
|
||||
ctx.Update(part);
|
||||
}
|
||||
}
|
||||
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
@ -226,14 +226,22 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void AreaCommitmentSaveButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
int? fbnr = null;
|
||||
AreaCommitmentSaveButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
|
||||
int fbnr;
|
||||
try {
|
||||
fbnr = await ViewModel.UpdateAreaCommitment((AreaCommitmentList.SelectedItem as AreaCom)?.FbNr);
|
||||
} 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, "Flächenbindung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
AreaCommitmentSaveButton.IsEnabled = true;
|
||||
return;
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
AreaCommitmentList.IsEnabled = true;
|
||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class BaseDataWindow : AdministrationWindow {
|
||||
@ -316,12 +317,19 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
SaveButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
|
||||
try {
|
||||
await Save();
|
||||
} 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, "Stammdaten aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
SaveButton.IsEnabled = true;
|
||||
return;
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
IsEditing = false;
|
||||
|
@ -661,6 +661,9 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||
SaveButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
|
||||
try {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
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;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Auszahlungsvariante speichern", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
SaveButton.IsEnabled = true;
|
||||
return;
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
LockContext = true;
|
||||
SetHasChanged(false);
|
||||
}
|
||||
|
@ -694,14 +694,28 @@ namespace Elwig.Windows {
|
||||
NewDeliveryPartButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
DeliveryPartList.IsEnabled = false;
|
||||
var p = await ViewModel.UpdateDeliveryPart(
|
||||
(DeliveryList.SelectedItem as Delivery)?.Year,
|
||||
(DeliveryList.SelectedItem as Delivery)?.DId,
|
||||
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
|
||||
InputHasChanged(DateInput),
|
||||
InputHasChanged(TimeInput),
|
||||
!InputIsNotDefault(TimeInput)
|
||||
);
|
||||
|
||||
DeliveryPart? p;
|
||||
try {
|
||||
p = await ViewModel.UpdateDeliveryPart(
|
||||
(DeliveryList.SelectedItem as Delivery)?.Year,
|
||||
(DeliveryList.SelectedItem as Delivery)?.DId,
|
||||
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
|
||||
InputHasChanged(DateInput),
|
||||
InputHasChanged(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();
|
||||
await RefreshList();
|
||||
await RefreshDeliveryParts();
|
||||
@ -718,14 +732,28 @@ namespace Elwig.Windows {
|
||||
NewDeliveryPartButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
DeliveryPartList.IsEnabled = false;
|
||||
var p = await ViewModel.UpdateDeliveryPart(
|
||||
(DeliveryList.SelectedItem as Delivery)?.Year,
|
||||
(DeliveryList.SelectedItem as Delivery)?.DId,
|
||||
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
|
||||
InputHasChanged(DateInput),
|
||||
InputHasChanged(TimeInput),
|
||||
!InputIsNotDefault(TimeInput)
|
||||
);
|
||||
|
||||
DeliveryPart? p;
|
||||
try {
|
||||
p = await ViewModel.UpdateDeliveryPart(
|
||||
(DeliveryList.SelectedItem as Delivery)?.Year,
|
||||
(DeliveryList.SelectedItem as Delivery)?.DId,
|
||||
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
|
||||
InputHasChanged(DateInput),
|
||||
InputHasChanged(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();
|
||||
await RefreshList();
|
||||
await RefreshDeliveryParts();
|
||||
@ -743,6 +771,7 @@ namespace Elwig.Windows {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
Mouse.OverrideCursor = null;
|
||||
DeliveryList.SelectedItem = null;
|
||||
await RenewContext();
|
||||
@ -940,22 +969,31 @@ namespace Elwig.Windows {
|
||||
SaveButton.IsEnabled = false;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
|
||||
DeliveryPart? p;
|
||||
try {
|
||||
p = await ViewModel.UpdateDeliveryPart(
|
||||
(DeliveryList.SelectedItem as Delivery)?.Year,
|
||||
(DeliveryList.SelectedItem as Delivery)?.DId,
|
||||
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
|
||||
InputHasChanged(DateInput),
|
||||
InputHasChanged(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;
|
||||
}
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
DeliveryList.IsEnabled = true;
|
||||
DeliveryPartList.IsEnabled = true;
|
||||
|
||||
var p = await ViewModel.UpdateDeliveryPart(
|
||||
(DeliveryList.SelectedItem as Delivery)?.Year,
|
||||
(DeliveryList.SelectedItem as Delivery)?.DId,
|
||||
(DeliveryPartList.SelectedItem as DeliveryPart)?.DPNr,
|
||||
InputHasChanged(DateInput),
|
||||
InputHasChanged(TimeInput),
|
||||
!InputIsNotDefault(TimeInput)
|
||||
);
|
||||
|
||||
Mouse.OverrideCursor = null;
|
||||
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
|
@ -341,6 +341,8 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
SaveButton.IsEnabled = false;
|
||||
|
||||
int year = -1, dsnr = -1, mgnr = -1;
|
||||
string? sortid = null;
|
||||
try {
|
||||
@ -350,8 +352,12 @@ namespace Elwig.Windows {
|
||||
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, "Anmeldung aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
SaveButton.IsEnabled = true;
|
||||
return;
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
DeliveryAncmtList.IsEnabled = true;
|
||||
|
@ -201,14 +201,20 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
SaveButton.IsEnabled = false;
|
||||
|
||||
try {
|
||||
await ViewModel.UpdateDeliverySchedule(ViewModel.SelectedDeliverySchedule?.Year, ViewModel.SelectedDeliverySchedule?.DsNr);
|
||||
} 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, "Leseplan aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
SaveButton.IsEnabled = true;
|
||||
return;
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
DeliveryScheduleList.IsEnabled = true;
|
||||
|
@ -391,14 +391,22 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void SaveButton_Click(object? sender, RoutedEventArgs? evt) {
|
||||
int? mgnr = null;
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
SaveButton.IsEnabled = false;
|
||||
|
||||
int mgnr;
|
||||
try {
|
||||
mgnr = await ViewModel.UpdateMember(ViewModel.SelectedMember?.MgNr);
|
||||
} 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, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
SaveButton.IsEnabled = true;
|
||||
return;
|
||||
} finally {
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
MemberList.IsEnabled = true;
|
||||
|
Reference in New Issue
Block a user