72 lines
3.3 KiB
C#
72 lines
3.3 KiB
C#
namespace LaaProduction.Services
|
|
{
|
|
using LaaProductionSQL.Interfaces;
|
|
using LaaProduction.Services.Interfaces;
|
|
using LaaProduction.Services.Models;
|
|
|
|
public class OrdersService : IOrdersService
|
|
{
|
|
private readonly ISQLConnection sqlConnection;
|
|
|
|
public OrdersService(ISQLConnection sqlConnection)
|
|
=> this.sqlConnection = sqlConnection;
|
|
|
|
public OrdersFoundModel FindOrders(string search)
|
|
{
|
|
var ordersFound = this.sqlConnection
|
|
.CreateCommand($@"
|
|
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]")
|
|
.SetParameter(nameof(search), $"%{search}%")
|
|
.ExecuteReader(reader => new OrderInfoModel
|
|
{
|
|
OrderNr = reader.GetInt(),
|
|
ProductionOrderNr = reader.GetInt(),
|
|
Customer = reader.GetString(),
|
|
});
|
|
|
|
return new OrdersFoundModel(ordersFound);
|
|
}
|
|
|
|
public OrderPositions FindPositions(string orderNr)
|
|
{
|
|
var positionsFound = this.sqlConnection
|
|
.CreateCommand($@"
|
|
SELECT DISTINCT
|
|
[AlleAuftragPositionen].[PositionNr] -- 0
|
|
FROM [AlleAuftragPositionen]
|
|
WHERE [AlleAuftragPositionen].[AuftragNr] = @{nameof(orderNr)}
|
|
OR [AlleAuftragPositionen].[FertigungsauftragNr] = @{nameof(orderNr)}
|
|
ORDER BY [AlleAuftragPositionen].[PositionNr]")
|
|
.SetParameter(nameof(orderNr), orderNr)
|
|
.ExecuteReader(reader => (int)reader.GetSmallint());
|
|
|
|
return new OrderPositions(positionsFound);
|
|
}
|
|
|
|
public ProductionOrders FindProductionOrders(string productionNr)
|
|
{
|
|
var ordersFound = this.sqlConnection
|
|
.CreateCommand($@"
|
|
SELECT DISTINCT
|
|
[AlleAuftragPositionen].[FertigungsauftragNr] -- 1
|
|
FROM [AlleAuftragPositionen]
|
|
WHERE [AlleAuftragPositionen].[Versand_Ist_datum] IS NOT NULL
|
|
AND [AlleAuftragPositionen].[AuftragNr] LIKE @{nameof(productionNr)}
|
|
ORDER BY [AlleAuftragPositionen].[FertigungsauftragNr]")
|
|
.SetParameter(nameof(productionNr), $"{productionNr}%")
|
|
.ExecuteReader(reader => reader.GetInt());
|
|
|
|
return new ProductionOrders(ordersFound);
|
|
}
|
|
}
|
|
} |