Add AreaCommitment area to MemberListWindow

This commit is contained in:
2023-03-14 14:08:23 +01:00
parent 3614445cff
commit 0d8f62f404
9 changed files with 48 additions and 27 deletions

View File

@ -8,12 +8,12 @@ namespace WGneu.Helpers {
public DbSet<AT_Gem> Gemeinden { get; set; } public DbSet<AT_Gem> Gemeinden { get; set; }
public DbSet<AT_Kg> Katastralgemeinden { get; set; } public DbSet<AT_Kg> Katastralgemeinden { get; set; }
public DbSet<AT_Ort> Orte { get; set; } public DbSet<AT_Ort> Orte { get; set; }
public DbSet<AT_Plz> Postleitzahlen { get; set; } public DbSet<AT_PlzDest> Postleitzahlen { get; set; }
public DbSet<PostalDest> PostalDestinations { get; set; } public DbSet<PostalDest> PostalDestinations { get; set; }
public DbSet<Branch> Branches { get; set; } public DbSet<Branch> Branches { get; set; }
public DbSet<WbKg> WbKgs { get; set; } public DbSet<WbKg> WbKgs { get; set; }
public DbSet<WbRd> WbRde { get; set; } public DbSet<WbRd> WbRde { get; set; }
public DbSet<AreaCommit> AreaCommitments { get; set; } public DbSet<AreaCommitment> AreaCommitments { get; set; }
public DbSet<Contract> Contracts { get; set; } public DbSet<Contract> Contracts { get; set; }
public DbSet<WineAttr> WineAttributes { get; set; } public DbSet<WineAttr> WineAttributes { get; set; }
public DbSet<WineCult> WineCultivations { get; set; } public DbSet<WineCult> WineCultivations { get; set; }
@ -21,7 +21,7 @@ namespace WGneu.Helpers {
public DbSet<WineVar> WineVarieties { get; set; } public DbSet<WineVar> WineVarieties { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.UseSqlite("Data Source=\"C:\\Users\\lorenz\\Desktop\\wgtest.sqlite3\"; foreign keys=true"); optionsBuilder.UseSqlite("Data Source=\"C:\\Users\\lorenz\\Desktop\\wgprod.sqlite3\"; foreign keys=true");
optionsBuilder.UseLazyLoadingProxies(); optionsBuilder.UseLazyLoadingProxies();
} }
} }

View File

