using MagData; using Newtonsoft.Json; using SteamWare; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MP_MAG { public class BaseUserControl : System.Web.UI.UserControl { /// /// Generico evento di richiesta refresh a aprent /// public event EventHandler eh_doRefresh; /// /// Generico evento di richiesta refresh a aprent /// public event EventHandler eh_doReset; /// /// 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() { // se qualcuno ascolta sollevo evento nuovo valore... if (eh_doReset != null) { eh_doReset(this, new EventArgs()); } } /// /// Wrapper traduzione termini /// /// /// public string traduci(string lemma) { return SteamWare.user_std.UtSn.Traduci(lemma); } /// /// Codice operatore salvato in cookie /// protected string cookieCodOpr { get { return memLayer.ML.getCookieVal("CTrack_CodOpr"); } } /// /// Codice post salvato in cookie /// protected string cookieCodPost { get { return memLayer.ML.getCookieVal("CTrack_CodPost"); } } /// /// Chiave redis dei dati di prod correnti /// public string redProdKey { get { return memLayer.ML.redHash(memLayer.ML.CRS("redProdKey")); } } /// /// TTL dati redis x prod /// public int redProdKeyTTL { get { return memLayer.ML.CRI("redProdKeyTTL"); } } /// /// Dati correnti di produzione /// public prodData currProdData { get { prodData answ = null; try { string rawData = memLayer.ML.getRSV("redProdKey"); answ = JsonConvert.DeserializeObject(rawData); } catch { } // se vuoto leggo da DB if (answ == null) { answ = getProdDataDb; // salvo in sessione currProdData = answ; } return answ; } set { string rawData = JsonConvert.SerializeObject(value); memLayer.ML.setRSV(redProdKey, rawData, redProdKeyTTL); } } public bool resetProdData() { bool answ = false; try { currProdData = getProdDataDb; answ = true; } catch { } return answ; } /// /// Rilegge i dati di prod da DB /// protected prodData getProdDataDb { get { prodData answ = null; // leggo da DB ODL... var tabOdl = MagDataLayer.man.taODL.getOpenByPost(cookieCodPost); if (tabOdl.Count == 1) { var rigaOdl = tabOdl[0]; var tabArt = MagDataLayer.man.taAA.getByKey(rigaOdl.CodArticolo); string descrArt = "ND"; if (tabArt.Count == 1) { descrArt = tabArt[0].DescrArt; } answ = new prodData() { CodPost = cookieCodPost, CodOpr = cookieCodOpr, RifExt = rigaOdl.KeyRichiesta, CurrODL = $"{rigaOdl.IdxODL}", CurrArtCod = rigaOdl.CodArticolo, CurrArtDesc = descrArt }; // ora descr articolo } return answ; } } /// /// Codice operatore /// public string CodOpr { get { return currProdData.CodOpr; } } /// /// Codice post /// public string CodPost { get { return currProdData.CodPost; } } /// /// Rif esterno (da ODL) /// public string RifExt { get { return currProdData.RifExt; } } /// /// ODL corrente x post /// public string CurrOdl { get { return currProdData.CurrODL; } } /// /// ODL corrente x post /// public string CurrOdlDesc { get { return $"ODL: {currProdData.CurrODL}"; } } /// /// Articolo corrente x post /// public string CurrCodArt { get { return currProdData.CurrArtCod; } } /// /// Verifica se il cod articolo passato (tipicamente Eval DataGrid) sia OK con articolo corrente /// /// /// public bool codArtOk(object _codArt) { bool answ = false; if (_codArt != null) { if (!string.IsNullOrEmpty(_codArt.ToString())) { answ = _codArt.ToString() == CurrCodArt; } } return answ; } /// /// Descr Articolo corrente x post /// public string CurrArtDesc { get { var dati = currProdData; return $"{dati.CurrArtCod} | {dati.CurrArtDesc}"; } } #if false 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 = DataLayer.man.taMat.GetData(); foreach (var item in tabMat) { answ.Add(item.MatID, item.MatDesc); } // salvo in redis anagMateriali = answ; } // restituisco return answ; } } public string matByKey(object _matId) { string answ = ""; int matId = 0; int.TryParse(_matId.ToString(), out matId); try { answ = anagMateriali[matId]; } catch { } return answ; } #endif } }