From 3f1536cd301c4c6871196d0cc7d517551824b1a1 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Tue, 9 May 2023 09:06:30 +0200 Subject: [PATCH] /Search/Wildcard was edited --- .../Areas/Serach/Models/WildcardModel.cs | 76 ++++++++++--------- .../Models/ModelResult[T].cs | 16 +++- .../Models/Search/SearchWildcardModel.cs | 2 +- .../App_Content/css/styles.css | 7 +- .../Views/Search/Wildcard.cshtml | 4 +- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/LaaProductionWeb/LaaProductionWeb.API/Areas/Serach/Models/WildcardModel.cs b/LaaProductionWeb/LaaProductionWeb.API/Areas/Serach/Models/WildcardModel.cs index a66a7a52..4c5bf9da 100644 --- a/LaaProductionWeb/LaaProductionWeb.API/Areas/Serach/Models/WildcardModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.API/Areas/Serach/Models/WildcardModel.cs @@ -11,25 +11,6 @@ public class WildcardModel : IWildcardModel { - public static readonly IEnumerable fields = new[] - { - "Client", - "OrderNo", - "PosNo", - "SerialNo", - "ClientSerialNo", - "KurzBez", - "Typ", - "Nennweite", - "Baulaenge", - "Quantity", - "FabricNo", - "IdentNr", - "PcbId", - "ERAddress", - "GMAddress", - }; - private readonly ISqlClient sqlClient; public WildcardModel(ISqlClient sqlClient) @@ -39,18 +20,18 @@ { if (validationState.IsValid) { - var requiredFields = model.GetRequiredFields(fields); - - return sqlClient.ExecuteReader($@" + var requiredFields = model.GetRequiredFields(this.Options().Value); + var ordersFound = sqlClient.ExecuteReader($@" DECLARE @serienNr TABLE([Nr] VARCHAR(50)); ----------------------------------------------------------------------------- -- 1. LOOK FOR SERIAL NUMBER ------------------------------------------------ ----------------------------------------------------------------------------- INSERT INTO @serienNr SELECT [APS].[SerienNr] - FROM [AuftragPositionSerienNr] AS [APS] - WHERE [APS].[SerienNr] LIKE @{nameof(model.Token)} - OR [APS].[KundeneigeneSerienNr] LIKE @{nameof(model.Token)}; + FROM [AuftragPositionSerienNr] AS [APS] + WHERE [APS].[SerienNr] LIKE @{nameof(model.Token)} + OR [APS].[KundeneigeneSerienNr] LIKE @{nameof(model.Token)} + OR REPLACE([APS].[KundeneigeneSerienNr], ' ', '') LIKE @{nameof(model.Token)}; ----------------------------------------------------------------------------- -- 2. LOOK FOR PCB NUMBER --------------------------------------------------- ----------------------------------------------------------------------------- @@ -76,13 +57,13 @@ -- 5. TAKE ORDERS INFO ------------------------------------------------------ ----------------------------------------------------------------------------- SELECT DISTINCT - -- KundenNr CustomerNr - [KN].[Name] AS [Client] -- Customer - -- FertigungNr - ProductionOrderNo - , [APS].[AuftragNr] AS [OrderNo] -- CustomerOrderNo + [KN].[KundenNr] AS [CustomerNo] + , [KN].[Name] AS [Customer] + , [AP].[FertigungsauftragNr] AS [ProductionOrderNo] + , [APS].[AuftragNr] AS [CustomerOrderNo] , [APS].[PositionNr] AS [PosNo] , [APS].[SerienNr] AS [SerialNo] - , [APS].[KundeneigeneSerienNr] AS [ClientSerialNo] -- CustomerSerialNo + , [APS].[KundeneigeneSerienNr] AS [CustomerSerialNo] , [IDN].[KurzBez] AS [KurzBez] , [IDN].[Typ] AS [Typ] , [IDN].[Nennweite] AS [Nennweite] @@ -91,8 +72,8 @@ , [APS].[FabNr] AS [FabricNo] , [IDN].[IdentNr] AS [IdentNr] , [PCBS].[MapPcbIdToSerialNumber_PcbId] AS [PcbId] - , [ER].[Adresse] AS [ERAddress] -- ErRadioAddress - , [GM].[Adresse] AS [GMAddress] -- GmRadioAddress + , [ER].[Adresse] AS [ErRadioAddress] + , [GM].[Adresse] AS [GmRadioAddress] FROM [AuftragPositionSerienNr] AS [APS] LEFT JOIN [AuftragPosition_Gesamt] AS [AP] ON [AP].[AuftragNr] = [APS].[AuftragNr] @@ -111,15 +92,40 @@ ON [GM].[Seriennummer] = [APS].[SerienNr] WHERE [APS].[SerienNr] IN (SELECT [Nr] FROM @serienNr)", parameters => parameters.Add(nameof(model.Token), model.Token), - reader => this.ToWildcardResult(reader, requiredFields)) - .ToList(); + reader => this.ToWildcardResult(reader, requiredFields)); + + if (ordersFound.Any()) + { + return ordersFound.ToList(); + } + + return KeyValuePair.Create(nameof(model.Token), $"Keine ergebnisse gefunden für '{model.Token}'"); } return validationState; } public ModelResult> Options() - => fields.ToList(); + => new string[] + { + "CustomerNo", + "Customer", + "ProductionOrderNo", + "CustomerOrderNo", + "PosNo", + "SerialNo", + "CustomerSerialNo", + "KurzBez", + "Typ", + "Nennweite", + "Baulaenge", + "Quantity", + "FabricNo", + "IdentNr", + "PcbId", + "ErRadioAddress", + "GmRadioAddress", + }; internal WildcardResult ToWildcardResult(ISqlReader reader, IEnumerable fields) { diff --git a/LaaProductionWeb/LaaProductionWeb.API/Models/ModelResult[T].cs b/LaaProductionWeb/LaaProductionWeb.API/Models/ModelResult[T].cs index 5f3f56f7..ff49f777 100644 --- a/LaaProductionWeb/LaaProductionWeb.API/Models/ModelResult[T].cs +++ b/LaaProductionWeb/LaaProductionWeb.API/Models/ModelResult[T].cs @@ -8,7 +8,6 @@ public class ModelResult { - private readonly T value; private readonly Dictionary errors; private ModelResult(bool succeeded) @@ -20,9 +19,11 @@ private ModelResult(T value) { this.Succeeded = true; - this.value = value; + this.Value = value; } + public T Value { get; } + public bool Succeeded { get; } public IReadOnlyDictionary ModelErrors @@ -39,6 +40,15 @@ public static implicit operator ModelResult(T value) => new ModelResult(value); + public static implicit operator ModelResult(KeyValuePair error) + { + var validationResults = new ModelResult(false); + + validationResults.AddModelError(error.Key, error.Value); + + return validationResults; + } + public static implicit operator ModelResult(ModelStateDictionary modelState) { var validationResults = new ModelResult(false); @@ -68,7 +78,7 @@ } else if (modelState.Succeeded) { - return new OkObjectResult(modelState.value); + return new OkObjectResult(modelState.Value); } return new BadRequestObjectResult(modelState.errors); diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/SearchWildcardModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/SearchWildcardModel.cs index 0511d93f..45c57895 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/SearchWildcardModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/Search/SearchWildcardModel.cs @@ -5,7 +5,7 @@ public class SearchWildcardModel { - [Display(Name = "Search text")] + [Display(Name = "Radioadress | PcbId | SerienNr | KundenSerienNr")] public string Token { get; set; } [Display(Name = "Select fields")] diff --git a/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css b/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css index 2a91a050..2bf744e4 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css +++ b/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css @@ -136,9 +136,12 @@ table.table table.table { bottom: 0; } - - .cursor-pointer:hover { cursor: pointer !important; text-decoration: underline !important; } + +label.bi-search:before { + position: relative !important; + left: -.5rem !important; +} diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Search/Wildcard.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Search/Wildcard.cshtml index 5d60620d..8b98b321 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Search/Wildcard.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Search/Wildcard.cshtml @@ -29,9 +29,9 @@
@this.Html.TextBoxFor(x => x.Token, new { id = "serial_nr", @class = "form-control", placeholder = "0000000000" }) - @this.Html.LabelFor(x => x.Token, new { @for = "serial_nr", @class = "text-smallcaps" }) + @this.Html.LabelFor(x => x.Token, new { @for = "serial_nr", @class = "opacity-50 text-smallcaps bi bi-search ps-4" })
- +
@this.Html.ValidationMessageFor(x => x.Token, string.Empty, new { @class = "small text-danger mt-0" })