@ -2,10 +2,10 @@
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace WGneu.Models { namespace WGneu.Models {
[Table("area_commitment"), PrimaryKey("Vnr", "KgNr", "GstNr")] [Table("area_commitment"), PrimaryKey("VNr", "KgNr", "GstNr")]
public class AreaCommit { public class AreaCommitment {
[Column("vnr")] [Column("vnr")]
public int Vnr { get; set; } public int VNr { get; set; }
[Column("kgnr")] [Column("kgnr")]
public int KgNr { get; set; } public int KgNr { get; set; }
@ -14,7 +14,7 @@ namespace WGneu.Models {
public string? GstNr { get; set; } public string? GstNr { get; set; }
[Column("rdnr")] [Column("rdnr")]
public int RdNr { get; set; } public int? RdNr { get; set; }
[Column("area")] [Column("area")]
public int Area { get; set; } public int Area { get; set; }
@ -28,19 +28,19 @@ namespace WGneu.Models {
[Column("cultid")] [Column("cultid")]
public string CultId { get; set; } public string CultId { get; set; }
[ForeignKey("Vnr")] [ForeignKey("VNr")]
public virtual Contract Contract { get; set; } public virtual Contract Contract { get; private set; }
[ForeignKey("SortId")] [ForeignKey("SortId")]
public virtual WineVar WineVar { get; set; } public virtual WineVar WineVar { get; private set; }
[ForeignKey("AttrId")] [ForeignKey("AttrId")]
public virtual WineAttr WineAttr { get; set; } public virtual WineAttr WineAttr { get; private set; }
[ForeignKey("CultId")] [ForeignKey("CultId")]
public virtual WineCult WineCult { get; set; } public virtual WineCult WineCult { get; private set; }
[ForeignKey("KgNr, RdNr")] [ForeignKey("KgNr, RdNr")]
public virtual WbRd WbRd { get; set; } public virtual WbRd? WbRd { get; private set; }
} }
} }

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace WGneu.Models { namespace WGneu.Models {
@ -9,5 +10,8 @@ namespace WGneu.Models {
[Column("name")] [Column("name")]
public string Name { get; set; } public string Name { get; set; }
[InverseProperty("Branch")]
public virtual ISet<Member> Members { get; private set; }
} }
} }

View File

@ -1,11 +1,13 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace WGneu.Models { namespace WGneu.Models {
[Table("contract"), PrimaryKey("Vnr")] [Table("contract"), PrimaryKey("VNr")]
public class Contract { public class Contract {
[Column("vnr")] [Column("vnr")]
public int Vnr { get; set; } public int VNr { get; set; }
[Column("mgnr")] [Column("mgnr")]
public int MgNr { get; set; } public int MgNr { get; set; }
@ -17,6 +19,12 @@ namespace WGneu.Models {
public int? YearTo { get; set; } public int? YearTo { get; set; }
[ForeignKey("MgNr")] [ForeignKey("MgNr")]
public virtual Member Member { get; set; } public virtual Member Member { get; private set; }
[InverseProperty("Contract")]
public virtual ISet<AreaCommitment> AreaCommitments { get; private set; }
[NotMapped]
public int Area => AreaCommitments.Select(a => a.Area).Sum();
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
namespace WGneu.Models { namespace WGneu.Models {
@ -78,7 +79,7 @@ namespace WGneu.Models {
public string CountryCode { get; set; } public string CountryCode { get; set; }
[Column("postal_dest")] [Column("postal_dest")]
public string PostalDestId { get; private set; } public string PostalDestId { get; set; }
[Column("address")] [Column("address")]
public string Address { get; set; } public string Address { get; set; }
@ -105,18 +106,21 @@ namespace WGneu.Models {
public string? Comment { get; set; } public string? Comment { get; set; }
[ForeignKey("PredecessorMgNr")] [ForeignKey("PredecessorMgNr")]
public virtual Member? Predecessor { get; set; } public virtual Member? Predecessor { get; private set; }
[ForeignKey("CountryCode")] [ForeignKey("CountryCode")]
public virtual Country Country { get; set; } public virtual Country Country { get; private set; }
[ForeignKey("CountryCode, PostalDestId")] [ForeignKey("CountryCode, PostalDestId")]
public virtual PostalDest PostalDest { get; set; } public virtual PostalDest PostalDest { get; private set; }
[ForeignKey("DefaultKgNr")] [ForeignKey("DefaultKgNr")]
public virtual AT_Kg? DefaultKg { get; set; } public virtual AT_Kg? DefaultKg { get; private set; }
[ForeignKey("ZwstId")] [ForeignKey("ZwstId")]
public virtual Branch Branch { get; set; } public virtual Branch? Branch { get; private set; }
[InverseProperty("Member")]
public virtual ISet<Contract> Contracts { get; private set; }
} }
} }

View File

@ -11,6 +11,6 @@ namespace WGneu.Models {
public int? GlNr { get; set; } public int? GlNr { get; set; }
[ForeignKey("KgNr")] [ForeignKey("KgNr")]
public virtual AT_Kg Kg { get; set; } public virtual AT_Kg Kg { get; private set; }
} }
} }

View File

@ -14,6 +14,6 @@ namespace WGneu.Models {
public string Name { get; set; } public string Name { get; set; }
[ForeignKey("KgNr")] [ForeignKey("KgNr")]
public virtual WbKg WbKg { get; set; } public virtual WbKg WbKg { get; private set; }
} }
} }

View File

