Models: Remove DeliveryPartAttr

This commit is contained in:
2023-10-31 22:21:24 +01:00
parent b1dad261d1
commit ad9f4d3a9a
12 changed files with 172 additions and 104 deletions

View File

@ -27,7 +27,7 @@
<th rowspan="3" style="text-align: left;">Lieferschein-Nr.</th>
<th rowspan="3">Pos.</th>
<th rowspan="3" style="text-align: left;">Sorte</th>
<th rowspan="3" style="text-align: left;">Attribut(e)</th>
<th rowspan="3" style="text-align: left;">Attribut</th>
<th rowspan="2" colspan="2">Gradation</th>
<th colspan="2">Zu-/Abschläge</th>
<th colspan="2">@Raw(string.Join("<br/>", Model.BinNames))</th>
@ -65,7 +65,7 @@
<td rowspan="@binNum" class="lsnr">@part.Delivery.LsNr</td>
<td rowspan="@binNum" class="dpnr">@part.DPNr</td>
<td rowspan="@binNum" class="variant">@part.Variant.Name</td>
<td rowspan="@binNum" class="attribute">@string.Join(" / ", part.PartAttributes.Select(a => a.AttrId))</td>
<td rowspan="@binNum" class="attribute">@part.Attribute?.Name</td>
<td rowspan="@binNum" class="oe">@($"{part.Oe:N0}")</td>
<td rowspan="@binNum" class="kmw">@($"{part.Kmw:N1}")</td>
<td rowspan="@binNum" class="abs">@abs</td>

View File

@ -24,7 +24,7 @@
<th rowspan="2" style="text-align: left;">Lieferschein-Nr.</th>
<th rowspan="2">Pos.</th>
<th rowspan="2" style="text-align: left;">Sorte</th>
<th rowspan="2" style="text-align: left;">Attribut(e)</th>
<th rowspan="2" style="text-align: left;">Attribut</th>
<th rowspan="2" style="text-align: left;">Qualitätsstufe</th>
<th colspan="2">Gradation</th>
<th colspan="2">Flächenbindung</th>
@ -56,7 +56,7 @@
<td rowspan="@rows">@p.Delivery.LsNr</td>
<td rowspan="@rows">@p.DPNr</td>
<td class="small">@p.Variant.Name</td>
<td class="small">@p.AttributesString</td>
<td class="small">@p.Attribute?.Name</td>
<td class="small">@p.Quality.Name</td>
<td rowspan="@rows" class="grad">@($"{p.Oe:N0}")</td>
<td rowspan="@rows" class="grad">@($"{p.Kmw:N1}")</td>

View File

@ -21,7 +21,7 @@
<tr>
<th class="main" rowspan="2" style="text-align: center;">Pos.</th>
<th class="main" rowspan="2" colspan="2">Sorte</th>
<th class="main" rowspan="2" colspan="2">Attribut(e)</th>
<th class="main" rowspan="2" colspan="2">Attribut</th>
<th class="main" rowspan="2">Qualitätsstufe</th>
<th colspan="2">Gradation</th>
<th>Gewicht</th>
@ -37,7 +37,7 @@
<tr class="main">
<td style="text-align: center;">@part.DPNr</td>
<td colspan="2">@part.Variant.Name</td>
<td colspan="2">@string.Join(" / ", part.Attributes)</td>
<td colspan="2">@part.Attribute?.Name</td>
<td>@part.Quality.Name</td>
<td class="narrow" style="text-align: center;">@($"{part.Oe:N0}")</td>
<td class="narrow" style="text-align: center;">@($"{part.Kmw:N1}")</td>

View File

