26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
101 lines
3.7 KiB
C#
Executable File
101 lines
3.7 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;
|
|
|
|
namespace DataModel.Process
|
|
{
|
|
/// <summary>
|
|
/// Work center tracking functions for LotFinderDB interface
|
|
/// </summary>
|
|
public partial class LotFinderDB
|
|
{
|
|
/// <summary>
|
|
/// Query to find profit centers with matching code or description
|
|
/// </summary>
|
|
private const string SQL_SEARCH_WORK_CENTERS = @"
|
|
SELECT TOP 25
|
|
wc.Code,
|
|
wc.Description,
|
|
wc.LastUpdateDT
|
|
FROM dbo.WorkCenter AS wc
|
|
WHERE wc.Code LIKE '%' + @filter + '%' OR
|
|
wc.Description LIKE '%' + @filter + '%'
|
|
ORDER BY wc.Code";
|
|
|
|
/// <summary>
|
|
/// Finds work centers with matching code or description
|
|
/// </summary>
|
|
/// <param name="filter">Search filter</param>
|
|
/// <returns>Work centers with matching code or description</returns>
|
|
public static List<WorkCenter> SearchWorkCenters(string filter)
|
|
{
|
|
List<WorkCenter> results = new List<WorkCenter>();
|
|
|
|
try
|
|
{
|
|
using (SqlConnection connection = GetConnection())
|
|
{
|
|
results.AddRange(connection.Query<WorkCenter>(SQL_SEARCH_WORK_CENTERS, new { filter }));
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
//Log and forward exception
|
|
logger.Error("SearchWorkCenters: failed to search for work centers '{0}': {1}.", filter, error.Message);
|
|
throw new Exception($"Failed to search for work centers '{filter}' from LotFinderDB.", error);
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query to find work orders with matching work order numbers
|
|
/// </summary>
|
|
private const string SQL_LOOKUP_WORK_CENTERS = @"
|
|
SELECT wc.Code,
|
|
wc.Description,
|
|
wc.LastUpdateDT
|
|
FROM dbo.WorkCenter AS wc INNER JOIN
|
|
@workCenterCodes wc2 ON (wc.Code = wc2.Code)
|
|
ORDER BY wc.Code";
|
|
|
|
/// <summary>
|
|
/// Finds work centers with matching work center codes
|
|
/// </summary>
|
|
/// <param name="workCenterCodes">Work center codes to match</param>
|
|
/// <returns>List of matching work centers</returns>
|
|
public static List<WorkCenter> LookupWorkCenters(List<string> workCenterCodes)
|
|
{
|
|
List<WorkCenter> results = new List<WorkCenter>();
|
|
|
|
try
|
|
{
|
|
//Create search filter parameter
|
|
DataTable dataTable = new DataTable();
|
|
dataTable.Columns.Add("Code", typeof(string));
|
|
foreach (string workCenter in workCenterCodes)
|
|
{
|
|
dataTable.Rows.Add(workCenter);
|
|
}
|
|
|
|
using (SqlConnection connection = GetConnection())
|
|
{
|
|
results = connection.Query<WorkCenter>(SQL_LOOKUP_WORK_CENTERS, new { workCenterCodes = dataTable.AsTableValuedParameter("WorkCenterFilterParameter") }).ToList();
|
|
}
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
//Log and forward exception
|
|
logger.Error("LookupWorkCenters: failed to find matching work centers: {0}.", error.Message);
|
|
throw new Exception("LookupWorkCenters: failed to find matching work centers in LotFinderDB.", error);
|
|
}
|
|
|
|
return results;
|
|
}
|
|
}
|
|
}
|