@ -31,7 +31,7 @@
</Style> </Style>
<Style TargetType="Button"> <Style TargetType="Button">
<Setter Property="FontSize" Value="14"/> <Setter Property="FontSize" Value="14"/>
<Setter Property="Padding" Value="3"/> <Setter Property="Padding" Value="9,3"/>
<Setter Property="Height" Value="27"/> <Setter Property="Height" Value="27"/>
</Style> </Style>
</Window.Resources> </Window.Resources>
@ -296,6 +296,10 @@
Checked="RadioButton_Changed" Unchecked="RadioButton_Changed" Checked="RadioButton_Changed" Unchecked="RadioButton_Changed"
HorizontalAlignment="Left" Margin="60,225,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/> HorizontalAlignment="Left" Margin="60,225,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
<Label Content="Gebundene Fläche:" Margin="10,250,0,0" Grid.Column="0"/>
<TextBlock x:Name="AreaCommitment" Text="- m²"
Grid.Column="1" HorizontalAlignment="Left" Margin="2,254,0,0" TextWrapping="NoWrap" VerticalAlignment="Top"/>
<Button x:Name="ContractButton" Content="Flächenbindungen" Click="ContractButton_Click" <Button x:Name="ContractButton" Content="Flächenbindungen" Click="ContractButton_Click"
HorizontalAlignment="Right" Margin="10,10,10,10" VerticalAlignment="Bottom" Grid.ColumnSpan="3"/> HorizontalAlignment="Right" Margin="10,10,10,10" VerticalAlignment="Bottom" Grid.ColumnSpan="3"/>
</Grid> </Grid>

View File

@ -175,7 +175,6 @@ namespace WGneu.Windows {
int newMgNr = int.Parse(MgNrInput.Text); int newMgNr = int.Parse(MgNrInput.Text);
m.PredecessorMgNr = (PredecessorMgNrInput.Text == "") ? null : int.Parse(PredecessorMgNrInput.Text); m.PredecessorMgNr = (PredecessorMgNrInput.Text == "") ? null : int.Parse(PredecessorMgNrInput.Text);
m.Predecessor = Context.Members.Find(m.PredecessorMgNr);
m.Prefix = (PrefixInput.Text == "") ? null : PrefixInput.Text; m.Prefix = (PrefixInput.Text == "") ? null : PrefixInput.Text;
m.GivenName = GivenNameInput.Text; m.GivenName = GivenNameInput.Text;
m.FamilyName = FamilyNameInput.Text; m.FamilyName = FamilyNameInput.Text;
@ -183,7 +182,6 @@ namespace WGneu.Windows {
m.Birthday = (BirthdayInput.Text == "") ? null : string.Join("-", BirthdayInput.Text.Split(".").Reverse()); m.Birthday = (BirthdayInput.Text == "") ? null : string.Join("-", BirthdayInput.Text.Split(".").Reverse());
m.CountryCode = "AT"; m.CountryCode = "AT";
m.PostalDestId = ((AT_PlzDest)OrtInput.SelectedItem).Id; m.PostalDestId = ((AT_PlzDest)OrtInput.SelectedItem).Id;
m.PostalDest = Context.PostalDestinations.Find(m.CountryCode, m.PostalDestId);
m.Address = AddressInput.Text; m.Address = AddressInput.Text;
m.Email = (EmailInput.Text == "") ? null : EmailInput.Text; m.Email = (EmailInput.Text == "") ? null : EmailInput.Text;
@ -400,6 +398,8 @@ namespace WGneu.Windows {
case "email": ContactEmailInput.IsChecked = true; break; case "email": ContactEmailInput.IsChecked = true; break;
} }
AreaCommitment.Text = $"{m.Contracts.Select(c => c.Area).Sum():N0} m²";
Menu_Member_SendEmail.IsEnabled = m.Email != null; Menu_Member_SendEmail.IsEnabled = m.Email != null;
FillOriginalValues(); FillOriginalValues();
@ -418,6 +418,7 @@ namespace WGneu.Windows {
private void ClearInputs() { private void ClearInputs() {
Menu_Member_SendEmail.IsEnabled = false; Menu_Member_SendEmail.IsEnabled = false;
AreaCommitment.Text = "- m²";
OriginalValues.Clear(); OriginalValues.Clear();
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) { foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) {
tb.Text = " "; tb.Text = " ";