using AppData; using Newtonsoft.Json; using NKC_SDK; using SteamWare; using System; using System.Collections.Generic; using System.Web; namespace NKC_WF { public class BaseUserControl : System.Web.UI.UserControl { #region Public Fields /// /// Codice macchina (da v2) /// public string PlaceCod = "VIRTNE"; #endregion Public Fields #region Public Events /// /// Generico evento di richiesta refresh a parent /// public event EventHandler eh_doRefresh; /// /// Generico evento di richiesta refresh a aprent /// public event EventHandler eh_doReset; #endregion Public Events #region Public Properties /// /// verifica sia ambiente PROD (vs DEV) /// public bool checkProd { get { return memLayer.ML.CRS("environment") == "PROD"; } } /// /// Recupera IP utente /// /// public string currIpAddress { get { string userip = Request.UserHostAddress; return userip; } } /// /// pagina corrente... /// public string currPage { get { string url = HttpContext.Current.Request.Url.PathAndQuery; if (url.Contains("?")) { url = url.Substring(0, url.IndexOf("?")); } return url; } } #endregion Public Properties #region Public Methods /// /// determina CSS x colore testo da perc svuotamento... /// /// /// public string getCssByRatio(double ratio) { string answ = "text-dark"; if (ratio == 0) { answ = "text-danger"; } else if (ratio == 1) { answ = "text-success"; } else { answ = "text-warning"; } return answ; } /// /// Restituisce URL immagine QRCode /// /// Parametro da renderizzare con QRCode /// public string getImgUrl(object QrValue) { string baseUrl = $"{memLayer.ML.CRS("matrixUrl")}/HOME/QR_site/JSON?val="; string payload = "{'baseUrl':'{0}','parameters':['" + $"{QrValue}" + "']}"; string answ = $"{baseUrl}{payload}"; return answ; } /// /// Recupera valore intero da OBJ /// /// /// public double getInt(object _val) { int answ = -999999; int.TryParse(_val.ToString(), out answ); return answ; } /// /// Calcola il rapporto tra 2 valori /// /// /// /// public double getRatio(object _dividendo, object _divisore) { double ratio = 0; double dividendo = 0; double divisore = 1; double.TryParse(_dividendo.ToString(), out dividendo); double.TryParse(_divisore.ToString(), out divisore); // se divisore 0 --> 1 divisore = divisore == 0 ? 1 : divisore; ratio = dividendo / divisore; return ratio; } /// /// Wrapper scrittura log DEBUG /// /// public void lgDebug(string message) { Log.Instance.Debug(message); } /// /// Wrapper scrittura log ERROR /// /// public void lgError(string message) { Log.Instance.Error(message); } /// /// Wrapper scrittura log EXCEPTION /// /// public void lgException(string message, Exception exc) { Log.Instance.Error($"{message}{Environment.NewLine}{exc}"); } /// /// Wrapper scrittura log FATAL /// /// public void lgFatal(string message, Exception exc) { Log.Instance.Error($"{message}{Environment.NewLine}{exc}"); } /// /// Wrapper scrittura log INFO /// /// public void lgInfo(string message) { Log.Instance.Info(message); } public string matByKey(object _matId) { string answ = ""; int matId = 0; int.TryParse(_matId.ToString(), out matId); try { answ = anagMateriali[matId]; } catch { } return answ; } /// /// Converte obja intero /// /// /// public int obj2int(object valore) { int answ = 0; int.TryParse(valore.ToString(), out answ); return answ; } /// /// Chiamata evento /// public void raiseEvent() { // se qualcuno ascolta sollevo evento nuovo valore... if (eh_doRefresh != null) { eh_doRefresh(this, new EventArgs()); } } /// /// Chiamata evento /// public void raiseReset() { if (eh_doReset != null) { eh_doReset(this, new EventArgs()); } } /// /// Wrapper traduzione termini /// /// /// public string traduci(string lemma) { string answ = $"__{lemma}__"; try { answ = SteamWare.user_std.UtSn.Traduci(lemma); } catch { } return answ; } #endregion Public Methods #region Protected Fields /// /// Membro gestione accessi al datalayer (istanza x ogni classe controllo) /// protected DataLayer DLMan = new DataLayer(); #endregion Protected Fields #region Protected Properties protected Dictionary anagMateriali { set { string jsonData = JsonConvert.SerializeObject(value); memLayer.ML.setRSV("anagMateriali", jsonData, 60); } get { Dictionary answ = new Dictionary(); //cerco in redis... string rawData = memLayer.ML.getRSV("anagMateriali"); if (!string.IsNullOrEmpty(rawData)) { answ = JsonConvert.DeserializeObject>(rawData); } // sennò nel DB e salvo in redis... else { var tabMat = DLMan.taMat.GetData(); foreach (var item in tabMat) { answ.Add(item.MatID, item.MatDesc); } // salvo in redis anagMateriali = answ; } // restituisco return answ; } } #endregion Protected Properties } }