Fix Models with PLZ

This commit is contained in:
2023-03-14 11:12:19 +01:00
parent 76b1a3de75
commit b5f6adc41c
19 changed files with 69 additions and 123 deletions

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Helpers {
// 1 °KMW = // 1 °KMW =
// 1 °NM = kg/100L = 10g/L // 1 °NM = kg/100L = 10g/L
// 1 °Oe = // 1 °Oe =

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("AT_gem"), PrimaryKey("Gkz")] [Table("AT_gem"), PrimaryKey("Gkz")]

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("AT_kg"), PrimaryKey("KgNr")] [Table("AT_kg"), PrimaryKey("KgNr")]

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("AT_ort"), PrimaryKey("Okz")] [Table("AT_ort"), PrimaryKey("Okz")]

View File

@ -1,39 +1,32 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WGneu.Helpers;
namespace WGneu.Models { namespace WGneu.Models {
[Table("AT_plz"), PrimaryKey("Plz", "Okz"), Index("Id", IsUnique = true)] [Table("AT_plz"), PrimaryKey("Plz")]
public class AT_Plz { public class AT_Plz {
[Column("plz")] [Column("plz")]
public int Plz { get; set; } public int Plz { get; set; }
[Column("okz")] [Column("ort")]
public int Okz { get; set; } public string Ort { get; set; }
[Column("country")] [Column("blnr")]
public string CountryCode { get; } public int BlNr { get; }
[Column("id")] [Column("type")]
public string Id { get; } public string Type { get; }
[Column("dest")] [Column("internal")]
public string Dest { get; set; } public bool Internal { get; set; }
[ForeignKey("Okz")] [Column("addressable")]
public virtual AT_Ort Ort { get; set; } public bool Addressable { get; set; }
[ForeignKey("CountryCode")] [Column("po_box")]
public virtual Country Country { get; set; } public bool PoBox { get; set; }
public ISet<AT_Plz> Orte(AppDbContext ctx) { [InverseProperty("AtPlz")]
return ctx.Postleitzahlen.Where(p => p.Plz == Plz).ToHashSet(); public virtual ISet<AT_PlzDest> Orte { get; set; }
}
} }
} }

View File

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace WGneu.Models {
[Table("AT_plz_dest"), PrimaryKey("Id"), Index("Plz", "Okz", IsUnique = true)]
public class AT_PlzDest {
[Column("plz")]
public int Plz { get; set; }
[Column("okz")]
public int Okz { get; set; }
[Column("country")]
public string CountryCode { get; }
[Column("id")]
public string Id { get; }
[Column("dest")]
public string Dest { get; set; }
[ForeignKey("Plz")]
public virtual AT_Plz AtPlz { get; set; }
[ForeignKey("Okz")]
public virtual AT_Ort Ort { get; set; }
[ForeignKey("CountryCode")]
public virtual Country Country { get; set; }
}
}

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("area_commitment"), PrimaryKey("Vnr", "KgNr", "GstNr")] [Table("area_commitment"), PrimaryKey("Vnr", "KgNr", "GstNr")]
@ -16,7 +11,7 @@ namespace WGneu.Models {
public int KgNr { get; set; } public int KgNr { get; set; }
[Column("gstnr")] [Column("gstnr")]
public String? GstNr { get; set; } public string? GstNr { get; set; }
[Column("rdnr")] [Column("rdnr")]
public int RdNr { get; set; } public int RdNr { get; set; }
@ -25,13 +20,13 @@ namespace WGneu.Models {
public int Area { get; set; } public int Area { get; set; }
[Column("sortid")] [Column("sortid")]
public String SortId { get; set; } public string SortId { get; set; }
[Column("attrid")] [Column("attrid")]
public String? AttrId { get; set; } public string? AttrId { get; set; }
[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; set; }

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("branch"), PrimaryKey("ZwstId")] [Table("branch"), PrimaryKey("ZwstId")]

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("contract"), PrimaryKey("Vnr")] [Table("contract"), PrimaryKey("Vnr")]

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("country"), PrimaryKey("Alpha2")] [Table("country"), PrimaryKey("Alpha2")]
@ -22,6 +17,6 @@ namespace WGneu.Models {
public string Name { get; set; } public string Name { get; set; }
[Column("is_visible")] [Column("is_visible")]
public int IsVisible { get; set; } public bool IsVisible { get; set; }
} }
} }

View File

@ -1,10 +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;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("member"), PrimaryKey("MgNr")] [Table("member"), PrimaryKey("MgNr")]

View File

