From edf2ed1d5ba6dced215a05eb20e52887b6c5f665 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Tue, 1 Apr 2025 14:10:35 +0200 Subject: [PATCH] radio key check --- Common/LaaPackages | 2 +- .../Interfaces/IPORepository[T].cs | 5 +- .../ProductionOrdersRepository.cs | 36 ++ .../Sentinel/Sentinel.cs | 18 + LaaProductionWeb/LaaPackages | 2 +- .../Components/CSD/Data/BasisCsdNwEr.cs | 19 - .../Components/CSD/Data/CSD.cs | 65 --- .../Components/CSD/Data/CSDDBContext.cs | 215 --------- .../Components/CSD/Data/CSDMerkmal.cs | 15 + .../Components/CSD/Data/CsdClient.cs | 15 - .../Components/CSD/Data/ParameterValue.cs | 17 - .../CSD/Data/ParameterValueTypes.cs | 15 - .../CSD/Data/ProgrammingParameters.cs | 136 ------ .../Components/CSD/Data/SelectItem[T].cs | 23 - .../CSD/Data/VAKOMerkmaleDbContext.cs | 422 +++--------------- .../Components/CSD/Models/BasisItem.cs | 23 - .../Components/CSD/Models/CSDItem.cs | 7 - .../Components/CSD/Models/Charcode.cs | 54 +++ .../Components/CSD/Models/UIElement.cs | 20 + .../CSD/Models/VAKOMerkmaleModel.cs | 217 ++++++++- .../Components/CSD/Navbar.razor | 119 +---- .../Components/CSD/Navbar.razor.cs | 30 +- .../Components/CSD/Options.razor | 59 +++ .../Components/CSD/Options.razor.cs | 21 + .../Components/CSD/Options.razor.js | 12 + .../CSD/ProgrammingParameters.razor | 50 --- .../CSD/ProgrammingParameters.razor.cs | 40 +- .../LaaProductionWeb.Blazor.csproj | 4 - .../LaaProductionWeb.Blazor/Program.cs | 4 - .../bootstrap/css/bootstrap.overrides.css | 12 +- 30 files changed, 554 insertions(+), 1123 deletions(-) delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/BasisCsdNwEr.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSD.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDDBContext.cs create mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDMerkmal.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CsdClient.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValue.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValueTypes.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ProgrammingParameters.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/SelectItem[T].cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/BasisItem.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/CSDItem.cs create mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/Charcode.cs create mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/UIElement.cs create mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor create mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.cs create mode 100644 LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.js diff --git a/Common/LaaPackages b/Common/LaaPackages index 7453c48a..e7aa3e27 160000 --- a/Common/LaaPackages +++ b/Common/LaaPackages @@ -1 +1 @@ -Subproject commit 7453c48ad3a55840ada65dd202aec78b87766dcc +Subproject commit e7aa3e2723a435f0a714df661dc5d86dfd45a71c diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Interfaces/IPORepository[T].cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Interfaces/IPORepository[T].cs index 685385df..44884982 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Interfaces/IPORepository[T].cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Interfaces/IPORepository[T].cs @@ -1,10 +1,13 @@ namespace LaaProduction.Data.Cordonel.Interfaces { - using System; + using LaaPackages.Features.Cordonel.Models; + using System.Collections.Generic; public interface IPORepository : IFilterRepository { IEnumerable GetPcbs(string ponr); + + IEnumerable HasRightRadioKey(ulong address); } } diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/ProductionOrdersRepository.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/ProductionOrdersRepository.cs index 5ab78243..7624af4b 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/ProductionOrdersRepository.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Repositories/ProductionOrdersRepository.cs @@ -121,5 +121,41 @@ PositionNr = x.GetValue(5), FertigungsauftragNr = x.GetValue(6), }); + + public IEnumerable HasRightRadioKey(ulong address) + => this.sqlConnection + .CreateCommand($@" + SELECT DISTINCT + apg.AuftragNr + , apg.PositionNr + , gm.Seriennummer + , gm.FunkschluesselIndex + , vmm.Wert + , apg.IstDatum + FROM Genesis_Meter AS gm + JOIN AuftragPositionSerienNr AS aps + ON gm.Seriennummer = aps.SerienNr + JOIN AuftragPosition_Gesamt AS apg + ON aps.AuftragNr = apg.AuftragNr + AND aps.PositionNr = apg.PositionNr + JOIN Identnr AS idn + ON apg.IdentNr = idn.IdentNr + JOIN VAKO_Merkmale AS vmm + ON vmm.Basis = 'GNS' + AND vmm.Stelle = 46 + AND vmm.Charcode = SUBSTRING(idn.VakoCode, vmm.Stelle, 1) + WHERE gm.Adresse = @{nameof(address)} + AND ((gm.FunkschluesselIndex IS NULL AND vmm.Charcode = '2') + OR (gm.FunkschluesselIndex IS NOT NULL AND vmm.Charcode = '1'))") + .SetParameter(nameof(address), $"10{address}") + .ExecuteReader(x => new RadioKeyEntry + { + Auftrag = x.GetValue(0), + Position = x.GetValue(1), + SerienNr = x.GetValue(2), + KeyIndex = x.GetValue(3), + KeyType = x.GetValue(4), + IsDate = x.GetValue(5) + }); } } diff --git a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs index dc75476f..368192a9 100644 --- a/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs +++ b/LaaProductionWeb/Data/LaaProduction.Data.Cordonel/Sentinel/Sentinel.cs @@ -57,6 +57,7 @@ this.TryGetPasswordFileContent(pcbId, out var passwordFile); // ~ slow // Data comparison + this.TryCompareRadioKeyUsed(productionData.Address); this.TryCompareRequirementsIdAndVersion(eolProgress, requirements); this.TryCompareAllPcbIds(pcbId, productionData, requirements, apps, eolProgress, metrologyValues); this.TryCompareProductionOrderNumber(productionData, requirements, eolProgress); @@ -97,6 +98,23 @@ return sentinelResult; } + private void TryCompareRadioKeyUsed(ulong address) + { + var entries = this.cordonelDbContext.ProductionOrders.HasRightRadioKey(address); + + if (entries.Any()) + { + var messages = new StringBuilder(); + + foreach (var entry in entries) + { + messages.AppendLine($"RadioKey mismatch: {entry.Auftrag}|{entry.Position}|{entry.SerienNr} - {entry.KeyType}|{entry.KeyIndex} - {entry.IsDate}"); + } + + this.ThrowSentinelException(messages.ToString()); + } + } + internal void TryCompareAllPcbIds(int pcbId, CordonelProductionData productionData, CordonelRequirements requirements, CordonelAppsDictionary apps, EOLProgressModel eolProgress, CordonelMetrologyValues metrologyValues) { if (eolProgress.RequirementPcbIdChecked == EOLStatus.NA) diff --git a/LaaProductionWeb/LaaPackages b/LaaProductionWeb/LaaPackages index 7453c48a..e7aa3e27 160000 --- a/LaaProductionWeb/LaaPackages +++ b/LaaProductionWeb/LaaPackages @@ -1 +1 @@ -Subproject commit 7453c48ad3a55840ada65dd202aec78b87766dcc +Subproject commit e7aa3e2723a435f0a714df661dc5d86dfd45a71c diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/BasisCsdNwEr.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/BasisCsdNwEr.cs deleted file mode 100644 index 96985311..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/BasisCsdNwEr.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - public class BasisCsdNwEr - { - public string Basis { get; set; } - - public int SCDPosition { get; set; } - - public int CSDLength { get; set; } - - public string NWPosition { get; set; } - - public string NWLength { get; set; } - - public string ERPosition { get; set; } - - public string ERLength { get; set; } - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSD.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSD.cs deleted file mode 100644 index 87895002..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSD.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - using System.Collections.Generic; - using System.Linq; - - public class CSD - { - public string CharCode { get; set; } - - public string Wert { get; set; } - - public IEnumerable BasisCodes { get; private set; } = []; - - public void AddBasisCodes(IEnumerable basisCodes) - { - var _basisCodes = basisCodes.ToDictionary(x => x, x => new CSDBasis { Basis = x }); - - foreach (var basis in this.BasisCodes.Where(x => x.Selected).Select(x => x.Basis)) - { - if (_basisCodes.ContainsKey(basis)) - { - _basisCodes[basis].Selected = true; - } - } - - this.BasisCodes = _basisCodes.Values; - } - } - - public class CSDBasis - { - public string Basis { get; set; } - - public bool Selected { get; set; } - - public IEnumerable Bezeichnungen { get; private set; } = []; - - public void Clear() => this.Bezeichnungen = []; - - public void AddBezeichnungen(IEnumerable bezeichnungen) - => this.Bezeichnungen = bezeichnungen; - } - - public class CSDBezeichnung - { - public string Bezeichnung { get; set; } - - public int Stelle { get; set; } - - public int Laenge { get; set; } - - public bool Selected { get; set; } - - public IEnumerable CharCodes { get; private set; } = []; - } - - public class CSDCharCode - { - public string CharCode { get; set; } - - public string Value { get; set; } - - public bool Selected { get; set; } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDDBContext.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDDBContext.cs deleted file mode 100644 index c56be76f..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDDBContext.cs +++ /dev/null @@ -1,215 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - using LaaPackages.SqlClient; - - using Microsoft.Extensions.Configuration; - - using SQLite; - - using System.Collections.Generic; - using System.Linq; - - public class CSDDBContext - { - private readonly SqlConnection connection; - private readonly SQLiteConnection csdSQLite; - - public CSDDBContext(IConfiguration configuration) - { - var connectionString = configuration.GetConnectionString("Auftrag"); - this.connection = SqlConnection.CreateSqlConnection(connectionString); - this.csdSQLite = new SQLiteConnection(new SQLiteConnectionString("csd_parameters.db")); - - this.SeedParameterValues(); - } - - public IDictionary GetAllCsds() - => this.connection - .CreateCommand(@" - SELECT DISTINCT - csd.Basis - , csd.Stelle - , csd.Laenge - , csd.Charcode - , csd.Wert - FROM VAKO_Merkmale AS csd - WHERE csd.Wert LIKE 'CSD%'") - .ExecuteReader(x => new CsdClient - { - Basis = x.GetValue(0), - Position = x.GetValue(1), - Length = x.GetValue(2), - Charcode = x.GetValue(3), - Client = x.GetValue(4), - }) - .GroupBy(x => x.Charcode) - .ToDictionary(x => x.Key, x => x.ToArray()); - - public IEnumerable GetBasisCodes() - => this.connection - .CreateCommand(@" - SELECT DISTINCT - vm.Basis - , bs.Stelle AS CSDPosition - , bs.Laenge AS CSDLength - , nw.Stelle AS NWPosition - , nw.Laenge AS NWLength - , er.Stelle AS ERPosition - , er.Laenge AS ERLength - FROM VAKO_Merkmale AS vm - LEFT JOIN (SELECT DISTINCT - _bs.Basis - , MAX(_bs.Stelle) OVER (PARTITION BY _bs.Basis) AS Stelle - , _bs.Laenge - FROM VAKO_Merkmale AS _bs - WHERE _bs.Wert LIKE 'CSD%') - AS bs - ON vm.Basis = bs.Basis - LEFT JOIN (SELECT DISTINCT - _nw.Basis - , MIN(_nw.Stelle) OVER (PARTITION BY _nw.Basis) AS Stelle - , 1 AS Laenge - FROM VAKO_Merkmale AS _nw - WHERE _nw.Name LIKE '%nw%' - OR _nw.Bezeichnung LIKE '%nw%' - OR _nw.Schluessel LIKE '%nw%') - AS nw - ON vm.Basis = nw.Basis - LEFT JOIN (SELECT DISTINCT - _er.Basis - , _er.Stelle - , _er.Laenge - FROM VAKO_Merkmale AS _er - WHERE _er.Wert LIKE '%433%') - AS er - ON vm.Basis = er.Basis - WHERE bs.Basis IS NOT NULL - OR nw.Basis IS NOT NULL - OR er.Basis IS NOT NULL - ORDER BY vm.Basis") - .ExecuteReader(x => new BasisCsdNwEr - { - Basis = x.GetValue(0), - SCDPosition = x.GetValue(1), - CSDLength = x.GetValue(2), - NWPosition = x.GetValue(3), - NWLength = x.GetValue(4), - ERPosition = x.GetValue(5), - ERLength = x.GetValue(6), - }); - - public IDictionary GetParameterValues() - => this.csdSQLite - .Table() - .GroupBy(x => x.Group) - .ToDictionary(x => x.Key, x => x.ToArray()); - - private void SeedParameterValues() - { - var createResult = this.csdSQLite.CreateTable(); - - if (createResult == CreateTableResult.Created) - { - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "1 h", Value = 1 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "2 h", Value = 2 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "6 h", Value = 6 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "12 h", Value = 12 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "1 d", Value = 1 * 24 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "2 d", Value = 2 * 24 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "3 d", Value = 3 * 24 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "7 d", Value = 7 * 24 * 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.HoursAndDays, Name = "14 d", Value = 14 * 24 * 60 * 60 }); - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "250 l/h", Value = 250 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "375 l/h", Value = 375 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "500 l/h", Value = 500 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "625 l/h", Value = 625 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "750 l/h", Value = 750 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "875 l/h", Value = 875 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "1000 l/h", Value = 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "1250 l/h", Value = 1250 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "2500 l/h", Value = 2500 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "3750 l/h", Value = 3750 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "5000 l/h", Value = 5000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "6250 l/h", Value = 6250 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "7500 l/h", Value = 7500 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "8750 l/h", Value = 8750 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.LitersPerHour, Name = "10000 l/h", Value = 10000 }); - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "1 min", Value = 5 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "2 min", Value = 5 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "3 min", Value = 5 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "4 min", Value = 5 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "5 min", Value = 5 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "6 min", Value = 5 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "10 min", Value = 10 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "15 min", Value = 15 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "30 min", Value = 30 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "45 min", Value = 45 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "60 min", Value = 60 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "120 min", Value = 120 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "180 min", Value = 180 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "240 min", Value = 240 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "360 min", Value = 360 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "720 min", Value = 720 * 60 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.PeriodsInMinutes, Name = "1440 min", Value = 1440 * 60 }); - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "7.5 m³/h", Value = (int)(7.5 * 1000) }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "8.75 m³/h", Value = (int)(8.75 * 1000) }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "10 m³/h", Value = 10 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "12.5 m³/h", Value = (int)(12.5 * 1000) }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "25 m³/h", Value = 25 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "37.5 m³/h", Value = (int)(37.5 * 1000) }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "50 m³/h", Value = 50 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "62.5 m³/h", Value = (int)(62.5 * 1000) }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "75 m³/h", Value = 75 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "87.5 m³/h", Value = (int)(87.5 * 1000) }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "100 m³/h", Value = 100 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "125 m³/h", Value = 125 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "250 m³/h", Value = 250 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "375 m³/h", Value = 375 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "500 m³/h", Value = 500 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "625 m³/h", Value = 625 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "750 m³/h", Value = 750 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "875 m³/h", Value = 875 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "1000 m³/h", Value = 1000 * 1000 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.CubicMetersPerHour, Name = "1250 m³/h", Value = 1250 * 1000 }); - - for (var d = 1; d <= 29; d++) - { - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.Days, Name = $"{d} d", Value = d * 24 * 60 * 60 }); - } - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.Days, Name = "90 d", Value = 90 * 24 * 60 * 60 }); - - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.WakeUpModes, Name = "3", Value = 3 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.WakeUpModes, Name = "6", Value = 6 }); - - string name; - - for (var h = -9; h <= 14; h++) - { - if (h < 0) - { - name = $"UTC {h:00}:00"; - } - else if (h > 0) - { - name = $"UTC +{h:00}:00"; - } - else - { - name = $"UTC {h:00}:00"; - } - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.UTCOffsetsSeconds, Name = name, Value = h * 24 * 60 * 60 }); - } - - - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.TransmissionIntervals, Name = "15", Value = 15 }); - this.csdSQLite.Insert(new ParameterValue { Group = ParameterValueTypes.Lats, Name = "3", Value = 3 }); - } - } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDMerkmal.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDMerkmal.cs new file mode 100644 index 00000000..36558870 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CSDMerkmal.cs @@ -0,0 +1,15 @@ +namespace LaaProductionWeb.Blazor.Components.CSD.Data +{ + using System; + + public class CSDMerkmal + { + public int Id { get; set; } + + public string CSD { get; set; } + + public string Pattern { get; set; } + + public DateTime TimeStamp { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CsdClient.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CsdClient.cs deleted file mode 100644 index a36ca6ed..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/CsdClient.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - public class CsdClient - { - public string Basis { get; set; } - - public int Position { get; set; } - - public int Length { get; set; } - - public string Charcode { get; set; } - - public string Client { get; set; } - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValue.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValue.cs deleted file mode 100644 index 0dabc031..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValue.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - using SQLite; - - public class ParameterValue - { - [PrimaryKey] - [AutoIncrement] - public int Id { get; set; } - - public string Group { get; set; } - - public string Name { get; set; } - - public int Value { get; set; } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValueTypes.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValueTypes.cs deleted file mode 100644 index 9d01fe29..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ParameterValueTypes.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - public class ParameterValueTypes - { - public const string HoursAndDays = nameof(HoursAndDays); - public const string LitersPerHour = nameof(LitersPerHour); - public const string PeriodsInMinutes = nameof(PeriodsInMinutes); - public const string CubicMetersPerHour = nameof(CubicMetersPerHour); - public const string Days = nameof(Days); - public const string WakeUpModes = nameof(WakeUpModes); - public const string UTCOffsetsSeconds = nameof(UTCOffsetsSeconds); - public const string TransmissionIntervals = nameof(TransmissionIntervals); - public const string Lats = nameof(Lats); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ProgrammingParameters.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ProgrammingParameters.cs deleted file mode 100644 index ea6c1608..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/ProgrammingParameters.cs +++ /dev/null @@ -1,136 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - using System.ComponentModel.DataAnnotations; - - public class ProgrammingParameters - { - [Display(Name = "Leakage Period")] - public int LeakagePeriode { get; set; } - - [Display(Name = "Leakage Threshold")] - public int LeakageThreshold { get; set; } - - [Display(Name = "Broken Pipe Period")] - public int BrokenPipePeriode { get; set; } - - [Display(Name = "Broken Pipe Threshold")] - public int BrokenPipeThreshold { get; set; } - - [Display(Name = "Alert Leakage")] - public bool AlertLeakage { get; set; } - - [Display(Name = "Alert Broken Pipe")] - public bool AlertBrokenPipe { get; set; } - - [Display(Name = "Alert Low Battery")] - public bool AlertLowBattery { get; set; } - - [Display(Name = "Alert Magnetic Tampering")] - public bool AlertMagneticTampering { get; set; } - - [Display(Name = "Alert Backflow")] - public bool AlertBackflow { get; set; } - - [Display(Name = "Historic Error Limit")] - public int HistoricErrorLimit { get; set; } - - [Display(Name = "DL Period")] - public int DataLoggingPeriod { get; set; } - - [Display(Name = "DL Forward Counter")] - public bool DataLoggingForwardCounter { get; set; } - - [Display(Name = "DL Time Of Minimum Flow")] - public bool DataLoggingTimeOfMinimumFlow { get; set; } - - [Display(Name = "DL Minimum Flow")] - public bool DataLoggingMinimumFlow { get; set; } - - [Display(Name = "DL Time Of Broken Pipe")] - public bool DataLoggingTimeOfBrokenPipe { get; set; } - - [Display(Name = "DL Broken Pipe Flow")] - public bool DataLoggingBrokenPipeFlow { get; set; } - - [Display(Name = "DL Current Flow")] - public bool DataLoggingCurrentFlow { get; set; } - - [Display(Name = "DL Time Of Peak Flow")] - public bool DataLoggingTimeOfPeakFlow { get; set; } - - [Display(Name = "DL Peak Flow")] - public bool DataLoggingPeakFlow { get; set; } - - [Display(Name = "DL Time Of Maximum Flow")] - public bool DataLoggingTimeOfMaximumFlow { get; set; } - - [Display(Name = "DL Maximum Flow")] - public bool DataLoggingMaximumFlow { get; set; } - - [Display(Name = "DL Backward Volume")] - public bool DataLoggingBackwardVolume { get; set; } - - [Display(Name = "DL Counter")] - public bool DataLoggingCounter { get; set; } - - [Display(Name = "DL Alert State")] - public bool DataLoggingAlertState { get; set; } - - [Display(Name = "Reading Day Of Month")] - public int ReadingDayofMonth { get; set; } - - [Display(Name = "FDR Forward Counter")] - public bool FixDataReadingForwardCounter { get; set; } - - [Display(Name = "FDR Time Of Minimum Flow")] - public bool FixDataReadingTimeOfMinimumFlow { get; set; } - - [Display(Name = "FDR Minimum Flow")] - public bool FixDataReadingMinimumFlow { get; set; } - - [Display(Name = "FDR Time Of Broken Pipe Flow")] - public bool FixDataReadingTimeOfBrokenPipe { get; set; } - - [Display(Name = "FDR Broken Pipe Flow")] - public bool FixDataReadingBrokenPipeFlow { get; set; } - - [Display(Name = "FDR Current Flow")] - public bool FixDataReadingCurrentFlow { get; set; } - - [Display(Name = "FDR Time Of Peak Flow")] - public bool FixDataReadingTimeOfPeakFlow { get; set; } - - [Display(Name = "FDR Peak Flow")] - public bool FixDataReadingPeakFlow { get; set; } - - [Display(Name = "FDR Time Of Maximum Flow")] - public bool FixDataReadingTimeOfMaximumFlow { get; set; } - - [Display(Name = "FDR Maximum Flow")] - public bool FixDataReadingMaximumFlow { get; set; } - - [Display(Name = "FDR Backward Volume")] - public bool FixDataReadingBackwardVolume { get; set; } - - [Display(Name = "FDR Counter")] - public bool FixDataReadingCounter { get; set; } - - [Display(Name = "FDR Alert State")] - public bool FixDataReadingAlertState { get; set; } - - [Display(Name = "Wake Up Interval")] - public int WakeUpInterval { get; set; } - - [Display(Name = "UTC Offset")] - public int UTCOffset { get; set; } - - [Display(Name = "Transmission Interval")] - public int TransmissionInterval { get; set; } - - [Display(Name = "WM-Bus Transmission Interval")] - public int TransmissionIntervalWMBus { get; set; } - - [Display(Name = "Listen After Talk")] - public int ListenAfterTalk { get; set; } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/SelectItem[T].cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/SelectItem[T].cs deleted file mode 100644 index 96353d74..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/SelectItem[T].cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Data -{ - using System; - - public class SelectItem where T : SelectItem - { - public event Action ItemSelected; - - private bool selected; - public bool Selected - { - get => this.selected; - set - { - this.selected = value; - - this.NotifyItemSelected(); - } - } - - protected void NotifyItemSelected() => this.ItemSelected?.Invoke(this as T); - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/VAKOMerkmaleDbContext.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/VAKOMerkmaleDbContext.cs index 7a39f5b5..4bd07a47 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/VAKOMerkmaleDbContext.cs +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Data/VAKOMerkmaleDbContext.cs @@ -1,406 +1,104 @@ namespace LaaProductionWeb.Blazor.Components.CSD.Data { using LaaPackages.SqlClient; + using LaaProductionWeb.Blazor.Components.CSD.Models; using Microsoft.Extensions.Configuration; - using System; using System.Collections.Generic; - using System.Linq; public class VAKOMerkmaleDbContext { - private static int uiid; - private readonly SqlConnection sqlConnection; - private readonly HashSet charCodes; - - private string basisFilter; - private string parameterFilter; - private string charCodeFilter; - private string basis; - private int stelle; - private int laenge; public VAKOMerkmaleDbContext(IConfiguration configuration) { - this.basisFilter = "%%"; - this.parameterFilter = "%%"; - this.charCodeFilter = "%%"; - var connectionString = configuration.GetConnectionString("Auftrag"); this.sqlConnection = SqlConnection.CreateSqlConnection(connectionString); - this.charCodes = []; - - this.UniqueBasisCodes = []; - this.UniqueParameters = []; - this.UniqueCharCodes = []; - this.SelectedItems = []; - - this.InitializeVAKOMErkmale(); } - public event Action SelectionChanged; - - public ICollection UniqueBasisCodes { get; private set; } - - public ICollection UniqueParameters { get; private set; } - - public ICollection UniqueCharCodes { get; private set; } - - public SortedDictionary>> SelectedItems { get; } - - public IEnumerable GetUniqueVAKOCodePatterns() + public IEnumerable GetAllCSDs(string filter) { - var vakoCodePatterns = new HashSet(); - var orderedCharCodes = this.UniqueCharCodes - .OrderBy(x => x.Stelle) - .GroupBy(x => x.Stelle) - .ToDictionary(x => x.Key, x => x.ToList()); - - if (orderedCharCodes.Count > 0) - { - var key = orderedCharCodes.Min(x => x.Key); - var patterns = new List(); - - GenerateUniqueCombinations(orderedCharCodes, patterns, this.basis, key); - - foreach (var pattern in patterns) - { - vakoCodePatterns.Add(new string(pattern)); - } - } - - return vakoCodePatterns; - } - - public void SetBasisFilter(object filter) - { - this.basisFilter = $"%{filter}%"; - - this.UpdateBasisCodes(); - this.UpdateParameters(); - this.UpdateCharCodes(); - } - - public void SetParameterFilter(object filter) - { - this.parameterFilter = $"%{filter}%"; - - this.UpdateParameters(); - this.UpdateCharCodes(); - } - - public void SetCharCodeFilter(object filter) - { - this.charCodeFilter = $"%{filter}%"; - - this.UpdateCharCodes(); - } - - public void BasisSelected(BasisCode basisCode) - { - this.basisFilter = $"%{basisCode.Name}%"; - this.basis = basisCode.Name; - this.stelle = 0; - this.laenge = 0; - - this.charCodes.Clear(); - this.SelectedItems.Clear(); - this.UpdateParameters(); - this.UpdateCharCodes(); - } - - public void ParameterSelected(Parameter parameter) - { - this.stelle = parameter.Stelle; - this.laenge = parameter.Laenge; - - this.UpdateParameters(); - this.UpdateCharCodes(); - } - - public void CharcodeSelected(CharCode charCode) - { - this.charCodes.Add(charCode); - this.charCodes.RemoveWhere(x => !x.Selected); - } - - private void InitializeVAKOMErkmale() - { - this.UpdateBasisCodes(); - this.UpdateParameters(); - } - - private void UpdateBasisCodes() - => this.UniqueBasisCodes = this.sqlConnection - .CreateCommand($@" - SELECT DISTINCT - vmm.Basis - FROM VAKO_Merkmale AS vmm - WHERE vmm.Basis IS NOT NULL - AND vmm.Basis LIKE @{nameof(basisFilter)} - ORDER BY vmm.Basis") - .SetParameter(nameof(this.basisFilter), this.basisFilter) - .ExecuteReader(x => new BasisCode - { - UIId = $"uiid_{++uiid}", - Name = x.GetValue(0) - }) - .ToList(); - - private void UpdateParameters() - => this.UniqueParameters = this.sqlConnection - .CreateCommand($@" - SELECT DISTINCT - vmm.Basis - , vmm.Bezeichnung - , vmm.Stelle - , vmm.Laenge - FROM VAKO_Merkmale AS vmm - WHERE vmm.Bezeichnung IS NOT NULL - AND vmm.Basis LIKE @{nameof(this.basisFilter)} - AND vmm.Bezeichnung LIKE @{nameof(this.parameterFilter)} - ORDER BY vmm.Bezeichnung") - .SetParameter(nameof(this.basisFilter), this.basisFilter) - .SetParameter(nameof(this.parameterFilter), this.parameterFilter) - .ExecuteReader(x => new Parameter - { - UIId = $"uiid_{++uiid}", - Basis = x.GetValue(0), - Name = x.GetValue(1), - Stelle = x.GetValue(2), - Laenge = x.GetValue(3) - }) - .ToList(); - - private void UpdateCharCodes() - { - this.UniqueCharCodes = this.sqlConnection - .CreateCommand($@" - SELECT DISTINCT - mm.Basis - , mm.Bezeichnung - , mm.Stelle - , mm.Laenge - , mm.Charcode - , mm.Wert - FROM (SELECT DISTINCT - vmm.Basis - , vmm.Bezeichnung - , vmm.Stelle - , vmm.Laenge - , vmm.Charcode - , vmm.Wert - , ROW_NUMBER() OVER (PARTITION BY vmm.Charcode ORDER BY vmm.Wert DESC) AS RowNr - FROM VAKO_Merkmale AS vmm - WHERE vmm.Basis LIKE @{nameof(this.basisFilter)} - AND vmm.Stelle = @{nameof(this.stelle)} - AND vmm.Laenge = @{nameof(this.laenge)}) - AS mm - WHERE RowNr = 1 - AND mm.Wert LIKE @{nameof(this.charCodeFilter)} - ORDER BY mm.Charcode") - .SetParameter(nameof(this.basisFilter), this.basisFilter) - .SetParameter(nameof(this.stelle), this.stelle) - .SetParameter(nameof(this.laenge), this.laenge) - .SetParameter(nameof(this.charCodeFilter), this.charCodeFilter) - .ExecuteReader(x => new CharCode - { - UIId = $"uiid_{++uiid}", - Basis = x.GetValue(0), - Name = x.GetValue(1), - Stelle = x.GetValue(2), - Laenge = x.GetValue(3), - Code = x.GetValue(4), - Value = x.GetValue(5), - }) - .ToList(); - - foreach (var charCode in charCodes) - { - charCode.Selected = this.charCodes - .FirstOrDefault(x => x.Basis == charCode.Basis - && x.Stelle == charCode.Stelle - && x.Laenge == charCode.Laenge - && x.Code == charCode.Code) - ?.Selected ?? false; - } - } - - private static void GenerateUniqueCombinations(Dictionary> charCodes, List patterns, string basis, int key) - { - var nextKey = charCodes.FirstOrDefault(x => x.Key > key).Key; - - if (nextKey > default(int)) - { - var parameter = charCodes[nextKey].FirstOrDefault(); - - if (parameter != null) - { - var length = parameter.Stelle + parameter.Laenge; - var tempalte = new char[length]; - - for (var ix = 0; ix < length; ix++) - { - tempalte[ix] = '_'; - } - - for (var ix = 0; ix < basis.Length; ix++) - { - tempalte[ix] = basis[ix]; - } - - tempalte[length - 1] = '%'; - - if (patterns.Count == 0) - { - patterns.Add(tempalte); - } - else - { - patterns[0] = tempalte; - } - } - - GenerateUniqueCombinations(charCodes, patterns, basis, nextKey); - } - - var templatePatterns = new List(); - templatePatterns.AddRange(patterns); - patterns.Clear(); - - foreach (var parameter in charCodes[key]) - { - foreach (var template in templatePatterns) - { - var pattern = new char[template.Length]; - - Array.Copy(template, 0, pattern, 0, pattern.Length); - - var codeLength = parameter.Code.Length; - - for (var charIX = 0; charIX < codeLength; charIX++) - { - pattern[parameter.Stelle + charIX - 1] = parameter.Code[charIX]; - } - - patterns.Add(pattern); - } - } - } - - public IEnumerable GetAllCSDs(string filter) - { - var like = $"csd%{filter}%"; + var likeCSD = $"csd%{filter}%"; + var likeQA = $"qa%{filter}%"; return this.sqlConnection .CreateCommand($@" - SELECT DISTINCT - vmm.Charcode - , vmm.Wert - FROM VAKO_Merkmale AS vmm - WHERE vmm.Wert LIKE @{nameof(like)} - ORDER BY vmm.Wert") - .SetParameter(nameof(like), like) - .ExecuteReader(x => new CSD - { - CharCode = x.GetValue(0), - Wert = x.GetValue(1), - }); + SELECT DISTINCT + vmm.Wert + FROM VAKO_Merkmale AS vmm + WHERE vmm.Wert LIKE @{nameof(likeCSD)} + OR vmm.Wert LIKE @{nameof(likeQA)} + ORDER BY vmm.Wert") + .SetParameter(nameof(likeQA), likeQA) + .SetParameter(nameof(likeCSD), likeCSD) + .ExecuteReader(x => x.GetValue(0)); } public IEnumerable GetBasisCodesForCSD(string csd) => this.sqlConnection .CreateCommand($@" - SELECT DISTINCT vmm.Basis + SELECT DISTINCT + vmm.Basis FROM VAKO_Merkmale AS vmm WHERE vmm.Wert = @{nameof(csd)} ORDER BY vmm.Basis") .SetParameter(nameof(csd), csd) .ExecuteReader(x => x.GetValue(0)); - public IEnumerable GetBezeichnungenForCSDAndBasis(string csd, string basis) + public IEnumerable GetBezeichnungenForBasis(string basis) => this.sqlConnection .CreateCommand($@" SELECT DISTINCT - vmm.Bezeichnung - , vmm.Stelle - , vmm.Laenge + vmm.Bezeichnung FROM VAKO_Merkmale AS vmm WHERE vmm.Basis = @{nameof(basis)} - AND vmm.Bezeichnung <> @{nameof(basis)} - AND vmm.Wert <> @{nameof(csd)} ORDER BY vmm.Bezeichnung") - .SetParameter(nameof(csd), csd) .SetParameter(nameof(basis), basis) - .ExecuteReader(x => new CSDBezeichnung + .ExecuteReader(x => x.GetValue(0)); + + public IEnumerable GetCharcodesForBezeichnung(string basis, string bezeichnung) + => this.sqlConnection + .CreateCommand($@" + SELECT DISTINCT + vmm.Basis + , vmm.Bezeichnung + , vmm.Stelle + , vmm.Laenge + , vmm.Charcode + , vmm.Wert + FROM VAKO_Merkmale AS vmm + WHERE vmm.Basis = @{nameof(basis)} + AND vmm.Bezeichnung = @{nameof(bezeichnung)} + ORDER BY vmm.Charcode") + .SetParameter(nameof(basis), basis) + .SetParameter(nameof(bezeichnung), bezeichnung) + .ExecuteReader(x => new Charcode { - Bezeichnung = x.GetValue(0), - Stelle = x.GetValue(1), - Laenge = x.GetValue(2), + Basis = x.GetValue(0), + Bezeichnung = x.GetValue(1), + Stelle = x.GetValue(2), + Laenge = x.GetValue(3), + Code = x.GetValue(4), + Value = x.GetValue(5), + }); + + public IEnumerable GetPatternsForCSD(string csd) + => this.sqlConnection + .CreateCommand($@" + SELECT cmm.Id + , cmm.Csd + , cmm.Pattern + , cmm.TimeStamp + FROM CSD_Merkmale AS cmm + WHERE cmm.CSD = @{nameof(csd)}") + .SetParameter(nameof(csd), csd) + .ExecuteReader(x => new CSDMerkmal + { + Id = x.GetValue(0), + CSD = x.GetValue(1), + Pattern = x.GetValue(2), + TimeStamp = x.GetValue(3), }); } - - public class BasisCode - { - public string UIId { get; set; } - - public string Name { get; set; } - } - - public class Parameter - { - public string UIId { get; set; } - - public string Name { get; set; } - - public string Basis { get; set; } - - public int Stelle { get; set; } - - public int Laenge { get; set; } - } - - public class CharCode - { - public event Action SelectionChanged; - - public string UIId { get; set; } - - public string Name { get; set; } - - public string Value { get; set; } - - public string Code { get; set; } - - public string Basis { get; set; } - - public int Stelle { get; set; } - - public int Laenge { get; set; } - - private bool selected; - public bool Selected - { - get => this.selected; - set - { - this.selected = value; - - this.SelectionChanged?.Invoke(); - } - } - - public override bool Equals(object other) - => other is CharCode charcode - && charcode.Code == this.Code; - - public override int GetHashCode() - => this.Code?.GetHashCode() - ?? default; - - public override string ToString() - => this.Code; - } } diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/BasisItem.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/BasisItem.cs deleted file mode 100644 index a098600d..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/BasisItem.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Models -{ - using System; - - public class BasisItem(string basis) - { - public event Action BasisSelected; - - public string Basis { get; } = basis; - - private bool selected; - public bool Selected - { - get => this.selected; - set - { - this.selected = value; - - this.BasisSelected?.Invoke(this); - } - } - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/CSDItem.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/CSDItem.cs deleted file mode 100644 index 671c04d9..00000000 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/CSDItem.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace LaaProductionWeb.Blazor.Components.CSD.Models -{ - public class CSDItem - { - public string Name { get; set; } - } -} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/Charcode.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/Charcode.cs new file mode 100644 index 00000000..d5e47d51 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/Charcode.cs @@ -0,0 +1,54 @@ +namespace LaaProductionWeb.Blazor.Components.CSD.Models +{ + using System.Text.RegularExpressions; + + public class Charcode + { + private string uiid; + public string UIId + { + get + { + if (string.IsNullOrWhiteSpace(this.uiid)) + { + this.uiid = Regex.Replace($"{this.Basis}_{this.Bezeichnung}_{this.Stelle}_{this.Laenge}_{this.Code}_{this.Value}", "[^a-zA-Z0-9]", "_").ToLower(); + } + + return this.uiid; + } + } + + public string Basis { get; set; } + + public string Bezeichnung { get; set; } + + public int Stelle { get; set; } + + public int Laenge { get; set; } + + public string Code { get; set; } + + public string Value { get; set; } + + public bool Selected { get; set; } + + public override bool Equals(object other) + => other is Charcode charcode && charcode == this; + + public override int GetHashCode() + => this.UIId.GetHashCode(); + + public override string ToString() + => $"{this.Basis} {this.Bezeichnung} {this.Stelle} {this.Laenge} {this.Code} {this.Value}"; + + public static bool operator ==(Charcode left, Charcode right) + => left?.Basis == right?.Basis + && left?.Bezeichnung == right?.Bezeichnung + && left?.Stelle == right?.Stelle + && left?.Laenge == right?.Laenge + && left?.Code == right?.Code; + + public static bool operator !=(Charcode left, Charcode right) + => !(left == right); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/UIElement.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/UIElement.cs new file mode 100644 index 00000000..3b54a9d9 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/UIElement.cs @@ -0,0 +1,20 @@ +namespace LaaProductionWeb.Blazor.Components.CSD.Models +{ + using System.Text.RegularExpressions; + + public readonly struct UIElement(string value) + { + public string UIId { get; } = Regex.Replace($"{value}", "[^a-zA-Z0-9]", "_").ToLower(); + + public string Value { get; } = value; + + public override string ToString() + => this.Value; + + public static implicit operator UIElement(string value) + => new (value); + + public static implicit operator string(UIElement basis) + => basis.Value; + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/VAKOMerkmaleModel.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/VAKOMerkmaleModel.cs index 0be961fa..b2d746fb 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/VAKOMerkmaleModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Models/VAKOMerkmaleModel.cs @@ -2,45 +2,222 @@ { using LaaProductionWeb.Blazor.Components.CSD.Data; + using System; using System.Collections.Generic; + using System.Linq; - public class VAKOMerkmaleModel + public class VAKOMerkmaleModel(VAKOMerkmaleDbContext vakoMerkmaleDbContext) { - private readonly VAKOMerkmaleDbContext vakoMerkmaleDbContext; + private readonly VAKOMerkmaleDbContext vakoMerkmaleDbContext = vakoMerkmaleDbContext; + private Dictionary>> charcodes; - public VAKOMerkmaleModel(VAKOMerkmaleDbContext vakoMerkmaleDbContext) - => this.vakoMerkmaleDbContext = vakoMerkmaleDbContext; + public event Action StateChanged; + public string CSD { get; private set; } - public CSD CSD { get; private set; } + public string CSDKey { get; private set; } - public IEnumerable GetAllCSDs(string filter) + public string Basis { get; private set; } + + public string Bezeichnung { get; private set; } + + public ICollection BasisCodes { get; private set; } = []; + + public ICollection Bezeichnungen { get; private set; } = []; + + public IEnumerable Charcodes { get; private set; } = []; + + public IEnumerable Patterns { get; private set; } = []; + + public IEnumerable GetAllCSDs(string filter) => this.vakoMerkmaleDbContext.GetAllCSDs(filter); - public void CSDSelected(CSD kvp) + public void CSDSelected(string csd) { - this.CSD = kvp; + this.CSDKey = this.GetCSDKey(csd); + this.CSD = csd; + this.BasisCodes = []; + this.Bezeichnungen = []; + this.Charcodes = []; - var basisCodes = this.vakoMerkmaleDbContext.GetBasisCodesForCSD(kvp.Wert); + foreach (UIElement basis in this.vakoMerkmaleDbContext.GetBasisCodesForCSD(this.CSD)) + { + this.BasisCodes.Add(basis); + } - this.CSD.AddBasisCodes(basisCodes); + // this.Patterns = this.vakoMerkmaleDbContext.GetPatternsForCSD(this.CSDKey); } - public void BasisSelected() + public void BasisSelected(string basis) { - foreach (var basis in this.CSD.BasisCodes) - { - if (!basis.Selected) - { - basis.Clear(); + this.Basis = basis; + this.Bezeichnungen = []; + this.Charcodes = this.vakoMerkmaleDbContext.GetCharcodesForBezeichnung(this.Basis, this.Bezeichnung); - continue; + foreach (UIElement bezeichnung in this.vakoMerkmaleDbContext.GetBezeichnungenForBasis(this.Basis)) + { + this.Bezeichnungen.Add(bezeichnung); + } + } + + public void BezeichnungSelected(string bezeichnung) + { + this.Bezeichnung = bezeichnung; + this.Charcodes = this.vakoMerkmaleDbContext.GetCharcodesForBezeichnung(this.Basis, this.Bezeichnung); + + foreach (var _charcode in this.SelectedCharcodes()) + { + foreach (var charcode in this.Charcodes) + { + if (_charcode == charcode) + { + charcode.Selected = _charcode.Selected; + } + } + } + } + + public void MerkmalSelected(Charcode charcode) + { + if (string.IsNullOrWhiteSpace(this.Basis) || string.IsNullOrWhiteSpace(this.Bezeichnung)) + { + return; + } + + if (this.charcodes is null) + { + this.charcodes = []; + } + + if (!this.charcodes.ContainsKey(this.Basis)) + { + this.charcodes[this.Basis] = []; + } + + if (!this.charcodes[this.Basis].ContainsKey(this.Bezeichnung)) + { + this.charcodes[this.Basis][this.Bezeichnung] = []; + } + + charcode.Selected = !this.IsMerkmalSelected(charcode); + + if (charcode.Selected) + { + this.charcodes[this.Basis][this.Bezeichnung].Add(charcode); + } + else + { + this.charcodes[this.Basis][this.Bezeichnung].RemoveWhere(x => x == charcode); + } + + this.UpdatePatterns(); + this.StateChanged?.Invoke(); + } + + public bool IsMerkmalSelected(Charcode charcode) + { + var __charcode = default(Charcode); + + foreach (var _charcode in this.SelectedCharcodes()) + { + if (_charcode == charcode) + { + __charcode = _charcode; + } + } + + if (__charcode is not null) + { + return __charcode.Selected; + } + + return charcode.Selected; + } + + public IEnumerable SelectedCharcodes() + { + if (string.IsNullOrWhiteSpace(this.Basis) || string.IsNullOrWhiteSpace(this.Bezeichnung)) + { + yield break; + } + + if (this.charcodes is null) + { + this.charcodes = []; + } + + if (!this.charcodes.ContainsKey(this.Basis)) + { + this.charcodes[this.Basis] = []; + } + + if (!this.charcodes[this.Basis].ContainsKey(this.Bezeichnung)) + { + this.charcodes[this.Basis][this.Bezeichnung] = []; + } + + foreach (var charcode in this.charcodes[this.Basis][this.Bezeichnung]) + { + yield return charcode; + } + } + + private string GetCSDKey(string csd) + { + if (!string.IsNullOrWhiteSpace(csd)) + { + var tokens = new string [0]; + + csd = csd.Trim(); + + if (csd.StartsWith("CSD", StringComparison.CurrentCultureIgnoreCase)) + { + tokens = csd + .Split(' ', StringSplitOptions.RemoveEmptyEntries) + .Take(2) + .ToArray(); + } + else if (csd.StartsWith("QA", StringComparison.CurrentCultureIgnoreCase)) + { + tokens = csd + .Split(' ', StringSplitOptions.RemoveEmptyEntries) + .Take(1) + .ToArray(); } - var bezeichnungen = this.vakoMerkmaleDbContext.GetBezeichnungenForCSDAndBasis(this.CSD.Wert, basis.Basis); - - basis.AddBezeichnungen(bezeichnungen); + return string.Join(" ", tokens); } + + return default(string); + } + + private void UpdatePatterns() + { + var patterns = new List(); + + foreach (var (basis, bezeichnungen) in this.charcodes) + { + var charcodes = bezeichnungen + .SelectMany(x => x.Value) + .OrderBy(x => x.Stelle) + .ThenBy(x => x.Laenge) + .ThenBy(x => x.Code) + .GroupBy(x => x.Stelle) + .ToDictionary(x => x.Key, x => x.ToArray()); + var basisPatterns = new List() { basis }; + + foreach (var (stelle, codes) in charcodes) + { + var actualPatterns = new List() { basis }; + + foreach (var code in codes) + { + patterns.Add($"{basis}{new string('_', code.Stelle + code.Laenge - 1 - basis.Length)}{code}"); + } + } + } + + this.Patterns = patterns; } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor index 721f9278..e3ecfbbc 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor @@ -1,112 +1,41 @@ - +
- - - - + + - @if (this.VAKOMerkmaleModel?.CSD is not null) - { - - - - - - - }
+ - - - - - +
+ Optionen + Programmierung
- @this.VAKOMerkmaleModel.CSD.Wert - - @foreach (var basis in this.VAKOMerkmaleModel.CSD.BasisCodes?.Where(x => x.Selected) ?? []) - { -
@basis.Basis
- } -
- -
diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor.cs index 53a0d98f..4526af4f 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor.cs +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Navbar.razor.cs @@ -1,6 +1,5 @@ namespace LaaProductionWeb.Blazor.Components.CSD { - using LaaProductionWeb.Blazor.Components.CSD.Data; using LaaProductionWeb.Blazor.Components.CSD.Models; using Microsoft.AspNetCore.Components; @@ -14,29 +13,38 @@ [Inject] private VAKOMerkmaleModel VAKOMerkmaleModel { get; set; } + [Parameter] + public EventCallback StateChanged { get; set; } + + protected override void OnInitialized() + => this.VAKOMerkmaleModel.StateChanged += this.StateHasChanged; + private void OnCSDFilterInput(ChangeEventArgs args) { this.csdFilter = $"{args.Value}"; this.StateHasChanged(); + + if (this.StateChanged.HasDelegate) + { + this.StateChanged.InvokeAsync(); + } } - private IEnumerable FilterCSDs() + private IEnumerable FilterCSDs() => this.VAKOMerkmaleModel.GetAllCSDs(this.csdFilter); - private void CSDSelected(CSD kvp) + private void CSDSelected(string csd) { - this.VAKOMerkmaleModel.CSDSelected(kvp); + this.csdFilter = default; + this.VAKOMerkmaleModel.CSDSelected(csd); this.StateHasChanged(); - } - private void BasisSelected(CSDBasis basis, ChangeEventArgs args) - { - basis.Selected = args.Value is bool selected && selected; - - this.VAKOMerkmaleModel.BasisSelected(); - this.StateHasChanged(); + if (this.StateChanged.HasDelegate) + { + this.StateChanged.InvokeAsync(); + } } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor new file mode 100644 index 00000000..b1d6076f --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor @@ -0,0 +1,59 @@ +@page "/csd/options" + +@using System.Text.RegularExpressions + +
+ +
+
+
+ @foreach (var basis in this.VAKOMerkmaleModel.BasisCodes) + { + var selected = default(string); + + if (this.VAKOMerkmaleModel.Basis == basis) + { + selected = "bg-secondary bg-opacity-25"; + } + +
@basis
+ } +
+
+
+
+ @foreach (var bezeichnung in this.VAKOMerkmaleModel.Bezeichnungen) + { + var selected = default(string); + + if (this.VAKOMerkmaleModel.Bezeichnung == bezeichnung) + { + selected = "bg-secondary bg-opacity-25"; + } + +
@bezeichnung
+ } +
+
+
+
+ @foreach (var charcode in this.VAKOMerkmaleModel.Charcodes) + { + var isSelected = this.VAKOMerkmaleModel.IsMerkmalSelected(charcode); + var selected = default(string); + + if (isSelected) + { + selected = "bg-secondary bg-opacity-25"; + } + +
+ @charcode.Code + [@(charcode.Stelle)..@(charcode.Laenge)] + @charcode.Value +
+ } +
+
+
+
\ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.cs new file mode 100644 index 00000000..5880d911 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.cs @@ -0,0 +1,21 @@ +namespace LaaProductionWeb.Blazor.Components.CSD +{ + using LaaProductionWeb.Blazor.Components.CSD.Models; + + using Microsoft.AspNetCore.Components; + + public partial class Options : ComponentBase + { + [Inject] + private VAKOMerkmaleModel VAKOMerkmaleModel { get; set; } + + private void BasisSelected(string basis) + => this.VAKOMerkmaleModel.BasisSelected(basis); + + private void BezeichnungSelected(string bezeichnung) + => this.VAKOMerkmaleModel.BezeichnungSelected(bezeichnung); + + private void MerkmalSelected(Charcode charcode) + => this.VAKOMerkmaleModel.MerkmalSelected(charcode); + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.js b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.js new file mode 100644 index 00000000..bd0ba9c8 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/Options.razor.js @@ -0,0 +1,12 @@ +export function setChecked (id) { + let input = document.querySelector(`input[id="${id}"]`); + if (input) { + input.checked = true; + } +} +export function setNotChecked(id) { + let input = document.querySelector(`input[id="${id}"]`); + if (input) { + input.checked = false; + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor index a9192c4c..1ada0809 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor @@ -3,56 +3,6 @@
-
- - @foreach (var basisCode in this.VAKOMerkmale.UniqueBasisCodes) - { - var id = basisCode.Name.ToLower(); -
- - -
- } -
-
- - @foreach (var parameter in this.VAKOMerkmale.UniqueParameters) - { - var id = parameter.UIId; - -
- - -
- } -
-
- - @foreach (var charCode in this.VAKOMerkmale.UniqueCharCodes) - { - charCode.SelectionChanged += this.StateHasChanged; - - var id = charCode.UIId; - -
- - -
- } -
-
- @foreach (var pattern in this.VAKOMerkmale.GetUniqueVAKOCodePatterns()) - { -
- @pattern -
- } -
\ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor.cs index 19ff8438..75b54b6c 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor.cs +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Components/CSD/ProgrammingParameters.razor.cs @@ -1,48 +1,12 @@ namespace LaaProductionWeb.Blazor.Components.CSD { - using LaaProductionWeb.Blazor.Components.CSD.Data; + using LaaProductionWeb.Blazor.Components.CSD.Models; using Microsoft.AspNetCore.Components; public partial class ProgrammingParameters : ComponentBase { [Inject] - private VAKOMerkmaleDbContext VAKOMerkmale { get; set; } - - private void FilterBasisCodes(ChangeEventArgs args) - { - this.VAKOMerkmale.SetBasisFilter(args.Value); - this.StateHasChanged(); - } - - private void FilterParameters(ChangeEventArgs args) - { - this.VAKOMerkmale.SetParameterFilter(args.Value); - this.StateHasChanged(); - } - - private void FilterCharcodes(ChangeEventArgs args) - { - this.VAKOMerkmale.SetCharCodeFilter(args.Value); - this.StateHasChanged(); - } - - private void BasisSelected(BasisCode basisCode, ChangeEventArgs args) - { - if (args.Value is string state && state == "on") - { - this.VAKOMerkmale.BasisSelected(basisCode); - this.StateHasChanged(); - } - } - - private void ParameterSelected(Parameter parameter, ChangeEventArgs args) - { - if (args.Value is string state && state == "on") - { - this.VAKOMerkmale.ParameterSelected(parameter); - this.StateHasChanged(); - } - } + private VAKOMerkmaleModel VAKOMerkmaleModel { get; set; } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/LaaProductionWeb.Blazor.csproj b/LaaProductionWeb/LaaProductionWeb.Blazor/LaaProductionWeb.Blazor.csproj index 1d652c46..f09d73a0 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/LaaProductionWeb.Blazor.csproj +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/LaaProductionWeb.Blazor.csproj @@ -14,10 +14,6 @@ IDE1701;IDE1702;CA2254; - - - - diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/Program.cs b/LaaProductionWeb/LaaProductionWeb.Blazor/Program.cs index f03b178d..d5c812b8 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/Program.cs +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/Program.cs @@ -39,7 +39,6 @@ namespace LaaProductionWeb.Blazor services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -62,9 +61,6 @@ namespace LaaProductionWeb.Blazor app.UseAuthentication(); app.UseAuthorization(); app.MapStaticAssets(); - //app.UseCors(c => c.AllowAnyHeader() - // .AllowAnyOrigin() - // .AllowAnyMethod()); app.MapRazorComponents() .AddInteractiveServerRenderMode(options => { diff --git a/LaaProductionWeb/LaaProductionWeb.Blazor/wwwroot/bootstrap/css/bootstrap.overrides.css b/LaaProductionWeb/LaaProductionWeb.Blazor/wwwroot/bootstrap/css/bootstrap.overrides.css index 86c5bb4f..ff69cef2 100644 --- a/LaaProductionWeb/LaaProductionWeb.Blazor/wwwroot/bootstrap/css/bootstrap.overrides.css +++ b/LaaProductionWeb/LaaProductionWeb.Blazor/wwwroot/bootstrap/css/bootstrap.overrides.css @@ -119,9 +119,19 @@ table.recipes-table input.form-check-input { } .form-select { - --bs-form-select-bg-img: url('data:image/svg+xml;utf8,'); + --bs-form-select-bg-img: url('data:image/svg+xml;utf8,'); + background-color: inherit; + background-image: var(--bs-form-select-bg-img), var(--bs-form-select-bg-icon, none); + background-repeat: no-repeat; + background-position: left .25rem center; + background-size: 12px 12px; + padding-left: 24px; } .dropdown-menu.dropdown-nav { --bs-dropdown-link-active-bg: var(--bs-light); +} + +.hover-light:hover { + background: var(--bs-light); } \ No newline at end of file