Multiple Tool Types for Run Headers
This commit is contained in:
@ -7,6 +7,7 @@ using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
|
||||
#pragma warning disable CS8600, CS8602, CS8603, CS8604, CS8625
|
||||
@ -287,7 +288,7 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
|
||||
protected string FormDynamicSelectQuery(IEnumerable<ToolTypeMetadata> fields, string tableName)
|
||||
{
|
||||
System.Text.StringBuilder sb = new();
|
||||
StringBuilder sb = new();
|
||||
_ = sb.Append("SELECT ");
|
||||
bool firstField = true;
|
||||
foreach (ToolTypeMetadata f in fields)
|
||||
@ -324,7 +325,7 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
DataTable dt = new();
|
||||
using (DbConnection conn = GetDbConnection())
|
||||
{
|
||||
System.Text.StringBuilder sb = new();
|
||||
StringBuilder sb = new();
|
||||
_ = sb.Append(
|
||||
FormDynamicSelectQuery(
|
||||
md.Where(m => m.Header == true).ToList(),
|
||||
@ -417,7 +418,7 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
DataTable dt = new();
|
||||
using (DbConnection conn = GetDbConnection())
|
||||
{
|
||||
System.Text.StringBuilder sb = new();
|
||||
StringBuilder sb = new();
|
||||
_ = sb.Append(
|
||||
FormDynamicSelectQuery(
|
||||
md.Where(m => m.Header == false).OrderBy(m => m.GridDisplayOrder).ToList(),
|
||||
@ -618,26 +619,60 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
return ds;
|
||||
}
|
||||
|
||||
internal IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
|
||||
private HeaderCommon[] GetHeaderTitles()
|
||||
{
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
IEnumerable<HeaderCommon> results;
|
||||
ToolType[] toolTypes = GetToolTypes().ToArray();
|
||||
|
||||
if (!toolTypes.Any() || toolTypes.FirstOrDefault() is null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
|
||||
ToolType tt;
|
||||
StringBuilder stringBuilder = new();
|
||||
using DbConnection conn = GetDbConnection();
|
||||
_ = stringBuilder.Append(" SELECT * FROM ( ");
|
||||
for (int i = 0; i < toolTypes.Length; i++)
|
||||
{
|
||||
tt = toolTypes[i];
|
||||
_ = stringBuilder.Append($" SELECT ID, InsertDate, AttachmentID, Title, [Date], {tt.ID} AS ToolID, '{tt.ToolTypeName}' AS ToolName FROM {tt.HeaderTableName} ");
|
||||
if (i != toolTypes.Length - 1)
|
||||
_ = stringBuilder.Append(" UNION ALL ");
|
||||
}
|
||||
_ = stringBuilder.Append(" ) AS A ORDER BY A.[Date] DESC ");
|
||||
results = conn.Query<HeaderCommon>(stringBuilder.ToString()).ToArray();
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
internal HeaderCommon[] GetHeaderTitles(int? toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
|
||||
{
|
||||
HeaderCommon[] headers;
|
||||
if (toolTypeId is not null && (pageNo is not null || pageSize is not null))
|
||||
throw new Exception();
|
||||
|
||||
if (toolTypeId is null)
|
||||
{
|
||||
headers = GetHeaderTitles();
|
||||
totalRecords = headers.Length;
|
||||
return headers;
|
||||
}
|
||||
|
||||
ToolType tt = GetToolTypeByID(toolTypeId.Value);
|
||||
if (tt is null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
|
||||
using DbConnection conn = GetDbConnection();
|
||||
string sql = $"SELECT ID, InsertDate, AttachmentID, Title, [Date] FROM {tt.HeaderTableName} ORDER BY [Date] DESC ";
|
||||
|
||||
IEnumerable<HeaderCommon> headers;
|
||||
string sql = $"SELECT ID, InsertDate, AttachmentID, Title, [Date], {tt.ID} AS ToolID, '{tt.ToolTypeName}' AS ToolName FROM {tt.HeaderTableName} ORDER BY [Date] DESC ";
|
||||
|
||||
if (pageNo.HasValue && pageSize.HasValue)
|
||||
{
|
||||
sql += "OFFSET @PageNum * @PageSize ROWS FETCH NEXT @PageSize ROWS ONLY";
|
||||
|
||||
headers = conn.Query<HeaderCommon>(sql, param: new { PageNum = pageNo.Value, PageSize = pageSize.Value }).ToList();
|
||||
headers = conn.Query<HeaderCommon>(sql, param: new { PageNum = pageNo.Value, PageSize = pageSize.Value }).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
headers = conn.Query<HeaderCommon>(sql).ToList();
|
||||
headers = conn.Query<HeaderCommon>(sql).ToArray();
|
||||
}
|
||||
|
||||
sql = $"SELECT COUNT(*) FROM [{tt.HeaderTableName}] ";
|
||||
@ -770,7 +805,7 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
DataTable IMetrologyRepository.ExportData(string spName, DateTime startTime, DateTime endTime) => ExportData(spName, startTime, endTime);
|
||||
DataTable IMetrologyRepository.GetHeaders(int toolTypeId, DateTime? startTime, DateTime? endTime, int? pageNo, int? pageSize, long? headerid, out long totalRecords) => GetHeaders(toolTypeId, startTime, endTime, pageNo, pageSize, headerid, out totalRecords);
|
||||
DataTable IMetrologyRepository.GetData(int toolTypeId, long headerId) => GetData(toolTypeId, headerId);
|
||||
IEnumerable<HeaderCommon> IMetrologyRepository.GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords) => GetHeaderTitles(toolTypeId, pageNo, pageSize, out totalRecords);
|
||||
HeaderCommon[] IMetrologyRepository.GetHeaderTitles(int? toolTypeId, int? pageNo, int? pageSize, out long totalRecords) => GetHeaderTitles(toolTypeId, pageNo, pageSize, out totalRecords);
|
||||
Guid IMetrologyRepository.GetHeaderAttachmentIDByTitle(int toolTypeId, string title) => GetHeaderAttachmentIDByTitle(toolTypeId, title);
|
||||
Guid IMetrologyRepository.GetDataAttachmentIDByTitle(int toolTypeId, string title) => GetDataAttachmentIDByTitle(toolTypeId, title);
|
||||
Guid IMetrologyRepository.GetHeaderAttachmentID(int toolTypeId, long headerId) => GetHeaderAttachmentID(toolTypeId, headerId);
|
||||
|
@ -113,7 +113,8 @@ public class ToolTypesRepository : IToolTypesRepository
|
||||
else
|
||||
{
|
||||
long totalRecs;
|
||||
HeaderCommon[] headerCommonCollection = metrologyRepository.GetHeaderTitles(id, page, pagesize, out totalRecs).ToArray();
|
||||
int? toolTypeId = id > -1 ? id : null;
|
||||
HeaderCommon[] headerCommonCollection = metrologyRepository.GetHeaderTitles(toolTypeId, page, pagesize, out totalRecs).ToArray();
|
||||
r = new()
|
||||
{
|
||||
Results = headerCommonCollection,
|
||||
|
Reference in New Issue
Block a user