using AppData;
using Newtonsoft.Json;
using SteamWare;
using System;
using System.Collections.Generic;
namespace NKC_WF
{
public class BaseUserControl : System.Web.UI.UserControl
{
#region Protected Fields
///
/// Membro gestione accessi al datalayer (istanza x ogni classe controllo)
///
protected DataLayer DLMan = new DataLayer();
#endregion Protected Fields
#region Public Events
///
/// Generico evento di richiesta refresh a aprent
///
public event EventHandler eh_doRefresh;
///
/// Generico evento di richiesta refresh a aprent
///
public event EventHandler eh_doReset;
#endregion Public Events
#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;
}
}
///
/// Postazione attuale (per ora cablata)
///
protected string PlaceId
{
get
{
return "WRK001";
}
}
#endregion Protected Properties
#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;
}
}
#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)
{
logger.lg.scriviLog(message, tipoLog.DEBUG);
}
///
/// Wrapper scrittura log ERROR
///
///
public void lgError(string message)
{
logger.lg.scriviLog(message, tipoLog.ERROR);
}
///
/// Wrapper scrittura log EXCEPTION
///
///
public void lgException(string message, Exception exc)
{
logger.lg.scriviLog($"{message}{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
}
///
/// Wrapper scrittura log FATAL
///
///
public void lgFatal(string message, Exception exc)
{
logger.lg.scriviLog(message, tipoLog.FATAL);
}
///
/// Wrapper scrittura log INFO
///
///
public void lgInfo(string message)
{
logger.lg.scriviLog(message, tipoLog.INFO);
}
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()
{
// 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);
}
#endregion Public Methods
}
}