// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this // file to you under the MIT license. using EgwCoreLib.Razor; using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; using MagMan.Data.Tenant.DbModels; using MagMan.Data.Tenant.Services; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.JSInterop; namespace MagMan.UI.Components { public partial class MacStatusMan : IDisposable { #region Public Properties [Parameter] public int CustomerId { get; set; } = 0; [Parameter] public int KeyNum { get; set; } = 0; #endregion Public Properties #region Public Methods public void Dispose() { AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated; } #endregion Public Methods #region Protected Properties [Inject] protected MessageService AppMService { get; set; } = null!; [Inject] protected IConfiguration Configuration { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected int maxRec { get; set; } = 1000; [Inject] protected MTAdminService MTService { get; set; } = null!; protected int totalCount { get; set; } = 0; [Inject] protected TenantService TService { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected string CheckSel(LogMachineModel curItem) { string answ = ""; #if false if (CurrItem != null) { answ = curItem.ProjDbId == CurrItem.ProjDbId ? "table-info" : ""; } else { answ = curItem.ProjDbId == ProjDbId ? "table-info" : ""; } #endif return answ; } protected void DoSelect(LogMachineModel? selItem) { #if false if (selItem != null) { ProjDbId = selItem.ProjDbId; } else { ProjDbId = 0; } E_ProjSel.InvokeAsync(selItem); #endif } protected async Task ForceReload(bool force) { #if false CurrItem = null; #endif await ReloadData(); } protected override async Task OnInitializedAsync() { currSearch = ""; AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; numRecord = await AppMService.NumRowGridGet(gridKey); } protected override async Task OnParametersSetAsync() { await ReloadData(); } protected async Task SetNumRec(int newNum) { numRecord = newNum; currPage = 1; await AppMService.NumRowGridSet(gridKey, newNum); await InvokeAsync(ReloadData); } protected async Task SetPage(int newNum) { currPage = newNum; DoSelect(null); await InvokeAsync(ReloadData); } protected async Task SortRequested(Sorter.SortCallBack e) { sortField = e.ParamName; sortAsc = e.IsAscending; await ReloadData(); } #endregion Protected Methods #region Private Fields private string currSearch = ""; private string gridKey = "MacStatus"; private List? ListRecords = null; private int machIdSel = 0; private List MachineList = new List(); private List? SearchRecords = null; private bool sortAsc = true; private string sortField = ""; #endregion Private Fields #region Private Properties private int currPage { get; set; } = 1; private bool isLoading { get; set; } = false; private int MachineIdSel { get => machIdSel; set { if (machIdSel != value) { machIdSel = value; InvokeAsync(ReloadData); } } } private int numRecord { get; set; } = 10; #endregion Private Properties #region Private Methods private async void AppMService_EA_SearchUpdated() { currSearch = AppMService.SearchVal; await ReloadData(); } private async Task ReloadData() { isLoading = true; //await InvokeAsync(StateHasChanged); ListRecords = null; if (KeyNum > 0) { MachineList = await MTService.MachineGetByCustId(CustomerId); // mettere var x maxNum? SearchRecords = await TService.LogMacGetLast(KeyNum, MachineIdSel, maxRec); // verifico filtro per ricerca if (!string.IsNullOrEmpty(currSearch)) { SearchRecords = SearchRecords.Where(x => x.VarValue.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList(); } totalCount = SearchRecords.Count; } SortTable(); isLoading = false; await InvokeAsync(StateHasChanged); } private void SortTable() { if (SearchRecords != null) { // se ho ordinamento riordino... if (!string.IsNullOrEmpty(sortField)) { #if false switch (sortField) { case "ID": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ProjExtId).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ProjExtId).ToList(); } break; case "ProjDescription": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ProjDescription).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ProjDescription).ToList(); } break; case "Machine": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.Machine).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.Machine).ToList(); } break; case "DtCreated": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtCreated).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtCreated).ToList(); } break; case "DtSchedule": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtSchedule).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtSchedule).ToList(); } break; case "DtStartProd": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtStartProd).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtStartProd).ToList(); } break; case "DtLastAction": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtLastAction).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtLastAction).ToList(); } break; case "ListName": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ListName).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ListName).ToList(); } break; case "IsActive": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.IsActive).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.IsActive).ToList(); } break; case "IsArchived": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.IsArchived).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.IsArchived).ToList(); } break; case "ProcTimeEst": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ProcTimeEst).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ProcTimeEst).ToList(); } break; default: break; } #endif } // filtro x display ListRecords = SearchRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); } else { ListRecords = new List(); } } #endregion Private Methods } }