Update model database schema
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<local:AdministrationWindow x:Class="Elwig.Windows.AreaCommAdminWindow"
|
||||
<local:AdministrationWindow x:Class="Elwig.Windows.AreaComAdminWindow"
|
||||
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"
|
@ -5,18 +5,17 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class AreaCommAdminWindow : AdministrationWindow {
|
||||
public partial class AreaComAdminWindow : AdministrationWindow {
|
||||
private readonly Member member;
|
||||
private bool IsEditing = false;
|
||||
private bool IsCreating = false;
|
||||
|
||||
public AreaCommAdminWindow(Member member) {
|
||||
public AreaComAdminWindow(Member member) {
|
||||
InitializeComponent();
|
||||
this.member = member;
|
||||
Title = $"Flächenbindungen - {member.FamilyName} {member.GivenName} - Elwig";
|
||||
@ -57,7 +56,7 @@ namespace Elwig.Windows {
|
||||
if (contracts.Count == 1)
|
||||
ContractList.SelectedIndex = 0;
|
||||
|
||||
//TODO notwendig?
|
||||
// TODO notwendig?
|
||||
await RefreshAreaCommitmentList();
|
||||
RefreshInputs();
|
||||
}
|
||||
@ -70,10 +69,10 @@ namespace Elwig.Windows {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AreaCommitment> commitments = await Context.AreaCommitments.Where(a => a.VNr == contract.VNr).ToListAsync();
|
||||
List<AreaComParcel> parcels = (await Context.AreaCommitments.FindAsync(contract.VNr)).Parcels.ToList();
|
||||
|
||||
AreaCommitmentList.ItemsSource = commitments;
|
||||
if (commitments.Count == 1)
|
||||
AreaCommitmentList.ItemsSource = parcels;
|
||||
if (parcels.Count == 1)
|
||||
AreaCommitmentList.SelectedIndex = 0;
|
||||
RefreshInputs();
|
||||
}
|
||||
@ -81,7 +80,7 @@ namespace Elwig.Windows {
|
||||
private void RefreshInputs(bool validate = false) {
|
||||
ClearInputStates();
|
||||
Contract? c = (Contract)ContractList.SelectedItem;
|
||||
AreaCommitment? a = (AreaCommitment)AreaCommitmentList.SelectedItem;
|
||||
AreaComParcel? a = (AreaComParcel)AreaCommitmentList.SelectedItem;
|
||||
|
||||
if (c != null) {
|
||||
DeleteContractButton.IsEnabled = true;
|
||||
@ -105,22 +104,23 @@ namespace Elwig.Windows {
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void FillInputs(AreaCommitment a) {
|
||||
private void FillInputs(AreaComParcel a) {
|
||||
ClearOriginalValues();
|
||||
|
||||
VNrInput.Text = a.VNr.ToString();
|
||||
MgNrInput.Text = a.Contract.MgNr.ToString();
|
||||
YearFromInput.Text = a.Contract.YearFrom.ToString();
|
||||
YearToInput.Text = a.Contract.YearTo.ToString();
|
||||
MgNrInput.Text = a.AreaCom.Contract.MgNr.ToString();
|
||||
YearFromInput.Text = a.AreaCom.Contract.YearFrom.ToString();
|
||||
YearToInput.Text = a.AreaCom.Contract.YearTo.ToString();
|
||||
|
||||
KgInput.SelectedItem = a.Kg.Kg;
|
||||
RdInput.SelectedItem = a.Rd;
|
||||
GstNrInput.Text = a.GstNr;
|
||||
AreaInput.Text = a.Area.ToString();
|
||||
|
||||
SortInput.SelectedItem = a.WineVar;
|
||||
AttrInput.SelectedItem = a.WineAttr;
|
||||
CultInput.SelectedItem = a.WineCult;
|
||||
SortInput.SelectedItem = a.AreaCom.WineVar;
|
||||
// FIXME
|
||||
//AttrInput.SelectedItem = a.WineAttr;
|
||||
CultInput.SelectedItem = a.AreaCom.WineCult;
|
||||
|
||||
FillOriginalValues();
|
||||
}
|
||||
@ -155,12 +155,12 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void DeleteAreaCommitmentButton_Click(object sender, RoutedEventArgs evt) {
|
||||
AreaCommitment a = (AreaCommitment)AreaCommitmentList.SelectedItem;
|
||||
AreaComParcel a = (AreaComParcel)AreaCommitmentList.SelectedItem;
|
||||
if (a == null) return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll die Flächenbindung {a.Kg.Kg.Name}{(a.Rd.Name == null ? "" : $", {a.Rd.Name}")}, {a.GstNr} wirklich unwiderruflich gelöscht werden?",
|
||||
"Flächenbindung löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
$"Soll die Parzelle {a.GstNr} ({a.Area} m²) wirklich unwiderruflich gelöscht werden?",
|
||||
"Parzelle löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
Context.Remove(a);
|
||||
Context.SaveChanges();
|
||||
@ -186,7 +186,7 @@ namespace Elwig.Windows {
|
||||
if (c == null) return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll der Vertrag \"{c.VNr} und alle enthaltenen Flächenbindungen wirklich unwiderruflich gelöscht werden?",
|
||||
$"Soll der Vertrag {c.VNr} und alle enthaltenen Parzellen wirklich unwiderruflich gelöscht werden?",
|
||||
"Vertrag löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
Context.Remove(c);
|
||||
@ -226,17 +226,18 @@ namespace Elwig.Windows {
|
||||
return c;
|
||||
}
|
||||
|
||||
private async Task<AreaCommitment> UpdateaAreaCommitment(AreaCommitment a) {
|
||||
private async Task<AreaComParcel> UpdateaAreaComParcel(AreaComParcel a) {
|
||||
a.VNr = int.Parse(VNrInput.Text);
|
||||
a.KgNr = ((AT_Kg)KgInput.SelectedItem).KgNr;
|
||||
a.RdNr = ((WbRd)RdInput.SelectedItem).RdNr;
|
||||
a.GstNr = GstNrInput.Text;
|
||||
a.Area = int.Parse(AreaInput.Text);
|
||||
a.SortId = ((WineVar)SortInput.SelectedItem).SortId;
|
||||
a.AttrId = ((WineAttr)AttrInput.SelectedItem).AttrId;
|
||||
a.CultId = ((WineCult)CultInput.SelectedItem).CultId;
|
||||
a.AreaCom.SortId = ((WineVar)SortInput.SelectedItem).SortId;
|
||||
// FIXME
|
||||
//a.AttrId = ((WineAttr)AttrInput.SelectedItem).AttrId;
|
||||
a.AreaCom.CultId = ((WineCult)CultInput.SelectedItem).CultId;
|
||||
|
||||
EntityEntry<AreaCommitment>? tr = null;
|
||||
EntityEntry<AreaComParcel>? tr = null;
|
||||
try {
|
||||
if (IsEditing) {
|
||||
tr = Context.Update(a);
|
||||
@ -257,7 +258,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void AreaCommitmentSaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Contract c = await UpdateContract((Contract)ContractList.SelectedItem);
|
||||
AreaCommitment a = await UpdateaAreaCommitment(IsEditing ? (AreaCommitment)AreaCommitmentList.SelectedItem : Context.CreateProxy<AreaCommitment>());
|
||||
AreaComParcel a = await UpdateaAreaComParcel(IsEditing ? (AreaComParcel)AreaCommitmentList.SelectedItem : Context.CreateProxy<AreaComParcel>());
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
@ -297,7 +298,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void ContractSaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Contract c = await UpdateContract(Context.CreateProxy<Contract>());
|
||||
AreaCommitment a = await UpdateaAreaCommitment(Context.CreateProxy<AreaCommitment>());
|
||||
AreaComParcel a = await UpdateaAreaComParcel(Context.CreateProxy<AreaComParcel>());
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
@ -189,7 +189,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void AreaCommitmentButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new AreaCommAdminWindow((Member)MemberList.SelectedItem);
|
||||
var w = new AreaComAdminWindow((Member)MemberList.SelectedItem);
|
||||
w.Show();
|
||||
}
|
||||
|
||||
@ -281,8 +281,8 @@ namespace Elwig.Windows {
|
||||
|
||||
// TODO Rechnungsadresse
|
||||
|
||||
m.EntryDate = (EntryDateInput.Text == "") ? null : string.Join("-", EntryDateInput.Text.Split(".").Reverse());
|
||||
m.ExitDate = (ExitDateInput.Text == "") ? null : string.Join("-", ExitDateInput.Text.Split(".").Reverse());
|
||||
m.EntryDateString = (EntryDateInput.Text == "") ? null : string.Join("-", EntryDateInput.Text.Split(".").Reverse());
|
||||
m.ExitDateString = (ExitDateInput.Text == "") ? null : string.Join("-", ExitDateInput.Text.Split(".").Reverse());
|
||||
m.BusinessShares = (BusinessSharesInput.Text == "") ? 0 : int.Parse(BusinessSharesInput.Text);
|
||||
m.AccountingNr = (AccountingNrInput.Text == "") ? null : AccountingNrInput.Text;
|
||||
m.IsActive = ActiveInput.IsChecked ?? false;
|
||||
@ -372,8 +372,8 @@ namespace Elwig.Windows {
|
||||
BillingOrtInput.SelectedItem = null;
|
||||
}
|
||||
|
||||
EntryDateInput.Text = (m.EntryDate != null) ? string.Join(".", m.EntryDate.Split("-").Reverse()) : null;
|
||||
ExitDateInput.Text = (m.ExitDate != null) ? string.Join(".", m.ExitDate.Split("-").Reverse()) : null;
|
||||
EntryDateInput.Text = (m.EntryDateString != null) ? string.Join(".", m.EntryDateString.Split("-").Reverse()) : null;
|
||||
ExitDateInput.Text = (m.ExitDateString != null) ? string.Join(".", m.ExitDateString.Split("-").Reverse()) : null;
|
||||
BusinessSharesInput.Text = m.BusinessShares.ToString();
|
||||
AccountingNrInput.Text = m.AccountingNr;
|
||||
BranchInput.SelectedItem = m.Branch;
|
||||
|
Reference in New Issue
Block a user