using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.DataProtection; using Microsoft.JSInterop; using MP.Data.DbModels; using MP.SPEC.Components; using MP.SPEC.Data; using MP.SPEC.Services; using NLog; namespace MP.SPEC.Components { public partial class ListODL : IDisposable { #region Public Properties [Parameter] public SelectXdlParams currFilter { get; set; } = null!; [Parameter] public string padCodXdl { get; set; } = "0000"; [Parameter] public EventCallback PagerResetReq { get; set; } [Parameter] public EventCallback updateRecordCount { get; set; } #endregion Public Properties #region Public Methods public string checkSelect(int IdxOdl) { string answ = ""; if (currRecord != null) { try { answ = (currRecord.IdxOdl == IdxOdl) ? "table-info" : ""; } catch { } } return answ; } public void Dispose() { currRecord = null; SearchRecords = null; ListRecords = null; ListStati = null; ListOdlStats = null; statRecord = null; GC.Collect(); } #endregion Public Methods #region Protected Fields protected bool enableForceSync = true; protected bool enableStartPODL = true; protected bool enableStopODL = true; #endregion Protected Fields #region Protected Properties [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected Dictionary MachHasFolderLut { get; set; } = new Dictionary(); [Inject] protected MpDataService MDService { get; set; } = null!; [Inject] protected IOApiService MpIoApiCall { get; set; } = null!; #endregion Protected Properties #region Protected Methods /// /// Verifica se sia un articolo di tipo "KIT" x mostrare show dettaglio /// /// /// protected bool CheckIsKit(string CodArticolo) { bool answ = false; if (ListArtKit != null && ListArtKit.Count > 0) { answ = ListArtKit.Count(x => x.CodArticolo == CodArticolo) > 0; } return answ; } /// /// Registra chiusura ODL alla data indicata /// /// protected async Task chiudiOdl() { if (!await JSRuntime.InvokeAsync("confirm", "Sei sicuro di voler chiudere l'ODL corrente?")) return; if (currRecord != null) { // effettua chiusura sul DB await MDService.ODLClose(currRecord.IdxOdl, currRecord.IdxMacchina, 0, true); Log.Info($"Effettuata chiusura ODL {currRecord.IdxOdl}"); // RESETTO task x setComm, setArt, SetPzComm await MpIoApiCall.addTask2Exe(currRecord.IdxMacchina, "setArt", ""); await MpIoApiCall.addTask2Exe(currRecord.IdxMacchina, "setComm", ""); await MpIoApiCall.addTask2Exe(currRecord.IdxMacchina, "setPzComm", ""); // richiesto anche sync DB await MpIoApiCall.callSyncDb(currRecord.IdxMacchina); // ricarica... await selRecord(null); } await ReloadData(); } /// /// Richiesta invio sync all'IOB-WIN /// /// protected async Task ForceSyncDb() { if (!await JSRuntime.InvokeAsync("confirm", "Sei sicuro di voler (re)inviare i dati (Articoli, PODL) all'impianto?")) return; if (currRecord != null) { // imposto task x setComm, setArt, SetPzComm await MpIoApiCall.addTask2Exe(currRecord.IdxMacchina, "setArt", currRecord.CodArticolo); string odlPad = currRecord.IdxOdl.ToString(padCodXdl); await MpIoApiCall.addTask2Exe(currRecord.IdxMacchina, "setComm", $"ODL{odlPad}"); //await MpIoApiCall.addTask2Exe(SelRecord.IdxMacchina, "setComm", $"ODL{SelRecord.IdxOdl:00000000}"); await MpIoApiCall.addTask2Exe(currRecord.IdxMacchina, "setPzComm", $"{currRecord.NumPezzi}"); // richiesto anche sync DB await MpIoApiCall.callSyncDb(currRecord.IdxMacchina); Log.Info($"Richiesto ForceSyncDb per idxMacc {currRecord.IdxMacchina}"); // ricarica... await selRecord(null); } await ReloadData(); } protected int getPodl(int idxOdl) { int answ = 0; var pOdlData = MDService.POdlGetByOdl(idxOdl); if (pOdlData != null) { answ = pOdlData.IdxPromessa; } return answ; } /// /// Determina se abbia gestione folder dati in ritorno /// /// /// protected bool HasFolderMan(string idxMacc) { bool answ = true; // cerco nella LUT if (MachHasFolderLut.ContainsKey(idxMacc)) { answ = MachHasFolderLut[idxMacc]; } // se non trovo cerco nella cache... else { var rawVal = MDService.MachIobConfVal(idxMacc, KeyFolderMan); if (rawVal != null) { bool.TryParse((string)rawVal, out answ); MachHasFolderLut.Add(idxMacc, answ); } } return answ; } protected void KitToggleDetail(string? selCodArt) { if (!string.IsNullOrEmpty(selCodArt)) { ListKitTemplate = MDService.TemplateKitFilt(selCodArt, ""); } else { ListKitTemplate = null; } showKitDetail = !showKitDetail; } protected override async Task OnInitializedAsync() { ListStati = await MDService.AnagStatiComm(); ListArtKit = MDService.ArticoliGetByTipo("KIT", "*"); string SPEC_PODL_gest = await MDService.ConfigTryGetAsync("SPEC_PODL_gest"); if (!string.IsNullOrEmpty(SPEC_PODL_gest)) { bool.TryParse(SPEC_PODL_gest, out enableStartPODL); } string SPEC_ODL_gest = await MDService.ConfigTryGetAsync("SPEC_ODL_gest"); if (!string.IsNullOrEmpty(SPEC_ODL_gest)) { bool.TryParse(SPEC_ODL_gest, out enableStopODL); } string SPEC_XODL_sync = await MDService.ConfigTryGetAsync("SPEC_XODL_sync"); if (!string.IsNullOrEmpty(SPEC_XODL_sync)) { bool.TryParse(SPEC_XODL_sync, out enableForceSync); } } protected override async Task OnParametersSetAsync() { await ReloadData(); } protected async Task resetSel() { await selRecord(null); await ReloadData(); } protected async Task selBrowseRecord(ODLExpModel? currRec) { browseRecord = null; showBrowse = true; showStats = false; await Task.Delay(1); browseRecord = currRec; } protected async Task selRecord(ODLExpModel? currRec) { await Task.Delay(1); browseRecord = null; selDtFine = DateTime.Now; currRecord = currRec; showStats = false; ListOdlStats = null; } protected async Task selStatRecord(ODLExpModel? currRec) { browseRecord = null; showBrowse = false; showStats = true; await Task.Delay(1); statRecord = currRec; if (currRec != null) { await reloadStatsData(currRec); } else { showStats = false; ListOdlStats = null; } } protected async Task UpdateData() { await selRecord(null); await ReloadData(); } #endregion Protected Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); private ODLExpModel? browseRecord = null; private ODLExpModel? currRecord = null; /// /// Chiave gestione folder (hard coded, da IOB OptPar) /// private string KeyFolderMan = "OP_ODL_FOLDER"; /// /// Elenco articoli tipo KIT /// private List? ListArtKit; private List? ListKitTemplate = null; private List? ListOdlStats; private List? ListRecords; private List? ListStati; private List? SearchRecords; private bool showKitDetail = false; private ODLExpModel? statRecord = null; #endregion Private Fields #region Private Properties private int _totalCount { get; set; } = 0; private int currPage { get => currFilter.CurrPage; set => currFilter.CurrPage = value; } /// /// Indica se si tratti di ODL correnti /// private bool isCurrOdl { get => currFilter.IsActive; } private bool isLoading { get; set; } = false; private int numRecord { get => currFilter.NumRec; set => currFilter.NumRec = value; } private DateTime selDtFine { get; set; } = DateTime.Now; private bool showBrowse { get; set; } = false; private bool showStats { get; set; } = false; private int totalCount { get => _totalCount; set { if (_totalCount != value) { _totalCount = value; updateRecordCount.InvokeAsync(value); } } } #endregion Private Properties #region Private Methods private async Task ReloadData() { isLoading = true; SearchRecords = await MDService.OdlListGetFilt(currFilter.IsActive, currFilter.SearchVal, currFilter.CodFase, currFilter.CodReparto, currFilter.IdxMacchina, currFilter.DtStart, currFilter.DtEnd); totalCount = SearchRecords.Count; ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } private async Task reloadStatsData(ODLExpModel? currRec) { showStats = true; if (currRec != null) { ListOdlStats = await MDService.StatOdl(currRec.IdxOdl); } else { ListOdlStats = null; } } private string tradFase(string codFase) { string answ = codFase; if (ListStati != null && ListStati.Count > 0) { var recSel = ListStati.FirstOrDefault(x => x.value == codFase); if (recSel != null) { answ = recSel.label; } } return answ; } #endregion Private Methods } }