@ -1,11 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WGneu.Helpers;
namespace WGneu.Models { namespace WGneu.Models {
[Table("postal_dest"), PrimaryKey("CountryCode", "Id")] [Table("postal_dest"), PrimaryKey("CountryCode", "Id")]
@ -19,10 +13,7 @@ namespace WGneu.Models {
[ForeignKey("CountryCode")] [ForeignKey("CountryCode")]
public virtual Country Country { get; set; } public virtual Country Country { get; set; }
public AT_Plz? Plz(AppDbContext ctx) { [ForeignKey("Id")]
// TODO getter public virtual AT_PlzDest? AtPlz { get; set; }
if (CountryCode != "AT") return null;
return ctx.Postleitzahlen.Where(p => p.Id == Id).FirstOrDefault();
}
} }
} }

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("wb_kg"), PrimaryKey("KgNr")] [Table("wb_kg"), PrimaryKey("KgNr")]

View File

@ -1,10 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("wb_rd"), PrimaryKey("KgNr", "RdNr")] [Table("wb_rd"), PrimaryKey("KgNr", "RdNr")]
@ -16,7 +11,7 @@ namespace WGneu.Models {
public int RdNr { get; set; } public int RdNr { get; set; }
[Column("name")] [Column("name")]
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; set; }

View File

@ -1,19 +1,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("wine_attribute"), PrimaryKey("AttrId")] [Table("wine_attribute"), PrimaryKey("AttrId")]
public class WineAttr { public class WineAttr {
[Column("attrid")] [Column("attrid")]
public String AttrId { get; set; } public string AttrId { get; set; }
[Column("name")] [Column("name")]
public String Name { get; set; } public string Name { get; set; }
[Column("kg_per_ha")] [Column("kg_per_ha")]
public int KgPerHa { get; set; } public int KgPerHa { get; set; }

View File

@ -1,18 +1,13 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("wine_cultivation"), PrimaryKey("CultId")] [Table("wine_cultivation"), PrimaryKey("CultId")]
public class WineCult { public class WineCult {
[Column("cultid")] [Column("cultid")]
public String CultId { get; set; } public string CultId { get; set; }
[Column("name")] [Column("name")]
public String Name { get; set; } public string Name { get; set; }
} }
} }

View File

@ -1,22 +1,17 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("wine_quality"), PrimaryKey("QualId")] [Table("wine_quality"), PrimaryKey("QualId")]
public class WineQual { public class WineQual {
[Column("qualid")] [Column("qualid")]
public String QualId { get; set; } public string QualId { get; set; }
[Column("origin_level")] [Column("origin_level")]
public int OriginLevel { get; set; } public int? OriginLevel { get; set; }
[Column("name")] [Column("name")]
public String Name { get; set; } public string Name { get; set; }
[Column("from_kmw")] [Column("from_kmw")]
public double? FromKmw { get; set; } public double? FromKmw { get; set; }

View File

@ -1,24 +1,19 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models { namespace WGneu.Models {
[Table("wine_variety"), PrimaryKey("SortId")] [Table("wine_variety"), PrimaryKey("SortId")]
public class WineVar { public class WineVar {
[Column("sortid")] [Column("sortid")]
public String SortId { get; set; } public string SortId { get; set; }
[Column("type")] [Column("type")]
public String Type { get; set; } public string Type { get; set; }
[Column("name")] [Column("name")]
public String Name { get; set; } public string Name { get; set; }
[Column("comment")] [Column("comment")]
public String? Comment { get; set; } public string? Comment { get; set; }
} }
} }

View File

@ -181,7 +181,7 @@ namespace WGneu.Windows {
m.Suffix = (SuffixInput.Text == "") ? null : SuffixInput.Text; m.Suffix = (SuffixInput.Text == "") ? null : SuffixInput.Text;
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_Plz)OrtInput.SelectedItem).Id; m.PostalDestId = ((AT_PlzDest)OrtInput.SelectedItem).Id;
m.PostalDest = Context.PostalDestinations.Find(m.CountryCode, m.PostalDestId); m.PostalDest = Context.PostalDestinations.Find(m.CountryCode, m.PostalDestId);
m.Address = AddressInput.Text; m.Address = AddressInput.Text;
@ -359,10 +359,10 @@ namespace WGneu.Windows {
SuffixInput.Text = m.Suffix; SuffixInput.Text = m.Suffix;
BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null; BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null;
AddressInput.Text = m.Address; AddressInput.Text = m.Address;
AT_Plz? p = m.PostalDest.Plz(Context); AT_PlzDest? p = m.PostalDest.AtPlz;
if (p != null) { if (p != null) {
PlzInput.Text = p.Plz.ToString(); PlzInput.Text = p.Plz.ToString();
OrtInput.ItemsSource = p.Orte(Context); OrtInput.ItemsSource = p.AtPlz.Orte;
OrtInput.SelectedItem = p; OrtInput.SelectedItem = p;
} else { } else {
PlzInput.Text = null; PlzInput.Text = null;