From bd14271451a1934d489db6fd22faa8bf6e09d4e4 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Wed, 12 Apr 2023 09:52:08 +0200 Subject: [PATCH] Shipment - hide/show - serials scan and serials list. HeReport - date filter from to date. Protocol - denyed upload of files when order has failed tests. --- .../LaaProductionWeb.Data/DbContext.cs | 7 +- .../Interfaces/IProtocolService.cs | 2 + .../Models/HeliumReportFilter.cs | 18 ++- .../ProtocolService.cs | 32 ++++ .../Controllers/ProtocolController.cs | 17 +- .../Views/Shipments/Batch.cshtml | 148 +++++++++--------- .../Views/Shipments/Scan.cshtml | 93 +++++------ 7 files changed, 184 insertions(+), 133 deletions(-) diff --git a/LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs b/LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs index 879f612f..ec1c6579 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/DbContext.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; + using System.Data; using System.Data.SqlClient; public class DbContext : IDbContext @@ -25,7 +26,7 @@ parameters(sqlCommand.Parameters); - using (SqlReader sqlReader = sqlCommand.ExecuteReader()) + using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { while (sqlReader.Read()) { @@ -46,7 +47,7 @@ { sqlCommand.CommandText = query; - using (SqlReader sqlReader = sqlCommand.ExecuteReader()) + using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { while (sqlReader.Read()) { @@ -71,7 +72,7 @@ parameters(sqlCommand.Parameters); - using (SqlReader sqlReader = sqlCommand.ExecuteReader()) + using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { if (sqlReader.Read()) { diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IProtocolService.cs b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IProtocolService.cs index 08f50374..29d1d68b 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IProtocolService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IProtocolService.cs @@ -19,6 +19,8 @@ IEnumerable LoadTestStatus(int orderId); + bool OrderCompleted(int orderNr); + int SaveFile(Stream fileStream, int clientId, int orderId); } } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs index 704fcc6f..059ca2f4 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs @@ -63,19 +63,21 @@ { var dateTokens = property .Like - .Split(new[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries) - .Select(x => DateTimeOffset.TryParse($"{x}", new CultureInfo("de"), DateTimeStyles.None, out DateTimeOffset date) - ? (DateTimeOffset?)date.AddHours(-date.Hour) + .Split(new[] { '-' }) + .Select(x => DateTimeOffset.TryParse($"{x}".Trim(), new CultureInfo("de"), DateTimeStyles.None, out DateTimeOffset date) + ? (DateTimeOffset?)date : null) .ToArray(); if (dateTokens.Length >= 1) { - var propertyValue = dateTokens[0]; + var date1 = dateTokens.FirstOrDefault(); - if (propertyValue != null) + if (date1 != null) { + var date = date1.Value; var propertyName = $"{property.Property}_{property.Index}_From"; + var propertyValue = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0); sqlExpression.Add($"{property.Column} >= @{propertyName}", propertyName, propertyValue); } @@ -83,11 +85,13 @@ if (dateTokens.Length >= 2) { - var propertyValue = dateTokens[1]; + var date2 = dateTokens.LastOrDefault(); - if (propertyValue != null) + if (date2 != null) { + var date = date2.Value.AddDays(1); var propertyName = $"{property.Property}_{property.Index}_To"; + var propertyValue = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0); sqlExpression.Add($"{property.Column} <= @{propertyName}", propertyName, propertyValue); } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs index f04250c7..3515b060 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ProtocolService.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.IO; + using System.Linq; public class ProtocolService : IProtocolService { @@ -162,6 +163,37 @@ RadioTest = reader.GetValue(5), }); + public bool OrderCompleted(int orderId) + { + var sumResults = this.dbContext.AsEnumerable($@" + SELECT CAST(CASE WHEN ISNULL([CPT].[CordonelPressureTest_Valid], 1) = 1 THEN 0 ELSE 1 END AS INT) + + CAST(CASE WHEN ISNULL([DP].[Dicht], 1) = 1 THEN 0 ELSE 1 END AS INT) + + ISNULL(MAX([APS].[StatusFertigung]) - 30, 0) + + CAST(CASE WHEN ISNULL([CRRH].[Result], 1) = 1 THEN 0 ELSE 1 END AS INT) + FROM [AuftragPositionSerienNr] AS [APS] + LEFT JOIN [Genesis_Meter] AS [GM] ON [GM].[Seriennummer] = [APS].[SerienNr] + LEFT JOIN [MapPcbIdToSerialNumber] AS [PCB] ON [PCB].[MapPcbIdToSerialNumber_SerialNumber] = [GM].[Seriennummer] + LEFT JOIN [Cordonel_Radio_RSSI_History] AS [CRRH] ON [CRRH].[RadioAdress] = [GM].[Adresse] - 10000000000 + AND [CRRH].[IsLast] = 1 + AND [CRRH].[Result] = 1 + LEFT JOIN [Druckpruefung] AS [DP] ON [DP].[FabNr] = [PCB].[MapPcbIdToSerialNumber_PcbId] + AND [DP].[Dicht] = 1 + LEFT JOIN [Cordonel_PressureTest] AS [CPT] ON [CPT].[CordonelPressureTest_PcbId] = [PCB].[MapPcbIdToSerialNumber_PcbId] + AND [CPT].[CordonelPressureTest_Valid] = 1 + WHERE [APS].[AuftragNr] = @{nameof(orderId)} + GROUP BY [APS].[PositionNr] + , [APS].[SerienNr] + , [APS].[KundeneigeneSerienNr] + , [CPT].[CordonelPressureTest_Valid] + , [DP].[Dicht] + , [CRRH].[Result]", + parameters => parameters.Add(nameof(orderId), orderId), + reader => reader.GetValue(0)) + .Sum(x => x); + + return sumResults == 0; + } + public int SaveFile(Stream fileStream, int clientId, int orderId) { var fileName = $"{clientId}_{orderId}.pdf"; diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs index 2cde3163..d5bedd5a 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs @@ -44,15 +44,22 @@ if (file.ContentType == "application/pdf" && model.ClientId > 0 && model.OrderId > 0) { - model.FileId = this.protocolService.SaveFile(file.InputStream, model.ClientId.Value, model.OrderId.Value); - - if (model.FileId > 0) + if (!this.protocolService.OrderCompleted(model.OrderId.Value)) { - return this.RedirectToAction(nameof(this.Document), model); + this.TempData[FilePDF] = $"Auftrag enthält nicht bestandene Prüfungen."; } else { - this.TempData[FilePDF] = $"Der PDF Datei wurde nicht hochgeladen."; + model.FileId = this.protocolService.SaveFile(file.InputStream, model.ClientId.Value, model.OrderId.Value); + + if (model.FileId > 0) + { + return this.RedirectToAction(nameof(this.Document), model); + } + else + { + this.TempData[FilePDF] = $"Der PDF Datei wurde nicht hochgeladen."; + } } } else diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml index 1e8ef70c..ae035e73 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml @@ -2,86 +2,88 @@ @model PalletsBatchModel - -
-
- +} diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Scan.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Scan.cshtml index b97efa1d..019b17e8 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Scan.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Scan.cshtml @@ -1,51 +1,54 @@ @model LaaProductionWeb.Services.Models.OrderScanModel -
-
@this.Model.ScanTitle
-
-
-
- @this.Html.AntiForgeryToken() - @this.Html.HiddenFor(x => x.OrderNr) - @this.Html.HiddenFor(x => x.PositionNr) - @this.Html.HiddenFor(x => x.PalletsCount) -
- @foreach (var pallet in this.Model.Pallets) - { - var css = pallet.Key != this.Model.PalletNr - ? "btn btn-outline-success" - : "btn btn-success"; - var id = $"pallet_{pallet.Key}"; - - - } - - Druckvorschau - - - Herunterladen - +@if (this.Model.PositionNr != null) +{ +
+
@this.Model.ScanTitle
+
-
-
- @this.Html.TextBoxFor(x => x.SerialNr, new { id = "serial_nr", @class = "form-control form-control-success text-center", placeholder = "0000000000" }) - @this.Html.LabelFor(x => x.SerialNr, new { @for = "serial_nr", @class = "text-smallcaps" }) + + @this.Html.AntiForgeryToken() + @this.Html.HiddenFor(x => x.OrderNr) + @this.Html.HiddenFor(x => x.PositionNr) + @this.Html.HiddenFor(x => x.PalletsCount) +
+ @foreach (var pallet in this.Model.Pallets) + { + var css = pallet.Key != this.Model.PalletNr + ? "btn btn-outline-success" + : "btn btn-success"; + var id = $"pallet_{pallet.Key}"; + + + } + + Druckvorschau + + + Herunterladen + +
+
+
+ @this.Html.TextBoxFor(x => x.SerialNr, new { id = "serial_nr", @class = "form-control form-control-success text-center", placeholder = "0000000000" }) + @this.Html.LabelFor(x => x.SerialNr, new { @for = "serial_nr", @class = "text-smallcaps" }) +
+
+ @this.Html.TextBoxFor(x => x.PalletNr, new { id = "pallet_nr", @class = "form-control form-control-success text-center", placeholder = "0" }) + @this.Html.LabelFor(x => x.PalletNr, new { @for = "pallet_nr", @class = "text-smallcaps" }) +
-
- @this.Html.TextBoxFor(x => x.PalletNr, new { id = "pallet_nr", @class = "form-control form-control-success text-center", placeholder = "0" }) - @this.Html.LabelFor(x => x.PalletNr, new { @for = "pallet_nr", @class = "text-smallcaps" }) + @if (this.TempData.TryGetValue(nameof(this.Model.SerialNr), out object errorMessage)) + { +
+ @($"{errorMessage}") +
+ } +
+
-
- @if (this.TempData.TryGetValue(nameof(this.Model.SerialNr), out object errorMessage)) - { -
- @($"{errorMessage}") -
- } -
- -
- + +}