From f82dcb7aa4d2c5202b010991c3c2e59fadd734df Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 13 Jan 2022 12:03:00 +0100 Subject: [PATCH] COmpletata review ADM x ridurre chiamate DB --- GPW_Admin/WebUserControls/mod_adminFasi.ascx | 4 +- .../WebUserControls/mod_adminFasi.ascx.cs | 48 ++++++++++++++----- .../WebUserControls/mod_adminProgetti.ascx.cs | 2 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/GPW_Admin/WebUserControls/mod_adminFasi.ascx b/GPW_Admin/WebUserControls/mod_adminFasi.ascx index 45e4d3d..8519b33 100644 --- a/GPW_Admin/WebUserControls/mod_adminFasi.ascx +++ b/GPW_Admin/WebUserControls/mod_adminFasi.ascx @@ -34,7 +34,7 @@
- + @@ -187,7 +187,7 @@ - + diff --git a/GPW_Admin/WebUserControls/mod_adminFasi.ascx.cs b/GPW_Admin/WebUserControls/mod_adminFasi.ascx.cs index 2a312cb..2f3610c 100644 --- a/GPW_Admin/WebUserControls/mod_adminFasi.ascx.cs +++ b/GPW_Admin/WebUserControls/mod_adminFasi.ascx.cs @@ -524,32 +524,56 @@ namespace GPW_Admin.WebUserControls } /// - /// determina se sia eliminabile il record (=non usato) + /// Determina se sia eliminabile il record (=non ha ore caricate ne fasi) /// - /// + /// + /// /// - public bool delEnabled(object idxObj) + public bool delEnabled(object _totOre, object _idxFase) { bool answ = isWritable(); // solo se ha diritti scrittura controllo - if (idxObj != null) + if (answ && _totOre != null && _idxFase != null) { + double numOre = 0; + _ = Double.TryParse($"{_totOre}", out numOre); + answ = (numOre == 0); + // se fosse true --> procedo con controllo fasi if (answ) { - int trovati = 0; int idxFase = 0; - _ = int.TryParse(idxObj.ToString(), out idxFase); - trovati = DataProxy.DP.taRA.getByFase(idxFase).Count; - // controllo se ci sono record correlati... - if (trovati > 0) - { - answ = false; - } + _ = int.TryParse($"{_idxFase}", out idxFase); + answ = !hasChildObj(idxFase); } } return answ; } + /// + /// Determina se abbia child obj --> NON eliminabile + /// + /// + /// + public bool hasChildObj(int idxFase) + { + bool answ = false; + string redKey = memLayer.ML.redHash($"faseHasChildObj:{idxFase}"); + // cerco inc ache redis... + string rawData = memLayer.ML.getRSV(redKey); + if (rawData == null) + { + int trovati = DataProxy.DP.taRA.getByFase(this.idxFase).Count; + answ = (trovati > 0); + memLayer.ML.setRSV(redKey, $"{answ}", 60 * 5); + } + else + { + bool.TryParse(rawData, out answ); + } + return answ; + } + + /// /// effettua update controllo /// diff --git a/GPW_Admin/WebUserControls/mod_adminProgetti.ascx.cs b/GPW_Admin/WebUserControls/mod_adminProgetti.ascx.cs index 87a1553..82de875 100644 --- a/GPW_Admin/WebUserControls/mod_adminProgetti.ascx.cs +++ b/GPW_Admin/WebUserControls/mod_adminProgetti.ascx.cs @@ -634,7 +634,7 @@ namespace GPW_Admin.WebUserControls { bool answ = isWritable(); // solo se ha diritti scrittura controllo - if (totOre != null && answ) + if (answ && totOre != null && idxProj !=null) { double numOre = 0; _ = Double.TryParse($"{totOre}", out numOre);