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.Threading.Tasks;
namespace WGneu.Models {
namespace WGneu.Helpers {
// 1 °KMW =
// 1 °NM = kg/100L = 10g/L
// 1 °Oe =

View File

@ -1,10 +1,5 @@
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("AT_gem"), PrimaryKey("Gkz")]

View File

@ -1,10 +1,5 @@
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("AT_kg"), PrimaryKey("KgNr")]

View File

@ -1,10 +1,5 @@
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("AT_ort"), PrimaryKey("Okz")]

View File

@ -1,39 +1,32 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
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 {
[Table("AT_plz"), PrimaryKey("Plz", "Okz"), Index("Id", IsUnique = true)]
[Table("AT_plz"), PrimaryKey("Plz")]
public class AT_Plz {
[Column("plz")]
public int Plz { get; set; }
[Column("okz")]
public int Okz { get; set; }
[Column("ort")]
public string Ort { get; set; }
[Column("country")]
public string CountryCode { get; }
[Column("blnr")]
public int BlNr { get; }
[Column("id")]
public string Id { get; }
[Column("type")]
public string Type { get; }
[Column("dest")]
public string Dest { get; set; }
[Column("internal")]
public bool Internal { get; set; }
[ForeignKey("Okz")]
public virtual AT_Ort Ort { get; set; }
[Column("addressable")]
public bool Addressable { get; set; }
[ForeignKey("CountryCode")]
public virtual Country Country { get; set; }
[Column("po_box")]
public bool PoBox { get; set; }
public ISet<AT_Plz> Orte(AppDbContext ctx) {
return ctx.Postleitzahlen.Where(p => p.Plz == Plz).ToHashSet();
}
[InverseProperty("AtPlz")]
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 System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WGneu.Models {
[Table("area_commitment"), PrimaryKey("Vnr", "KgNr", "GstNr")]
@ -16,7 +11,7 @@ namespace WGneu.Models {
public int KgNr { get; set; }
[Column("gstnr")]
public String? GstNr { get; set; }
public string? GstNr { get; set; }
[Column("rdnr")]
public int RdNr { get; set; }
@ -25,13 +20,13 @@ namespace WGneu.Models {
public int Area { get; set; }
[Column("sortid")]
public String SortId { get; set; }
public string SortId { get; set; }
[Column("attrid")]
public String? AttrId { get; set; }
public string? AttrId { get; set; }
[Column("cultid")]
public String CultId { get; set; }
public string CultId { get; set; }
[ForeignKey("Vnr")]
public virtual Contract Contract { get; set; }

View File

@ -1,10 +1,5 @@
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")]

View File

@ -1,10 +1,5 @@
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("contract"), PrimaryKey("Vnr")]

View File

@ -1,10 +1,5 @@
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("country"), PrimaryKey("Alpha2")]
@ -22,6 +17,6 @@ namespace WGneu.Models {
public string Name { get; set; }
[Column("is_visible")]
public int IsVisible { get; set; }
public bool IsVisible { get; set; }
}
}

View File

@ -1,10 +1,6 @@
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("member"), PrimaryKey("MgNr")]

View File

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

View File

@ -1,10 +1,5 @@
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")]

View File

@ -1,10 +1,5 @@
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_rd"), PrimaryKey("KgNr", "RdNr")]
@ -16,7 +11,7 @@ namespace WGneu.Models {
public int RdNr { get; set; }
[Column("name")]
public String Name { get; set; }
public string Name { get; set; }
[ForeignKey("KgNr")]
public virtual WbKg WbKg { get; set; }

View File

@ -1,19 +1,14 @@
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("wine_attribute"), PrimaryKey("AttrId")]
public class WineAttr {
[Column("attrid")]
public String AttrId { get; set; }
public string AttrId { get; set; }
[Column("name")]
public String Name { get; set; }
public string Name { get; set; }
[Column("kg_per_ha")]
public int KgPerHa { get; set; }

View File

@ -1,18 +1,13 @@
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("wine_cultivation"), PrimaryKey("CultId")]
public class WineCult {
[Column("cultid")]
public String CultId { get; set; }
public string CultId { get; set; }
[Column("name")]
public String Name { get; set; }
public string Name { get; set; }
}
}

View File

@ -1,22 +1,17 @@
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("wine_quality"), PrimaryKey("QualId")]
public class WineQual {
[Column("qualid")]
public String QualId { get; set; }
public string QualId { get; set; }
[Column("origin_level")]
public int OriginLevel { get; set; }
public int? OriginLevel { get; set; }
[Column("name")]
public String Name { get; set; }
public string Name { get; set; }
[Column("from_kmw")]
public double? FromKmw { get; set; }

View File

@ -1,24 +1,19 @@
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("wine_variety"), PrimaryKey("SortId")]
public class WineVar {
[Column("sortid")]
public String SortId { get; set; }
public string SortId { get; set; }
[Column("type")]
public String Type { get; set; }
public string Type { get; set; }
[Column("name")]
public String Name { get; set; }
public string Name { get; set; }
[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.Birthday = (BirthdayInput.Text == "") ? null : string.Join("-", BirthdayInput.Text.Split(".").Reverse());
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.Address = AddressInput.Text;
@ -359,10 +359,10 @@ namespace WGneu.Windows {
SuffixInput.Text = m.Suffix;
BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null;
AddressInput.Text = m.Address;
AT_Plz? p = m.PostalDest.Plz(Context);
AT_PlzDest? p = m.PostalDest.AtPlz;
if (p != null) {
PlzInput.Text = p.Plz.ToString();
OrtInput.ItemsSource = p.Orte(Context);
OrtInput.ItemsSource = p.AtPlz.Orte;
OrtInput.SelectedItem = p;
} else {
PlzInput.Text = null;