using global::Microsoft.AspNetCore.Components; using MP.Data.DbModels; using MP.Data.Services; using NLog; using static EgwCoreLib.Utils.DtUtils; namespace MP_TAB3.Components { public partial class ControlsMan : IDisposable { #region Public Properties [Parameter] public EventCallback E_MachSel { get; set; } [Parameter] public EventCallback E_Updated { get; set; } [Parameter] public MappaStatoExplModel? RecMSE { get; set; } = null; #endregion Public Properties #region Public Methods public void Dispose() { ListComplete.Clear(); ListPaged.Clear(); } /// /// Aggiorno valori produzione alla data richiesta... /// /// public async Task doUpdate() { isProcessing = true; await Task.Delay(1); if (!string.IsNullOrEmpty(IdxMaccSel)) { ListComplete = await TabDServ.RegControlliFiltAsync(IdxMaccSel, IdxOdl, CurrPeriodo.Inizio, CurrPeriodo.Fine, false); TotalCount = ListComplete.Count; // esegue paginazione UpdateTable(); } isProcessing = false; await Task.Delay(1); } #endregion Public Methods #region Protected Properties protected string btnCss { get => showInsert ? "bt-dark text-primary border-primary border-2" : "btn-primary"; } protected string ConfTitle { get => showInsert ? "Nascondi Controllo" : "Registra Controllo"; } protected bool enableControlli { get; set; } = true; protected string faCss { get => showInsert ? "fa-chevron-up" : "fa-chevron-down"; } protected List ListComplete { get; set; } = new List(); protected List ListPaged { get; set; } = new List(); [Inject] protected MessageService MServ { get; set; } = null!; [Inject] protected SharedMemService SMServ { get; set; } = null!; [Inject] protected TabDataService TabDServ { get; set; } = null!; #endregion Protected Properties #region Protected Methods /// /// Restituisce il codice IdxMacchina dell'impianto PARENT (se multi) altrimenti la stessa macchina... /// protected string getIdxMaccParent() { string answ = IdxMaccSel; // se fosse multi controllo if (isMulti) { // verifico se SIA una tavola (ha char "#") int iSharp = IdxMaccSel.IndexOf('#'); if (iSharp > 0) { // sistemo nome answ = IdxMaccSel.Substring(0, iSharp); } } return answ; } protected override async Task OnInitializedAsync() { await Task.Delay(1); if (RecMSE != null) { enableControlli = SMServ.GetConfBool("enableControlli"); IdxMaccSel = RecMSE.IdxMacchina; isMulti = SMServ.DictMacchMulti[IdxMaccSel] == 1; if (isMulti) { var idxMSel = MServ.UserPrefGet(IdxMaccSel); if (!string.IsNullOrEmpty(idxMSel)) { IdxMaccSel = idxMSel; } } DateTime fine = DateTime.Today.AddDays(1); DateTime inizio = fine.AddDays(-3); CurrPeriodo = new Periodo(inizio, fine); await doUpdate(); } } protected async Task SaveKo() { isProcessing = true; await TabDServ.RegControlliInsert(IdxMaccSel, MServ.MatrOpr, false, noteKo, DateTime.Now); showInsert = false; showNote = false; await doUpdate(); await E_Updated.InvokeAsync(false); if (isMulti) { await E_MachSel.InvokeAsync(idxMaccAltraTav); await Task.Delay(100); } else { TabDServ.NotifyDataInvalidated(IdxMaccSel); } await E_MachSel.InvokeAsync(IdxMaccSel); Log.Info("Registrazione SaveKo x controllo pezzo"); isProcessing = false; } protected void SaveNumRec(int newNum) { NumRecPage = newNum; UpdateTable(); } protected async Task SaveOk() { isProcessing = true; await TabDServ.RegControlliInsert(IdxMaccSel, MServ.MatrOpr, true, noteKo, DateTime.Now); showInsert = false; showNote = false; await doUpdate(); await E_Updated.InvokeAsync(true); if (isMulti) { await E_MachSel.InvokeAsync(idxMaccAltraTav); await Task.Delay(100); } else { TabDServ.NotifyDataInvalidated(IdxMaccSel); } await E_MachSel.InvokeAsync(IdxMaccSel); Log.Info("Registrazione SaveOk x controllo pezzo"); isProcessing = false; } protected void SavePage(int newNum) { PageNum = newNum; UpdateTable(); } protected async Task SetMacc(string selIdxMacc) { isProcessing = true; await Task.Delay(1); IdxMaccSel = selIdxMacc; await doUpdate(); await Task.Delay(1); isProcessing = false; await E_MachSel.InvokeAsync(selIdxMacc); } protected async Task SetOdl(int selIdxOdl) { isProcessing = true; await Task.Delay(1); IdxOdl = selIdxOdl; await doUpdate(); isProcessing = false; await Task.Delay(1); } protected async Task SetPeriodo(Periodo newPeriodo) { CurrPeriodo = newPeriodo; await doUpdate(); } protected void ShowKo() { showNote = true; } protected void ToggleBtn() { showInsert = !showInsert; if (showInsert) { noteKo = ""; showNote = false; } } protected void UpdateTable() { // esegue paginazione if (TotalCount > NumRecPage) { ListPaged = ListComplete.Skip((PageNum - 1) * NumRecPage).Take(NumRecPage).ToList(); } else { ListPaged = ListComplete; } } #endregion Protected Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); private bool isMulti = false; private bool isProcessing = false; private string noteKo = ""; private int NumRecPage = 10; private int PageNum = 1; private bool showInsert = false; private bool showNote = false; private int TotalCount = 0; private bool useOdl = false; #endregion Private Fields #region Private Properties private Periodo CurrPeriodo { get; set; } = new Periodo(); private string IdxMaccAltra { get; set; } = ""; /// /// Restituisce il codice IdxMacchina dell'altra tavola (se multi) altrimenti la stessa macchina... /// private string idxMaccAltraTav { get { string answ = ""; if (RecMSE != null) { try { // verifico se SIA una tavola (ha char "#") int iSharp = IdxMaccMain.IndexOf('#'); if (iSharp > 0) { // ora verifico SE ALTRA TAVOLA ha ODL... string nomeTav = IdxMaccMain.Substring(iSharp); string altraTav = nomeTav.Substring(0, nomeTav.Length - 1); altraTav += nomeTav.EndsWith("1") ? "2" : "1"; // sistemo nome answ = IdxMaccMain.Replace(nomeTav, altraTav); } } catch { } } return answ; } } /// /// Macchina selezionata MAIN /// private string IdxMaccMain { get => RecMSE != null ? RecMSE.IdxMacchina : ""; } private string IdxMaccSel { get; set; } = ""; private int IdxOdl { get; set; } = 0; private string selMessage { get => useOdl ? "Periodo da ODL" : "Periodo Libero"; } private bool UseOdl { get => useOdl; set { useOdl = value; if (!value) { IdxOdl = 0; } } } #endregion Private Properties } }