[#43] MemberAdminWindow: Do not use Context from ContextWindow any more

This commit is contained in:
2024-03-10 13:05:15 +01:00
parent 239b8a9091
commit 1eba3d9d20
6 changed files with 86 additions and 72 deletions

View File

@ -156,7 +156,7 @@ namespace Elwig.Documents {
tbl += $"<tr><th>Gesamtlieferung lt. gez. GA</th>{FormatRow( tbl += $"<tr><th>Gesamtlieferung lt. gez. GA</th>{FormatRow(
Member.BusinessShares * season.MinKgPerBusinessShare, Member.BusinessShares * season.MinKgPerBusinessShare,
Member.BusinessShares * season.MaxKgPerBusinessShare, Member.BusinessShares * season.MaxKgPerBusinessShare,
Member.Deliveries.Where(d => d.Year == season.Year).Sum(d => d.Weight), season.Deliveries.Where(d => d.MgNr == Member.MgNr).Sum(d => d.Weight),
isGa: true, showPayment: includePayment, showArea: !includeDelivery isGa: true, showPayment: includePayment, showArea: !includeDelivery
)}</tr>"; )}</tr>";
if (fbs.Any()) { if (fbs.Any()) {

View File

@ -11,11 +11,13 @@ namespace Elwig.Documents {
public Season Season; public Season Season;
public Dictionary<string, MemberBucket> MemberBuckets; public Dictionary<string, MemberBucket> MemberBuckets;
public IEnumerable<AreaCom> ActiveAreaCommitments;
public MemberDataSheet(Member m, AppDbContext ctx) : base($"{Name} {m.AdministrativeName}", m) { public MemberDataSheet(Member m, AppDbContext ctx) : base($"{Name} {m.AdministrativeName}", m) {
DocumentId = $"{Name} {m.MgNr}"; DocumentId = $"{Name} {m.MgNr}";
Season = ctx.Seasons.ToList().MaxBy(s => s.Year) ?? throw new ArgumentException("invalid season"); Season = ctx.Seasons.ToList().MaxBy(s => s.Year) ?? throw new ArgumentException("invalid season");
MemberBuckets = ctx.GetMemberBuckets(Utils.CurrentYear, m.MgNr).GetAwaiter().GetResult(); MemberBuckets = ctx.GetMemberBuckets(Utils.CurrentYear, m.MgNr).GetAwaiter().GetResult();
ActiveAreaCommitments = m.ActiveAreaCommitments(ctx);
} }
} }
} }

View File

@ -149,7 +149,7 @@
@Raw(Model.PrintBucketTable(Model.Season, Model.MemberBuckets, includeDelivery: false)) @Raw(Model.PrintBucketTable(Model.Season, Model.MemberBuckets, includeDelivery: false))
@{ @{
var areaComs = Model.Member.ActiveAreaCommitments.GroupBy(a => a.AreaComType).Select(group => new { var areaComs = Model.ActiveAreaCommitments.GroupBy(a => a.AreaComType).Select(group => new {
AreaComType = group.Key, AreaComType = group.Key,
AreaComs = group.OrderBy(c => c.Kg.AtKg.Name), AreaComs = group.OrderBy(c => c.Kg.AtKg.Name),
Size = group.Sum(c => c.Area) Size = group.Sum(c => c.Area)
@ -205,7 +205,7 @@
} }
<tr class="sum bold"> <tr class="sum bold">
<td colspan="3">Gesamt:</td> <td colspan="3">Gesamt:</td>
<td class="number">@($"{Model.Member.ActiveAreaCommitments.Select(a => a.Area).Sum():N0}")</td> <td class="number">@($"{Model.ActiveAreaCommitments.Sum(a => a.Area):N0}")</td>
<td colspan="2"></td> <td colspan="2"></td>
</tr> </tr>
</tbody> </tbody>

View File

@ -429,7 +429,7 @@ namespace Elwig.Helpers {
return new(true, null); return new(true, null);
} }
public static ValidationResult CheckNewMgNr(TextBox input, bool required, AppDbContext ctx, Member? m) { public static ValidationResult CheckNewMgNr(TextBox input, bool required, Member? m) {
var res = CheckInteger(input, required); var res = CheckInteger(input, required);
if (!res.IsValid) { if (!res.IsValid) {
return res; return res;
@ -437,6 +437,7 @@ namespace Elwig.Helpers {
return new(true, null); return new(true, null);
} }
using var ctx = new AppDbContext();
int nr = int.Parse(input.Text); int nr = int.Parse(input.Text);
if (nr != m?.MgNr && ctx.MgNrExists(nr).GetAwaiter().GetResult()) { if (nr != m?.MgNr && ctx.MgNrExists(nr).GetAwaiter().GetResult()) {
return new(false, "Mitgliedsnummer wird bereits verwendet"); return new(false, "Mitgliedsnummer wird bereits verwendet");

View File

@ -156,9 +156,10 @@ namespace Elwig.Models.Entities {
[InverseProperty("Member")] [InverseProperty("Member")]
public virtual ISet<AreaCom> AreaCommitments { get; private set; } = null!; public virtual ISet<AreaCom> AreaCommitments { get; private set; } = null!;
[NotMapped] public IEnumerable<AreaCom> ActiveAreaCommitments(AppDbContext ctx) {
public IEnumerable<AreaCom> ActiveAreaCommitments => AreaCommitments return ctx.AreaCommitments
.Where(c => c.YearFrom <= Utils.CurrentYear && (c.YearTo ?? int.MaxValue) >= Utils.CurrentYear); .Where(c => c.MgNr == MgNr && c.YearFrom <= Utils.CurrentYear && (c.YearTo ?? int.MaxValue) >= Utils.CurrentYear);
}
[InverseProperty("Member")] [InverseProperty("Member")]
public virtual BillingAddr? BillingAddress { get; private set; } public virtual BillingAddr? BillingAddress { get; private set; }

View File

@ -8,7 +8,6 @@ using System.Windows.Input;
using Elwig.Helpers; using Elwig.Helpers;
using Elwig.Models.Entities; using Elwig.Models.Entities;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Elwig.Documents; using Elwig.Documents;
using System.Diagnostics; using System.Diagnostics;
@ -77,7 +76,8 @@ namespace Elwig.Windows {
if (IsEditing || IsCreating) return; if (IsEditing || IsCreating) return;
var item = MemberList.ItemsSource.Cast<Member>().FirstOrDefault(m => m.MgNr == mgnr); var item = MemberList.ItemsSource.Cast<Member>().FirstOrDefault(m => m.MgNr == mgnr);
if (item == null) { if (item == null) {
var m = Context.Members.Find(mgnr); using var ctx = new AppDbContext();
var m = ctx.Members.Find(mgnr);
if (m == null) return; if (m == null) return;
if (SearchInput.Text.Length > 0) { if (SearchInput.Text.Length > 0) {
SearchInput.Text = ""; SearchInput.Text = "";
@ -96,12 +96,12 @@ namespace Elwig.Windows {
} }
private async Task RefreshMemberList() { private async Task RefreshMemberList() {
await Context.Members.LoadAsync();
await RefreshMemberListQuery(); await RefreshMemberListQuery();
} }
private async Task RefreshMemberListQuery(bool updateSort = false) { private async Task RefreshMemberListQuery(bool updateSort = false) {
IQueryable<Member> memberQuery = Context.Members; using var ctx = new AppDbContext();
IQueryable<Member> memberQuery = ctx.Members;
if (ActiveMemberInput.IsChecked == true) memberQuery = memberQuery.Where(m => m.IsActive); if (ActiveMemberInput.IsChecked == true) memberQuery = memberQuery.Where(m => m.IsActive);
var filterMgNr = new List<int>(); var filterMgNr = new List<int>();
@ -113,10 +113,10 @@ namespace Elwig.Windows {
var filter = TextFilter.ToList(); var filter = TextFilter.ToList();
if (filter.Count > 0) { if (filter.Count > 0) {
var branches = await Context.Branches.ToListAsync(); var branches = await ctx.Branches.ToListAsync();
var mgnr = await Context.Members.ToDictionaryAsync(m => m.MgNr.ToString(), m => m); var mgnr = await ctx.Members.ToDictionaryAsync(m => m.MgNr.ToString(), m => m);
var kgs = await Context.WbKgs.ToDictionaryAsync(k => k.AtKg.Name.ToLower(), k => k.AtKg); var kgs = await ctx.WbKgs.ToDictionaryAsync(k => k.AtKg.Name.ToLower(), k => k.AtKg);
var areaComs = await Context.AreaCommitmentTypes.ToDictionaryAsync(t => $"{t.SortId}{t.AttrId}", t => t); var areaComs = await ctx.AreaCommitmentTypes.ToDictionaryAsync(t => $"{t.SortId}{t.AttrId}", t => t);
for (int i = 0; i < filter.Count; i++) { for (int i = 0; i < filter.Count; i++) {
var e = filter[i]; var e = filter[i];
@ -189,6 +189,15 @@ namespace Elwig.Windows {
if (filterUstIdNr.Count > 0) memberQuery = memberQuery.Where(m => m.UstIdNr != null && filterUstIdNr.Contains(m.UstIdNr)); if (filterUstIdNr.Count > 0) memberQuery = memberQuery.Where(m => m.UstIdNr != null && filterUstIdNr.Contains(m.UstIdNr));
} }
memberQuery = memberQuery
.Include(m => m.Branch)
.Include(m => m.DefaultWbKg.AtKg)
.Include(m => m.EmailAddresses)
.Include(m => m.TelephoneNumbers)
.Include(m => m.PostalDest.AtPlz.Ort)
.Include(m => m.PostalDest.AtPlz.Country)
.Include(m => m.BillingAddress.PostalDest.AtPlz.Ort)
.Include(m => m.BillingAddress.PostalDest.AtPlz.Country);
List<Member> members = await memberQuery.ToListAsync(); List<Member> members = await memberQuery.ToListAsync();
if (filter.Count > 0 && members.Count > 0) { if (filter.Count > 0 && members.Count > 0) {
@ -240,13 +249,15 @@ namespace Elwig.Windows {
ClearOriginalValues(); ClearOriginalValues();
ClearDefaultValues(); ClearDefaultValues();
MgNrInput.Text = (await Context.NextMgNr()).ToString(); using (var ctx = new AppDbContext()) {
EntryDateInput.Text = DateTime.Now.ToString("dd.MM.yyyy"); MgNrInput.Text = (await ctx.NextMgNr()).ToString();
if (Context.Branches.Count() == 1) EntryDateInput.Text = DateTime.Now.ToString("dd.MM.yyyy");
BranchInput.SelectedItem = Context.Branches.First(); if (await ctx.Branches.CountAsync() == 1)
ActiveInput.IsChecked = true; BranchInput.SelectedIndex = 0;
ContactPostalInput.IsChecked = true; ActiveInput.IsChecked = true;
MemberReferenceButton.IsEnabled = false; ContactPostalInput.IsChecked = true;
MemberReferenceButton.IsEnabled = false;
}
SetDefaultValue(MgNrInput); SetDefaultValue(MgNrInput);
SetDefaultValue(EntryDateInput); SetDefaultValue(EntryDateInput);
@ -256,11 +267,12 @@ namespace Elwig.Windows {
protected override async Task OnRenewContext() { protected override async Task OnRenewContext() {
await base.OnRenewContext(); await base.OnRenewContext();
ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId); using var ctx = new AppDbContext();
ControlUtils.RenewItemsSource(DefaultKgInput, await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr); ControlUtils.RenewItemsSource(BranchInput, await ctx.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId);
ControlUtils.RenewItemsSource(DefaultKgInput, await ctx.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr);
await RefreshMemberList(); await RefreshMemberList();
StatusMembers.Text = $"Mitglieder: {await Context.Members.CountAsync(m => m.IsActive):N0} ({await Context.Members.CountAsync():N0})"; StatusMembers.Text = $"Mitglieder: {await ctx.Members.CountAsync(m => m.IsActive):N0} ({await ctx.Members.CountAsync():N0})";
StatusBusinessShares.Text = $"Geschäftsanteile: {await Context.Members.Where(m => m.IsActive).SumAsync(m => m.BusinessShares):N0} ({await Context.Members.SumAsync(m => m.BusinessShares):N0})"; StatusBusinessShares.Text = $"Geschäftsanteile: {await ctx.Members.Where(m => m.IsActive).SumAsync(m => m.BusinessShares):N0} ({await ctx.Members.SumAsync(m => m.BusinessShares):N0})";
} }
private void SetPhoneNrInput(int nr, string? type, string? number, string? comment) { private void SetPhoneNrInput(int nr, string? type, string? number, string? comment) {
@ -359,14 +371,15 @@ namespace Elwig.Windows {
$"Sämtliche Lieferungen und Flächenbindungen dieses Mitglieds werden auch gelöscht!", $"Sämtliche Lieferungen und Flächenbindungen dieses Mitglieds werden auch gelöscht!",
"Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); "Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (r == MessageBoxResult.Yes) { if (r == MessageBoxResult.Yes) {
Context.Remove(m); using var ctx = new AppDbContext();
await Context.SaveChangesAsync(); ctx.Remove(m);
await ctx.SaveChangesAsync();
await RefreshMemberList(); await RefreshMemberList();
} }
} }
private async void SaveButton_Click(object sender, RoutedEventArgs evt) { private async void SaveButton_Click(object sender, RoutedEventArgs evt) {
Member m = await UpdateMember(MemberList.SelectedItem as Member); var mgnr = await UpdateMember((MemberList.SelectedItem as Member)?.MgNr);
IsEditing = false; IsEditing = false;
IsCreating = false; IsCreating = false;
MemberList.IsEnabled = true; MemberList.IsEnabled = true;
@ -379,7 +392,7 @@ namespace Elwig.Windows {
await RefreshMemberList(); await RefreshMemberList();
RefreshInputs(); RefreshInputs();
SearchInput.Text = ""; SearchInput.Text = "";
MemberList.SelectedItem = m; FocusMember(mgnr);
} }
private void ResetButton_Click(object sender, RoutedEventArgs evt) { private void ResetButton_Click(object sender, RoutedEventArgs evt) {
@ -446,7 +459,8 @@ namespace Elwig.Windows {
return; return;
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
try { try {
using var doc = new MemberDataSheet(m, Context); using var ctx = new AppDbContext();
using var doc = new MemberDataSheet(m, ctx);
await doc.Generate(); await doc.Generate();
if (App.Config.Debug) { if (App.Config.Debug) {
doc.Show(); doc.Show();
@ -464,7 +478,8 @@ namespace Elwig.Windows {
return; return;
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
try { try {
using var doc = new MemberDataSheet(m, Context); using var ctx = new AppDbContext();
using var doc = new MemberDataSheet(m, ctx);
await doc.Generate(); await doc.Generate();
doc.Show(); doc.Show();
} catch (Exception exc) { } catch (Exception exc) {
@ -548,9 +563,11 @@ namespace Elwig.Windows {
} }
} }
private async Task<Member> UpdateMember(Member? m) { private async Task<int> UpdateMember(int? mgnr) {
bool memberNew = (m == null); using var ctx = new AppDbContext();
m ??= Context.CreateProxy<Member>(); var m = ctx.CreateProxy<Member>();
if (mgnr != null)
m.MgNr = (int)mgnr;
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);
@ -585,23 +602,22 @@ namespace Elwig.Windows {
m.ContactViaPost = ContactPostalInput.IsChecked ?? false; m.ContactViaPost = ContactPostalInput.IsChecked ?? false;
m.ContactViaEmail = ContactEmailInput.IsChecked ?? false; m.ContactViaEmail = ContactEmailInput.IsChecked ?? false;
EntityEntry<Member>? tr = null;
try { try {
if (IsEditing) { if (IsEditing) {
tr = Context.Update(m); ctx.Update(m);
} else if (IsCreating) { } else if (IsCreating) {
m.MgNr = newMgNr; m.MgNr = newMgNr;
tr = (await Context.AddAsync(m)); await ctx.AddAsync(m);
} else { } else {
throw new Exception(); throw new Exception();
} }
if (BillingOrtInput.SelectedItem == null) { if (BillingOrtInput.SelectedItem == null) {
if (m.BillingAddress != null) { if (m.BillingAddress != null) {
Context.Remove(m.BillingAddress); ctx.Remove(m.BillingAddress);
} }
} else { } else {
BillingAddr b = m.BillingAddress ?? Context.CreateProxy<BillingAddr>(); BillingAddr b = m.BillingAddress ?? ctx.CreateProxy<BillingAddr>();
b.Name = BillingNameInput.Text; b.Name = BillingNameInput.Text;
b.Address = BillingAddressInput.Text; b.Address = BillingAddressInput.Text;
var p = (AT_PlzDest)BillingOrtInput.SelectedItem; var p = (AT_PlzDest)BillingOrtInput.SelectedItem;
@ -609,60 +625,52 @@ namespace Elwig.Windows {
b.PostalDestId = p.Id; b.PostalDestId = p.Id;
if (m.BillingAddress == null) { if (m.BillingAddress == null) {
b.MgNr = newMgNr; b.MgNr = newMgNr;
await Context.AddAsync(b); await ctx.AddAsync(b);
} else { } else {
Context.Update(b); ctx.Update(b);
} }
} }
Context.RemoveRange(m.TelephoneNumbers); ctx.RemoveRange(m.TelephoneNumbers);
for (int i = 0, j = 0; i < PhoneNrInputs.Length; i++) { for (int i = 0, j = 0; i < PhoneNrInputs.Length; i++) {
var input = GetPhoneNrInput(i); var input = GetPhoneNrInput(i);
if (input != null) { if (input != null) {
var pInput = input.Value; var pInput = input.Value;
MemberTelNr p = Context.CreateProxy<MemberTelNr>(); MemberTelNr p = ctx.CreateProxy<MemberTelNr>();
p.MgNr = newMgNr; p.MgNr = newMgNr;
p.Nr = ++j; p.Nr = ++j;
p.Type = pInput.Type; p.Type = pInput.Type;
p.Number = pInput.Number; p.Number = pInput.Number;
p.Comment = pInput.Comment; p.Comment = pInput.Comment;
await Context.AddAsync(p); await ctx.AddAsync(p);
} }
} }
Context.RemoveRange(m.EmailAddresses); ctx.RemoveRange(m.EmailAddresses);
for (int i = 0, j = 0; i < EmailAddressInputs.Length; i++) { for (int i = 0, j = 0; i < EmailAddressInputs.Length; i++) {
var input = GetEmailAddressInput(i); var input = GetEmailAddressInput(i);
if (input != null && input != "") { if (input != null && input != "") {
MemberEmailAddr a = Context.CreateProxy<MemberEmailAddr>(); MemberEmailAddr a = ctx.CreateProxy<MemberEmailAddr>();
a.MgNr = newMgNr; a.MgNr = newMgNr;
a.Nr = ++j; a.Nr = ++j;
a.Address = input; a.Address = input;
a.Comment = null; a.Comment = null;
await Context.AddAsync(a); await ctx.AddAsync(a);
} }
} }
await Context.SaveChangesAsync(); await ctx.SaveChangesAsync();
if (newMgNr != m.MgNr) { if (newMgNr != m.MgNr) {
await Context.Database.ExecuteSqlAsync($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}"); await ctx.Database.ExecuteSqlAsync($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}");
tr.State = EntityState.Detached;
await Context.SaveChangesAsync();
await tr.ReloadAsync();
m = await Context.Members.FindAsync(newMgNr);
} }
} catch (Exception exc) { } catch (Exception exc) {
if (tr != null) {
tr.State = EntityState.Detached;
await tr.ReloadAsync();
}
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
} }
return m; return m.MgNr;
} }
private void FillInputs(Member m) { private void FillInputs(Member m) {
@ -689,7 +697,7 @@ namespace Elwig.Windows {
AT_PlzDest? p = m.PostalDest.AtPlz; AT_PlzDest? p = m.PostalDest.AtPlz;
if (p != null) { if (p != null) {
PlzInput.Text = p.Plz.ToString(); PlzInput.Text = p.Plz.ToString();
OrtInput.SelectedItem = p; ControlUtils.SelectComboBoxItem(OrtInput, o => (o as AT_PlzDest)?.Okz, p.Okz);
} else { } else {
PlzInput.Text = null; PlzInput.Text = null;
OrtInput.SelectedItem = null; OrtInput.SelectedItem = null;
@ -731,7 +739,7 @@ namespace Elwig.Windows {
AT_PlzDest? b = billingAddr.PostalDest.AtPlz; AT_PlzDest? b = billingAddr.PostalDest.AtPlz;
if (b != null) { if (b != null) {
BillingPlzInput.Text = b.Plz.ToString(); BillingPlzInput.Text = b.Plz.ToString();
BillingOrtInput.SelectedItem = b; ControlUtils.SelectComboBoxItem(BillingOrtInput, o => (o as AT_PlzDest)?.Okz, b.Okz);
} }
} else { } else {
BillingNameInput.Text = ""; BillingNameInput.Text = "";
@ -744,8 +752,8 @@ namespace Elwig.Windows {
ExitDateInput.Text = (m.ExitDateString != null) ? string.Join(".", m.ExitDateString.Split("-").Reverse()) : null; ExitDateInput.Text = (m.ExitDateString != null) ? string.Join(".", m.ExitDateString.Split("-").Reverse()) : null;
BusinessSharesInput.Text = m.BusinessShares.ToString(); BusinessSharesInput.Text = m.BusinessShares.ToString();
AccountingNrInput.Text = m.AccountingNr; AccountingNrInput.Text = m.AccountingNr;
BranchInput.SelectedItem = m.Branch; ControlUtils.SelectComboBoxItem(BranchInput, b => (b as Branch)?.ZwstId, m.ZwstId);
DefaultKgInput.SelectedItem = m.DefaultKg; ControlUtils.SelectComboBoxItem(DefaultKgInput, k => (k as AT_Kg)?.KgNr, m.DefaultKgNr);
CommentInput.Text = m.Comment; CommentInput.Text = m.Comment;
ActiveInput.IsChecked = m.IsActive; ActiveInput.IsChecked = m.IsActive;
VollLieferantInput.IsChecked = m.IsVollLieferant; VollLieferantInput.IsChecked = m.IsVollLieferant;
@ -753,11 +761,13 @@ namespace Elwig.Windows {
ContactPostalInput.IsChecked = m.ContactViaPost; ContactPostalInput.IsChecked = m.ContactViaPost;
ContactEmailInput.IsChecked = m.ContactViaEmail; ContactEmailInput.IsChecked = m.ContactViaEmail;
var d1 = Context.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason && d.MgNr == m.MgNr); using (var ctx = new AppDbContext()) {
var d2 = Context.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason - 1 && d.MgNr == m.MgNr); var d1 = ctx.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason && d.MgNr == m.MgNr);
StatusDeliveriesLastSeason.Text = $"Lieferungen ({Utils.CurrentLastSeason - 1}): {d2.Count():N0} ({d2.Sum(d => d.Parts.Count):N0}), {d2.SelectMany(d => d.Parts).Sum(p => p.Weight):N0} kg"; var d2 = ctx.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason - 1 && d.MgNr == m.MgNr);
StatusDeliveriesThisSeason.Text = $"Lieferungen ({Utils.CurrentLastSeason}): {d1.Count():N0} ({d1.Sum(d => d.Parts.Count):N0}), {d1.SelectMany(d => d.Parts).Sum(p => p.Weight):N0} kg"; StatusDeliveriesLastSeason.Text = $"Lieferungen ({Utils.CurrentLastSeason - 1}): {d2.Count():N0} ({d2.Sum(d => d.Parts.Count):N0}), {d2.SelectMany(d => d.Parts).Sum(p => p.Weight):N0} kg";
StatusAreaCommitment.Text = $"Gebundene Fläche: {m.ActiveAreaCommitments.Select(c => c.Area).Sum():N0} "; StatusDeliveriesThisSeason.Text = $"Lieferungen ({Utils.CurrentLastSeason}): {d1.Count():N0} ({d1.Sum(d => d.Parts.Count):N0}), {d1.SelectMany(d => d.Parts).Sum(p => p.Weight):N0} kg";
StatusAreaCommitment.Text = $"Gebundene Fläche: {m.ActiveAreaCommitments(ctx).Select(c => c.Area).Sum():N0} m²";
}
Menu_Member_SendEmail.IsEnabled = m.EmailAddresses.Count > 0; Menu_Member_SendEmail.IsEnabled = m.EmailAddresses.Count > 0;
Menu_Print_Letterhead.IsEnabled = true; Menu_Print_Letterhead.IsEnabled = true;
@ -787,12 +797,12 @@ namespace Elwig.Windows {
SaveButton.IsEnabled = v && ch; SaveButton.IsEnabled = v && ch;
} }
protected void InputTextChanged(TextBox input, Func<TextBox, bool, AppDbContext, Member?, ValidationResult> checker) { protected void InputTextChanged(TextBox input, Func<TextBox, bool, Member?, ValidationResult> checker) {
InputTextChanged(input, checker(input, SenderIsRequired(input), Context, (Member)MemberList.SelectedItem)); InputTextChanged(input, checker(input, SenderIsRequired(input), (Member)MemberList.SelectedItem));
} }
protected void InputLostFocus(TextBox input, Func<TextBox, bool, AppDbContext, Member?, ValidationResult> checker, string? msg = null) { protected void InputLostFocus(TextBox input, Func<TextBox, bool, Member?, ValidationResult> checker, string? msg = null) {
InputLostFocus(input, checker(input, SenderIsRequired(input), Context, (Member)MemberList.SelectedItem), msg); InputLostFocus(input, checker(input, SenderIsRequired(input), (Member)MemberList.SelectedItem), msg);
} }
private void MgNrInput_TextChanged(object sender, RoutedEventArgs evt) { private void MgNrInput_TextChanged(object sender, RoutedEventArgs evt) {