@ -40,7 +40,6 @@ namespace Elwig.Helpers {
public DbSet<Modifier> Modifiers { get; private set; }
public DbSet<Delivery> Deliveries { get; private set; }
public DbSet<DeliveryPart> DeliveryParts { get; private set; }
public DbSet<DeliveryPartAttr> DeliveryPartAttributes { get; private set; }
public DbSet<DeliveryPartModifier> DeliveryPartModifiers { get; private set; }
public DbSet<PaymentVar> PaymentVariants { get; private set; }
public DbSet<PaymentMember> MemberPayments { get; private set; }
@ -166,28 +165,6 @@ namespace Elwig.Helpers {
.LastOrDefaultAsync();
}
public async Task UpdateDeliveryPartAttributes(DeliveryPart part, IEnumerable<WineAttr> attributes) {
foreach (var a in WineAttributes) {
var attr = part.PartAttributes.Where(pa => pa.AttrId == a.AttrId).FirstOrDefault();
if (attributes.Contains(a)) {
DeliveryPartAttr dpa = attr ?? this.CreateProxy<DeliveryPartAttr>();
dpa.Year = part.Year;
dpa.DId = part.DId;
dpa.DPNr = part.DPNr;
dpa.AttrId = a.AttrId;
if (attr == null) {
await AddAsync(dpa);
} else {
Update(dpa);
}
} else {
if (attr != null) {
Remove(attr);
}
}
}
}
public async Task UpdateDeliveryPartModifiers(DeliveryPart part, IEnumerable<Modifier> modifiers) {
foreach (var m in Modifiers.Where(m => m.Year == part.Year)) {
var mod = part.PartModifiers.Where(pa => pa.ModId == m.ModId).FirstOrDefault();

View File

@ -4,11 +4,11 @@ using System;
namespace Elwig.Helpers {
public static class AppDbUpdater {
public static readonly int RequiredSchemaVersion = 4;
public static readonly int RequiredSchemaVersion = 5;
private static int _versionOffset = 0;
private static readonly Action<SqliteConnection>[] _updaters = new[] {
UpdateDbSchema_1_To_2, UpdateDbSchema_2_To_3, UpdateDbSchema_3_To_4
UpdateDbSchema_1_To_2, UpdateDbSchema_2_To_3, UpdateDbSchema_3_To_4, UpdateDbSchema_4_To_5
};
private static void ExecuteNonQuery(SqliteConnection cnx, string sql) {
@ -65,11 +65,14 @@ namespace Elwig.Helpers {
}
ExecuteNonQuery(cnx, "PRAGMA locking_mode = EXCLUSIVE");
ExecuteNonQuery(cnx, "PRAGMA foreign_keys = OFF");
ExecuteNonQuery(cnx, "BEGIN EXCLUSIVE");
for (int i = fromVersion; i < toVersion; i++) {
_updaters[i - 1](cnx);
}
ExecuteNonQuery(cnx, "PRAGMA foreign_key_check");
ExecuteNonQuery(cnx, "COMMIT");
ExecuteNonQuery(cnx, "PRAGMA foreign_keys = ON");
ExecuteNonQuery(cnx, "VACUUM");
ExecuteNonQuery(cnx, $"PRAGMA schema_version = {toVersion * 100 + _versionOffset}");
}
@ -213,5 +216,119 @@ namespace Elwig.Helpers {
ORDER BY s.year, c.mgnr, LENGTH(c.vtrgid) DESC, c.vtrgid;
""");
}
private static void UpdateDbSchema_4_To_5(SqliteConnection cnx) {
ExecuteNonQuery(cnx, """
CREATE TABLE _area_commitment_type (
vtrgid TEXT NOT NULL CHECK (vtrgid = sortid || COALESCE(attrid, '') || disc),
sortid TEXT NOT NULL,
attrid TEXT,
disc TEXT DEFAULT NULL CHECK (disc REGEXP '^[A-Z0-9]+$'),
min_kg_per_ha INTEGER,
max_kg_per_ha INTEGER,
penalty_amount INTEGER,
CONSTRAINT pk_area_commitment_type PRIMARY KEY (vtrgid),
CONSTRAINT sk_area_commitment_type_sort_attr UNIQUE (sortid, attrid, disc),
CONSTRAINT fk_area_commitment_type_wine_variety FOREIGN KEY (sortid) REFERENCES wine_variety (sortid)
ON UPDATE CASCADE
ON DELETE RESTRICT,
CONSTRAINT fk_area_commitment_type_wine_attribute FOREIGN KEY (attrid) REFERENCES wine_attribute (attrid)
ON UPDATE CASCADE
ON DELETE RESTRICT
) STRICT;
""");
ExecuteNonQuery(cnx, """
INSERT INTO _area_commitment_type (vtrgid, sortid, attrid, disc, min_kg_per_ha, max_kg_per_ha, penalty_amount)
SELECT vtrgid, sortid, attrid_1, disc, min_kg_per_ha, max_kg_per_ha, penalty_amount FROM area_commitment_type
""");
ExecuteNonQuery(cnx, "PRAGMA writable_schema = ON");
ExecuteNonQuery(cnx, "DROP TABLE area_commitment_type");
ExecuteNonQuery(cnx, "ALTER TABLE _area_commitment_type RENAME TO area_commitment_type");
ExecuteNonQuery(cnx, "PRAGMA writable_schema = OFF");
ExecuteNonQuery(cnx, """
ALTER TABLE delivery_part ADD COLUMN attrid TEXT DEFAULT NULL
REFERENCES wine_attribute (attrid)
ON UPDATE CASCADE
ON DELETE RESTRICT
""");
ExecuteNonQuery(cnx, """
UPDATE delivery_part
SET attrid = (SELECT attrid
FROM delivery_part_attribute a
WHERE (delivery_part.year, delivery_part.did, delivery_part.dpnr) = (a.year, a.did, a.dpnr)
ORDER BY attrid DESC
LIMIT 1)
""");
ExecuteNonQuery(cnx, "DROP TRIGGER t_delivery_part_attribute_i_mtime_delivery_part");
ExecuteNonQuery(cnx, "DROP TRIGGER t_delivery_part_attribute_u_mtime_delivery_part");
ExecuteNonQuery(cnx, "DROP TRIGGER t_delivery_part_attribute_d_mtime_delivery_part");
ExecuteNonQuery(cnx, "DROP TABLE delivery_part_attribute");
ExecuteNonQuery(cnx, "DROP VIEW v_delivery");
ExecuteNonQuery(cnx, """
CREATE VIEW v_delivery AS
SELECT p.year, p.did, p.dpnr,
d.date, d.time, d.zwstid, d.lnr, d.lsnr,
m.mgnr, m.family_name, m.given_name,
p.sortid, a.attrid,
p.weight, p.kmw, ROUND(p.kmw * (4.54 + 0.022 * p.kmw), 0) AS oe, p.qualid,
p.hkid, p.kgnr, p.rdnr,
p.gerebelt, p.gebunden,
p.qualid IN (SELECT l.qualid FROM wine_quality_level l WHERE NOT l.predicate AND (p.kmw >= l.min_kmw OR l.min_kmw IS NULL) ORDER BY l.min_kmw DESC LIMIT 1,100) AS abgewertet,
p.qualid NOT IN ('WEI', 'RSW', 'LDW') AS min_quw,
COALESCE(a.fill_lower_bins, 0) AS attribute_prio,
GROUP_CONCAT(o.modid) AS modifiers,
d.comment, p.comment AS part_comment
FROM delivery_part p
JOIN delivery d ON (d.year, d.did) = (p.year, p.did)
JOIN member m ON m.mgnr = d.mgnr
LEFT JOIN wine_attribute a ON a.attrid = p.attrid
LEFT JOIN delivery_part_modifier o ON (o.year, o.did, o.dpnr) = (p.year, p.did, p.dpnr)
GROUP BY p.year, p.did, p.dpnr
ORDER BY p.year, p.did, p.dpnr, o.modid;
""");
ExecuteNonQuery(cnx, "DROP VIEW v_delivery_bin");
ExecuteNonQuery(cnx, """
CREATE VIEW v_delivery_bin AS
SELECT year, mgnr,
sortid || IIF(min_quw, COALESCE(attrid, ''), '_') AS bin,
SUM(weight) AS weight
FROM v_delivery
GROUP BY year, mgnr, bin
ORDER BY year, mgnr, LENGTH(bin) DESC, bin;
""");
ExecuteNonQuery(cnx, "DROP VIEW v_stat_attr");
ExecuteNonQuery(cnx, """
CREATE VIEW v_stat_attr AS
SELECT year, attrid,
SUM(weight) as sum,
ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw,
ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe,
COUNT(DISTINCT did) AS lieferungen,
COUNT(DISTINCT mgnr) AS mitglieder
FROM v_delivery
GROUP BY year, attrid
ORDER BY year, attrid;
""");
ExecuteNonQuery(cnx, "DROP VIEW v_stat_sort_attr");
ExecuteNonQuery(cnx, """
CREATE VIEW v_stat_sort_attr AS
SELECT year, sortid, attrid,
SUM(weight) as sum,
ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw,
ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe,
COUNT(DISTINCT did) AS lieferungen,
COUNT(DISTINCT mgnr) AS mitglieder
FROM v_delivery
GROUP BY year, sortid, attrid
ORDER BY year, sortid, attrid;
""");
}
}
}

View File

@ -11,14 +11,14 @@ namespace Elwig.Helpers.Billing {
protected readonly AppDbContext Context;
protected readonly Dictionary<string, string> Attributes;
protected readonly Dictionary<string, (decimal?, decimal?)> Modifiers;
protected readonly Dictionary<string, (string, string?, string?, string?, int?, int?, decimal?)> AreaComTypes;
protected readonly Dictionary<string, (string, string?, string?, int?, int?, decimal?)> AreaComTypes;
public Billing(int year) {
Year = year;
Context = new AppDbContext();
Attributes = Context.WineAttributes.ToDictionary(a => a.AttrId, a => a.Name);
Modifiers = Context.Modifiers.Where(m => m.Year == Year).ToDictionary(m => m.ModId, m => (m.Abs, m.Rel));
AreaComTypes = Context.AreaCommitmentTypes.ToDictionary(v => v.VtrgId, v => (v.SortId, v.AttrId1, v.AttrId2, v.Discriminator, v.MinKgPerHa, v.MaxKgPerHa, v.PenaltyAmount));
AreaComTypes = Context.AreaCommitmentTypes.ToDictionary(v => v.VtrgId, v => (v.SortId, v.AttrId, v.Discriminator, v.MinKgPerHa, v.MaxKgPerHa, v.PenaltyAmount));
}
public async Task FinishSeason() {

View File

@ -1,5 +1,14 @@
namespace Elwig.Helpers {
public class NullItem {
public static string Name => "- Keine Angabe -";
public string Name { get; private set; }
public NullItem(string name = "- Keine Angabe -") {
Name = name;
}
public override string ToString() {
return Name;
}
}
}

View File

@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models {
[Table("area_commitment_type"), PrimaryKey("VtrgId"), Index("SortId", "AttrId1", "AttrId2", "Discriminator")]
[Table("area_commitment_type"), PrimaryKey("VtrgId"), Index("SortId", "AttrId", "Discriminator")]
public class AreaComType {
[Column("vtrgid")]
public string VtrgId { get; set; }
@ -12,11 +12,8 @@ namespace Elwig.Models {
[Column("sortid")]
public string SortId { get; set; }
[Column("attrid_1")]
public string? AttrId1 { get; set; }
[Column("attrid_2")]
public string? AttrId2 { get; set; }
[Column("attrid")]
public string? AttrId { get; set; }
[Column("disc")]
public string? Discriminator { get; set; }
@ -39,14 +36,10 @@ namespace Elwig.Models {
[ForeignKey("SortId")]
public virtual WineVar WineVar { get; private set; }
[ForeignKey("AttrId1")]
public virtual WineAttr? WineAttr1 { get; private set; }
[ForeignKey("AttrId2")]
public virtual WineAttr? WineAttr2 { get; private set; }
[ForeignKey("AttrId")]
public virtual WineAttr? WineAttr { get; private set; }
[NotMapped]
public string DisplayName => WineVar.Name + (WineAttr1 != null ? $" {WineAttr1.Name}" : "") +
(WineAttr2 != null ? $" {WineAttr2.Name}" : "") + (Discriminator != null ? $" ({Discriminator})" : "");
public string DisplayName => WineVar.Name + (WineAttr != null ? $" {WineAttr.Name}" : "") + (Discriminator != null ? $" ({Discriminator})" : "");
}
}

View File

@ -25,6 +25,12 @@ namespace Elwig.Models {
[ForeignKey("SortId")]
public virtual WineVar Variant { get; private set; }
[Column("attrid")]
public string? AttrId { get; set; }
[ForeignKey("AttrId")]
public virtual WineAttr? Attribute { get; private set; }
[Column("weight")]
public int Weight { get; set; }
@ -96,15 +102,6 @@ namespace Elwig.Models {
[Column("comment")]
public string? Comment { get; set; }
[InverseProperty("Part")]
public virtual ISet<DeliveryPartAttr> PartAttributes { get; private set; }
[NotMapped]
public IEnumerable<WineAttr> Attributes => PartAttributes.Select(a => a.Attr);
[NotMapped]
public string AttributesString => string.Join(" / ", Attributes);
[InverseProperty("Part")]
public virtual ISet<DeliveryPartModifier> PartModifiers { get; private set; }

View File

@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("delivery_part_attribute"), PrimaryKey("Year", "DId", "DPNr", "AttrId")]
public class DeliveryPartAttr {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[Column("dpnr")]
public int DPNr { get; set; }
[ForeignKey("Year, DId, DPNr")]
public virtual DeliveryPart Part { get; private set; }
[Column("attrid")]
public string AttrId { get; set; }
[ForeignKey("AttrId")]
public virtual WineAttr Attr { get; private set; }
}
}

View File

@ -271,10 +271,10 @@
ItemTemplate="{StaticResource WineVarietyTemplate}" TextSearch.TextPath="Name"
SelectionChanged="WineVarietyInput_SelectionChanged" KeyUp="Input_KeyUp"/>
<Label Content="Attribute:" Margin="10,40,0,0" Grid.Column="0"/>
<xctk:CheckComboBox x:Name="AttributesInput" Grid.Row="1" Grid.Column="1" Margin="0,40,10,10"
DisplayMemberPath="Name" Delimiter=", " AllItemsSelectedContent="Alle"
ItemSelectionChanged="AttributesInput_SelectionChanged" KeyUp="Input_KeyUp"/>
<Label Content="Attribut:" Margin="10,40,0,0" Grid.Column="0"/>
<ComboBox x:Name="AttributeInput" Grid.Row="1" Grid.Column="1" Margin="0,40,10,10"
DisplayMemberPath="Name"
SelectionChanged="AttributeInput_SelectionChanged" KeyUp="Input_KeyUp"/>
</Grid>
</GroupBox>
@ -403,7 +403,7 @@
<TextBlock Text="{Binding Kmw, StringFormat='{}{0:0.0}°'}" Width="40" TextAlignment="Right" Padding="0,0,10,0"/>
<TextBlock Text="{Binding QualId}" Width="30"/>
<TextBlock Text="{Binding Weight, StringFormat='{}{0:N0} kg'}" Width="60" TextAlignment="Right" Padding="0,0,10,0"/>
<TextBlock Text="{Binding AttributesString}" Width="100"/>
<TextBlock Text="{Binding Attribute.Name}" Width="100"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>

View File

@ -280,7 +280,7 @@ namespace Elwig.Windows {
if (ctrl == MgNrInput || ctrl == MemberInput) {
SortIdInput.Focus();
SortIdInput.SelectAll();
} else if (ctrl == SortIdInput || ctrl == WineVarietyInput || ctrl == AttributesInput) {
} else if (ctrl == SortIdInput || ctrl == WineVarietyInput || ctrl == AttributeInput) {
GradationOeInput.Focus();
GradationOeInput.SelectAll();
} else if (ctrl == GradationKmwInput || ctrl == GradationOeInput || ctrl == WineQualityLevelInput) {
@ -486,12 +486,8 @@ namespace Elwig.Windows {
if (filterNotVar.Count > 0) dpq = dpq.Where(p => !filterNotVar.Contains(p.SortId));
if (filterQual.Count > 0) dpq = dpq.Where(p => filterQual.Contains(p.QualId));
if (filterZwst.Count > 0) dpq = dpq.Where(p => filterZwst.Contains(p.Delivery.ZwstId));
if (filterAttr.Count > 0)
foreach (var a in filterAttr)
dpq = dpq.Where(p => p.PartAttributes.Select(a => a.Attr.AttrId).Contains(a));
if (filterNotAttr.Count > 0)
foreach (var a in filterNotAttr)
dpq = dpq.Where(p => !p.PartAttributes.Select(a => a.Attr.AttrId).Contains(a));
if (filterAttr.Count > 0) dpq = dpq.Where(p => p.AttrId != null && filterAttr.Contains(p.AttrId));
if (filterNotAttr.Count > 0) dpq = dpq.Where(p => p.AttrId == null || !filterAttr.Contains(p.AttrId));
if (filterKmwGt > 0) dpq = dpq.Where(p => p.Kmw >= filterKmwGt);
if (filterKmwLt > 0) dpq = dpq.Where(p => p.Kmw < filterKmwLt);
if (filterOeGt > 0) dpq = dpq.Where(p => p.Kmw * (4.54 + 0.022 * p.Kmw) >= filterOeGt);
@ -570,7 +566,7 @@ namespace Elwig.Windows {
if (n > 0 && (n <= 200 || TodayOnlyInput.IsChecked == true)) {
var parts = await deliveryParts.ToListAsync();
var groups = parts
.GroupBy(p => string.Join("/", p.Attributes.Select(a => a.Name)))
.GroupBy(p => p.Attribute?.Name)
.Select(g => (g.Key, g.Sum(p => p.Weight), g.Min(p => p.Kmw), Utils.AggregateDeliveryPartsKmw(g), g.Max(p => p.Kmw)))
.OrderByDescending(g => g.Item2)
.ToList();
@ -636,7 +632,9 @@ namespace Elwig.Windows {
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsCreating).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId);
ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId);
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.Where(a => !IsCreating || a.IsActive).OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
var attrList = await Context.WineAttributes.Where(a => !IsCreating || a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync(), i => (i as WineQualLevel)?.QualId);
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == y).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId);
ControlUtils.RenewItemsSource(WineOriginInput, (await Context.WineOrigins.ToListAsync()).OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId), i => (i as WineOrigin)?.HkId);
@ -710,7 +708,7 @@ namespace Elwig.Windows {
ClearDefaultValues();
SortIdInput.Text = p?.SortId ?? "";
ControlUtils.SelectCheckComboBoxItems(AttributesInput, p?.Attributes, i => (i as WineAttr)?.AttrId);
ControlUtils.SelectComboBoxItem(AttributeInput, p?.Attribute, i => (i as WineAttr)?.AttrId);
GradationKmwInput.Text = (p != null) ? $"{p.Kmw:N1}" : "";
ControlUtils.SelectComboBoxItem(WineQualityLevelInput, q => (q as WineQualLevel)?.QualId, p?.QualId);
ControlUtils.SelectComboBoxItem(WineKgInput, k => (k as AT_Kg)?.KgNr, p?.KgNr);
@ -774,6 +772,7 @@ namespace Elwig.Windows {
d.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
p.SortId = (WineVarietyInput.SelectedItem as WineVar)?.SortId;
p.AttrId = (AttributeInput.SelectedItem as WineAttr)?.AttrId;
p.Kmw = double.Parse(GradationKmwInput.Text);
p.QualId = (WineQualityLevelInput.SelectedItem as WineQualLevel)?.QualId;
p.HkId = (WineOriginInput.SelectedItem as WineOrigin)?.HkId;
@ -805,7 +804,6 @@ namespace Elwig.Windows {
pEntry = partNew ? await Context.AddAsync(p) : Context.Update(p);
}
await Context.UpdateDeliveryPartAttributes(p, AttributesInput.SelectedItems.Cast<WineAttr>());
await Context.UpdateDeliveryPartModifiers(p, ModifiersInput.SelectedItems.Cast<Modifier>());
if (originalMgNr != null && originalMgNr.Value != d.MgNr) {
@ -1013,7 +1011,9 @@ namespace Elwig.Windows {
if (r != MessageBoxResult.Yes) return;
}
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
var attrList = await Context.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
if (DeliveryList.SelectedItem is not Delivery d) {
// switch away from creating mode
@ -1039,7 +1039,9 @@ namespace Elwig.Windows {
private async void NewDeliveryButton_Click(object? sender, RoutedEventArgs? evt) {
TodayOnlyInput.IsChecked = true;
SearchInput.Text = "";
ControlUtils.RenewItemsSource(AttributesInput, await Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
var attrList = await Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
IsCreating = true;
DeliveryList.IsEnabled = false;
@ -1084,7 +1086,6 @@ namespace Elwig.Windows {
p2.HkId = "OEST";
entry2 = await Context.AddAsync(p2);
await Context.UpdateDeliveryPartAttributes(p2, p.Attributes);
await Context.UpdateDeliveryPartModifiers(p2, p.Modifiers);
}
await Context.SaveChangesAsync();
@ -1425,13 +1426,12 @@ namespace Elwig.Windows {
var text = SortIdInput.Text;
WineVarietyInput.SelectedItem = Context.WineVarieties.Find(text[0..2]);
if (text.Length >= 3) {
AttributesInput.UnSelectAll();
AttributesInput.SelectedItems.Add(Context.WineAttributes.Find(text[2..]));
ControlUtils.SelectComboBoxItem(AttributeInput, Context.WineAttributes.Find(text[2..]), a => (a as WineAttr)?.AttrId);
SortIdInput.Text = text[0..2];
}
} else {
WineVarietyInput.SelectedItem = null;
AttributesInput.UnSelectAll();
AttributeInput.SelectedIndex = 0;
}
}
@ -1508,7 +1508,7 @@ namespace Elwig.Windows {
GradationKmwInput.Text += ",0";
}
private void AttributesInput_SelectionChanged(object sender, ItemSelectionChangedEventArgs evt) {
private void AttributeInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
}