using global::Microsoft.AspNetCore.Components; using MP.Data.DatabaseModels; using MP.Data.Services; using MP_TAB3.Shared; using System; using System.Reflection.Metadata; namespace MP_TAB3.Components { public partial class MachSel { #region Public Properties [Parameter] public EventCallback E_MachSel { get; set; } [Parameter] public MappaStatoExpl? RecMSE { get; set; } = null; #endregion Public Properties #region Protected Properties protected string IdxMaccSel { get => idxMaccSel; set { if (idxMaccSel != value) { idxMaccSel = value; MsgServ.UserPrefSet(idxMaccCurr, value); E_MachSel.InvokeAsync(value).ConfigureAwait(false); } } } private string idxMaccSel { get; set; } = ""; [Inject] protected MessageService MsgServ { get; set; } = null!; protected Dictionary? ListMacchine { get; set; } = null; [Inject] protected SharedMemService SMServ { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected string idxMaccCurr { get { string answ = ""; if (RecMSE != null) { answ = RecMSE?.IdxMacchina ?? ""; } return answ; } } protected override async Task OnParametersSetAsync() { // inizilamente riporto machcina corrente da MSE if (RecMSE == null) { IdxMaccSel = ""; } else { if (string.IsNullOrEmpty(idxMaccSel)) { // verifico se la macchina sia configurata tra le MSFD... if (SMServ.DictMacchMulti.ContainsKey(RecMSE.IdxMacchina)) { isMulti = SMServ.DictMacchMulti[RecMSE.IdxMacchina] == 1; } if (isMulti) { var listMulti = await TDataService.VMSFDGetAll(); ListMacchine = listMulti .Where(x => x.IdxMacchina.Contains($"{RecMSE.IdxMacchina}#")) .ToDictionary(x => x.IdxMacchina, x => x.CodMaccArticolo); if (ListMacchine.Count > 0) { // cerco se ho in storage la macchina selezionata... var idxMSel = MsgServ.UserPrefGet(idxMaccCurr); if (!string.IsNullOrEmpty(idxMSel)) { IdxMaccSel = idxMSel; } else { IdxMaccSel = ListMacchine.FirstOrDefault().Key; } } } } } await Task.Delay(1); } [Inject] protected TabDataService TDataService { get; set; } = null!; #endregion Protected Methods #region Private Fields private bool isMulti = false; #endregion Private Fields } }