[#16] Dialogs: Add DeleteMemberDialog
All checks were successful
Test / Run tests (push) Successful in 2m0s
All checks were successful
Test / Run tests (push) Successful in 2m0s
This commit is contained in:
64
Elwig/Dialogs/DeleteMemberDialog.xaml
Normal file
64
Elwig/Dialogs/DeleteMemberDialog.xaml
Normal file
@ -0,0 +1,64 @@
|
||||
<Window x:Class="Elwig.Dialogs.DeleteMemberDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Elwig.Dialogs"
|
||||
ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
DataContext="{Binding RelativeSource={RelativeSource Self}}"
|
||||
Title="Mitglied löschen" Height="280" Width="400">
|
||||
<Window.Resources>
|
||||
<Style TargetType="Label">
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="Padding" Value="2,4,2,4"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
</Style>
|
||||
<Style TargetType="TextBox">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="FontSize" Value="14"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
<Setter Property="TextWrapping" Value="NoWrap"/>
|
||||
</Style>
|
||||
<Style TargetType="CheckBox">
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
<Setter Property="Width" Value="100"/>
|
||||
<Setter Property="Height" Value="25"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
|
||||
<TextBlock TextAlignment="Center" Margin="10,10,10,10" VerticalAlignment="Top">
|
||||
Bei Bestätigung wird das Mitglied samt zugehöriger Daten<LineBreak/>
|
||||
<Bold>unwiderruflich gelöscht!</Bold> Wenn möglich sollte stattdessen<LineBreak/>
|
||||
der Status des Mitglieds auf <Italic>Inaktiv</Italic> gesetzt werden!
|
||||
</TextBlock>
|
||||
|
||||
<Label Content="Name u. MgNr. wiederholen:" Margin="10,60,10,10" HorizontalAlignment="Center"/>
|
||||
<TextBox x:Name="NameInput" Margin="10,85,10,10"
|
||||
TextChanged="NameInput_TextChanged"/>
|
||||
|
||||
<Label Content="Beim Löschen müssen folgende Daten auch gelöscht werden:" Margin="10,120,10,10"/>
|
||||
<CheckBox x:Name="AreaComInput" Content="Flächenbindungen" Margin="40,145,0,0"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"
|
||||
IsChecked="{Binding DeleteAreaComs}"/>
|
||||
<CheckBox x:Name="DeliveryInput" Content="Lieferungen" Margin="40,165,0,0"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"
|
||||
IsChecked="{Binding DeleteDeliveries}"/>
|
||||
<CheckBox x:Name="PaymentInput" Content="Auszahlungsdaten" Margin="40,185,0,0"
|
||||
Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"
|
||||
IsChecked="{Binding DeletePaymentData}"/>
|
||||
|
||||
<Button x:Name="ConfirmButton" Content="Bestätigen" Margin="10,10,115,10" Grid.Column="1" IsEnabled="False"
|
||||
Click="ConfirmButton_Click"/>
|
||||
<Button x:Name="CancelButton" Content="Abbrechen" Margin="10,10,10,10" Grid.Column="1" IsCancel="True"/>
|
||||
</Grid>
|
||||
</Window>
|
48
Elwig/Dialogs/DeleteMemberDialog.xaml.cs
Normal file
48
Elwig/Dialogs/DeleteMemberDialog.xaml.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Elwig.Dialogs {
|
||||
public partial class DeleteMemberDialog : Window {
|
||||
|
||||
protected string[] NameParts;
|
||||
|
||||
public bool DeleteAreaComs { get; set; }
|
||||
public bool DeleteDeliveries { get; set; }
|
||||
public bool DeletePaymentData { get; set; }
|
||||
|
||||
public DeleteMemberDialog(int mgnr, string name, int numAreaComs, int numDeliveries, int numCredits) {
|
||||
NameParts = name.ToLower().Split(' ').Where(p => p.Length > 0).Append($"{mgnr}").ToArray();
|
||||
InitializeComponent();
|
||||
Title += " - " + name;
|
||||
AreaComInput.IsEnabled = numAreaComs != 0;
|
||||
AreaComInput.Content += $" ({numAreaComs:N0})";
|
||||
DeliveryInput.IsEnabled = numDeliveries != 0;
|
||||
DeliveryInput.Content += $" ({numDeliveries:N0})";
|
||||
PaymentInput.IsEnabled = numCredits != 0;
|
||||
PaymentInput.Content += $" ({numCredits:N0})";
|
||||
}
|
||||
|
||||
private void NameInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
Update();
|
||||
}
|
||||
|
||||
private void CheckBox_Changed(object sender, RoutedEventArgs evt) {
|
||||
Update();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
var t = NameInput.Text.ToLower();
|
||||
ConfirmButton.IsEnabled =
|
||||
(!AreaComInput.IsEnabled || DeleteAreaComs) &&
|
||||
(!DeliveryInput.IsEnabled || DeleteDeliveries) &&
|
||||
(!PaymentInput.IsEnabled || DeletePaymentData) &&
|
||||
NameParts.All(t.Contains);
|
||||
}
|
||||
|
||||
private void ConfirmButton_Click(object sender, RoutedEventArgs evt) {
|
||||
DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -166,6 +166,9 @@ namespace Elwig.Models.Entities {
|
||||
[InverseProperty(nameof(Delivery.Member))]
|
||||
public virtual ICollection<Delivery> Deliveries { get; private set; } = null!;
|
||||
|
||||
[InverseProperty(nameof(Credit.Member))]
|
||||
public virtual ICollection<Credit> Credits { get; private set; } = null!;
|
||||
|
||||
[InverseProperty(nameof(MemberTelNr.Member))]
|
||||
public virtual ICollection<MemberTelNr> TelephoneNumbers { get; private set; } = null!;
|
||||
|
||||
|
@ -15,6 +15,7 @@ using Elwig.Models.Dtos;
|
||||
using Elwig.Helpers.Export;
|
||||
using Microsoft.Win32;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Dialogs;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class MemberAdminWindow : AdministrationWindow {
|
||||
@ -454,20 +455,38 @@ namespace Elwig.Windows {
|
||||
if (MemberList.SelectedItem is not Member m)
|
||||
return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll das Mitglied \"{m.AdministrativeName}\" (MgNr. {m.MgNr}) wirklich unwiderruflich gelöscht werden?\n" +
|
||||
$"Sämtliche Lieferungen und Flächenbindungen dieses Mitglieds werden auch gelöscht!",
|
||||
"Mitglied löschen", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
|
||||
if (r == MessageBoxResult.OK) {
|
||||
int areaComs = 0, deliveries = 0, credits = 0;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
var l = (await ctx.Members.FindAsync(m.MgNr))!;
|
||||
areaComs = l.AreaCommitments.Count;
|
||||
deliveries = l.Deliveries.Count;
|
||||
credits = l.Credits.Count;
|
||||
}
|
||||
var d = new DeleteMemberDialog(m.MgNr, m.AdministrativeName, areaComs, deliveries, credits);
|
||||
if (d.ShowDialog() == true) {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
try {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
ctx.Remove(m);
|
||||
var l = (await ctx.Members.FindAsync(m.MgNr))!;
|
||||
if (d.DeletePaymentData) {
|
||||
ctx.RemoveRange(l.Credits);
|
||||
}
|
||||
if (d.DeleteDeliveries) {
|
||||
ctx.RemoveRange(l.Deliveries);
|
||||
}
|
||||
if (d.DeleteAreaComs) {
|
||||
ctx.RemoveRange(l.AreaCommitments);
|
||||
}
|
||||
ctx.Remove(l);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
await App.HintContextChange();
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show(exc.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
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 löschen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
Mouse.OverrideCursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user