diff --git a/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs b/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs index 4c8a290f..ac71743b 100644 --- a/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs +++ b/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs @@ -22,7 +22,7 @@ { using (var client = new SmtpClient()) { - await client.AuthenticateAsync(this.settings.Username, this.settings.Password); + // await client.AuthenticateAsync(this.settings.Username, this.settings.Password); await client.ConnectAsync(this.settings.Host, this.settings.Port); var message = new MimeMessage diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs index 965d17db..a6fca309 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs @@ -1,11 +1,19 @@ -namespace LaaProductionWeb.Data.Interfaces +using System; + +namespace LaaProductionWeb.Data.Interfaces { public interface ISqlReader { + bool GetBool(int index = -1); + byte[] GetBytes(int index = -1); + DateTime GetDate(int index = -1); + int GetInt(int index = -1); + long GetLong(int index = -1); + short GetSmallint(int index = -1); string GetString(int index = -1); diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs b/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs index 650684bf..ddbac85e 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs @@ -4,53 +4,35 @@ using System; using System.Collections.Generic; - using System.Data; - using System.Data.SqlClient; - using System.Linq; public class SQLCommand { private readonly SqlClient sqlClient; - private readonly ICollection parameters; + private readonly IDictionary parameters; public SQLCommand(SqlClient sqlClient, string commandText) { this.sqlClient = sqlClient; this.CommandText = commandText; - this.parameters = new List(); + this.parameters = new Dictionary(); } internal string CommandText { get; } - internal SqlParameter[] Parameters - => this.parameters.ToArray(); + internal IReadOnlyDictionary Parameters + => this.parameters as IReadOnlyDictionary; public SQLCommand AddParameter(string name, object value) { - this.parameters.Add(new SqlParameter(name, value ?? DBNull.Value)); - - return this; - } - - public SQLCommand AddParameter(string name, byte[] fileContent) - { - var sqlParameter = new SqlParameter(name, SqlDbType.VarBinary); - - if (fileContent is null) - { - sqlParameter.Value = DBNull.Value; - } - else - { - sqlParameter.Value = fileContent; - } - - this.parameters.Add(sqlParameter); + this.parameters[name] = value ?? DBNull.Value; return this; } public T FirstOrDefault(Func expression) - => this.sqlClient.FirstOrDefault(this, expression); + => this.sqlClient.FirstOrDefault(this, expression); + + public IEnumerable ExecuteReader(Func expression) + => this.sqlClient.ExecuteReader(this, expression); } } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs index d2e9aeaa..49dbb650 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs @@ -11,8 +11,21 @@ { private readonly string connectionString; - public SqlClient(string connectionString) - => this.connectionString = connectionString; + public SqlClient(string connectionString) + { + this.connectionString = connectionString; + +#if DEBUG + //var connectionBuilder = new SqlConnectionStringBuilder(connectionString); + //connectionBuilder.PersistSecurityInfo = false; + //connectionBuilder.Password = string.Empty; + //connectionBuilder.UserID = string.Empty; + //connectionBuilder.IntegratedSecurity = true; + //connectionBuilder.InitialCatalog = "AuftragKopie"; + + //this.connectionString = connectionBuilder.ToString(); +#endif + } public SQLCommand CreateCommand(string commandText) => new SQLCommand(this, commandText); @@ -37,6 +50,36 @@ return rowsAffected; } + internal IEnumerable ExecuteReader(SQLCommand command, Func expression) + { + using (var sqlConnection = new SqlConnection(this.connectionString)) + { + sqlConnection.OpenWithErrorHandling(); + + using (var sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = command.CommandText; + + foreach (var kvp in command.Parameters) + { + var param = sqlCommand.CreateParameter(); + param.ParameterName = kvp.Key; + param.Value = kvp.Value; + + sqlCommand.Parameters.Add(param); + } + + using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) + { + while (sqlReader.Read()) + { + yield return expression(sqlReader); + } + } + } + } + } + public IEnumerable ExecuteReader(string query, Func reader, SqlInfoMessageEventHandler errorCallback = null) { using (var sqlConnection = new SqlConnection(this.connectionString)) @@ -167,7 +210,14 @@ { sqlCommand.CommandText = command.CommandText; - sqlCommand.Parameters.AddRange(command.Parameters); + foreach (var kvp in command.Parameters) + { + var param = sqlCommand.CreateParameter(); + param.ParameterName = kvp.Key; + param.Value = kvp.Value; + + sqlCommand.Parameters.Add(param); + } using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs index 3007e79c..66404a4e 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs @@ -3,8 +3,7 @@ using LaaProductionWeb.Data.Interfaces; using Microsoft.Extensions.DependencyInjection; - - using System; + using System.Data.SqlClient; using System.Diagnostics; using System.Threading.Tasks; @@ -46,16 +45,7 @@ internal static void SqlConnectionInfoMessage(object sender, SqlInfoMessageEventArgs e) { - Debug.WriteLine(e); - - Log($"[{DateTime.Now: hh:mm:ss}] Error: {e.Source} - {e.Message}{Environment.NewLine}{string.Join(Environment.NewLine, e.Errors)}"); - - // TODO: Handle errors - } - - internal static void Log(string message) - { - // File.AppendAllText($"{Environment.CurrentDirectory}/App_Data/{DateTime.Now:yyyy_MM_dd}.log", $"{Environment.NewLine}{message}{Environment.NewLine}"); + Debug.Write(e); } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs index 8c05c912..833283a8 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs @@ -36,6 +36,21 @@ this.sqlDataReader.Dispose(); } + public bool GetBool(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetBoolean(index); + } + + return default(bool); + } + public byte[] GetBytes(int index = -1) { var bytes = default(byte[]); @@ -56,6 +71,51 @@ internal string[] GetColumns() => this.columns.Keys.ToArray(); + public DateTime GetDate(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetDateTime(index); + } + + return default(DateTime); + } + + public int GetInt(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetInt32(index); + } + + return default(int); + } + + public long GetLong(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetInt64(index); + } + + return default(long); + } + public string GetString(int index = -1) { if (index < 0) @@ -116,21 +176,6 @@ return default(object); } - public int GetInt(int index = -1) - { - if (index < 0) - { - index = this.column++; - } - - if (!this.sqlDataReader.IsDBNull(index)) - { - return this.sqlDataReader.GetInt32(index); - } - - return default(int); - } - public short GetSmallint(int index = -1) { if (index < 0) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs index e8b3ff8f..edb8c453 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs @@ -11,7 +11,9 @@ PalletsBatchModel LoadBatchModel(OrderScanModel model); - IEnumerable LoadPallets(OrderScanModel model); + OrderScanModel LoadPallets(OrderScanModel model); + + IEnumerable MissingItems(); Result UpdateBatchModel(OrderScanModel model); } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj index 2315413c..450b269d 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj +++ b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj @@ -63,6 +63,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs index a61a7ac3..c1f43210 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs @@ -16,6 +16,14 @@ public int OrderNr => this.batchModel.OrderNr; + public int PalletNr + => this.batchModel + .Positions + ?.FirstOrDefault() + ?.Items + ?.FirstOrDefault() + ?.PalletNr ?? 0; + public int ProductionOrderNr => this.batchModel.ProductionOrderNr; diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/MissingItem.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/MissingItem.cs new file mode 100644 index 00000000..dbbc8f7b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/MissingItem.cs @@ -0,0 +1,21 @@ +namespace LaaProductionWeb.Services.Models +{ + using System; + + public class MissingItem + { + public DateTime EntryDate { get; set; } + + public int OrderNr { get; set; } + + public int PosNr { get; set; } + + public int SerialNr { get; set; } + + public string CustomSerial { get; set; } + + public string Term { get; set; } + + public string Type { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs index b9372851..0a77cfd3 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs @@ -9,7 +9,9 @@ [Required] public int? OrderNr { get; set; } - + + + [Display(Name = "Positions-Nr. auswählen")] public int? PositionNr { get; set; } [Required] diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs index ee67c18c..61d96dd2 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs @@ -14,7 +14,10 @@ public int PalletsCount { get; set; } [Display(Name = "Paletten-Nr.")] - public int PalletNr { get; set; } + public int? PalletNr { get; set; } + + public IEnumerable Positions { get; set; } + = Array.Empty(); public IDictionary Pallets { get; set; } = new Dictionary { { 1, false } }; @@ -22,21 +25,28 @@ public string PrintUrl => $"~/Shipments/Print?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}"; - public string PalletUrl - => $"~/Shipments/Pallet?ordernr={this.OrderNr}&positionnr={this.PositionNr}"; + public string PalletUrl(int? palletNr) + => $"~/Shipments/Pallet?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={palletNr}"; - public void UpdatePallets(IEnumerable pallets) + internal void UpdatePallets(IEnumerable> pallets) { - this.Pallets = pallets.ToDictionary(x => x, x => x == this.PalletNr); + this.Pallets = pallets.ToDictionary(x => x.Key, x => x.Value); - if (this.PalletNr == 0) + if (this.PalletNr is null || this.PalletNr == 0) { - this.PalletNr = Math.Max(this.Pallets.Keys.LastOrDefault(), 1); - } - - if (!this.Pallets.ContainsKey(this.PalletNr)) - { - this.Pallets[this.PalletNr] = true; + if (pallets.Any(x => x.Value)) + { + this.PalletNr = Math.Max(pallets + .Where(x => x.Value) + .OrderByDescending(x => x.Key) + .FirstOrDefault().Key, 1); + } + else + { + this.PalletNr = Math.Max(pallets + .OrderByDescending(x => x.Key) + .FirstOrDefault().Key, 1); + } } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs index 0a4b2c17..7b388396 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs @@ -4,16 +4,16 @@ { public int Id { get; set; } - public int Nr { get; set; } + public int Serial { get; set; } public int PositionNr { get; set; } public int? PalletNr { get; set; } - public string CustomerNr { get; set; } + public string CustomerSerial { get; set; } - public bool IsScaned { get; set; } + public bool IsScanned { get; set; } - public string BarcodeNr => this.CustomerNr ?? $"{this.Nr}"; + public string BarcodeNr => this.CustomerSerial ?? $"{this.Serial}"; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs index 8d592b76..80acfd24 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs @@ -5,7 +5,9 @@ public class ShipmentModel { public readonly string BtnSubmit = "Auftrag suchen"; - private readonly OrderModel orderModel; + + private readonly int? palletNr; + private readonly int? positionNr; public ShipmentModel() { } @@ -13,36 +15,22 @@ { if (orderModel != null) { - this.orderModel = orderModel; this.OrderNr = orderModel.OrderNr; - this.PositionNr = orderModel.PositionNr; + this.positionNr = orderModel.PositionNr; + this.palletNr = orderModel.PalletNr; } } [Required(ErrorMessage = "Auftrags-Nr. ist erforderlich!")] [Display(Name = "Auftrags-Nr. scanen oder eingeben")] public int? OrderNr { get; set; } - - [Display(Name = "Positions-Nr. auswählen")] - public int? PositionNr { get; set; } - public bool HasOrder - => this.orderModel != null && this.orderModel.OrderNr > 0; - - public OrderModel OrderModel - => this.orderModel - ?? new OrderModel + public OrderScanModel OrderScanModel + => new OrderScanModel { OrderNr = this.OrderNr, - PositionNr = this.PositionNr - }; - - public OrderModel OrderScanModel - => this.orderModel - ?? new OrderScanModel - { - OrderNr = this.OrderNr, - PositionNr = this.PositionNr + PalletNr = this.palletNr, + PositionNr = this.positionNr }; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs index 2173b184..35cc660f 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs @@ -17,16 +17,21 @@ => this.sqlClient = sqlClient; public OrderScanModel DeletePalletEntry(int id) - { - var orderScanModel = this.DeletePalletEntryById(id); - - if (orderScanModel != null) - { - var updated = this.UpdatePalletsNr(orderScanModel.OrderNr ?? 0); - } - - return orderScanModel; - } + => this.sqlClient + .CreateCommand($@" + DELETE + FROM [PalettenScan] + OUTPUT [deleted].[AuftragNr] + , [deleted].[PositionNr] + , [deleted].[PalettenNr] + WHERE [ID] = @{nameof(id)}") + .AddParameter(nameof(id), id) + .FirstOrDefault(x => new OrderScanModel + { + OrderNr = x.GetInt(), + PositionNr = x.GetInt(), + PalletNr = x.GetSmallint() + }); public byte[] LoadBatchBuffer(OrderScanModel model) { @@ -56,41 +61,368 @@ public PalletsBatchModel LoadBatchModel(OrderScanModel model) { var batchModel = new PalletsBatchModel(); - var pallets = this.LoadPallets(model); - model.UpdatePallets(pallets); if (model != null && model.OrderNr != null) { - var palletNo = this.PalletsNr(model); + var orderNo = model.OrderNr.Value; + var positionNo = model.PositionNr > 0 ? model.PositionNr : null; + var palletNo = model.PalletNr > 0 ? model.PalletNr : null; - batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, palletNo); + batchModel = this.LoadBatchModel(orderNo, positionNo, palletNo); - if (model.PositionNr != null && !batchModel.Positions.Any()) + if (positionNo is null) { - batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, null); + if (this.PalletNrExists(orderNo, palletNo)) + { + batchModel.Positions = this.LoadPalletPositions(orderNo, palletNo); + } + else + { + batchModel.Positions = this.LoadLastPalletPositions(orderNo); + } + } + else + { + if (this.SamePallet(orderNo, positionNo, palletNo)) + { + batchModel.Positions = this.LoadPalletPosition(orderNo, positionNo, palletNo); + } + else + { + batchModel.Positions = this.LoadLastPalletPosition(orderNo, positionNo); + } } } return batchModel; } - private int? PalletsNr(OrderScanModel model) - { - var palletNr = this.sqlClient.FirstOrDefault( - query: $@" - SELECT [PalettenNr] - FROM [PalettenScan] - WHERE [AuftragNr] = @{nameof(model.OrderNr)} - AND [PalettenNr] = @{nameof(model.PalletNr)}", - parameters: parameters => parameters - .Add(nameof(model.OrderNr), model.OrderNr) - .Add(nameof(model.PalletNr), model.PalletNr), - reader: reader => reader.GetSmallint()); + public IEnumerable MissingItems() + => this.sqlClient + .CreateCommand($@" + DECLARE @PalletOrders TABLE([OrderNo] INT NOT NULL) + INSERT INTO @PalletOrders([OrderNo]) + SELECT DISTINCT [AuftragNr] FROM [PalettenScan] - return palletNr > 0 ? (int?)palletNr : null; + SELECT [result].[Date] + , [result].[OrderNo] + , [result].[PosNo] + , [result].[SerialNo] + , [result].[CustomSerial] + , [result].[Bezeichnung] + , [result].[Type] + FROM (SELECT DISTINCT + CAST(MAX([x].[Date]) AS DATE) AS [Date] + , [x].[OrderNo] + , [x].[PosNo] + , [x].[SerialNo] + , [dbo].[NORMALIZE_SERIAL]([x].[CustomSerialNo]) AS [CustomSerial] + , ([inr].[Typ] + + ' ' + + CASE WHEN [inr].[Typzusatz] IS NULL + THEN CAST([inr].[Nennweite] AS NVARCHAR(100)) + ELSE [inr].[Typzusatz] + + ' ' + + CAST([inr].[Nennweite] AS NVARCHAR(100)) + END) AS [Type] + , [inr].[Bezeichnung] + FROM (SELECT CAST([aps].[AnlageDatum] AS DATE) AS [Date] + , [aps].[AuftragNr] AS [OrderNo] + , [aps].[PositionNr] AS [PosNo] + , [aps].[SerienNr] AS [SerialNo] + , ISNULL([aps].[KundeneigeneSerienNr], [aps].[SerienNr]) AS [CustomSerialNo] + FROM [AuftragPositionSerienNr] AS [aps] + JOIN @PalletOrders AS [po] + ON [po].[OrderNo] = [aps].[AuftragNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aps].[AuftragNr] + AND [ps].[PositionNr] = [aps].[PositionNr] + AND [ps].[SerienNr] = [dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]) + WHERE [ps].[SerienNr] IS NULL) + AS [x] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[AuftragNr] = [x].[OrderNo] + AND [aap].[PositionNr] = [x].[PosNo] + JOIN [Identnr] AS [inr] + ON [inr].[IdentNr] = [aap].[IdentNr] + GROUP BY [x].[OrderNo] + , [x].[PosNo] + , [x].[SerialNo] + , [x].[CustomSerialNo] + , [inr].[Typ] + , [inr].[Typzusatz] + , [inr].[Nennweite] + , [inr].[Bezeichnung]) + AS [result] + ORDER BY [result].[OrderNo] DESC") + .ExecuteReader(x => new MissingItem + { + EntryDate = x.GetDate(), + OrderNr = x.GetInt(), + PosNr = x.GetSmallint(), + SerialNr = x.GetInt(), + CustomSerial = x.GetString(), + Term = x.GetString(), + Type = x.GetString() + }); + + private bool PalletNrExists(int orderNo, int? palletNo) + { + var countPalletsByNo = this.sqlClient + .CreateCommand($@" + SELECT ISNULL(COUNT(1), 0) AS [Found] + FROM [PalettenScan] AS [PS] + WHERE [PS].[AuftragNr] = @{nameof(orderNo)} + AND [PS].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(palletNo), palletNo) + .FirstOrDefault(x => x.GetInt()); + + return countPalletsByNo > 0; } - private PalletsBatchModel LoadBatchModel(int? orderNo, int? posNo, int? palletNo) + private IEnumerable LoadLastPalletPositions(int orderNo) + => this.sqlClient + .CreateCommand($@" + DECLARE @palettenNr INT; + + SELECT @palettenNr = MAX([PalettenNr]) + FROM [PalettenScan] + WHERE [AuftragNr] = @{nameof(orderNo)} + + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND [ps].[PalettenNr] = @palettenNr") + .AddParameter(nameof(orderNo), orderNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private IEnumerable LoadPalletPositions(int orderNo, int? palletNo) + => this.sqlClient + .CreateCommand($@" + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND [ps].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(palletNo), palletNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private bool SamePallet(int orderNo, int? positionNo, int? palletNo) + { + var countPalletsByNo = this.sqlClient + .CreateCommand($@" + SELECT ISNULL(COUNT(1), 0) AS [Found] + FROM [PalettenScan] AS [PS] + WHERE [PS].[AuftragNr] = @{nameof(orderNo)} + AND [PS].[PositionNr] = @{nameof(positionNo)} + AND [PS].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(positionNo), positionNo) + .AddParameter(nameof(palletNo), palletNo) + .FirstOrDefault(x => x.GetInt()); + + return countPalletsByNo > 0; + } + + private IEnumerable LoadLastPalletPosition(int orderNo, int? positionNo) + => this.sqlClient + .CreateCommand($@" + DECLARE @palettenNr INT; + + SELECT @palettenNr = MAX([PalettenNr]) + FROM [PalettenScan] + WHERE [AuftragNr] = @{nameof(orderNo)} + AND [PositionNr] = @{nameof(positionNo)} + + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND ([ps].[PalettenNr] = @palettenNr + OR [aap].[PositionNr] = @{nameof(positionNo)})") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(positionNo), positionNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private IEnumerable LoadPalletPosition(int orderNo, int? positionNo, int? palletNo) + => this.sqlClient + .CreateCommand($@" + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND [ps].[PositionNr] = @{nameof(positionNo)} + AND [ps].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(positionNo), positionNo) + .AddParameter(nameof(palletNo), palletNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private IEnumerable LoadPalletItems(int orderNo, int posNo, int palletNr) + => this.sqlClient + .CreateCommand($@" + SELECT [x].[Id] AS [Id] + , [x].[PositionNr] AS [Pos] + , [x].[Serial] AS [Serial] + , [x].[CustomerSerial] AS [CustomerSerial] + , [x].[IsScanned] AS [IsScanned] + FROM (SELECT DISTINCT + [ps].[ID] AS [Id] + , [aps].[PositionNr] AS [PositionNr] + , [aps].[SerienNr] AS [Serial] + , ISNULL([dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]), [aps].[SerienNr]) AS [CustomerSerial] + , CAST(CASE WHEN [ps].[Datum] IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS [IsScanned] + , [ps].[Datum] AS [DateAdded] + FROM [AuftragPositionSerienNr] AS [aps] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aps].[AuftragNr] + AND [ps].[PositionNr] = [aps].[PositionNr] + AND [ps].[SerienNr] = [dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]) + AND [ps].[PalettenNr] = @{nameof(palletNr)} + WHERE [aps].[AuftragNr] = @{nameof(orderNo)} + AND [aps].[PositionNr] = @{nameof(posNo)} + AND [dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]) + NOT IN (SELECT [SerienNr] + FROM [PalettenScan] + WHERE [AuftragNr] = @{nameof(orderNo)} + AND [PositionNr] = @{nameof(posNo)} + AND [PalettenNr] != @{nameof(palletNr)})) + AS [x] + ORDER BY [x].[IsScanned] DESC + , [x].[CustomerSerial]") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(posNo), posNo) + .AddParameter(nameof(palletNr), palletNr) + .ExecuteReader(x => new SerialNr + { + Id = x.GetInt(), + PositionNr = x.GetSmallint(), + Serial = x.GetInt(), + CustomerSerial = x.GetString(), + IsScanned = x.GetBool(), + PalletNr = palletNr + }); + + private PalletsBatchModel LoadBatchModel(int orderNo, int? posNo, int? palletNo) { var batchModel = this.sqlClient.FirstOrDefault( query: $@" @@ -102,8 +434,6 @@ FROM [AlleAuftragPositionen] AS [AAP] JOIN [Kunde] ON [Kunde].[KundenNr] = [AAP].[KundenNr] WHERE [AAP].[AuftragNr] = @{nameof(orderNo)} - AND (@{nameof(posNo)} IS NULL - OR [AAP].[PositionNr] = @{nameof(posNo)}) ORDER BY [AAP].[FertigungsauftragNr] DESC", parameters: parameters => parameters .Add(nameof(orderNo), orderNo) @@ -113,151 +443,48 @@ OrderNr = reader.GetValue(), ProductionOrderNr = reader.GetValue(), Customer = reader.GetString(), - AdditionalText = reader.GetString(), - Positions = this.LoadBatchPositions(orderNo, posNo, palletNo) + AdditionalText = reader.GetString() }); - - if (batchModel != null) - { - batchModel.Positions = this.LoadBatchPositions(orderNo, posNo, palletNo); - } return batchModel ?? new PalletsBatchModel(); } - private IEnumerable LoadBatchPositions(int? orderNo, int? posNo, int? palletNo) - => this.sqlClient.ExecuteReader( - query: $@"SELECT [AAP].[PositionNr] AS [Pos] - , [Identnr].[Typ] AS [Typ] - , [Identnr].[Typzusatz] AS [Typzusatz] - , [Identnr].[Nennweite] AS [Nennweite] - , (SELECT COUNT(1) - FROM [PalettenScan] AS [x] - WHERE [x].[AuftragNr] = [PS].[AuftragNr] - AND [x].[PositionNr] = [PS].[PositionNr] - AND [x].[PalettenNr] = [PS].[PalettenNr]) AS [Count] - , (SELECT TOP 1 [Menge] - FROM [AlleAuftragPositionen] AS [x] - WHERE [x].[AuftragNr] = [AAP].[AuftragNr] - AND [x].[PositionNr] = [AAP].[PositionNr]) AS [TotalCount] - FROM [Identnr] - JOIN [AlleAuftragPositionen] AS [AAP] - ON [AAP].[IdentNr] = [Identnr].[IdentNr] - LEFT JOIN [PalettenScan] AS [PS] - ON [PS].[AuftragNr] = [AAP].[AuftragNr] - AND [PS].[PositionNr] = [AAP].[PositionNr] - WHERE [AAP].[AuftragNr] = @{nameof(orderNo)} - AND (@{nameof(palletNo)} IS NULL - OR [PS].[PalettenNr] = @{nameof(palletNo)}) - AND (@{nameof(posNo)} IS NULL - OR [AAP].[PositionNr] = @{nameof(posNo)}) - GROUP BY [AAP].[AuftragNr] - , [PS].[AuftragNr] - , [AAP].[PositionNr] - , [PS].[PositionNr] - , [Identnr].[Typ] - , [Identnr].[Typzusatz] - , [Identnr].[Nennweite] - , [PS].[PalettenNr] - ORDER BY [AAP].[PositionNr]", - parameters: parameters => parameters - .Add(nameof(orderNo), orderNo) - .Add(nameof(posNo), posNo) - .Add(nameof(palletNo), palletNo), - reader: reader => new PalletPosition - { - PositionNr = reader.GetValue(), - Description = string - .Join(" ", new[] - { - reader.GetString(), - reader.GetString(), - reader.GetString(), - } - .Where(x => !string.IsNullOrWhiteSpace(x))), - ItemsCount = reader.GetValue(), - TotalItemsCount = reader.GetValue(), - Items = this.LoadBatchItems(orderNo, posNo, palletNo), - }); - - private IEnumerable LoadBatchItems(int? orderNo, int? posNo, int? palletNo) - => this.sqlClient.ExecuteReader( - query: $@"SELECT DISTINCT - [x].[Id] - , [x].[PositionNr] - , [x].[SerienNr] - , [x].[CustomerSerienNr] - , [x].[PalettenNr] - , [x].[IsScanned] - FROM (SELECT [PS].[ID] AS [Id] - , ISNULL([PS].[PositionNr], [APS].[PositionNr]) AS [PositionNr] - , [APS].[SerienNr] AS [SerienNr] - , REPLACE(RTRIM(LTRIM([APS].[KundeneigeneSerienNr])), ' ', '') AS [CustomerSerienNr] - , [PS].[PalettenNr] AS [PalettenNr] - , CAST(CASE WHEN [PS].[ID] IS NULL THEN 0 ELSE 1 END AS BIT) AS [IsScanned] - FROM [AuftragPositionSerienNr] AS [APS] - LEFT JOIN [PalettenScan] AS [PS] - ON [PS].[AuftragNr] = [APS].[AuftragNr] - AND [PS].[PositionNr] = [APS].[PositionNr] - AND [PS].[SerienNr] = REPLACE(RTRIM(LTRIM([APS].[KundeneigeneSerienNr])), ' ', '') - WHERE [APS].[AuftragNr] = @{nameof(orderNo)} - AND (@{nameof(palletNo)} IS NULL - OR [PS].[PalettenNr] = @{nameof(palletNo)}) - AND (@{nameof(posNo)} IS NULL - OR [APS].[PositionNr] = @{nameof(posNo)})) - AS [x] - ORDER BY [x].[IsScanned] DESC - , [x].[PositionNr] - , [x].[CustomerSerienNr] - , [x].[SerienNr]", - parameters: parameters => parameters - .Add(nameof(orderNo), orderNo) - .Add(nameof(posNo), posNo) - .Add(nameof(palletNo), palletNo), - reader: reader => new SerialNr - { - Id = reader.GetValue(), - PositionNr = reader.GetValue(), - Nr = reader.GetValue(), - CustomerNr = reader.GetString(), - PalletNr = reader.GetValue(), - IsScaned = reader.GetValue(), - }); - - public IEnumerable LoadPallets(OrderScanModel model) + public OrderScanModel LoadPallets(OrderScanModel model) { - this.UpdatePalletsNr(model.OrderNr ?? 0); + if (model != null && model.OrderNr != null && model.OrderNr > 0) + { + var pallets = this.sqlClient.ExecuteReader( + query: $@" SELECT DISTINCT + [PSI].[PalettenNr] + , CAST(CASE WHEN [PSII].[ID] IS NULL + THEN 0 + ELSE 1 + END AS BIT) + FROM [PalettenScan] AS [PSI] + LEFT JOIN [PalettenScan] AS [PSII] + ON [PSII].[ID] = [PSI].[ID] + AND [PSII].[PositionNr] = @{nameof(model.PositionNr)} + WHERE [PSI].[AuftragNr] = @{nameof(model.OrderNr)} + ORDER BY [PSI].[PalettenNr]", + parameters: parameters => parameters + .Add(nameof(model.OrderNr), model.OrderNr) + .Add(nameof(model.PositionNr), model.PositionNr), + reader: reader => new KeyValuePair( + key: (int)reader.GetValue(), + value: reader.GetValue())); - var pallets = this.sqlClient.ExecuteReader( - query: $@"SELECT DISTINCT [PS].[PalettenNr] - FROM [PalettenScan] AS [PS] - WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)} - AND (@{nameof(model.PositionNr)} IS NULL - OR [PS].[PositionNr] = @{nameof(model.PositionNr)}) - ORDER BY [PS].[PalettenNr]", - parameters: parameters => parameters - .Add(nameof(model.OrderNr), model.OrderNr) - .Add(nameof(model.PositionNr), model.PositionNr), - reader: reader => (int)reader.GetValue()); + model.UpdatePallets(pallets); - //if (!pallets.Any()) - //{ - // return this.sqlClient.ExecuteReader( - // query: $@"SELECT CAST(ISNULL(MAX([PS].[PalettenNr]) - // , (SELECT ISNULL(MAX([PS].[PalettenNr]), 0) - // FROM [PalettenScan] AS [PS] - // WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)})) AS INT) - // FROM [PalettenScan] AS [PS] - // WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)} - // AND (@{nameof(model.PositionNr)} IS NULL - // OR [PS].[PositionNr] = @{nameof(model.PositionNr)})", - // parameters: parameters => parameters - // .Add(nameof(model.OrderNr), model.OrderNr) - // .Add(nameof(model.PositionNr), model.PositionNr), - // reader: reader => reader.GetValue()); - //} + model.Positions = this.sqlClient.ExecuteReader( + query: $@"SELECT DISTINCT [x].[PositionNr] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = @{nameof(model.OrderNr)} + ORDER BY [x].[PositionNr]", + parameters: parameters => parameters.Add(nameof(model.OrderNr), model.OrderNr), + reader: reader => (int)reader.GetValue()); + } - return pallets; + return model; } public Result UpdateBatchModel(OrderScanModel model) @@ -284,9 +511,6 @@ model.SerialNr = orderIdentity.CustomerSerialNr; model.PositionNr = orderIdentity.PositionNr; - var nextPalletNr = this.NextPallet(model.OrderNr.Value); - model.PalletNr = Math.Max(Math.Min(model.PalletNr, nextPalletNr), 1); - if (this.PalletsEntryExists(model.OrderNr, model.PositionNr, model.SerialNr)) { return $"Wasserzähler mit Serien-Nr: {model.SerialNr} wurde bereits hinzugefügt."; @@ -300,29 +524,6 @@ return false; } - private int NextPallet(int orderno) - => this.sqlClient.FirstOrDefault( - query: $@"SELECT MAX([PalettenNr]) + 1 FROM [PalettenScan] WHERE [AuftragNr] = @{nameof(orderno)}", - parameters: parameters => parameters.Add(nameof(orderno), orderno), - reader: reader => reader.GetValue()); - - private OrderScanModel DeletePalletEntryById(int id) - => this.sqlClient.FirstOrDefault( - query: $@" - DELETE - FROM [PalettenScan] - OUTPUT [deleted].[AuftragNr] - , [deleted].[PositionNr] - , [deleted].[PalettenNr] - WHERE [ID] = @{nameof(id)}", - parameters: parameters => parameters.Add(nameof(id), id), - reader: reader => new OrderScanModel - { - OrderNr = reader.GetValue(0), - PositionNr = reader.GetValue(1), - PalletNr = reader.GetValue(2) - }); - private OrderIdentity UpdateOrderIdentifiers(int? orderNr, int? positionNr, string serialNr) => this.sqlClient.FirstOrDefault( query: $@" @@ -440,27 +641,11 @@ FROM [PalettenScan] WHERE [PalettenScan].[AuftragNr] = @{nameof(orderNr)} AND [PalettenScan].[PositionNr] = @{nameof(positionNr)} - AND @{nameof(serialNr)} = [PalettenScan].[SerienNr]", + AND [PalettenScan].[SerienNr] = @{nameof(serialNr)}", parameters => parameters .Add(nameof(orderNr), orderNr) .Add(nameof(positionNr), positionNr) .Add(nameof(serialNr), serialNr), reader => reader.GetValue()); - - private bool UpdatePalletsNr(int orderNo) - => this.sqlClient.ExecuteNonQuery( - query: $@"UPDATE [PalettenScan] - SET [PalettenNr] = [P2].[RowNumber] - FROM [PalettenScan] AS [P1] - JOIN (SELECT [P].[PalettenNr] - , ROW_NUMBER() OVER (ORDER BY [P].[PalettenNr]) AS [RowNumber] - FROM (SELECT DISTINCT - [PalettenNr] - FROM [PalettenScan] - WHERE [AuftragNr] = @{nameof(orderNo)}) - AS [P]) - AS [P2] - ON [P2].[PalettenNr] = [P1].[PalettenNr]", - parameters: parameters => parameters.Add(nameof(orderNo), orderNo)) == 1; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs index 39a23ef8..3fed505e 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs @@ -1,6 +1,7 @@ namespace LaaProductionWeb.App_Infrastructure { using LaaProductionWeb.Services.Interfaces; + using LaaProductionWeb.Services.Models; using System.Collections.Generic; using System.Security.Claims; @@ -13,14 +14,19 @@ var httpContext = filterContext.HttpContext; var userId = httpContext.UserId(); var accountService = ServiceProvider.Current.GetService(); - var employee = accountService.FindEmployee(userId); - var claims = new List(); - httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] + httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, string.Empty), new Claim(ClaimTypes.Role, UserRoles.WEB_Anonymous), }, nameof(Claim), ClaimTypes.Name, ClaimTypes.Role)); + +#if DEBUG + var employee = new Employee("DEVELOPER", UserRoles.ALL); +#else + var employee = accountService.FindEmployee(userId); +#endif + var claims = new List(); if (employee.IsValid) { diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs index e326dc78..42a9823f 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs @@ -9,5 +9,15 @@ public const string WEB_PalettenScan = nameof(WEB_PalettenScan); public const string WEB_ProdApproval = nameof(WEB_ProdApproval); public const string WEB_PuneProtokoll = nameof(WEB_PuneProtokoll); + + public static string[] ALL = new string [] + { + WEB_Admin, + WEB_API_Explorer, + WEB_HeReport, + WEB_PalettenScan, + WEB_ProdApproval, + WEB_PuneProtokoll + }; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs index cdad98a2..48eb9ab9 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs @@ -18,7 +18,6 @@ => new ServiceCollection() .ConfigureServices() .BuildServiceProvider() - .BuildControllerFactory() .RegisterServiceProvider(); /// @@ -29,7 +28,6 @@ static IServiceCollection ConfigureServices(this IServiceCollection services) { services - .AddControllers() .AddTransientServices() .AddHttpClient(ApplicationSettings.APIURL) .AddDbContext(ApplicationSettings.ConnectionString); diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs new file mode 100644 index 00000000..2e7421cf --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Http; + +namespace LaaProductionWeb +{ + public static class WebApiConfig + { + public static void Register(HttpConfiguration config) + { + config.MapHttpAttributeRoutes(); + + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{id}", + defaults: new { id = RouteParameter.Optional } + ); + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs index d5cb25c9..228b0e72 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs @@ -10,8 +10,8 @@ { private readonly IAccountService accountService; - public AdminController(IAccountService accountService) - => this.accountService = accountService; + public AdminController() + => this.accountService = ServiceProvider.Current.GetService(); public ActionResult Index() => this.View(); diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs index c68d3737..7b63f99f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs @@ -12,8 +12,8 @@ { private readonly IApprovalsService approvals; - public ApprovalsController(IApprovalsService approvals) - => this.approvals = approvals; + public ApprovalsController() + => this.approvals = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Add() diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs index e83ddbda..0b0e8b0b 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs @@ -10,8 +10,8 @@ { private readonly IAccountService accountService; - public HomeController(IAccountService accountService) - => this.accountService = accountService; + public HomeController() + => this.accountService = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Index() diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs index 40a3c6bb..cb52fb71 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs @@ -13,8 +13,8 @@ private readonly IProtocolService protocolService; - public ProtocolController(IProtocolService protocolService) - => this.protocolService = protocolService; + public ProtocolController() + => this.protocolService = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Index(int orderId = 0) diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs index e68df09e..c30a6ff1 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs @@ -12,8 +12,8 @@ { private readonly IReportService reportService; - public ReportController(IReportService reportService) - => this.reportService = reportService; + public ReportController() + => this.reportService = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Helium() diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs index 70a7f18c..dd532d5f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs @@ -15,10 +15,10 @@ private readonly IOrdersService ordersService; private readonly IHttpService httpService; - public SearchController(IOrdersService ordersService, IHttpService httpService) + public SearchController() { - this.ordersService = ordersService; - this.httpService = httpService; + this.ordersService = ServiceProvider.Current.GetService(); + this.httpService = ServiceProvider.Current.GetService(); } [HttpGet] diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs index fdb23f70..695f0287 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs @@ -21,10 +21,10 @@ private readonly IShipmentsService shipmentsService; private readonly IHttpService httpService; - public ShipmentsController(IShipmentsService shipmentsService, IHttpService httpService) + public ShipmentsController() { - this.shipmentsService = shipmentsService; - this.httpService = httpService; + this.shipmentsService = ServiceProvider.Current.GetService(); + this.httpService = ServiceProvider.Current.GetService(); } [HttpGet] @@ -45,39 +45,31 @@ [HttpPost] public ActionResult Index(ShipmentModel model) { - this.HttpContext.SetUserData(model.OrderScanModel as OrderScanModel); + this.HttpContext.SetUserData(model.OrderScanModel); return this.View(model); } [HttpGet] - public ActionResult Pallet(OrderScanModel model) - => this.View(nameof(this.Index), new ShipmentModel(model)); + public ActionResult Pallet(OrderScanModel model) + { + this.HttpContext.SetUserData(model); + + return this.View(nameof(this.Index), new ShipmentModel(model)); + } public ActionResult Batch(OrderScanModel model) { - var batchModel = this.shipmentsService - .LoadBatchModel(model ?? new OrderScanModel()); + var batchModel = this.shipmentsService.LoadBatchModel(model); this.UpdateClientName(batchModel); return this.PartialView(batchModel); } - [HttpGet] - public ActionResult Print(OrderScanModel model) - { - var batchModel = this.shipmentsService.LoadBatchModel(model); - var batchPrintModel = new BatchPrintModel(batchModel); - - return this.View(batchPrintModel); - } - public ActionResult Scan(OrderScanModel model) { - var pallets = this.shipmentsService.LoadPallets(model); - - model.UpdatePallets(pallets); + model = this.shipmentsService.LoadPallets(model); return this.PartialView(model); } @@ -106,6 +98,14 @@ this.TempData[nameof(model.SerialNr)] = result; } } + else if (this.TempData[nameof(model.PositionNr)] is int p && p != model.PositionNr) + { + this.TempData[nameof(model.PositionNr)] = model.PositionNr; + + return this.Pallet(model); + } + + this.TempData[nameof(model.PositionNr)] = model.PositionNr; return this.View(nameof(this.Index), new ShipmentModel(model)); } @@ -118,6 +118,23 @@ return this.View(nameof(this.Index), new ShipmentModel(orderScanModel)); } + [HttpGet] + public ActionResult Missing() + { + var model = this.shipmentsService.MissingItems(); + + return this.View(model); + } + + [HttpGet] + public ActionResult Print(OrderScanModel model) + { + var batchModel = this.shipmentsService.LoadBatchModel(model); + var batchPrintModel = new BatchPrintModel(batchModel); + + return this.View(batchPrintModel); + } + [HttpGet] public ActionResult Download(OrderScanModel model) { diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index 64220d2a..f02848cc 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -18,8 +18,8 @@ true - enabled - disabled + disabled + enabled @@ -189,6 +189,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml index ce4c365b..7f5c6fe3 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml @@ -60,23 +60,23 @@ foreach (var item in this.Model.Positions.SelectMany(x => x.Items)) { - - @(count++). - (@item.PositionNr) @item.BarcodeNr + + @(count++). + (@item.PositionNr) @item.BarcodeNr - @(item.IsScaned ? item.PalletNr : null) + @(item.IsScanned ? item.PalletNr : null) diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml index 6d289f21..7968c8ec 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml @@ -15,14 +15,6 @@ @this.Html.ValidationMessageFor(x => x.OrderNr, string.Empty, new { @class = "small text-danger m-0 p-0" }) -
@this.Html.HiddenFor(x => x.OrderNr) - @this.Html.HiddenFor(x => x.PositionNr) - @this.Html.HiddenFor(x => x.PalletNr)
@foreach (var pallet in this.Model.Pallets) { - var css = pallet.Key == this.Model.PalletNr - ? "btn btn-success" - : "btn btn-outline-success"; - var id = $"pallet_{pallet.Key}"; + var palletNr = pallet.Key; + var forPosition = pallet.Value; + var href = this.Url.Content(this.Model.PalletUrl(palletNr)); - @pallet.Key + if (!forPosition && palletNr == this.Model.PalletNr) + { + @palletNr + } + else if (!forPosition) + { + @palletNr + } + else if (forPosition && palletNr == this.Model.PalletNr) + { + @palletNr + } + else + { + @palletNr + } } - @{ - var nextPalletNr = this.Model.Pallets.Keys.LastOrDefault() + 1; - } - - - - - Druckvorschau
+
@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.LabelFor(x => x.PalletNr) + + @this.Html.LabelFor(x => x.PalletNr, new { @class = "text-smallcaps", @for = "palletnr" })
@if (this.IsPost)