Existing code
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace LaaProductionWeb.Services.Interfaces
|
||||
{
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
public interface IOrdersService : ITransient
|
||||
{
|
||||
OrdersFoundModel FindOrders(string search);
|
||||
|
||||
OrderPositions FindPositions(string id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace LaaProductionWeb.Services.Interfaces
|
||||
{
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public interface IProtocolService : ITransient
|
||||
{
|
||||
string FileContent(int? fileId);
|
||||
|
||||
OrderClientModel FindOrder(int orderId);
|
||||
|
||||
IEnumerable<KeyValuePair<int, string>> FindOrdersById(int orderno);
|
||||
|
||||
IEnumerable<KeyValuePair<int, string>> FindOrdersByClient(string clientName);
|
||||
|
||||
IEnumerable<TestStatus> LoadTestStatus(int orderId);
|
||||
|
||||
int SaveFile(Stream fileStream, int clientId, int orderId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace LaaProductionWeb.Services.Interfaces
|
||||
{
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
public interface IShipmentsService : ITransient
|
||||
{
|
||||
OrderScanModel DeletePalletEntry(int id);
|
||||
|
||||
int GetPalletsCount(OrderScanModel model);
|
||||
|
||||
byte[] LoadBatchBuffer(OrderScanModel model);
|
||||
|
||||
PalletsBatchModel LoadBatchModel(OrderScanModel model);
|
||||
|
||||
Result UpdateBatchModel(OrderScanModel model);
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,10 @@
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
@@ -56,15 +57,36 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interfaces\IOrdersService.cs" />
|
||||
<Compile Include="Interfaces\IProtocolService.cs" />
|
||||
<Compile Include="Interfaces\IShipmentsService.cs" />
|
||||
<Compile Include="Interfaces\ITransient.cs" />
|
||||
<Compile Include="Models\BatchPrintModel.cs" />
|
||||
<Compile Include="Models\OrderClientModel.cs" />
|
||||
<Compile Include="Models\OrderInfoModel.cs" />
|
||||
<Compile Include="Models\OrderModel.cs" />
|
||||
<Compile Include="Models\OrderPositions.cs" />
|
||||
<Compile Include="Models\OrderScanModel.cs" />
|
||||
<Compile Include="Models\OrdersFoundModel.cs" />
|
||||
<Compile Include="Models\PalletsBatchModel.cs" />
|
||||
<Compile Include="Models\Result.cs" />
|
||||
<Compile Include="Models\SerialNr.cs" />
|
||||
<Compile Include="Models\ShipmentModel.cs" />
|
||||
<Compile Include="Models\TestStatus.cs" />
|
||||
<Compile Include="OrdersService.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ProtocolService.cs" />
|
||||
<Compile Include="ServicesExtensions.cs" />
|
||||
<Compile Include="ShipmentsService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<ProjectReference Include="..\LaaProductionWeb.Data\LaaProductionWeb.Data.csproj">
|
||||
<Project>{4B5BF112-D3BE-4E84-9A8E-74A0E314BBA7}</Project>
|
||||
<Name>LaaProductionWeb.Data</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,37 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class BatchPrintModel
|
||||
{
|
||||
private readonly PalletsBatchModel batchModel;
|
||||
|
||||
public BatchPrintModel(PalletsBatchModel batchModel)
|
||||
=> this.batchModel = batchModel;
|
||||
|
||||
public string ClientName
|
||||
=> this.batchModel.ClientName;
|
||||
|
||||
public int OrderNr
|
||||
=> this.batchModel.OrderNr;
|
||||
|
||||
public int ProductionOrderNr
|
||||
=> this.batchModel.ProductionOrderNr;
|
||||
|
||||
public int PositionNr
|
||||
=> this.batchModel.PositionNr;
|
||||
|
||||
public int TotlalItemsCount
|
||||
=> this.batchModel.TotlalItemsCount;
|
||||
|
||||
public string ItemsType
|
||||
=> this.batchModel.ItemsType;
|
||||
|
||||
public SerialNr[] Items
|
||||
=> this.batchModel
|
||||
.Items
|
||||
.Where(x => x.IsScaned)
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Web;
|
||||
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
public class OrderClientModel
|
||||
{
|
||||
public int? OrderId { get; set; }
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string ClientName { get; set; }
|
||||
|
||||
public string Positions { get; set; }
|
||||
|
||||
public int? FileId { get; set; }
|
||||
|
||||
public string FileContent { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class OrderInfoModel
|
||||
{
|
||||
public int OrderNr { get; set; }
|
||||
|
||||
public int ProductionOrderNr { get; set; }
|
||||
|
||||
public string ClientName { get; set; }
|
||||
|
||||
public string Nr
|
||||
=> this.OrderNr > 0
|
||||
? $"{this.OrderNr}"
|
||||
: this.ProductionOrderNr > 0
|
||||
? $"{this.ProductionOrderNr}"
|
||||
: default(string);
|
||||
|
||||
public static readonly OrderInfoComparer Comparer
|
||||
= new OrderInfoComparer();
|
||||
|
||||
public class OrderInfoComparer : IEqualityComparer<OrderInfoModel>
|
||||
{
|
||||
public bool Equals(OrderInfoModel x, OrderInfoModel y)
|
||||
=> x?.OrderNr == y?.OrderNr;
|
||||
|
||||
public int GetHashCode(OrderInfoModel obj)
|
||||
=> obj?.OrderNr ?? default(int);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class OrderModel
|
||||
{
|
||||
public readonly string ScanTitle = "Scanvorgang";
|
||||
public readonly string BtnSerialNr = "Serien-Nr. hinzufügen";
|
||||
|
||||
[Required]
|
||||
public int? OrderNr { get; set; }
|
||||
|
||||
[Required]
|
||||
public int? PositionNr { get; set; }
|
||||
|
||||
[Required]
|
||||
[Display(Name = "Serien-Nr. scanen oder eingeben")]
|
||||
public string SerialNr { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class OrderPositions : IEnumerable<int>
|
||||
{
|
||||
private readonly IEnumerable<int> positions;
|
||||
|
||||
public OrderPositions(IEnumerable<int> positions)
|
||||
=> this.positions = positions;
|
||||
|
||||
public IEnumerator<int> GetEnumerator()
|
||||
=> this.positions.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> this.GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
public class OrderScanModel : OrderModel
|
||||
{
|
||||
public string Host { get; set; }
|
||||
|
||||
public string Place { get; set; }
|
||||
|
||||
public int PalletsCount { get; set; }
|
||||
|
||||
[Display(Name = "Paletten-Nr.")]
|
||||
public int PalletNr { get; set; } = 1;
|
||||
|
||||
public IDictionary<int, bool> Pallets { get; set; }
|
||||
= new Dictionary<int, bool> { { 1, false } };
|
||||
|
||||
public string PrintUrl
|
||||
=> $"/Shipments/Print?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}";
|
||||
|
||||
public string DownloadUrl
|
||||
=> $"/Shipments/Download?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}";
|
||||
|
||||
public void UpdatePalletsCount(int palletsCount)
|
||||
{
|
||||
this.PalletsCount = palletsCount;
|
||||
this.Pallets = Enumerable
|
||||
.Range(1, palletsCount)
|
||||
.ToDictionary(x => x, x => false);
|
||||
this.Pallets[this.PalletNr] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class OrdersFoundModel : IEnumerable<OrderInfoModel>
|
||||
{
|
||||
private readonly IEnumerable<OrderInfoModel> orders;
|
||||
|
||||
public OrdersFoundModel(IEnumerable<OrderInfoModel> orders)
|
||||
=> this.orders = orders;
|
||||
|
||||
public IEnumerator<OrderInfoModel> GetEnumerator()
|
||||
=> this.orders
|
||||
.Distinct(OrderInfoModel.Comparer)
|
||||
.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> this.GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class PalletsBatchModel
|
||||
{
|
||||
public string ClientName { get; set; }
|
||||
|
||||
public int OrderNr { get; set; }
|
||||
|
||||
public int ProductionOrderNr { get; set; }
|
||||
|
||||
public int PositionNr { get; set; }
|
||||
|
||||
public int TotlalItemsCount { get; set; }
|
||||
|
||||
public string ItemsType { get; set; }
|
||||
|
||||
public string AdditionalText { get; set; }
|
||||
|
||||
public IEnumerable<SerialNr> Items { get; set; }
|
||||
= Array.Empty<SerialNr>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
public struct Result
|
||||
{
|
||||
private readonly bool succeeded;
|
||||
private readonly string message;
|
||||
|
||||
private Result(bool succeeded = true)
|
||||
{
|
||||
this.succeeded = succeeded;
|
||||
this.message = string.Empty;
|
||||
}
|
||||
|
||||
private Result(string message = default(string))
|
||||
{
|
||||
this.message = message;
|
||||
this.succeeded = string.IsNullOrWhiteSpace(message);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> this.message;
|
||||
|
||||
public static implicit operator Result(bool succeeded)
|
||||
=> new Result(succeeded);
|
||||
|
||||
public static implicit operator Result(string message)
|
||||
=> new Result(message);
|
||||
|
||||
public static implicit operator bool(Result result)
|
||||
=> result.succeeded;
|
||||
|
||||
public static implicit operator string(Result result)
|
||||
=> result.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
public class SerialNr
|
||||
{
|
||||
private int id;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get => this.id;
|
||||
set
|
||||
{
|
||||
this.id = value;
|
||||
this.IsScaned = this.id > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int Nr { get; set; }
|
||||
|
||||
public int? PalletNr { get; set; }
|
||||
|
||||
public string ClientNr { get; set; }
|
||||
|
||||
public bool IsScaned { get; set; }
|
||||
|
||||
public string BarcodeNr => this.ClientNr ?? $"{this.Nr}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class ShipmentModel
|
||||
{
|
||||
public readonly string BtnSubmit = "Auftrag suchen";
|
||||
private readonly OrderModel orderModel;
|
||||
|
||||
public ShipmentModel() { }
|
||||
|
||||
public ShipmentModel(OrderScanModel orderModel)
|
||||
{
|
||||
if (orderModel != null)
|
||||
{
|
||||
this.orderModel = orderModel;
|
||||
this.OrderNr = orderModel.OrderNr;
|
||||
this.PositionNr = orderModel.PositionNr;
|
||||
}
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Auftrags-Nr. ist erforderlich!")]
|
||||
[Display(Name = "Auftrags-Nr. scanen oder eingeben")]
|
||||
public int? OrderNr { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "Positions-Nr. ist erforderlich!")]
|
||||
[Display(Name = "Positions-Nr. auswählen")]
|
||||
public int? PositionNr { get; set; }
|
||||
|
||||
public bool HasOrder
|
||||
=> this.orderModel != null;
|
||||
|
||||
public OrderModel OrderModel
|
||||
=> this.orderModel
|
||||
?? new OrderModel
|
||||
{
|
||||
OrderNr = this.OrderNr,
|
||||
PositionNr = this.PositionNr
|
||||
};
|
||||
|
||||
public OrderModel OrderScanModel
|
||||
=> this.orderModel
|
||||
?? new OrderScanModel
|
||||
{
|
||||
OrderNr = this.OrderNr,
|
||||
PositionNr = this.PositionNr
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace LaaProductionWeb.Services.Models
|
||||
{
|
||||
public class TestStatus
|
||||
{
|
||||
public string PosNr { get; set; }
|
||||
|
||||
public string SerialNr { get; set; }
|
||||
|
||||
public bool? HeliumTest { get; set; }
|
||||
|
||||
public bool? PressureTest { get; set; }
|
||||
|
||||
public bool? MetroTest { get; set; }
|
||||
|
||||
public bool? RadioTest { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace LaaProductionWeb.Services
|
||||
{
|
||||
using LaaProductionWeb.Data.Interfaces;
|
||||
using LaaProductionWeb.Services.Interfaces;
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
public class OrdersService : IOrdersService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
|
||||
public OrdersService(IDbContext dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public OrdersFoundModel FindOrders(string search)
|
||||
{
|
||||
var ordersFound = this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[AlleAuftragPositionen].[AuftragNr] -- 0
|
||||
, [AlleAuftragPositionen].[FertigungsauftragNr] -- 1
|
||||
, [Kunde].[Name] -- 2
|
||||
FROM [AlleAuftragPositionen]
|
||||
LEFT JOIN [Kunde] ON [Kunde].[KundenNr] = [AlleAuftragPositionen].[KundenNr]
|
||||
WHERE [AlleAuftragPositionen].[Versand_Ist_datum] IS NOT NULL
|
||||
AND [AlleAuftragPositionen].[AuftragNr] LIKE @{nameof(search)}
|
||||
ORDER BY [AlleAuftragPositionen].[AuftragNr]
|
||||
, [AlleAuftragPositionen].[FertigungsauftragNr]
|
||||
, [Kunde].[Name]",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(search), $"%{search}%"),
|
||||
reader: reader => new OrderInfoModel
|
||||
{
|
||||
OrderNr = reader.GetValue<int>(0),
|
||||
ProductionOrderNr = reader.GetValue<int>(1),
|
||||
ClientName = reader.GetValue<string>(2),
|
||||
});
|
||||
|
||||
return new OrdersFoundModel(ordersFound);
|
||||
}
|
||||
|
||||
public OrderPositions FindPositions(string orderNr)
|
||||
{
|
||||
var positionsFound = this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[AlleAuftragPositionen].[PositionNr] -- 0
|
||||
FROM [AlleAuftragPositionen]
|
||||
WHERE [AlleAuftragPositionen].[AuftragNr] = @{nameof(orderNr)}
|
||||
OR [AlleAuftragPositionen].[FertigungsauftragNr] = @{nameof(orderNr)}
|
||||
ORDER BY [AlleAuftragPositionen].[PositionNr]",
|
||||
parameters: parameters => parameters.Add(nameof(orderNr), orderNr),
|
||||
reader: reader => (int)reader.GetValue<short>(0));
|
||||
|
||||
return new OrderPositions(positionsFound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
namespace LaaProductionWeb.Services
|
||||
{
|
||||
using LaaProductionWeb.Data.Interfaces;
|
||||
using LaaProductionWeb.Services.Interfaces;
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class ProtocolService : IProtocolService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
|
||||
public ProtocolService(IDbContext dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public string FileContent(int? fileId)
|
||||
{
|
||||
var fileContent = this.dbContext.FirstOrDefault(
|
||||
query: $@"
|
||||
SELECT [dbo].[File].[FileContent]
|
||||
FROM [dbo].[File]
|
||||
WHERE [dbo].[File].[FileId] = @{nameof(fileId)}",
|
||||
parameters: parameters => parameters.Add(nameof(fileId), fileId),
|
||||
reader: reader => reader.GetBytes(0));
|
||||
|
||||
return string.Format("data:application/pdf;base64,{0}", Convert.ToBase64String(fileContent));
|
||||
}
|
||||
|
||||
public OrderClientModel FindOrder(int orderId)
|
||||
=> this.dbContext.FirstOrDefault(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[APG].[AuftragNr]
|
||||
, [K].[KundenNr]
|
||||
, [K].[Name]
|
||||
, ISNULL((SELECT CAST([Positions].[PositionNr] AS VARCHAR) + ', '
|
||||
FROM (SELECT DISTINCT TOP 1000 [PositionNr]
|
||||
FROM [AuftragPositionSerienNr]
|
||||
WHERE [AuftragNr] = [APG].[AuftragNr]
|
||||
ORDER BY [PositionNr]) AS [Positions]
|
||||
FOR XML PATH('')), '') AS [Positions]
|
||||
FROM [AuftragPosition_Gesamt] AS [APG]
|
||||
JOIN [Auftrag_Gesamt] AS [AG]
|
||||
ON [AG].[AuftragNr] = [APG].[AuftragNr]
|
||||
JOIN [IdentNr] AS [IN]
|
||||
ON [IN].[IdentNr] = [APG].[Identnr]
|
||||
AND [IN].[Typ] = 'GNS'
|
||||
JOIN [Kunde] AS [K]
|
||||
ON [K].[KundenNr] = [AG].[KundenNr]
|
||||
WHERE [APG].[AuftragNr] = @{nameof(orderId)}",
|
||||
parameters: parameters => parameters.Add(nameof(orderId), orderId),
|
||||
reader: reader => new OrderClientModel
|
||||
{
|
||||
OrderId = reader.GetValue<int>(0),
|
||||
ClientId = reader.GetValue<int>(1),
|
||||
ClientName = reader.GetString(2),
|
||||
Positions = reader.GetString(3).Trim().Trim(',')
|
||||
}) ?? new OrderClientModel();
|
||||
|
||||
public IEnumerable<KeyValuePair<int, string>> FindOrdersById(int orderno)
|
||||
=> this.dbContext.AsEnumerable($@"
|
||||
SELECT DISTINCT
|
||||
[APG].[AuftragNr]
|
||||
, [K].[Name]
|
||||
FROM [AuftragPosition_Gesamt] AS [APG]
|
||||
JOIN [Auftrag_Gesamt] AS [AG]
|
||||
ON [AG].[AuftragNr] = [APG].[AuftragNr]
|
||||
JOIN [IdentNr] AS [IN]
|
||||
ON [IN].[IdentNr] = [APG].[Identnr]
|
||||
AND [IN].[Typ] = 'GNS'
|
||||
JOIN [Kunde] AS [K]
|
||||
ON [K].[KundenNr] = [AG].[KundenNr]
|
||||
WHERE [APG].[AuftragNr] LIKE @{nameof(orderno)}",
|
||||
parameters: parameters => parameters.Add(nameof(orderno), $"%{orderno}%"),
|
||||
reader: reader => new KeyValuePair<int, string>(
|
||||
key: reader.GetValue<int>(0),
|
||||
value: reader.GetString(1)));
|
||||
|
||||
public IEnumerable<KeyValuePair<int, string>> FindOrdersByClient(string clientName)
|
||||
=> this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[APG].[AuftragNr]
|
||||
, [K].[Name]
|
||||
FROM [AuftragPosition_Gesamt] AS [APG]
|
||||
JOIN [Auftrag_Gesamt] AS [AG]
|
||||
ON [AG].[AuftragNr] = [APG].[AuftragNr]
|
||||
JOIN [IdentNr] AS [IN]
|
||||
ON [IN].[IdentNr] = [APG].[Identnr]
|
||||
AND [IN].[Typ] = 'GNS'
|
||||
JOIN [Kunde] AS [K]
|
||||
ON [K].[KundenNr] = [AG].[KundenNr]
|
||||
WHERE [K].[Name] LIKE @{nameof(clientName)}",
|
||||
parameters: parameters => parameters.Add(nameof(clientName), $"%{clientName}%"),
|
||||
reader: reader => new KeyValuePair<int, string>(
|
||||
key: reader.GetValue<int>(0),
|
||||
value: reader.GetString(1)));
|
||||
|
||||
public IEnumerable<TestStatus> LoadTestStatus(int orderId)
|
||||
=> this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[APS].[PositionNr] AS [PosNr] -- 0
|
||||
, ISNULL([APS].[KundeneigeneSerienNr], [APS].[SerienNr]) AS [SerialNr] -- 1
|
||||
, [CPT].[CordonelPressureTest_Valid] AS [3TightnessTest] -- 2
|
||||
, [DP].[Dicht] AS [4PressureAndTightness] -- 3
|
||||
, MAX([APS].[StatusFertigung]) AS [5Metrologicaltesting] -- 4
|
||||
, [CRRH].[Result] AS [6ConfigComparisonAndRadiotest] -- 5
|
||||
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]
|
||||
ORDER BY [APS].[PositionNr]
|
||||
, ISNULL([APS].[KundeneigeneSerienNr], [APS].[SerienNr])",
|
||||
parameters: parameters => parameters.Add(nameof(orderId), orderId),
|
||||
reader: reader => new TestStatus
|
||||
{
|
||||
PosNr = $"{reader.GetValue<short>(0)}",
|
||||
SerialNr = reader.GetValue<string>(1),
|
||||
HeliumTest = reader.GetValue<bool?>(2),
|
||||
PressureTest = reader.GetValue<bool?>(3),
|
||||
MetroTest = this.MetrologicalValue(reader.GetValue<byte?>(4)),
|
||||
RadioTest = reader.GetValue<bool?>(5),
|
||||
});
|
||||
|
||||
public int SaveFile(Stream fileStream, int clientId, int orderId)
|
||||
{
|
||||
var fileName = $"{clientId}_{orderId}.pdf";
|
||||
var fileContent = this.GetBuffer(fileStream);
|
||||
|
||||
return this.dbContext.ScalarTransaction<int>(
|
||||
query: $@"
|
||||
INSERT INTO [dbo].[File] (
|
||||
[FileName]
|
||||
, [FileContent])
|
||||
OUTPUT @{nameof(orderId)}, [Inserted].[FileId], 'PROTOCOL'
|
||||
INTO [dbo].[FilesOrders]([OrderId], [FileId], [Usage])
|
||||
OUTPUT [Inserted].[FileId]
|
||||
VALUES (@{nameof(fileName)}
|
||||
, @{nameof(fileContent)})",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(orderId), orderId)
|
||||
.Add(nameof(fileName), fileName)
|
||||
.AddFile(nameof(fileContent), fileContent));
|
||||
}
|
||||
|
||||
private byte[] GetBuffer(Stream fileStream)
|
||||
{
|
||||
var fileContent = new byte[fileStream.Length];
|
||||
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
fileStream.CopyTo(memoryStream);
|
||||
|
||||
fileContent = memoryStream.ToArray();
|
||||
}
|
||||
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
private bool? MetrologicalValue(byte? value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return value == 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
namespace LaaProductionWeb.Services
|
||||
{
|
||||
using LaaProductionWeb.Data.Interfaces;
|
||||
using LaaProductionWeb.Services.Interfaces;
|
||||
using LaaProductionWeb.Services.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
public class ShipmentsService : IShipmentsService
|
||||
{
|
||||
private readonly IDbContext dbContext;
|
||||
|
||||
public ShipmentsService(IDbContext dbContext)
|
||||
=> this.dbContext = dbContext;
|
||||
|
||||
public OrderScanModel DeletePalletEntry(int id)
|
||||
{
|
||||
var orderScanModel = this.DeletePalletEntryById(id);
|
||||
|
||||
if (orderScanModel != null)
|
||||
{
|
||||
var updated = this.UpdatePalletsNr(orderScanModel);
|
||||
}
|
||||
|
||||
return orderScanModel;
|
||||
}
|
||||
|
||||
public int GetPalletsCount(OrderScanModel model)
|
||||
{
|
||||
var palletsCount = this.dbContext.FirstOrDefault(
|
||||
query: $@"
|
||||
SELECT COUNT(1)
|
||||
FROM (SELECT [PalettenNr] AS [PalletNr]
|
||||
, COUNT([SerienNr]) AS [Count]
|
||||
FROM [PalettenScan]
|
||||
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [PositionNr] = @{nameof(model.PositionNr)}
|
||||
GROUP BY [PalettenNr])
|
||||
AS [Paletten]
|
||||
WHERE [Count] > 0",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr),
|
||||
reader: reader => reader.GetValue<int>(0));
|
||||
|
||||
return Math.Max(palletsCount, 1);
|
||||
}
|
||||
|
||||
public byte[] LoadBatchBuffer(OrderScanModel model)
|
||||
{
|
||||
var palletLoad = this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT [PalettenNr]
|
||||
, [SerienNr]
|
||||
FROM [PalettenScan]
|
||||
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [PositionNr] = @{nameof(model.PositionNr)}
|
||||
AND [PalettenNr] = @{nameof(model.PalletNr)}
|
||||
ORDER BY [SerienNr]",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr)
|
||||
.Add(nameof(model.PalletNr), model.PalletNr),
|
||||
reader: reader => string.Join(",", new string[]
|
||||
{
|
||||
reader.GetString(0),
|
||||
reader.GetString(1),
|
||||
}));
|
||||
var csvContent = string.Join(Environment.NewLine, palletLoad);
|
||||
|
||||
return Encoding.UTF8.GetBytes($"Pallet Nr.,Serial Nr.{Environment.NewLine}{csvContent}");
|
||||
}
|
||||
|
||||
public IEnumerable<SerialNr> LoadBatchItems(OrderScanModel model)
|
||||
=> this.dbContext.AsEnumerable(
|
||||
query: $@"
|
||||
SELECT DISTINCT
|
||||
[PalettenScan].[ID] -- 0
|
||||
, [AuftragPositionSerienNr].[SerienNr] -- 1
|
||||
, REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '') -- 2
|
||||
, [PalettenScan].[PalettenNr] -- 3
|
||||
, CAST(CASE WHEN [PalettenScan].[ID] IS NULL THEN 0 ELSE 1 END AS BIT) -- 4
|
||||
FROM [AuftragPositionSerienNr]
|
||||
LEFT JOIN [PalettenScan]
|
||||
ON [PalettenScan].[AuftragNr] = [AuftragPositionSerienNr].[AuftragNr]
|
||||
AND [PalettenScan].[PositionNr] = [AuftragPositionSerienNr].[PositionNr]
|
||||
AND [PalettenScan].[SerienNr] = REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '')
|
||||
WHERE [AuftragPositionSerienNr].[AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [AuftragPositionSerienNr].[PositionNr] = @{nameof(model.PositionNr)}
|
||||
AND ([PalettenScan].[PalettenNr] = @{nameof(model.PalletNr)}
|
||||
OR [PalettenScan].[PalettenNr] IS NULL)",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr)
|
||||
.Add(nameof(model.PalletNr), model.PalletNr),
|
||||
reader: reader => new SerialNr
|
||||
{
|
||||
Id = reader.GetValue<int>(0),
|
||||
Nr = reader.GetValue<int>(1),
|
||||
ClientNr = reader.GetString(2),
|
||||
PalletNr = reader.GetValue<short>(3),
|
||||
IsScaned = reader.GetValue<bool>(4)
|
||||
})
|
||||
.OrderByDescending(x => x.IsScaned)
|
||||
.ThenBy(x => x.ClientNr);
|
||||
|
||||
public PalletsBatchModel LoadBatchModel(OrderScanModel model)
|
||||
{
|
||||
var batchModel = this.dbContext.FirstOrDefault(
|
||||
query: $@"
|
||||
SELECT TOP 1
|
||||
[Auftrag].[AuftragNr] -- 0
|
||||
, [Auftrag].[FertigungsauftragNr] -- 1
|
||||
, [Auftrag].[PositionNr] -- 2
|
||||
, [Auftrag].[Menge] -- 3
|
||||
, [Kunde].[Name] -- 4
|
||||
, [IdentNr].[Typ] -- 5
|
||||
, [IdentNr].[Typzusatz] -- 6
|
||||
, [IdentNr].[Nennweite] -- 7
|
||||
, [Auftrag].[ZusatzText] -- 8
|
||||
FROM [AlleAuftragPositionen] AS [Auftrag]
|
||||
JOIN [Kunde] ON [Kunde].[KundenNr] = [Auftrag].[KundenNr]
|
||||
JOIN [IdentNr] ON [IdentNr].[IdentNr] = [Auftrag].[IdentNr]
|
||||
WHERE [Auftrag].[AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [Auftrag].[PositionNr] = @{nameof(model.PositionNr)}
|
||||
ORDER BY [Auftrag].[FertigungsauftragNr] DESC",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr),
|
||||
reader: reader => new PalletsBatchModel
|
||||
{
|
||||
OrderNr = reader.GetValue<int>(0),
|
||||
ProductionOrderNr = reader.GetValue<int>(1),
|
||||
PositionNr = reader.GetValue<short>(2),
|
||||
TotlalItemsCount = reader.GetValue<int>(3),
|
||||
ClientName = reader.GetValue<string>(4),
|
||||
ItemsType = string.Join(" ", new[]
|
||||
{
|
||||
reader.GetString(5),
|
||||
reader.GetString(6),
|
||||
reader.GetString(7),
|
||||
}.Where(x => !string.IsNullOrWhiteSpace(x))),
|
||||
AdditionalText = reader.GetValue<string>(8),
|
||||
}) ?? new PalletsBatchModel();
|
||||
|
||||
if (batchModel.OrderNr > 0)
|
||||
{
|
||||
batchModel.Items = this.LoadBatchItems(model);
|
||||
}
|
||||
|
||||
return batchModel;
|
||||
}
|
||||
|
||||
public Result UpdateBatchModel(OrderScanModel model)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(model.SerialNr))
|
||||
{
|
||||
if (this.PalletsEntryExists(model.OrderNr, model.PositionNr, model.SerialNr))
|
||||
{
|
||||
return $"Der Packet mit Serien-Nr: {model.SerialNr} wurde bereits hinzugefügt.";
|
||||
}
|
||||
|
||||
var orderKVP = this.GetOrderKVP(model.OrderNr, model.PositionNr, model.SerialNr);
|
||||
|
||||
if (orderKVP.Key <= 0)
|
||||
{
|
||||
return $"Der Packet mit Serien-Nr: {model.SerialNr} ist nicht dem Auftrag/Position: {model.OrderNr}/{model.PositionNr} zugewiesen.";
|
||||
}
|
||||
else
|
||||
{
|
||||
model.SerialNr = orderKVP.Value;
|
||||
model.PalletNr = this.GetPalletNr(model);
|
||||
}
|
||||
|
||||
var rowsAffected = this.InsertPalletEntry(model);
|
||||
|
||||
return rowsAffected == 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int GetPalletNr(OrderScanModel model)
|
||||
=> this.dbContext.FirstOrDefault(
|
||||
query: $@"
|
||||
SELECT MAX([PalettenNr]) + 1
|
||||
FROM [PalettenScan]
|
||||
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [PositionNr] = @{nameof(model.PositionNr)}",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr),
|
||||
reader: reader => Math.Min(reader.GetValue<int>(0), model.PalletNr));
|
||||
|
||||
private OrderScanModel DeletePalletEntryById(int id)
|
||||
=> this.dbContext.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<int>(0),
|
||||
PositionNr = reader.GetValue<int>(1),
|
||||
PalletNr = reader.GetValue<short>(2)
|
||||
});
|
||||
|
||||
private KeyValuePair<int, string> GetOrderKVP(int? orderNr, int? positionNr, string serialNr)
|
||||
=> this.dbContext.FirstOrDefault(
|
||||
query: $@"
|
||||
SELECT DISTINCT TOP 1
|
||||
[AuftragPositionSerienNr].[SerienNr] -- 0
|
||||
, REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '') -- 1
|
||||
FROM [AuftragPositionSerienNr]
|
||||
WHERE [AuftragPositionSerienNr].[AuftragNr] = @{nameof(orderNr)}
|
||||
AND [AuftragPositionSerienNr].[PositionNr] = @{nameof(positionNr)}
|
||||
AND @{nameof(serialNr)} LIKE '%' + (REPLACE(RTRIM(LTRIM([AuftragPositionSerienNr].[KundeneigeneSerienNr])), ' ', '')) + '%'",
|
||||
parameters: parameters => parameters
|
||||
.Add(nameof(orderNr), orderNr)
|
||||
.Add(nameof(positionNr), positionNr)
|
||||
.Add(nameof(serialNr), serialNr),
|
||||
reader: reader => new KeyValuePair<int, string>(
|
||||
key: reader.GetValue<int>(0),
|
||||
value: reader.GetValue<string>(1)));
|
||||
|
||||
private int InsertPalletEntry(OrderScanModel model)
|
||||
=> this.dbContext.ScalarTransaction<int>($@"
|
||||
INSERT
|
||||
INTO [PalettenScan] (
|
||||
[PalettenNr]
|
||||
, [AuftragNr]
|
||||
, [PositionNr]
|
||||
, [SerienNr]
|
||||
, [Host]
|
||||
, [Platz]
|
||||
, [Datum])
|
||||
VALUES (@{nameof(model.PalletNr)}
|
||||
, @{nameof(model.OrderNr)}
|
||||
, @{nameof(model.PositionNr)}
|
||||
, @{nameof(model.SerialNr)}
|
||||
, @{nameof(model.Host)}
|
||||
, @{nameof(model.Place)}
|
||||
, GETDATE())",
|
||||
parameters => parameters
|
||||
.Add(nameof(model.PalletNr), model.PalletNr)
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr)
|
||||
.Add(nameof(model.SerialNr), model.SerialNr)
|
||||
.Add(nameof(model.Host), model.Host)
|
||||
.Add(nameof(model.Place), model.Place));
|
||||
|
||||
private bool PalletsEntryExists(int? orderNr, int? positionNr, string serialNr)
|
||||
=> this.dbContext.FirstOrDefault($@"
|
||||
SELECT CAST(CASE WHEN [PalettenScan].[ID] IS NULL THEN 0 ELSE 1 END AS BIT)
|
||||
FROM [PalettenScan]
|
||||
WHERE [PalettenScan].[AuftragNr] = @{nameof(orderNr)}
|
||||
AND [PalettenScan].[PositionNr] = @{nameof(positionNr)}
|
||||
AND [PalettenScan].[SerienNr] = @{nameof(serialNr)}",
|
||||
parameters => parameters
|
||||
.Add(nameof(orderNr), orderNr)
|
||||
.Add(nameof(positionNr), positionNr)
|
||||
.Add(nameof(serialNr), serialNr),
|
||||
reader => reader.GetValue<bool>(0));
|
||||
|
||||
private bool UpdatePalletsNr(OrderScanModel model)
|
||||
=> this.dbContext.FirstOrDefault($@"
|
||||
BEGIN TRANSACTION
|
||||
------------------------------------------------------------------------
|
||||
DECLARE @rowsByAuftragPosition INT = (
|
||||
SELECT COUNT(1)
|
||||
FROM [PalettenScan]
|
||||
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [PositionNr] = @{nameof(model.PositionNr)})
|
||||
------------------------------------------------------------------------
|
||||
UPDATE [PalettenScan]
|
||||
SET [PalettenNr] = [OrderedPallets].[NewPalletNr]
|
||||
FROM [PalettenScan]
|
||||
JOIN (SELECT [ID]
|
||||
, [PalettenNr]
|
||||
, DENSE_RANK() OVER(ORDER BY [PalettenNr]) AS [NewPalletNr]
|
||||
FROM [PalettenScan]
|
||||
WHERE [AuftragNr] = @{nameof(model.OrderNr)}
|
||||
AND [PositionNr] = @{nameof(model.PositionNr)})
|
||||
AS [OrderedPallets]
|
||||
ON [PalettenScan].[ID] = [OrderedPallets].[ID]
|
||||
------------------------------------------------------------------------
|
||||
IF @rowsByAuftragPosition = @@ROWCOUNT
|
||||
BEGIN SELECT CAST(1 AS BIT); COMMIT; END
|
||||
ELSE BEGIN SELECT CAST(0 AS BIT); ROLLBACK; END",
|
||||
parameters => parameters
|
||||
.Add(nameof(model.OrderNr), model.OrderNr)
|
||||
.Add(nameof(model.PositionNr), model.PositionNr),
|
||||
reader => reader.GetValue<bool>(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -3,6 +3,6 @@
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net462" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="7.0.0" targetFramework="net462" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0" targetFramework="net462" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net462" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net462" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net462" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user