[#43] BaseDataWindow: Do not use Context from ContextWindow any more
This commit is contained in:
@ -18,16 +18,20 @@ namespace Elwig.Windows {
|
||||
private bool _actChanged = false;
|
||||
private bool _actUpdate = false;
|
||||
|
||||
private void AreaCommitmentTypesInitEditing() {
|
||||
_actList = new(Context.AreaCommitmentTypes.OrderBy(v => v.VtrgId).ToList());
|
||||
private async Task AreaCommitmentTypesInitEditing(AppDbContext ctx) {
|
||||
_actList = new(await ctx.AreaCommitmentTypes
|
||||
.OrderBy(v => v.VtrgId)
|
||||
.Include(t => t.WineVar)
|
||||
.Include(t => t.WineAttr)
|
||||
.ToListAsync());
|
||||
_acts = _actList.ToDictionary(v => v.VtrgId, v => (string?)v.VtrgId);
|
||||
_actIds = _actList.ToDictionary(v => v, v => v.VtrgId);
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, _actList, a => (a as AreaComType)?.VtrgId);
|
||||
AreaCommitmentTypeList_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private void AreaCommitmentTypesFinishEditing() {
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, Context.AreaCommitmentTypes.OrderBy(v => v.SortId).ToList(), v => (v as AreaComType)?.VtrgId);
|
||||
private async Task AreaCommitmentTypesFinishEditing(AppDbContext ctx) {
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes.OrderBy(v => v.SortId).ToListAsync(), v => (v as AreaComType)?.VtrgId);
|
||||
_actList = null;
|
||||
_acts = null;
|
||||
_actIds = null;
|
||||
@ -37,31 +41,31 @@ namespace Elwig.Windows {
|
||||
AreaCommitmentTypeDeleteButton.IsEnabled = false;
|
||||
}
|
||||
|
||||
private async Task AreaCommitmentTypesSave() {
|
||||
private async Task AreaCommitmentTypesSave(AppDbContext ctx) {
|
||||
if (!_actChanged || _actList == null || _acts == null || _actIds == null)
|
||||
return;
|
||||
|
||||
foreach (var (vtrgid, _) in _acts.Where(a => a.Value == null)) {
|
||||
Context.Remove(Context.AreaCommitmentTypes.Find(vtrgid));
|
||||
ctx.Remove(ctx.AreaCommitmentTypes.Find(vtrgid)!);
|
||||
}
|
||||
foreach (var (attr, old) in _actIds) {
|
||||
attr.VtrgId = old;
|
||||
}
|
||||
foreach (var (old, vtrgid) in _acts.Where(a => a.Value != null)) {
|
||||
Context.Update(Context.AreaCommitmentTypes.Find(old));
|
||||
ctx.Update(ctx.AreaCommitmentTypes.Find(old)!);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var (old, vtrgid) in _acts.Where(a => a.Value != null)) {
|
||||
await Context.Database.ExecuteSqlAsync($"UPDATE area_commitment_type SET vtrgid = {vtrgid} WHERE vtrgid = {old}");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE area_commitment_type SET vtrgid = {vtrgid} WHERE vtrgid = {old}");
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var type in _actList.Where(a => !_actIds.ContainsKey(a))) {
|
||||
if (type.VtrgId == null) continue;
|
||||
await Context.AddAsync(type);
|
||||
ctx.Add(type);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void AreaCommitmentTypeList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
|
||||
@ -90,7 +94,7 @@ namespace Elwig.Windows {
|
||||
private void AreaCommitmentTypeAddButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (_actList == null) return;
|
||||
_actChanged = true;
|
||||
var item = Context.CreateProxy<AreaComType>();
|
||||
var item = new AreaComType { VtrgId = "", SortId = "" };
|
||||
_actList.Add(item);
|
||||
AreaCommitmentTypeList.SelectedItem = item;
|
||||
UpdateButtons();
|
||||
|
@ -18,16 +18,22 @@ namespace Elwig.Windows {
|
||||
private bool _branchChanged = false;
|
||||
private bool _branchUpdate = false;
|
||||
|
||||
private void BranchesInitEditing() {
|
||||
_branchList = new(Context.Branches.OrderBy(b => b.Name).ToList());
|
||||
private async Task BranchesInitEditing(AppDbContext ctx) {
|
||||
_branchList = new(await ctx.Branches
|
||||
.OrderBy(b => b.Name)
|
||||
.Include(b => b.PostalDest!.AtPlz)
|
||||
.ToListAsync());
|
||||
_branches = _branchList.ToDictionary(b => b.ZwstId, b => (string?)b.ZwstId);
|
||||
_branchIds = _branchList.ToDictionary(b => b, b => b.ZwstId);
|
||||
ControlUtils.RenewItemsSource(BranchList, _branchList, b => (b as Branch)?.ZwstId);
|
||||
BranchList_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private void BranchesFinishEditing() {
|
||||
ControlUtils.RenewItemsSource(BranchList, Context.Branches.OrderBy(b => b.Name).ToList(), b => (b as Branch)?.ZwstId);
|
||||
private async Task BranchesFinishEditing(AppDbContext ctx) {
|
||||
ControlUtils.RenewItemsSource(BranchList, await ctx.Branches
|
||||
.OrderBy(b => b.Name)
|
||||
.Include(b => b.PostalDest!.AtPlz)
|
||||
.ToListAsync(), b => (b as Branch)?.ZwstId);
|
||||
_branchList = null;
|
||||
_branches = null;
|
||||
_branchIds = null;
|
||||
@ -37,31 +43,31 @@ namespace Elwig.Windows {
|
||||
BranchDeleteButton.IsEnabled = false;
|
||||
}
|
||||
|
||||
private async Task BranchesSave() {
|
||||
private async Task BranchesSave(AppDbContext ctx) {
|
||||
if (!_branchChanged || _branchList == null || _branches == null || _branchIds == null)
|
||||
return;
|
||||
|
||||
foreach (var (zwstid, _) in _branches.Where(b => b.Value == null)) {
|
||||
Context.Remove(Context.Branches.Find(zwstid));
|
||||
ctx.Remove(ctx.Branches.Find(zwstid)!);
|
||||
}
|
||||
foreach (var (branch, old) in _branchIds) {
|
||||
branch.ZwstId = old;
|
||||
}
|
||||
foreach (var (old, zwstid) in _branches.Where(b => b.Value != null)) {
|
||||
Context.Update(Context.Branches.Find(old));
|
||||
ctx.Update(ctx.Branches.Find(old)!);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var (old, zwstid) in _branches.Where(b => b.Value != null)) {
|
||||
await Context.Database.ExecuteSqlAsync($"UPDATE branch SET zwstid = {zwstid} WHERE zwstid = {old}");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE branch SET zwstid = {zwstid} WHERE zwstid = {old}");
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var branch in _branchList.Where(b => !_branchIds.ContainsKey(b))) {
|
||||
if (branch.ZwstId == null) continue;
|
||||
await Context.AddAsync(branch);
|
||||
ctx.Add(branch);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void BranchList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
|
||||
@ -91,7 +97,7 @@ namespace Elwig.Windows {
|
||||
private void BranchAddButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (_branchList == null) return;
|
||||
_branchChanged = true;
|
||||
var item = Context.CreateProxy<Branch>();
|
||||
var item = new Branch { ZwstId = "", Name = "" };
|
||||
_branchList.Add(item);
|
||||
BranchList.SelectedItem = item;
|
||||
UpdateButtons();
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Entities;
|
||||
using LinqKit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@ -18,19 +19,19 @@ namespace Elwig.Windows {
|
||||
private bool _modChanged = false;
|
||||
private bool _modUpdate = false;
|
||||
|
||||
private void ModifiersInitEditing() {
|
||||
private async Task ModifiersInitEditing(AppDbContext ctx) {
|
||||
SeasonList.IsEnabled = false;
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
_modList = new(Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToList());
|
||||
_modList = new(await ctx.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync());
|
||||
_mods = _modList.ToDictionary(m => m.ModId, m => (string?)m.ModId);
|
||||
_modIds = _modList.ToDictionary(m => m, m => m.ModId);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, _modList, m => (m as Modifier)?.ModId);
|
||||
SeasonModifierList_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private void ModifiersFinishEditing() {
|
||||
private async Task ModifiersFinishEditing(AppDbContext ctx) {
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToList(), m => (m as Modifier)?.ModId);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync(), m => (m as Modifier)?.ModId);
|
||||
_modList = null;
|
||||
_mods = null;
|
||||
_modIds = null;
|
||||
@ -43,7 +44,7 @@ namespace Elwig.Windows {
|
||||
SeasonList.IsEnabled = true;
|
||||
}
|
||||
|
||||
private async Task ModifiersSave() {
|
||||
private async Task ModifiersSave(AppDbContext ctx) {
|
||||
if (!_modChanged || _modList == null || _mods == null || _modIds == null)
|
||||
return;
|
||||
|
||||
@ -52,26 +53,26 @@ namespace Elwig.Windows {
|
||||
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
foreach (var (modid, _) in _mods.Where(m => m.Value == null)) {
|
||||
Context.Remove(Context.Modifiers.Find(year, modid)!);
|
||||
ctx.Remove(ctx.Modifiers.Find(year, modid)!);
|
||||
}
|
||||
foreach (var (mod, old) in _modIds) {
|
||||
mod.ModId = old;
|
||||
}
|
||||
foreach (var (old, modid) in _mods.Where(m => m.Value != null)) {
|
||||
Context.Update(Context.Modifiers.Find(year, old)!);
|
||||
ctx.Update(ctx.Modifiers.Find(year, old)!);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var (old, modid) in _mods.Where(m => m.Value != null)) {
|
||||
await Context.Database.ExecuteSqlAsync($"UPDATE modifier SET modid = {modid} WHERE (year, modid) = ({year}, {old})");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE modifier SET modid = {modid} WHERE (year, modid) = ({year}, {old})");
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var mod in _modList.Where(m => !_modIds.ContainsKey(m))) {
|
||||
if (mod.ModId == null) continue;
|
||||
await Context.AddAsync(mod);
|
||||
await ctx.AddAsync(mod);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void SeasonModifierUpButton_Click(object sender, RoutedEventArgs evt) {
|
||||
@ -102,11 +103,7 @@ namespace Elwig.Windows {
|
||||
if (_modList == null || SeasonList.SelectedItem is not Season s) return;
|
||||
_modChanged = true;
|
||||
var idx = (SeasonModifierList.SelectedIndex != -1) ? SeasonModifierList.SelectedIndex + 1 : _modList.Count;
|
||||
var item = new Modifier {
|
||||
Year = s.Year,
|
||||
ModId = "",
|
||||
Name = "",
|
||||
};
|
||||
var item = new Modifier { Year = s.Year, ModId = "", Name = "" };
|
||||
_modList.Insert(idx, item);
|
||||
SeasonModifierList.SelectedIndex = idx;
|
||||
UpdateButtons();
|
||||
|
@ -12,27 +12,27 @@ namespace Elwig.Windows {
|
||||
private bool _seasonChanged = false;
|
||||
private bool _seasonUpdate = false;
|
||||
|
||||
private void SeasonsInitEditing() {
|
||||
ControlUtils.RenewItemsSource(SeasonList, Context.Seasons.OrderByDescending(s => s.Year).ToList(), s => (s as Season)?.Year);
|
||||
private async Task SeasonsInitEditing(AppDbContext ctx) {
|
||||
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year);
|
||||
SeasonList_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private void SeasonsFinishEditing() {
|
||||
ControlUtils.RenewItemsSource(SeasonList, Context.Seasons.OrderByDescending(s => s.Year).ToList(), s => (s as Season)?.Year);
|
||||
private async Task SeasonsFinishEditing(AppDbContext ctx) {
|
||||
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).Include(s => s.Modifiers).ToListAsync(), s => (s as Season)?.Year);
|
||||
_seasonChanged = false;
|
||||
}
|
||||
|
||||
private async Task SeasonsSave() {
|
||||
private async Task SeasonsSave(AppDbContext ctx) {
|
||||
if (!_seasonChanged || SeasonList.SelectedItem is not Season s)
|
||||
return;
|
||||
Context.Update(s);
|
||||
await Context.SaveChangesAsync();
|
||||
ctx.Update(s);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private async void SeasonList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
|
||||
private void SeasonList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
|
||||
_seasonUpdate = true;
|
||||
if (SeasonList.SelectedItem is Season s) {
|
||||
SeasonModifierList.ItemsSource = await Context.Modifiers.Where(m => m.Year == s.Year).OrderBy(m => m.Ordering).ToListAsync();
|
||||
SeasonModifierList.ItemsSource = s.Modifiers.OrderBy(m => m.Ordering).ToList();
|
||||
SeasonMaxKgPerHaInput.Text = s.MaxKgPerHa.ToString();
|
||||
SeasonVatNormalInput.Text = (s.VatNormal * 100).ToString();
|
||||
SeasonVatFlatrateInput.Text = (s.VatFlatrate * 100).ToString();
|
||||
|
@ -18,16 +18,16 @@ namespace Elwig.Windows {
|
||||
private bool _attrChanged = false;
|
||||
private bool _attrUpdate = false;
|
||||
|
||||
private void WineAttributesInitEditing() {
|
||||
_attrList = new(Context.WineAttributes.OrderBy(a => a.Name).ToList());
|
||||
private async Task WineAttributesInitEditing(AppDbContext ctx) {
|
||||
_attrList = new(await ctx.WineAttributes.OrderBy(a => a.Name).ToListAsync());
|
||||
_attrs = _attrList.ToDictionary(a => a.AttrId, a => (string?)a.AttrId);
|
||||
_attrIds = _attrList.ToDictionary(a => a, a => a.AttrId);
|
||||
ControlUtils.RenewItemsSource(WineAttributeList, _attrList, a => (a as WineAttr)?.AttrId);
|
||||
WineAttributeList_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private void WineAttributesFinishEditing() {
|
||||
ControlUtils.RenewItemsSource(WineAttributeList, Context.WineAttributes.OrderBy(a => a.Name).ToList(), a => (a as WineAttr)?.AttrId);
|
||||
private async Task WineAttributesFinishEditing(AppDbContext ctx) {
|
||||
ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes.OrderBy(a => a.Name).ToListAsync(), a => (a as WineAttr)?.AttrId);
|
||||
_attrList = null;
|
||||
_attrs = null;
|
||||
_attrIds = null;
|
||||
@ -37,31 +37,31 @@ namespace Elwig.Windows {
|
||||
WineAttributeDeleteButton.IsEnabled = false;
|
||||
}
|
||||
|
||||
private async Task WineAttributesSave() {
|
||||
private async Task WineAttributesSave(AppDbContext ctx) {
|
||||
if (!_attrChanged || _attrList == null || _attrs == null || _attrIds == null)
|
||||
return;
|
||||
|
||||
foreach (var (attrid, _) in _attrs.Where(a => a.Value == null)) {
|
||||
Context.Remove(Context.WineAttributes.Find(attrid));
|
||||
ctx.Remove(ctx.WineAttributes.Find(attrid)!);
|
||||
}
|
||||
foreach (var (attr, old) in _attrIds) {
|
||||
attr.AttrId = old;
|
||||
}
|
||||
foreach (var (old, attrid) in _attrs.Where(a => a.Value != null)) {
|
||||
Context.Update(Context.WineAttributes.Find(old));
|
||||
ctx.Update(ctx.WineAttributes.Find(old)!);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var (old, attrid) in _attrs.Where(a => a.Value != null)) {
|
||||
await Context.Database.ExecuteSqlAsync($"UPDATE wine_attribute SET attrid = {attrid} WHERE attrid = {old}");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE wine_attribute SET attrid = {attrid} WHERE attrid = {old}");
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var attr in _attrList.Where(a => !_attrIds.ContainsKey(a))) {
|
||||
if (attr.AttrId == null) continue;
|
||||
await Context.AddAsync(attr);
|
||||
ctx.Add(attr);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void WineAttributeList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
|
||||
@ -88,7 +88,7 @@ namespace Elwig.Windows {
|
||||
private void WineAttributeAddButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (_attrList == null) return;
|
||||
_attrChanged = true;
|
||||
var item = Context.CreateProxy<WineAttr>();
|
||||
var item = new WineAttr { AttrId = "", Name = "" };
|
||||
_attrList.Add(item);
|
||||
WineAttributeList.SelectedItem = item;
|
||||
UpdateButtons();
|
||||
|
@ -18,16 +18,16 @@ namespace Elwig.Windows {
|
||||
private bool _cultChanged = false;
|
||||
private bool _cultUpdate = false;
|
||||
|
||||
private void WineCultivationsInitEditing() {
|
||||
_cultList = new(Context.WineCultivations.OrderBy(c => c.Name).ToList());
|
||||
private async Task WineCultivationsInitEditing(AppDbContext ctx) {
|
||||
_cultList = new(await ctx.WineCultivations.OrderBy(c => c.Name).ToListAsync());
|
||||
_cults = _cultList.ToDictionary(c => c.CultId, c => (string?)c.CultId);
|
||||
_cultIds = _cultList.ToDictionary(c => c, c => c.CultId);
|
||||
ControlUtils.RenewItemsSource(WineCultivationList, _cultList, c => (c as WineCult)?.CultId);
|
||||
WineCultivationList_SelectionChanged(null, null);
|
||||
}
|
||||
|
||||
private void WineCultivationsFinishEditing() {
|
||||
ControlUtils.RenewItemsSource(WineCultivationList, Context.WineCultivations.OrderBy(c => c.Name).ToList(), c => (c as WineCult)?.CultId);
|
||||
private async Task WineCultivationsFinishEditing(AppDbContext ctx) {
|
||||
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations.OrderBy(c => c.Name).ToListAsync(), c => (c as WineCult)?.CultId);
|
||||
_cultList = null;
|
||||
_cults = null;
|
||||
_cultIds = null;
|
||||
@ -37,31 +37,31 @@ namespace Elwig.Windows {
|
||||
WineCultivationDeleteButton.IsEnabled = false;
|
||||
}
|
||||
|
||||
private async Task WineCultivationsSave() {
|
||||
private async Task WineCultivationsSave(AppDbContext ctx) {
|
||||
if (!_cultChanged || _cultList == null || _cults == null || _cultIds == null)
|
||||
return;
|
||||
|
||||
foreach (var (cultid, _) in _cults.Where(c => c.Value == null)) {
|
||||
Context.Remove(Context.WineCultivations.Find(cultid));
|
||||
ctx.Remove(ctx.WineCultivations.Find(cultid)!);
|
||||
}
|
||||
foreach (var (cult, old) in _cultIds) {
|
||||
cult.CultId = old;
|
||||
}
|
||||
foreach (var (old, cultid) in _cults.Where(c => c.Value != null)) {
|
||||
Context.Update(Context.WineCultivations.Find(old));
|
||||
ctx.Update(ctx.WineCultivations.Find(old)!);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var (old, cultid) in _cults.Where(c => c.Value != null)) {
|
||||
await Context.Database.ExecuteSqlAsync($"UPDATE wine_cultivation SET cultid = {cultid} WHERE cultid = {old}");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE wine_cultivation SET cultid = {cultid} WHERE cultid = {old}");
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var cult in _cultList.Where(c => !_cultIds.ContainsKey(c))) {
|
||||
if (cult.CultId == null) continue;
|
||||
await Context.AddAsync(cult);
|
||||
ctx.Add(cult);
|
||||
}
|
||||
await Context.SaveChangesAsync();
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void WineCultivationList_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
|
||||
@ -82,7 +82,7 @@ namespace Elwig.Windows {
|
||||
private void WineCultivationAddButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (_cultList == null) return;
|
||||
_cultChanged = true;
|
||||
var item = Context.CreateProxy<WineCult>();
|
||||
var item = new WineCult { CultId = "", Name = "" };
|
||||
_cultList.Add(item);
|
||||
WineCultivationList.SelectedItem = item;
|
||||
UpdateButtons();
|
||||
|
@ -133,18 +133,37 @@ namespace Elwig.Windows {
|
||||
|
||||
protected override async Task OnRenewContext() {
|
||||
await base.OnRenewContext();
|
||||
using var ctx = new AppDbContext();
|
||||
FillInputs(App.Client);
|
||||
ControlUtils.RenewItemsSource(SeasonList, await Context.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons
|
||||
.OrderByDescending(s => s.Year)
|
||||
.ToListAsync(), s => (s as Season)?.Year, null, ControlUtils.RenewSourceDefault.First);
|
||||
var year = (SeasonList.SelectedItem as Season)?.Year;
|
||||
ControlUtils.RenewItemsSource(BranchList, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), b => (b as Branch)?.ZwstId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineAttributeList, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), a => (a as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineVariantInput, await Context.WineVarieties.OrderBy(s => s.Name).ToListAsync(), s => (s as WineVar)?.SortId);
|
||||
var attrList = await Context.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
|
||||
ControlUtils.RenewItemsSource(BranchList, await ctx.Branches
|
||||
.OrderBy(b => b.Name)
|
||||
.Include(b => b.PostalDest!.AtPlz)
|
||||
.ToListAsync(), b => (b as Branch)?.ZwstId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes
|
||||
.OrderBy(a => a.Name)
|
||||
.ToListAsync(), a => (a as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineVariantInput, await ctx.WineVarieties
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync(), s => (s as WineVar)?.SortId);
|
||||
var attrList = await ctx.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
|
||||
attrList.Insert(0, new NullItem(""));
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineAttributeInput, attrList, a => (a as WineAttr)?.AttrId);
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await Context.AreaCommitmentTypes.OrderBy(v => v.VtrgId).ToListAsync(), v => (v as AreaComType)?.VtrgId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineCultivationList, await Context.WineCultivations.OrderBy(c => c.Name).ToListAsync(), c=> (c as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await Context.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync(), m => (m as Modifier)?.ModId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes
|
||||
.OrderBy(t => t.VtrgId)
|
||||
.Include(t => t.WineVar)
|
||||
.Include(t => t.WineAttr)
|
||||
.ToListAsync(), t => (t as AreaComType)?.VtrgId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations
|
||||
.OrderBy(c => c.Name)
|
||||
.ToListAsync(), c=> (c as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers
|
||||
.Where(m => m.Year == year)
|
||||
.OrderBy(m => m.Ordering)
|
||||
.ToListAsync(), m => (m as Modifier)?.ModId, null, ControlUtils.RenewSourceDefault.First);
|
||||
}
|
||||
|
||||
protected override void UpdateButtons() {
|
||||
@ -174,23 +193,52 @@ namespace Elwig.Windows {
|
||||
App.FocusOriginHierarchy();
|
||||
}
|
||||
|
||||
private void EditButton_Click(object sender, RoutedEventArgs evt) {
|
||||
private async Task InitEditing() {
|
||||
using var ctx = new AppDbContext();
|
||||
await BranchesInitEditing(ctx);
|
||||
await WineAttributesInitEditing(ctx);
|
||||
await WineCultivationsInitEditing(ctx);
|
||||
await AreaCommitmentTypesInitEditing(ctx);
|
||||
await SeasonsInitEditing(ctx);
|
||||
await ModifiersInitEditing(ctx);
|
||||
}
|
||||
|
||||
private async Task Save() {
|
||||
using var ctx = new AppDbContext();
|
||||
// FIXME
|
||||
//using var tx = await ctx.Database.BeginTransactionAsync();
|
||||
await UpdateClientParameters(App.Client);
|
||||
await BranchesSave(ctx);
|
||||
await WineAttributesSave(ctx);
|
||||
await WineCultivationsSave(ctx);
|
||||
await AreaCommitmentTypesSave(ctx);
|
||||
await SeasonsSave(ctx);
|
||||
await ModifiersSave(ctx);
|
||||
//await tx.CommitAsync();
|
||||
}
|
||||
|
||||
private async Task FinishEditing() {
|
||||
using var ctx = new AppDbContext();
|
||||
await BranchesFinishEditing(ctx);
|
||||
await WineAttributesFinishEditing(ctx);
|
||||
await WineCultivationsFinishEditing(ctx);
|
||||
await AreaCommitmentTypesFinishEditing(ctx);
|
||||
await SeasonsFinishEditing(ctx);
|
||||
await ModifiersFinishEditing(ctx);
|
||||
}
|
||||
|
||||
private async void EditButton_Click(object sender, RoutedEventArgs evt) {
|
||||
IsEditing = true;
|
||||
EditButton.Visibility = Visibility.Hidden;
|
||||
ResetButton.Visibility = Visibility.Visible;
|
||||
|
||||
BranchesInitEditing();
|
||||
WineAttributesInitEditing();
|
||||
WineCultivationsInitEditing();
|
||||
AreaCommitmentTypesInitEditing();
|
||||
SeasonsInitEditing();
|
||||
ModifiersInitEditing();
|
||||
await InitEditing();
|
||||
|
||||
UnlockInputs();
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs evt) {
|
||||
private async void CancelButton_Click(object sender, RoutedEventArgs evt) {
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
EditButton.Visibility = Visibility.Visible;
|
||||
@ -199,32 +247,20 @@ namespace Elwig.Windows {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
|
||||
Context.ChangeTracker.Clear();
|
||||
BranchesFinishEditing();
|
||||
WineCultivationsFinishEditing();
|
||||
WineAttributesFinishEditing();
|
||||
AreaCommitmentTypesFinishEditing();
|
||||
SeasonsFinishEditing();
|
||||
ModifiersFinishEditing();
|
||||
await FinishEditing();
|
||||
|
||||
ClearInputStates();
|
||||
FillInputs(App.Client);
|
||||
LockInputs();
|
||||
}
|
||||
|
||||
private void ResetButton_Click(object sender, RoutedEventArgs evt) {
|
||||
private async void ResetButton_Click(object sender, RoutedEventArgs evt) {
|
||||
_branchChanged = false;
|
||||
_attrChanged = false;
|
||||
_cultChanged = false;
|
||||
_modChanged = false;
|
||||
Context.ChangeTracker.Clear();
|
||||
|
||||
BranchesInitEditing();
|
||||
WineAttributesInitEditing();
|
||||
WineCultivationsInitEditing();
|
||||
AreaCommitmentTypesInitEditing();
|
||||
SeasonsInitEditing();
|
||||
ModifiersInitEditing();
|
||||
await InitEditing();
|
||||
|
||||
ClearInputStates();
|
||||
FillInputs(App.Client);
|
||||
@ -233,13 +269,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
await UpdateClientParameters(App.Client);
|
||||
await BranchesSave();
|
||||
await WineAttributesSave();
|
||||
await WineCultivationsSave();
|
||||
await AreaCommitmentTypesSave();
|
||||
await SeasonsSave();
|
||||
await ModifiersSave();
|
||||
await Save();
|
||||
} catch (Exception exc) {
|
||||
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;
|
||||
@ -254,12 +284,7 @@ namespace Elwig.Windows {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
|
||||
BranchesFinishEditing();
|
||||
WineAttributesFinishEditing();
|
||||
WineCultivationsFinishEditing();
|
||||
AreaCommitmentTypesFinishEditing();
|
||||
SeasonsFinishEditing();
|
||||
ModifiersFinishEditing();
|
||||
await FinishEditing();
|
||||
|
||||
ClearInputStates();
|
||||
FillInputs(App.Client);
|
||||
|
Reference in New Issue
Block a user