Added Add/Edit function to MemberListWindow
This commit is contained in:
@ -19,5 +19,15 @@
|
|||||||
<TextBlock Text=")"/>
|
<TextBlock Text=")"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
<DataTemplate x:Key="BranchTemplate">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding Name}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
<DataTemplate x:Key="KgTemplate">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding Name}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
20
WGneu/Models/Branch.cs
Normal file
20
WGneu/Models/Branch.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WGneu.Models
|
||||||
|
{
|
||||||
|
[Table("branch"), PrimaryKey("ZwstId")]
|
||||||
|
public class Branch
|
||||||
|
{
|
||||||
|
[Column("zwstid")]
|
||||||
|
public string ZwstId { get; set; }
|
||||||
|
|
||||||
|
[Column("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ namespace WGneu.Models
|
|||||||
public string FamilyName { get; set; }
|
public string FamilyName { get; set; }
|
||||||
|
|
||||||
[Column("zwstid")]
|
[Column("zwstid")]
|
||||||
public string Zweigstelle { get; set; }
|
public string ZwstId { get; set; }
|
||||||
|
|
||||||
[Column("country")]
|
[Column("country")]
|
||||||
public string CountryCode { get; set; }
|
public string CountryCode { get; set; }
|
||||||
@ -43,5 +43,8 @@ namespace WGneu.Models
|
|||||||
|
|
||||||
[ForeignKey("DefaultKgNr")]
|
[ForeignKey("DefaultKgNr")]
|
||||||
public virtual AT_Kg DefaultKg { get; set; }
|
public virtual AT_Kg DefaultKg { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ZwstId")]
|
||||||
|
public virtual Branch Branch { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
WGneu/Models/WbKg.cs
Normal file
23
WGneu/Models/WbKg.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WGneu.Models
|
||||||
|
{
|
||||||
|
[Table("wb_kg"), PrimaryKey("KgNr")]
|
||||||
|
public class WbKg
|
||||||
|
{
|
||||||
|
[Column("kgnr")]
|
||||||
|
public int KgNr { get; set; }
|
||||||
|
|
||||||
|
[Column("glnr")]
|
||||||
|
public int? GlNr { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("KgNr")]
|
||||||
|
public virtual AT_Kg Kg { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,8 @@ namespace WGneu
|
|||||||
public DbSet<AT_Ort> Orte { get; set; }
|
public DbSet<AT_Ort> Orte { get; set; }
|
||||||
public DbSet<AT_Plz> Postleitzahlen { get; set; }
|
public DbSet<AT_Plz> Postleitzahlen { get; set; }
|
||||||
public DbSet<PostalDest> PostalDestinations { get; set; }
|
public DbSet<PostalDest> PostalDestinations { get; set; }
|
||||||
|
public DbSet<Branch> Branches { get; set; }
|
||||||
|
public DbSet<WbKg> WbKgs { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<Window x:Class="WGneu.Windows.MemberAddWindow"
|
|
||||||
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:WGneu.Windows"
|
|
||||||
mc:Ignorable="d"
|
|
||||||
Title="Mitglied anlegen" Height="450" Width="800"
|
|
||||||
Loaded="Window_Loaded">
|
|
||||||
<Grid>
|
|
||||||
<Label Content="MNR:" HorizontalAlignment="Left" Margin="392,137,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="MgNr" HorizontalAlignment="Left" Margin="475,141,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Vorname:" HorizontalAlignment="Left" Margin="392,160,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="GivenName" HorizontalAlignment="Left" Margin="475,164,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Nachname:" HorizontalAlignment="Left" Margin="392,182,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="FamilyName" HorizontalAlignment="Left" Margin="475,187,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Zweigstelle:" HorizontalAlignment="Left" Margin="392,206,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="Zweigstelle" HorizontalAlignment="Left" Margin="475,210,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Country:" HorizontalAlignment="Left" Margin="392,229,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="Country" HorizontalAlignment="Left" Margin="475,233,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="PostalDest:" HorizontalAlignment="Left" Margin="392,252,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="PostalDest" HorizontalAlignment="Left" Margin="475,256,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Address:" HorizontalAlignment="Left" Margin="392,275,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="Address" HorizontalAlignment="Left" Margin="475,279,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="DefaultKgnr:" HorizontalAlignment="Left" Margin="392,298,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="DefaultKgnr" HorizontalAlignment="Left" Margin="475,302,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Button x:Name="Save_Button" Content="Save" HorizontalAlignment="Left" Margin="682,199,0,0" VerticalAlignment="Top" Click="Save_Button_Click"/>
|
|
||||||
<Label x:Name="SaveError" Content="" HorizontalAlignment="Left" Height="32" Margin="639,233,0,0" VerticalAlignment="Top" Width="115"/>
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
@ -1,81 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using WGneu.Models;
|
|
||||||
|
|
||||||
|
|
||||||
namespace WGneu.Windows
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Interaction logic for MemberAddWindow.xaml
|
|
||||||
/// </summary>
|
|
||||||
public partial class MemberAddWindow : Window
|
|
||||||
{
|
|
||||||
private WgContext _context;
|
|
||||||
private readonly Member member = new Member();
|
|
||||||
public event EventHandler Event;
|
|
||||||
|
|
||||||
public MemberAddWindow(WgContext context)
|
|
||||||
{
|
|
||||||
this._context = context;
|
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
MgNr.Text = member.MgNr.ToString();
|
|
||||||
GivenName.Text = member.GivenName;
|
|
||||||
FamilyName.Text = member.FamilyName;
|
|
||||||
Zweigstelle.Text = member.Zweigstelle;
|
|
||||||
Country.Text = member.Country.Alpha2;
|
|
||||||
// PostalDest.Text= member.PostalDest;
|
|
||||||
Address.Text = member.Address;
|
|
||||||
DefaultKgnr.Text = member.DefaultKg.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Save_Button_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
member.MgNr = Int32.Parse(MgNr.Text);
|
|
||||||
member.GivenName = GivenName.Text;
|
|
||||||
member.FamilyName = FamilyName.Text;
|
|
||||||
member.Zweigstelle = Zweigstelle.Text;
|
|
||||||
member.Country.Alpha2 = Country.Text;
|
|
||||||
// member.PostalDest = PostalDest.Text;
|
|
||||||
member.Address= Address.Text;
|
|
||||||
member.DefaultKg.KgNr = Int32.Parse(DefaultKgnr.Text);
|
|
||||||
|
|
||||||
_context.Add(member);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_context.SaveChanges();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
SaveError.Content = "There was an Error!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.Call_Event();
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Call_Event()
|
|
||||||
{
|
|
||||||
if (this.Event != null)
|
|
||||||
{
|
|
||||||
this.Event(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
<Window x:Class="WGneu.Windows.MemberEditWindow"
|
|
||||||
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:WGneu.Windows"
|
|
||||||
mc:Ignorable="d"
|
|
||||||
Title="MemberEditWindow" Height="450" Width="800"
|
|
||||||
Loaded="Window_Loaded">
|
|
||||||
<Grid>
|
|
||||||
<Label Content="MNR:" HorizontalAlignment="Left" Margin="392,137,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="MgNr" HorizontalAlignment="Left" Margin="475,141,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Vorname:" HorizontalAlignment="Left" Margin="392,160,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="GivenName" HorizontalAlignment="Left" Margin="475,164,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Nachname:" HorizontalAlignment="Left" Margin="392,182,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="FamilyName" HorizontalAlignment="Left" Margin="475,187,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Zweigstelle:" HorizontalAlignment="Left" Margin="392,206,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="Zweigstelle" HorizontalAlignment="Left" Margin="475,210,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Country:" HorizontalAlignment="Left" Margin="392,229,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="Country" HorizontalAlignment="Left" Margin="475,233,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="PostalDest:" HorizontalAlignment="Left" Margin="392,252,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="PostalDest" HorizontalAlignment="Left" Margin="475,256,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="Address:" HorizontalAlignment="Left" Margin="392,275,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="Address" HorizontalAlignment="Left" Margin="475,279,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Label Content="DefaultKgnr:" HorizontalAlignment="Left" Margin="392,298,0,0" VerticalAlignment="Top"/>
|
|
||||||
<TextBox x:Name="DefaultKgnr" HorizontalAlignment="Left" Margin="475,302,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
|
|
||||||
<Button x:Name="Save_Button" Content="Save" HorizontalAlignment="Left" Margin="662,194,0,0" VerticalAlignment="Top" Click="Save_Button_Click"/>
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
@ -1,74 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using WGneu.Models;
|
|
||||||
|
|
||||||
|
|
||||||
namespace WGneu.Windows
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Interaction logic for MemberEditWindow.xaml
|
|
||||||
/// </summary>
|
|
||||||
public partial class MemberEditWindow : Window
|
|
||||||
{
|
|
||||||
private WgContext _context;
|
|
||||||
private readonly Member member;
|
|
||||||
public event EventHandler Event;
|
|
||||||
|
|
||||||
public MemberEditWindow(Member member, WgContext context)
|
|
||||||
{
|
|
||||||
this._context= context;
|
|
||||||
this.member = member;
|
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
MgNr.Text = member.MgNr.ToString();
|
|
||||||
GivenName.Text = member.GivenName;
|
|
||||||
FamilyName.Text = member.FamilyName;
|
|
||||||
Zweigstelle.Text = member.Zweigstelle;
|
|
||||||
// Country.Text = member.Country;
|
|
||||||
// PostalDest.Text = member.PostalDest;
|
|
||||||
Address.Text = member.Address;
|
|
||||||
// DefaultKgnr.Text = member.DefaultKgnr.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Save_Button_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
member.MgNr = Int32.Parse(MgNr.Text);
|
|
||||||
member.GivenName = GivenName.Text;
|
|
||||||
member.FamilyName = FamilyName.Text;
|
|
||||||
member.Zweigstelle = Zweigstelle.Text;
|
|
||||||
// member.Country = Country.Text;
|
|
||||||
// member.PostalDest = PostalDest.Text;
|
|
||||||
member.Address = Address.Text;
|
|
||||||
// member.DefaultKgnr = Int32.Parse(DefaultKgnr.Text);
|
|
||||||
|
|
||||||
_context.Update(member);
|
|
||||||
_context.SaveChanges();
|
|
||||||
this.Call_Event();
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Call_Event()
|
|
||||||
{
|
|
||||||
if (this.Event != null)
|
|
||||||
{
|
|
||||||
this.Event(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,20 +10,49 @@
|
|||||||
Title="Mitglieder" Height="500" Width="800" MinHeight="500" MinWidth="800"
|
Title="Mitglieder" Height="500" Width="800" MinHeight="500" MinWidth="800"
|
||||||
Loaded="Window_Loaded">
|
Loaded="Window_Loaded">
|
||||||
<Grid>
|
<Grid>
|
||||||
<DataGrid x:Name="MemberList" AutoGenerateColumns="False" CanUserAddRows="False"
|
<DataGrid x:Name="MemberList" AutoGenerateColumns="False" CanUserAddRows="False" HeadersVisibility="Column" IsReadOnly="True"
|
||||||
SelectionChanged="MemberList_SelectionChanged" VerticalAlignment="Top" Margin="10,10,540,0" FontSize="14" HeadersVisibility="Column" IsReadOnly="True">
|
SelectionChanged="MemberList_SelectionChanged"
|
||||||
|
Margin="10,10,0,47.5" FontSize="14" Width="310" HorizontalAlignment="Left">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Header="Nr." Binding="{Binding MgNr}" Width="50"/>
|
<DataGridTextColumn Header="MgNr." Binding="{Binding MgNr}" Width="50"/>
|
||||||
<DataGridTextColumn Header="Nachname" Binding="{Binding FamilyName}" Width="100"/>
|
<DataGridTextColumn Header="Nachname" Binding="{Binding FamilyName}" Width="100"/>
|
||||||
<DataGridTextColumn Header="Vorname" Binding="{Binding GivenName}" Width="*"/>
|
<DataGridTextColumn Header="Vorname" Binding="{Binding GivenName}" Width="*"/>
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
<TextBox x:Name="MgNr" HorizontalAlignment="Left" Margin="351,26,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183" IsReadOnly="True" FontSize="14"/>
|
|
||||||
<TextBox x:Name="GivenName" HorizontalAlignment="Left" Margin="351,67,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183" IsReadOnly="True"/>
|
<Button x:Name="NewMemberButton" Content="Neu" Click="NewMemberButton_Click"
|
||||||
<TextBox x:Name="FamilyName" HorizontalAlignment="Left" Margin="351,129,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183" IsReadOnly="True"/>
|
HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10,0,0,10" FontSize="14" Padding="3,3,3,3" Width="100" Height="27.5"/>
|
||||||
<Button x:Name="Edit_Member" Content="Mitglied bearbeiten" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="130,407,0,20" Click="Edit_Member_Button_Click" IsEnabled="False" FontSize="14" Padding="3,3,3,3"/>
|
<Button x:Name="EditMemberButton" Content="Bearbeiten" Click="EditMemberButton_Click" IsEnabled="False"
|
||||||
<Button x:Name="Add_Member" Content="Mitglied erstellen" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10,407,0,20" Click="Add_Member_Button_Click" FontSize="14" Padding="3,3,3,3"/>
|
HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="115,0,0,10" FontSize="14" Padding="3,3,3,3" Width="100" Height="27.5"/>
|
||||||
<TextBox x:Name="Plz" HorizontalAlignment="Left" Margin="351,191,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="Plz_TextChanged"/>
|
<Button x:Name="DeleteMemberButton" Content="Löschen" Click="DeleteMemberButton_Click" IsEnabled="False"
|
||||||
<ComboBox x:Name="Ort" HorizontalAlignment="Left" Margin="498,189,0,0" VerticalAlignment="Top" Width="200" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}"/>
|
HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="220,0,0,10" FontSize="14" Padding="3,3,3,3" Width="100" Height="27.5"/>
|
||||||
|
|
||||||
|
<Button x:Name="SaveButton" Content="Speichern" Click="SaveButton_Click" IsEnabled="False" Visibility="Hidden"
|
||||||
|
HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10,0,0,10" FontSize="14" Padding="3,3,3,3" Width="100" Height="27.5"/>
|
||||||
|
<Button x:Name="ResetButton" Content="Zurücksetzen" Click="ResetButton_Click" IsEnabled="False" Visibility="Hidden"
|
||||||
|
HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="115,0,0,10" FontSize="14" Padding="3,3,3,3" Width="100" Height="27.5"/>
|
||||||
|
<Button x:Name="CancelButton" Content="Abbrechen" Click="CancelButton_Click" IsEnabled="False" Visibility="Hidden"
|
||||||
|
HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="220,0,0,10" FontSize="14" Padding="3,3,3,3" Width="100" Height="27.5"/>
|
||||||
|
|
||||||
|
<TextBox x:Name="MgNrInput" IsReadOnly="True"
|
||||||
|
HorizontalAlignment="Left" Margin="351,26,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183" FontSize="14"/>
|
||||||
|
<TextBox x:Name="GivenNameInput" IsReadOnly="True"
|
||||||
|
HorizontalAlignment="Left" Margin="351,52,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183"/>
|
||||||
|
<TextBox x:Name="FamilyNameInput" IsReadOnly="True"
|
||||||
|
HorizontalAlignment="Left" Margin="351,75,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183"/>
|
||||||
|
|
||||||
|
<TextBox x:Name="AddressInput" IsReadOnly="True"
|
||||||
|
HorizontalAlignment="Left" Margin="351,166,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="183"/>
|
||||||
|
<TextBox x:Name="PlzInput" IsReadOnly="True"
|
||||||
|
TextChanged="PlzInput_TextChanged"
|
||||||
|
HorizontalAlignment="Left" Margin="351,191,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="60"/>
|
||||||
|
<ComboBox x:Name="OrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
||||||
|
HorizontalAlignment="Left" Margin="416,189,0,0" VerticalAlignment="Top" Width="200"/>
|
||||||
|
|
||||||
|
<ComboBox x:Name="BranchInput" ItemTemplate="{StaticResource BranchTemplate}" IsEnabled="False"
|
||||||
|
HorizontalAlignment="Left" Margin="351,242,0,0" VerticalAlignment="Top" Width="120"/>
|
||||||
|
<ComboBox x:Name="DefaultKgInput" ItemTemplate="{StaticResource KgTemplate}" IsEnabled="False"
|
||||||
|
HorizontalAlignment="Left" Margin="351,269,0,0" VerticalAlignment="Top" Width="120"/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@ -18,12 +21,11 @@ using WGneu.Models;
|
|||||||
|
|
||||||
namespace WGneu.Windows
|
namespace WGneu.Windows
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Interaktionslogik für Window1.xaml
|
|
||||||
/// </summary>
|
|
||||||
public partial class MemberListWindow : Window
|
public partial class MemberListWindow : Window
|
||||||
{
|
{
|
||||||
private readonly WgContext _context = new WgContext();
|
private bool isEditing = false;
|
||||||
|
private bool isCreating = false;
|
||||||
|
private readonly WgContext context = new();
|
||||||
|
|
||||||
public MemberListWindow()
|
public MemberListWindow()
|
||||||
{
|
{
|
||||||
@ -32,79 +34,255 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Refresh_Member_Data();
|
RefreshMemberList();
|
||||||
|
BranchInput.ItemsSource = context.Branches.ToList();
|
||||||
|
DefaultKgInput.ItemsSource = context.WbKgs.Select(k => k.Kg).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClosing(CancelEventArgs e)
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
{
|
{
|
||||||
_context.Dispose();
|
context.Dispose();
|
||||||
base.OnClosing(e);
|
base.OnClosing(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RefreshMemberList()
|
||||||
|
{
|
||||||
|
context.Members.Load();
|
||||||
|
MemberList.ItemsSource = context.Members.ToList();
|
||||||
|
|
||||||
|
Member m = (Member)MemberList.SelectedItem;
|
||||||
|
if (m != null)
|
||||||
|
{
|
||||||
|
EditMemberButton.IsEnabled = true;
|
||||||
|
FillInputs(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void MemberList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void MemberList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
Member m = (Member) MemberList.SelectedItem;
|
Member m = (Member) MemberList.SelectedItem;
|
||||||
MgNr.Text = m.MgNr.ToString();
|
if (m == null)
|
||||||
GivenName.Text = m.GivenName;
|
return;
|
||||||
FamilyName.Text = m.FamilyName;
|
|
||||||
|
|
||||||
AT_Plz? p = m.PostalDest.Plz(_context);
|
FillInputs(m);
|
||||||
|
EditMemberButton.IsEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlzInput_TextChanged(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit))
|
||||||
|
{
|
||||||
|
int plz = int.Parse(PlzInput.Text);
|
||||||
|
var o = context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
||||||
|
OrtInput.ItemsSource = o;
|
||||||
|
OrtInput.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NewMemberButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
isCreating = true;
|
||||||
|
MemberList.IsEnabled = false;
|
||||||
|
|
||||||
|
// TODO fill input fields
|
||||||
|
|
||||||
|
ClearInputs();
|
||||||
|
MgNrInput.Text = (context.Members.Select(m => m.MgNr).Max() + 1).ToString();
|
||||||
|
|
||||||
|
HideNewEditDeleteButtons();
|
||||||
|
ShowSaveResetCancelButtons();
|
||||||
|
UnlockInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EditMemberButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (MemberList.SelectedItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isEditing = true;
|
||||||
|
MemberList.IsEnabled = false;
|
||||||
|
|
||||||
|
HideNewEditDeleteButtons();
|
||||||
|
ShowSaveResetCancelButtons();
|
||||||
|
UnlockInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteMemberButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// TODO delete member button
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// TODO only allow to click button, if values were checked
|
||||||
|
|
||||||
|
int originalMgNr = -1;
|
||||||
|
Member? m = null;
|
||||||
|
if (isEditing)
|
||||||
|
{
|
||||||
|
m = (Member)MemberList.SelectedItem;
|
||||||
|
originalMgNr = m.MgNr;
|
||||||
|
}
|
||||||
|
else if (isCreating)
|
||||||
|
{
|
||||||
|
m = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
m.MgNr = int.Parse(MgNrInput.Text);
|
||||||
|
m.GivenName = GivenNameInput.Text;
|
||||||
|
m.FamilyName = FamilyNameInput.Text;
|
||||||
|
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
|
||||||
|
m.CountryCode = "AT";
|
||||||
|
m.PostalDestId = ((AT_Plz)OrtInput.SelectedItem).Id;
|
||||||
|
m.Address = AddressInput.Text;
|
||||||
|
m.DefaultKgNr = ((AT_Kg)DefaultKgInput.SelectedItem).KgNr;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isEditing)
|
||||||
|
{
|
||||||
|
context.Update(m);
|
||||||
|
}
|
||||||
|
else if (isCreating)
|
||||||
|
{
|
||||||
|
context.Add(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
"Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message.ToString(),
|
||||||
|
"Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
isEditing = false;
|
||||||
|
isCreating = false;
|
||||||
|
MemberList.IsEnabled = true;
|
||||||
|
HideSaveResetCancelButtons();
|
||||||
|
ShowNewEditDeleteButtons();
|
||||||
|
LockInputs();
|
||||||
|
RefreshMemberList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// TODO reset button
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
isEditing = false;
|
||||||
|
isCreating = false;
|
||||||
|
MemberList.IsEnabled = true;
|
||||||
|
HideSaveResetCancelButtons();
|
||||||
|
ShowNewEditDeleteButtons();
|
||||||
|
LockInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowSaveResetCancelButtons()
|
||||||
|
{
|
||||||
|
SaveButton.IsEnabled = true;
|
||||||
|
ResetButton.IsEnabled = false;
|
||||||
|
CancelButton.IsEnabled = true;
|
||||||
|
SaveButton.Visibility = Visibility.Visible;
|
||||||
|
ResetButton.Visibility = Visibility.Visible;
|
||||||
|
CancelButton.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HideSaveResetCancelButtons()
|
||||||
|
{
|
||||||
|
SaveButton.IsEnabled = false;
|
||||||
|
ResetButton.IsEnabled = false;
|
||||||
|
CancelButton.IsEnabled = false;
|
||||||
|
SaveButton.Visibility = Visibility.Hidden;
|
||||||
|
ResetButton.Visibility = Visibility.Hidden;
|
||||||
|
CancelButton.Visibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowNewEditDeleteButtons()
|
||||||
|
{
|
||||||
|
NewMemberButton.IsEnabled = true;
|
||||||
|
EditMemberButton.IsEnabled = MemberList.SelectedItem != null;
|
||||||
|
DeleteMemberButton.IsEnabled = true;
|
||||||
|
NewMemberButton.Visibility = Visibility.Visible;
|
||||||
|
EditMemberButton.Visibility = Visibility.Visible;
|
||||||
|
DeleteMemberButton.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HideNewEditDeleteButtons()
|
||||||
|
{
|
||||||
|
NewMemberButton.IsEnabled = false;
|
||||||
|
EditMemberButton.IsEnabled = false;
|
||||||
|
DeleteMemberButton.IsEnabled = false;
|
||||||
|
NewMemberButton.Visibility = Visibility.Hidden;
|
||||||
|
EditMemberButton.Visibility = Visibility.Hidden;
|
||||||
|
DeleteMemberButton.Visibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LockInputs()
|
||||||
|
{
|
||||||
|
MgNrInput.IsReadOnly = true;
|
||||||
|
GivenNameInput.IsReadOnly = true;
|
||||||
|
FamilyNameInput.IsReadOnly = true;
|
||||||
|
AddressInput.IsReadOnly = true;
|
||||||
|
PlzInput.IsReadOnly = true;
|
||||||
|
OrtInput.IsEnabled = false;
|
||||||
|
BranchInput.IsEnabled = false;
|
||||||
|
DefaultKgInput.IsEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UnlockInputs()
|
||||||
|
{
|
||||||
|
MgNrInput.IsReadOnly = false;
|
||||||
|
GivenNameInput.IsReadOnly = false;
|
||||||
|
FamilyNameInput.IsReadOnly = false;
|
||||||
|
AddressInput.IsReadOnly = false;
|
||||||
|
PlzInput.IsReadOnly = false;
|
||||||
|
OrtInput.IsEnabled = true;
|
||||||
|
BranchInput.IsEnabled = true;
|
||||||
|
DefaultKgInput.IsEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FillInputs(Member m)
|
||||||
|
{
|
||||||
|
MgNrInput.Text = m.MgNr.ToString();
|
||||||
|
GivenNameInput.Text = m.GivenName;
|
||||||
|
FamilyNameInput.Text = m.FamilyName;
|
||||||
|
BranchInput.SelectedItem = m.Branch;
|
||||||
|
DefaultKgInput.SelectedItem = m.DefaultKg;
|
||||||
|
AddressInput.Text = m.Address;
|
||||||
|
|
||||||
|
// TODO PostalDest may be null after creation?
|
||||||
|
AT_Plz? p = m.PostalDest.Plz(context);
|
||||||
if (p != null)
|
if (p != null)
|
||||||
{
|
{
|
||||||
Plz.Text = p.Plz.ToString();
|
PlzInput.Text = p.Plz.ToString();
|
||||||
|
|
||||||
var o = p.Orte(_context);
|
var o = p.Orte(context);
|
||||||
Ort.ItemsSource = o;
|
OrtInput.ItemsSource = o;
|
||||||
Ort.SelectedItem = p;
|
OrtInput.SelectedItem = p;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Ort.ItemsSource = null;
|
OrtInput.ItemsSource = null;
|
||||||
Ort.SelectedItem = null;
|
OrtInput.SelectedItem = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ClearInputs()
|
||||||
Edit_Member.IsEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Plz_TextChanged(object sender, RoutedEventArgs e)
|
|
||||||
{
|
{
|
||||||
if (Plz.Text.Length == 4 && Plz.Text.All(char.IsDigit))
|
MgNrInput.Text = "";
|
||||||
{
|
GivenNameInput.Text = "";
|
||||||
int plz = int.Parse(Plz.Text);
|
FamilyNameInput.Text = "";
|
||||||
var o = _context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
BranchInput.SelectedItem = null;
|
||||||
Ort.ItemsSource = o;
|
PlzInput.Text = "";
|
||||||
Ort.SelectedItem = null;
|
OrtInput.SelectedItem = null;
|
||||||
}
|
AddressInput.Text = "";
|
||||||
}
|
DefaultKgInput.SelectedItem = null;
|
||||||
|
|
||||||
private void Edit_Member_Button_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
Member m = (Member)MemberList.SelectedItem;
|
|
||||||
|
|
||||||
if (m == null) return;
|
|
||||||
|
|
||||||
MemberEditWindow w = new MemberEditWindow(m, _context);
|
|
||||||
w.Event += new EventHandler(Refresh_Member_Data_Event);
|
|
||||||
w.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Add_Member_Button_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
MemberAddWindow w = new MemberAddWindow(_context);
|
|
||||||
w.Event += new EventHandler(Refresh_Member_Data_Event);
|
|
||||||
w.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Refresh_Member_Data()
|
|
||||||
{
|
|
||||||
_context.Members.Load();
|
|
||||||
MemberList.ItemsSource = _context.Members.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Refresh_Member_Data_Event(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Refresh_Member_Data();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user