Multiple Tool Types for Run Headers
This commit is contained in:
parent
3145c1b501
commit
aae9cd18b2
@ -669,9 +669,12 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
return ds;
|
||||
}
|
||||
|
||||
public IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
|
||||
public HeaderCommon[] GetHeaderTitles(int? toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
|
||||
{
|
||||
ToolType tt = GetToolTypeByID(toolTypeId);
|
||||
if (toolTypeId is null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
|
||||
ToolType tt = GetToolTypeByID(toolTypeId.Value);
|
||||
if (tt is null)
|
||||
throw new Exception("Invalid tool type ID");
|
||||
|
||||
@ -680,17 +683,17 @@ public class MetrologyRepository : IMetrologyRepository
|
||||
{
|
||||
string sql = $"SELECT ID, InsertDate, AttachmentID, Title, [Date] FROM {tt.HeaderTableName} ORDER BY [Date] DESC ";
|
||||
|
||||
IEnumerable<HeaderCommon> headers;
|
||||
HeaderCommon[] headers;
|
||||
|
||||
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}] ";
|
||||
|
@ -102,7 +102,7 @@ function initExport(apiUrl, startTimeValue, endTimeValue) {
|
||||
};
|
||||
|
||||
function loadHeaderGridRunHeaders() {
|
||||
var toolTypeID = $("#ToolType").igCombo("value");
|
||||
var toolTypeID = -1; // $("#ToolType").igCombo("value");
|
||||
var gridCreated = $("#HeaderGrid").data("igGrid");
|
||||
if (gridCreated)
|
||||
$("#HeaderGrid").igGrid("destroy");
|
||||
@ -120,7 +120,9 @@ function loadHeaderGridRunHeaders() {
|
||||
],
|
||||
columns: [
|
||||
{ key: "ID", dataType: "number", hidden: true },
|
||||
{ key: "Title", dataType: "string", width: "80%" },
|
||||
{ key: "ToolID", dataType: "number", hidden: true },
|
||||
{ key: "ToolName", dataType: "string", width: "10%" },
|
||||
{ key: "Title", dataType: "string", width: "70%" },
|
||||
{ key: "InsertDate", dataType: "date", format: "dateTime", width: "20%" }
|
||||
],
|
||||
dataSource: headerURL,
|
||||
@ -135,9 +137,9 @@ function clearFieldsGridRunHeaders() {
|
||||
}
|
||||
|
||||
function headerSelectionChangedRunHeaders(evt, ui) {
|
||||
var toolTypeID = $("#ToolType").igCombo("value");
|
||||
clearFieldsGridRunHeaders();
|
||||
var url = _apiUrl + "/api/tooltypes/" + toolTypeID + "/headers/" + ui.row.id + "/fields";
|
||||
var rowData = ui.owner.grid.dataSource.dataView()[ui.row.index];
|
||||
var url = _apiUrl + "/api/tooltypes/" + rowData.ToolID + "/headers/" + ui.row.id + "/fields";
|
||||
$("#FieldsGrid").igGrid({
|
||||
autoGenerateColumns: false,
|
||||
primaryKey: "Column",
|
||||
@ -158,19 +160,20 @@ function headerSelectionChangedRunHeaders(evt, ui) {
|
||||
|
||||
function initRunHeaders(apiUrl) {
|
||||
_apiUrl = apiUrl;
|
||||
$("#ToolType").igCombo({
|
||||
dataSource: _apiUrl + '/api/tooltypes',
|
||||
responseDataKey: "Results",
|
||||
textKey: "ToolTypeName",
|
||||
valueKey: "ID",
|
||||
mode: "dropdown",
|
||||
width: 150,
|
||||
dataBound: function (evt, ui) {
|
||||
$("#ToolType").igCombo("index", 0);
|
||||
loadHeaderGridRunHeaders();
|
||||
},
|
||||
selectionChanged: loadHeaderGridRunHeaders,
|
||||
});
|
||||
// $("#ToolType").igCombo({
|
||||
// dataSource: _apiUrl + '/api/tooltypes',
|
||||
// responseDataKey: "Results",
|
||||
// textKey: "ToolTypeName",
|
||||
// valueKey: "ID",
|
||||
// mode: "dropdown",
|
||||
// width: 150,
|
||||
// dataBound: function (evt, ui) {
|
||||
// $("#ToolType").igCombo("index", 0);
|
||||
// loadHeaderGridRunHeaders();
|
||||
// },
|
||||
// selectionChanged: loadHeaderGridRunHeaders,
|
||||
// });
|
||||
loadHeaderGridRunHeaders();
|
||||
}
|
||||
|
||||
function loadHeaderGridRunInfo() {
|
||||
|
@ -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,
|
||||
|
@ -8,4 +8,6 @@ public class HeaderCommon
|
||||
public string? Title { get; set; }
|
||||
public string? Recipe { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public long ToolID { get; set; }
|
||||
public string? ToolName { get; set; }
|
||||
}
|
@ -25,7 +25,7 @@ public interface IMetrologyRepository
|
||||
DataTable GetData(int toolTypeId, long headerId);
|
||||
DataTable GetDataSharePoint(int toolTypeId, string headerId);
|
||||
|
||||
IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords);
|
||||
HeaderCommon[] GetHeaderTitles(int? toolTypeId, int? pageNo, int? pageSize, out long totalRecords);
|
||||
|
||||
Guid GetHeaderAttachmentIDByTitle(int toolTypeId, string title);
|
||||
Guid GetDataAttachmentIDByTitle(int toolTypeId, string title);
|
||||
|
@ -130,7 +130,7 @@ public class UnitTestToolTypesController
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<HeaderCommon[]> result = toolTypesRepository.GetHeaderTitles(metrologyRepository, id: 1, page: null, pagesize: null);
|
||||
Result<HeaderCommon[]> result = toolTypesRepository.GetHeaderTitles(metrologyRepository, id: -1, page: null, pagesize: null);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
@ -141,7 +141,7 @@ public class UnitTestToolTypesController
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headertitles");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/-1/headertitles");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{nameof(GetHeaderTitlesApi)}.json"), json);
|
||||
Result<HeaderCommon[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
|
Loading…
x
Reference in New Issue
Block a user