Adust AreaComAdminWindow to new db schema
This commit is contained in:
@ -25,12 +25,12 @@ namespace Elwig.Windows {
|
||||
};
|
||||
RequiredInputs = new Control[] {
|
||||
FbNrInput, YearFromInput, KgInput,
|
||||
GstNrInput, AreaInput, WineVarietyInput, WineCultivationInput
|
||||
GstNrInput, AreaInput, AreaComTypeInput, WineCultivationInput
|
||||
};
|
||||
}
|
||||
|
||||
private async void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
await RenewContext();
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
LockInputs();
|
||||
}
|
||||
|
||||
private async Task RefreshAreaCommitmentList() {
|
||||
@ -50,9 +50,7 @@ namespace Elwig.Windows {
|
||||
|
||||
private void RefreshInputs(bool validate = false) {
|
||||
ClearInputStates();
|
||||
AreaCom? a = (AreaCom)AreaCommitmentList.SelectedItem;
|
||||
|
||||
if (a != null) {
|
||||
if (AreaCommitmentList.SelectedItem is AreaCom a) {
|
||||
EditAreaCommitmentButton.IsEnabled = true;
|
||||
DeleteAreaCommitmentButton.IsEnabled = true;
|
||||
FillInputs(a);
|
||||
@ -60,11 +58,9 @@ namespace Elwig.Windows {
|
||||
EditAreaCommitmentButton.IsEnabled = false;
|
||||
DeleteAreaCommitmentButton.IsEnabled = false;
|
||||
ClearOriginalValues();
|
||||
ClearInputs();
|
||||
AttributesInput.UnSelectAll();
|
||||
MgNrInput.Text = "";
|
||||
ClearInputs(validate);
|
||||
ClearInputStates();
|
||||
}
|
||||
if (!validate) ClearInputStates();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
@ -81,13 +77,7 @@ namespace Elwig.Windows {
|
||||
GstNrInput.Text = a.GstNr;
|
||||
AreaInput.Text = a.Area.ToString();
|
||||
|
||||
WineVarietyInput.SelectedItem = a.WineVar;
|
||||
|
||||
AttributesInput.UnSelectAll();
|
||||
foreach (var attr in a.Attributes) {
|
||||
AttributesInput.SelectedItems.Add(attr);
|
||||
}
|
||||
|
||||
AreaComTypeInput.SelectedItem = a.AreaComType;
|
||||
WineCultivationInput.SelectedItem = a.WineCult;
|
||||
|
||||
FillOriginalValues();
|
||||
@ -103,8 +93,7 @@ namespace Elwig.Windows {
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
ControlUtils.RenewItemsSource(KgInput, await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr);
|
||||
ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId);
|
||||
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
|
||||
ControlUtils.RenewItemsSource(AreaComTypeInput, await Context.AreaCommitmentTypes.OrderBy(v => v.VtrgId).ToListAsync(), i => (i as AreaComType)?.VtrgId);
|
||||
ControlUtils.RenewItemsSource(WineCultivationInput, await Context.WineCultivations.OrderBy(c => c.Name).ToListAsync(), i => (i as WineCult)?.CultId);
|
||||
await RefreshAreaCommitmentList();
|
||||
}
|
||||
@ -116,7 +105,6 @@ namespace Elwig.Windows {
|
||||
HideAreaCommitmentNewEditDeleteButtons();
|
||||
ShowAreaCommitmentSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
AttributesInput.IsEnabled = true;
|
||||
InitInputs();
|
||||
}
|
||||
|
||||
@ -130,7 +118,6 @@ namespace Elwig.Windows {
|
||||
HideAreaCommitmentNewEditDeleteButtons();
|
||||
ShowAreaCommitmentSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
AttributesInput.IsEnabled = true;
|
||||
}
|
||||
|
||||
private async void DeleteAreaCommitmentButton_Click(object sender, RoutedEventArgs evt) {
|
||||
@ -139,7 +126,7 @@ namespace Elwig.Windows {
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll die Flächenbindung {a.GstNr} ({a.Area} m²) wirklich unwiderruflich gelöscht werden?",
|
||||
"Parzelle löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
"Flächenbindung löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
Context.Remove(a);
|
||||
Context.SaveChanges();
|
||||
@ -156,8 +143,8 @@ namespace Elwig.Windows {
|
||||
a.RdNr = RdInput.SelectedItem.GetType() == typeof(NullItem) ? null : ((WbRd)RdInput.SelectedItem).RdNr;
|
||||
a.GstNr = GstNrInput.Text;
|
||||
a.Area = int.Parse(AreaInput.Text);
|
||||
a.SortId = ((WineVar)WineVarietyInput.SelectedItem).SortId;
|
||||
a.CultId = ((WineCult)WineCultivationInput.SelectedItem).CultId;
|
||||
a.VtrgId = (AreaComTypeInput.SelectedItem as AreaComType)?.VtrgId;
|
||||
a.CultId = (WineCultivationInput.SelectedItem as WineCult)?.CultId;
|
||||
|
||||
EntityEntry<AreaCom>? tr = null;
|
||||
try {
|
||||
@ -168,23 +155,6 @@ namespace Elwig.Windows {
|
||||
tr = (await Context.AddAsync(a));
|
||||
}
|
||||
|
||||
|
||||
foreach (WineAttr attr in a.Attributes) {
|
||||
if (!AttributesInput.SelectedItems.Contains(attr)) {
|
||||
var aca = a.AttributeEntries.FirstOrDefault(h => h.AttrId == attr.AttrId);
|
||||
Context.Remove(aca);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (WineAttr attr in AttributesInput.SelectedItems) {
|
||||
if (!a.Attributes.Contains(attr)) {
|
||||
AreaComAttr aca = Context.CreateProxy<AreaComAttr>();
|
||||
aca.FbNr = a.FbNr;
|
||||
aca.AttrId = attr.AttrId;
|
||||
await Context.AddAsync(aca);
|
||||
}
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
if (newFbNr != a.FbNr) {
|
||||
@ -211,7 +181,6 @@ namespace Elwig.Windows {
|
||||
HideAreaCommitmentSaveResetCancelButtons();
|
||||
ShowAreaCommitmentNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
AttributesInput.IsEnabled = false;
|
||||
await RefreshAreaCommitmentList();
|
||||
AreaCommitmentList.SelectedItem = a;
|
||||
}
|
||||
@ -234,7 +203,6 @@ namespace Elwig.Windows {
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
AttributesInput.IsEnabled = false;
|
||||
}
|
||||
|
||||
override protected void UpdateButtons() {
|
||||
@ -297,11 +265,13 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private async void KgInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
AT_Kg? curr_kg = (AT_Kg)KgInput.SelectedItem;
|
||||
if (curr_kg != null) {
|
||||
if (KgInput.SelectedItem is AT_Kg curr_kg) {
|
||||
var rdList = await Context.WbRde.Where(r => r.KgNr == curr_kg.KgNr).OrderBy(r => r.Name).Cast<object>().ToListAsync();
|
||||
rdList.Insert(0, new NullItem());
|
||||
ControlUtils.RenewItemsSource(RdInput, rdList, i => (i as WbRd)?.RdNr);
|
||||
} else {
|
||||
var rdList = new object[] { new NullItem() };
|
||||
ControlUtils.RenewItemsSource(RdInput, rdList, i => (i as WbRd)?.RdNr);
|
||||
}
|
||||
ComboBox_SelectionChanged(sender, evt);
|
||||
}
|
||||
|
Reference in New Issue
Block a user