From df32e85aab784aee9e719aaa3dab179f80946dcd Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 7 Mar 2025 13:54:44 +0100 Subject: [PATCH] Completato review TAB3 x DP --- MP-TAB3/Components/MachineBlock.razor.cs | 551 +++++++++++------------ MP-TAB3/Components/OdlMan.razor.cs | 2 +- 2 files changed, 263 insertions(+), 290 deletions(-) diff --git a/MP-TAB3/Components/MachineBlock.razor.cs b/MP-TAB3/Components/MachineBlock.razor.cs index f6a58099..eb06be66 100644 --- a/MP-TAB3/Components/MachineBlock.razor.cs +++ b/MP-TAB3/Components/MachineBlock.razor.cs @@ -11,9 +11,43 @@ namespace MP_TAB3.Components { public partial class MachineBlock { + #region Protected Fields + + protected string baseCss = "sem"; + protected int currMaxVal = 1000; + protected List innerCircleVals = new List(); + protected int kaFactor = 60 / 2; + protected int maxVal = 1000; + protected List outerCircleVals = new List(); + + #endregion Protected Fields + + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private bool enableDisegno = false; + private bool forceCloseOdl = true; + private int IdxOdl = 0; + private int IdxOdlAltra = 0; + private string imgBasePath = ""; + private bool inAttr = false; + private bool isLoading = false; + private bool isMulti = false; + private bool LastFullMode = true; + private string LastIdxMacchSub = ""; + private int LastKeepAliveMin = 5; + private MappaStatoExpl? LastRecMSE = null; + private bool LastShowCard = true; + private bool showOdlDetail = false; + private bool showPodl = false; + + #endregion Private Fields + #region Public Properties - public string currIpv4 { get; set; } = ""; +#if false + public string currIpv4 { get; set; } = ""; +#endif [Parameter] public bool doBlink { get; set; } = false; @@ -39,96 +73,8 @@ namespace MP_TAB3.Components [Parameter] public int Width { get; set; } = 0; - private bool LastFullMode = true; - private MappaStatoExpl? LastRecMSE = null; - private bool LastShowCard = true; - private int LastKeepAliveMin = 5; - private string LastIdxMacchSub = ""; - - /// - /// Info correnti secondo tipo selezione - /// - private MappaStatoExpl? CRecMSE - { - get - { - MappaStatoExpl? answ = RecMSE; - if (!string.IsNullOrEmpty(IdxMacchSub)) - { - answ = RecMSESub; - } - return answ; - } - } - - private MappaStatoExpl? RecMSESub { get; set; } = null; - #endregion Public Properties - #region Public Methods - - /// - /// formatta la durata in minuti in un modo "human readable" gg/ore/min - /// - /// minuti - /// - public static string FormatDurata(double? minuti) - { - string answ = "??"; - TimeSpan tempo = TimeSpan.FromMinutes(minuti ?? 0); - if (tempo.TotalMinutes < 60) - { - answ = $"{tempo.Minutes:00}:{tempo.Seconds:00}"; - } - else if (tempo.TotalHours < 24) - { - answ = $"{tempo.Hours}h {tempo.Minutes}m"; - } - else - { - answ = $"{tempo.Days}g {tempo.Hours}h"; - } - return answ; - } - - /// - /// url completo immagine - /// - /// - /// - public string ImgUrlMacc(string url) - { - if (string.IsNullOrEmpty(url.ToString())) - { - url = "Steamware.png"; - } - string fullPath = Path.Combine(imgBasePath, url); - return fullPath; - } - - protected int NumScartiConf - { - get => datiProdAct != null ? datiProdAct.PzConfScarto - datiProdAct.PzConfRilav : 0; - } - - #endregion Public Methods - - #region Protected Fields - - protected string baseCss = "sem"; - - protected int currMaxVal = 1000; - - protected List innerCircleVals = new List(); - - protected int kaFactor = 60 / 2; - - protected int maxVal = 1000; - - protected List outerCircleVals = new List(); - - #endregion Protected Fields - #region Protected Properties [Inject] @@ -241,6 +187,11 @@ namespace MP_TAB3.Components [Inject] protected NavigationManager NavMan { get; set; } = null!; + protected int NumScartiConf + { + get => datiProdAct != null ? datiProdAct.PzConfScarto - datiProdAct.PzConfRilav : 0; + } + [Inject] protected StatusData SDService { get; set; } = null!; @@ -252,8 +203,136 @@ namespace MP_TAB3.Components #endregion Protected Properties + #region Private Properties + + /// + /// Info correnti secondo tipo selezione + /// + private MappaStatoExpl? CRecMSE + { + get + { + MappaStatoExpl? answ = RecMSE; + if (!string.IsNullOrEmpty(IdxMacchSub)) + { + answ = RecMSESub; + } + return answ; + } + } + + private ODLExpModel currOdl { get; set; } = new ODLExpModel(); + private PODLExpModel currPodl { get; set; } = new PODLExpModel(); + private Dictionary heightList { get; set; } = new Dictionary() { { "200", "200px" }, { "400", "400px" }, { "600", "600px" }, { "800", "800px" }, { "1000", "1000px" } }; + + /// + /// 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 => CRecMSE != null ? CRecMSE.IdxMacchina : ""; + } + + /// + /// Macchina corrente (main oppure sub) + /// + private string IdxMaccCur + { + get => string.IsNullOrEmpty(IdxMacchSub) ? IdxMaccMain : IdxMacchSub; + } + + /// + /// Boolean Mobile vs Desktop + /// + private bool isMobile { get; set; } + + private MappaStatoExpl? RecMSESub { get; set; } = null; + + private bool showDraw { get; set; } = false; + + #endregion Private Properties + + #region Public Methods + + /// + /// formatta la durata in minuti in un modo "human readable" gg/ore/min + /// + /// minuti + /// + public static string FormatDurata(double? minuti) + { + string answ = "??"; + TimeSpan tempo = TimeSpan.FromMinutes(minuti ?? 0); + if (tempo.TotalMinutes < 60) + { + answ = $"{tempo.Minutes:00}:{tempo.Seconds:00}"; + } + else if (tempo.TotalHours < 24) + { + answ = $"{tempo.Hours}h {tempo.Minutes}m"; + } + else + { + answ = $"{tempo.Days}g {tempo.Hours}h"; + } + return answ; + } + + /// + /// url completo immagine + /// + /// + /// + public string ImgUrlMacc(string url) + { + if (string.IsNullOrEmpty(url.ToString())) + { + url = "Steamware.png"; + } + string fullPath = Path.Combine(imgBasePath, url); + return fullPath; + } + + #endregion Public Methods + #region Protected Methods + protected string isDisabled(bool testCond) + { + return testCond ? $"disabled" : ""; + } + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) @@ -286,15 +365,84 @@ namespace MP_TAB3.Components await Task.Delay(1); } - private void saveParams() + protected override async Task OnParametersSetAsync() { - LastIdxMacchSub = IdxMacchSub; - LastRecMSE = RecMSE; - LastFullMode = FullMode; - LastShowCard = ShowCard; - LastKeepAliveMin = KeepAliveMin; + // controllo variazione parametri... + if (paramsChanged()) + { + saveParams(); + DateTime adesso = DateTime.Now; + isLoading = RecMSE == null; + // controllo SE ho variazioni così rileggo + if (!string.IsNullOrEmpty(IdxMacchSub) && RecMSE != null) + { + RecMSESub = TabDServ.MseGetSub(RecMSE.IdxMacchina, IdxMacchSub, true); + } + else + { + RecMSESub = RecMSE; + } + if (CRecMSE != null) + { + if (SDService.MachNumPzGet(IdxMaccCur) != CRecMSE.PezziProd || SDService.MachProdStGet(IdxMaccCur).IdxOdl != CRecMSE.IdxOdl || (datiProdAct != null && datiProdAct.PzTotODL != CRecMSE.PezziProd)) + { + datiProdAct = await TabDServ.StatoProdMacchina(IdxMaccCur, adesso); + SDService.MachProdStSet(IdxMaccCur, datiProdAct); + SDService.MachNumPzSet(IdxMaccCur, CRecMSE.PezziProd); + } + else + { + datiProdAct = SDService.MachProdStGet(IdxMaccCur); + } + isMulti = SMServ.DictMacchMulti[IdxMaccMain] == 1; + await ReloadXDL(true); + } + setGaugeVals(); + } } + protected void setGaugeVals() + { + if (RecMSE != null) + { + innerCircleVals.Clear(); + outerCircleVals.Clear(); + currMaxVal = int.Parse(CRecMSE.NumPezzi.ToString()!); + innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#FFC107", Value = CRecMSE.PezziProd }); + if (CRecMSE.PezziConf > 0) + { + innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#198754", Value = CRecMSE.PezziConf }); + // se ho scarti aggiungo all'inizio + if (datiProdAct != null && datiProdAct.PzConfScarto > 0) + { + innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#CD1916", Value = datiProdAct.PzConfScarto }); + } + } + if (CRecMSE.extraVal > 0) + { + outerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#1367FD", Value = CRecMSE.extraVal }); + } + //Log.Trace($"MBlock | {RecMSE.IdxMacchina} | 03"); + } + else + { + Log.Info("MBlock NO DATA"); + } + } + + protected async Task ShowDetail() + { + // salvo idxMacch + await MServ.IdxMaccSet(RecMSE!.IdxMacchina); + await MServ.LastOpenedPageSet("machine-detail"); + // navigo! + NavMan.NavigateTo($"machine-detail"); + } + + #endregion Protected Methods + + #region Private Methods + /// /// Verifica variazione parametri /// @@ -315,200 +463,16 @@ namespace MP_TAB3.Components return false; } - protected override async Task OnParametersSetAsync() - { - // controllo variazione parametri... - if (paramsChanged()) - { - saveParams(); - DateTime adesso = DateTime.Now; - isLoading = RecMSE == null; - // controllo SE ho variazioni così rileggo - if (RecMSE != null) - { - if (SDService.MachNumPzGet(RecMSE.IdxMacchina) != RecMSE.PezziProd || SDService.MachProdStGet(RecMSE.IdxMacchina).IdxOdl != RecMSE.IdxOdl || (datiProdAct != null && datiProdAct.PzTotODL != RecMSE.PezziProd)) - { - datiProdAct = await TabDServ.StatoProdMacchina(RecMSE.IdxMacchina, adesso); - SDService.MachProdStSet(RecMSE.IdxMacchina, datiProdAct); - SDService.MachNumPzSet(RecMSE.IdxMacchina, RecMSE.PezziProd); - } - else - { - datiProdAct = SDService.MachProdStGet(RecMSE.IdxMacchina); - } - - if (string.IsNullOrEmpty(IdxMaccSel)) - { - IdxMaccSel = RecMSE.IdxMacchina; - } - isMulti = SMServ.DictMacchMulti[RecMSE.IdxMacchina] == 1; - } - if (!string.IsNullOrEmpty(IdxMacchSub) && RecMSE != null) - { - RecMSESub = TabDServ.MseGetSub(RecMSE.IdxMacchina, IdxMacchSub, true); - } - else - { - RecMSESub = RecMSE; - } - setGaugeVals(); - } - } - - protected void setGaugeVals() - { - if (RecMSE != null) - { - innerCircleVals.Clear(); - outerCircleVals.Clear(); - currMaxVal = int.Parse(RecMSE.NumPezzi.ToString()!); - innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#FFC107", Value = RecMSE.PezziProd }); - if (RecMSE.PezziConf > 0) - { - innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#198754", Value = RecMSE.PezziConf }); - // se ho scarti aggiungo all'inizio - if (datiProdAct != null && datiProdAct.PzConfScarto > 0) - { - innerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#CD1916", Value = datiProdAct.PzConfScarto }); - } - } - if (RecMSE.extraVal > 0) - { - outerCircleVals.Add(new CircleGaugeMulti.CircSegm() { Color = "#1367FD", Value = RecMSE.extraVal }); - } - //Log.Trace($"MBlock | {RecMSE.IdxMacchina} | 03"); - } - else - { - Log.Info("MBlock NO DATA"); - } - } - - protected async Task ShowDetail() - { - // salvo idxMacch - await MServ.IdxMaccSet(RecMSE!.IdxMacchina); - await MServ.LastOpenedPageSet("machine-detail"); - // navigo! - NavMan.NavigateTo($"machine-detail"); - } - - #endregion Protected Methods - - #region Private Fields - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private bool enableDisegno = false; - private bool forceCloseOdl = true; - private int IdxOdl = 0; - private int IdxOdlAltra = 0; - private string imgBasePath = ""; - private bool inAttr = false; - private bool isLoading = false; - private bool isMulti = false; - private bool showOdlDetail = false; - private bool showPodl = false; - - protected string isDisabled(bool testCond) - { - return testCond ? $"disabled" : ""; - } - - #endregion Private Fields - - #region Private Properties - - private ODLExpModel currOdl { get; set; } = new ODLExpModel(); - private PODLExpModel currPodl { get; set; } = new PODLExpModel(); - private Dictionary heightList { get; set; } = new Dictionary() { { "200", "200px" }, { "400", "400px" }, { "600", "600px" }, { "800", "800px" }, { "1000", "1000px" } }; - - /// - /// 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 = IdxMaccSel.IndexOf('#'); - if (iSharp > 0) - { - // ora verifico SE ALTRA TAVOLA ha ODL... - string nomeTav = IdxMaccSel.Substring(iSharp); - string altraTav = nomeTav.Substring(0, nomeTav.Length - 1); - altraTav += nomeTav.EndsWith("1") ? "2" : "1"; - // sistemo nome - answ = IdxMaccSel.Replace(nomeTav, altraTav); - } - } - catch - { } - } - return answ; - } - } - - private string IdxMaccSel { get; set; } = ""; - - /// - /// Boolean Mobile vs Desktop - /// - private bool isMobile { get; set; } - - private bool showDraw { get; set; } = false; - - #endregion Private Properties - - #region Private Methods - - private string cssComStatus(string semaforo, DateTime? lastUpdateN) - { - DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); - string answ = cssStatus(semaforo); - if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (KeepAliveMin * kaFactor)) - { - answ = $"{baseCss}Ro"; - // blink se secondo pari... - DateTime adesso = DateTime.Now; - int resto = 0; - Math.DivRem(adesso.Second, 2, out resto); - if (resto == 0) - { - answ += "_b"; - } - } - - return answ; - } - - private string cssStatus(string codSemaforo) - { - // se vuoto --> mostra nero! - if (string.IsNullOrEmpty(codSemaforo)) - { - codSemaforo = "sNe"; - } - - string codColore = codSemaforo.Substring(1, 2); - string answ = $"{baseCss}{codColore}"; - return answ; - } - private async Task ReloadXDL(bool reloadFromOdl) { - if (RecMSE != null) + if (CRecMSE != null) { - int currIdxPOdl = RecMSE.IdxPOdl ?? 0; - if (RecMSE != null) + int currIdxPOdl = CRecMSE.IdxPOdl ?? 0; + if (CRecMSE != null) { if (reloadFromOdl) { - currIdxPOdl = RecMSE.IdxPOdl ?? 0; + currIdxPOdl = CRecMSE.IdxPOdl ?? 0; } // se ho PODL valido... if (currIdxPOdl > 0) @@ -519,12 +483,12 @@ namespace MP_TAB3.Components { currPodl = new PODLExpModel() { - IdxOdl = RecMSE.IdxOdl ?? 0, + IdxOdl = CRecMSE.IdxOdl ?? 0, KeyRichiesta = "-", - CodArticolo = RecMSE.CodArticolo, - DescArticolo = RecMSE.CodArticolo, - NumPezzi = RecMSE.NumPezzi, - Tcassegnato = RecMSE.TCAssegnato + CodArticolo = CRecMSE.CodArticolo, + DescArticolo = CRecMSE.CodArticolo, + NumPezzi = CRecMSE.NumPezzi, + Tcassegnato = CRecMSE.TCAssegnato }; } } @@ -537,6 +501,15 @@ namespace MP_TAB3.Components } } + private void saveParams() + { + LastIdxMacchSub = IdxMacchSub; + LastRecMSE = RecMSE; + LastFullMode = FullMode; + LastShowCard = ShowCard; + LastKeepAliveMin = KeepAliveMin; + } + /// /// Toggle visibilità button /// @@ -558,7 +531,7 @@ namespace MP_TAB3.Components if (RecMSE != null) { // sistemo idxOdl... - var tabOdl = await TabDServ.OdlCurrByMacc(IdxMaccSel, false); + var tabOdl = await TabDServ.OdlCurrByMacc(IdxMaccMain, false); IdxOdl = tabOdl.IdxOdl; if (isMulti) { diff --git a/MP-TAB3/Components/OdlMan.razor.cs b/MP-TAB3/Components/OdlMan.razor.cs index 1f9318f0..23958164 100644 --- a/MP-TAB3/Components/OdlMan.razor.cs +++ b/MP-TAB3/Components/OdlMan.razor.cs @@ -1242,7 +1242,7 @@ namespace MP_TAB3.Components // var pUpd = Task.Run(async () => // { // // controllo ANCHE che la tav correntemente selezionata NON abbia pezzi da confermare - // datiProdAct = await TabDServ.StatoProdMacchina(IdxMaccSel, adesso); + // datiProdAct = await TabDServ.StatoProdMacchina(IdxMaccMain, adesso); // answ = datiProdAct.PzConfBuoni == 0 && datiProdAct.Pz2RecScarto == 0; // }); // pUpd.Wait();