26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
69 lines
2.4 KiB
C#
Executable File
69 lines
2.4 KiB
C#
Executable File
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using Dapper;
|
|
using DataModel.Models;
|
|
using DataModel.ViewModels;
|
|
|
|
namespace DataModel.Process
|
|
{
|
|
/// <summary>
|
|
/// Lot tracking functions for LotFinderDB interface
|
|
/// </summary>
|
|
public partial class LotFinderDB
|
|
{
|
|
/// <summary>
|
|
/// Query to find lots with matching lot numbers
|
|
/// </summary>
|
|
private const string SQL_LOOKUP_LOTS = @"
|
|
SELECT DISTINCT
|
|
l.LotNumber,
|
|
l.BranchCode,
|
|
l.ShortItemNumber,
|
|
l.ItemNumber,
|
|
l.SupplierCode,
|
|
l.LastUpdateDT
|
|
FROM dbo.Lot AS l INNER JOIN
|
|
@lotNumbers ln ON (l.LotNumber = ln.ComponentLotNumber AND
|
|
((l.ItemNumber IS NULL AND ln.ItemNumber IS NULL) OR l.ItemNumber = ln.ItemNumber))";
|
|
|
|
/// <summary>
|
|
/// Finds lots with matching lot numbers
|
|
/// </summary>
|
|
/// <param name="lots">Lot numbers to match</param>
|
|
/// <returns>List of matching lots</returns>
|
|
public static List<Lot> LookupLots(List<LotViewModel> lots)
|
|
{
|
|
List<Lot> results = new List<Lot>();
|
|
|
|
try
|
|
{
|
|
//Create search filter parameter
|
|
DataTable dataTable = new DataTable();
|
|
dataTable.Columns.Add("ComponentLotNumber", typeof(string));
|
|
dataTable.Columns.Add("ItemNumber", typeof(string));
|
|
|
|
foreach (LotViewModel lot in lots)
|
|
{
|
|
dataTable.Rows.Add(lot.LotNumber, lot.ItemNumber);
|
|
}
|
|
|
|
using (SqlConnection connection = GetConnection())
|
|
{
|
|
results = connection.Query<Lot>(SQL_LOOKUP_LOTS, new { lotNumbers = dataTable.AsTableValuedParameter("ComponentLotFilterParameter") }).ToList();
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
//Log and forward exception
|
|
logger.Error("LookupLots: failed to find matching lots: {0}.", error.Message);
|
|
throw new Exception("LookupLots: failed to find matching lots in LotFinderDB.", error);
|
|
}
|
|
|
|
return results;
|
|
}
|
|
}
|
|
}
|