411 lines
12 KiB
C#
411 lines
12 KiB
C#
using MapoDb;
|
|
using Newtonsoft.Json;
|
|
using SteamWare;
|
|
using System;
|
|
|
|
namespace MP_SITE.WebUserControls
|
|
{
|
|
public partial class mod_statoMacchina : System.Web.UI.UserControl
|
|
{
|
|
#region area protected / private
|
|
|
|
/// <summary>
|
|
/// seriale associato alla macchina da controllare
|
|
/// </summary>
|
|
protected string _IdxMacchina;
|
|
/// <summary>
|
|
/// posizione macchina nella tabella
|
|
/// </summary>
|
|
protected string _locazione;
|
|
protected bool _linkActive = true;
|
|
|
|
protected DS_ProdTempi.MappaStatoExplDataTable tabMSE;
|
|
protected DS_applicazione.AnagraficaStatiDataTable tabAnagStati;
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
//updateMe();
|
|
}
|
|
/// <summary>
|
|
/// aggiorna controllo
|
|
/// </summary>
|
|
public void updateMe()
|
|
{
|
|
//SE E SOLO SE ho una macchina e/o locazione...
|
|
if (!string.IsNullOrEmpty(IdxMacchina) && !IdxMacchina.Contains("#") && (locazione != "00"))
|
|
{
|
|
// effettua update visualizzazione
|
|
try
|
|
{
|
|
retrieveData();
|
|
updateLayout();
|
|
updateText();
|
|
updateImg();
|
|
updateHL();
|
|
// controllo se link attivo...
|
|
if (!_linkActive)
|
|
{
|
|
valMacchina.Enabled = false;
|
|
}
|
|
//logger.lg.scriviLog(string.Format("Retrieve: {0}", DateTime.Now.Subtract(tick).Milliseconds), tipoLog.INFO);
|
|
divSegnaposto.Visible = false;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Eccezione in fase popolamento statoMacchina per IdxMacchina {IdxMacchina} - locazione {locazione}{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pnlMacchina.Visible = false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupera i dati
|
|
/// </summary>
|
|
private void retrieveData()
|
|
{
|
|
// cerco se ho i dati in REDIS x non richiederli...
|
|
string hashKeyMSE = memLayer.ML.redHash("Tab:MSE:" + IdxMacchina);
|
|
string hashKeyAS = memLayer.ML.redHash("Tab:AnagStati");
|
|
string serVal = "";
|
|
if (memLayer.ML.redKeyPresent(hashKeyMSE))
|
|
//if (memLayer.ML.redHashPresent(hashKeyMSE))
|
|
{
|
|
serVal = memLayer.ML.getRSV(hashKeyMSE);
|
|
|
|
tabMSE = JsonConvert.DeserializeObject<DS_ProdTempi.MappaStatoExplDataTable>(serVal);
|
|
//tabMSE = (DS_ProdTempi.MappaStatoExplDataTable)memLayer.ML.deserializeVal(serVal);
|
|
|
|
serVal = memLayer.ML.getRSV(hashKeyAS);
|
|
tabAnagStati = JsonConvert.DeserializeObject<DS_applicazione.AnagraficaStatiDataTable>(serVal);
|
|
//tabAnagStati = (DS_applicazione.AnagraficaStatiDataTable)memLayer.ML.deserializeVal(serVal);
|
|
}
|
|
else
|
|
{
|
|
// altrimenti prendo da DB...
|
|
try
|
|
{
|
|
// popolazione tabelle
|
|
tabMSE = DataLayer.obj.taMSE.getByIdxMacchina(IdxMacchina);
|
|
tabAnagStati = DataLayer.obj.taAnagStati.GetData();
|
|
}
|
|
catch
|
|
{ }
|
|
// salvo su DB! dati principali x 30 secondi...
|
|
serVal = memLayer.ML.serializeVal(tabMSE);
|
|
memLayer.ML.setRSV(hashKeyMSE, serVal, 30);
|
|
// anche il resto...
|
|
serVal = memLayer.ML.serializeVal(tabAnagStati);
|
|
memLayer.ML.setRSV(hashKeyAS, serVal);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// sistema il testo
|
|
/// </summary>
|
|
private void updateText()
|
|
{
|
|
if (_IdxMacchina != "nd" && _IdxMacchina != "")
|
|
{
|
|
// labels
|
|
lblCodArticolo.Text = "Art.";
|
|
lblStato.Text = "Stato";
|
|
lblProd.Text = "T.Ciclo"; // era OEE
|
|
lblDurata.Text = "Durata";
|
|
// 2018.02.05 cambio x fix nuovi impianti
|
|
// valMacchina.Text = tabMacchine.FindByIdxMacchina(IdxMacchina).Nome;
|
|
// valCodArticolo.Text = tabStatoMacchine.FindByIdxMacchina(IdxMacchina).CodArticolo;
|
|
|
|
// leggo valori da MSE...
|
|
valMacchina.Text = tabMSE[0].Nome;
|
|
valCodArticolo.Text = tabMSE[0].CodArticolo;
|
|
// carico ultimo stato che sia durato almeno 6 sec (0.1 min)
|
|
int idxStato = 0;
|
|
int oreTot = 0;
|
|
float minuti = 0;
|
|
try
|
|
{
|
|
DS_ProdTempi.stp_repDonati_getLastStatoDurataMacchinaRow rigaStato = DataLayer.obj.taDatiStatoMacch.GetData(IdxMacchina, 0.1)[0];
|
|
idxStato = rigaStato.idxStato;
|
|
oreTot = Convert.ToInt32(Math.Floor(rigaStato.Minuti / 60));
|
|
minuti = (float)rigaStato.Minuti - 60 * oreTot;
|
|
}
|
|
catch
|
|
{
|
|
// 2018.02.05 cambio x fix nuovi impianti
|
|
//idxStato = tabStatoMacchine.FindByIdxMacchina(IdxMacchina).IdxStato;
|
|
//DateTime inizioStato = tabStatoMacchine.FindByIdxMacchina(IdxMacchina).InizioStato;
|
|
//DateTime ora = DateTime.Now;
|
|
//TimeSpan durata = ora.Subtract(inizioStato);
|
|
//oreTot = durata.Days * 24 + durata.Hours;
|
|
//minuti = durata.Minutes;
|
|
idxStato = tabMSE[0].idxStato;
|
|
oreTot = (int)tabMSE[0].durata / 60;
|
|
minuti = (int)tabMSE[0].durata - 60 * oreTot;
|
|
}
|
|
// 2018.02.05 cambio x fix nuovi impianti
|
|
//valStato.Text = tabAnagStati.FindByIdxStato(idxStato).Descrizione;
|
|
valStato.Text = tabMSE[0].DescrizioneStato;
|
|
valDurata.Text = string.Format("{0}h {1}min", oreTot, minuti);
|
|
// solo se in stato NON di run...
|
|
if (idxStato != 13)
|
|
{
|
|
lblCausale.Text = "Causale fermo";
|
|
string cauFermo = "nd";
|
|
try
|
|
{
|
|
cauFermo = tabAnagStati.FindByIdxStato(tabMSE[0].idxStato).Descrizione;
|
|
//cauFermo = tabAnagStati.FindByIdxStato(Convert.ToInt32(tabStatoMacchine.FindByIdxMacchina(IdxMacchina).IdxStato)).Descrizione;
|
|
}
|
|
catch
|
|
{
|
|
// 2018.02.05 cambio x fix nuovi impianti
|
|
//cauFermo = string.Format("IN: {0}", tabStatoMacchine.FindByIdxMacchina(IdxMacchina).Value);
|
|
cauFermo = string.Format("IN: {0}", tabMSE[0].idxStato);
|
|
}
|
|
valCausale.Text = cauFermo;
|
|
}
|
|
else
|
|
{
|
|
lblCausale.Text = "";
|
|
valCausale.Text = "";
|
|
}
|
|
|
|
// ATTENZIONE! dati generati casualmente, da cambiare in produzione!!!
|
|
bool demoRandom = false;
|
|
if (demoRandom)
|
|
{
|
|
// indico a caso % pz prodotti...
|
|
Random RandomClass = new Random(DateTime.Now.Millisecond);
|
|
if (idxStato == 13)
|
|
{
|
|
valProd.Text = string.Format("{0:P}", RandomClass.NextDouble() / 4 + 0.75);
|
|
}
|
|
else if (oreTot > 8)
|
|
{
|
|
valProd.Text = string.Format("{0:P}", 0);
|
|
}
|
|
else
|
|
{
|
|
valProd.Text = string.Format("{0:P}", RandomClass.NextDouble() / 2 + 0.25);
|
|
}
|
|
}
|
|
else // mostra lo stesso valore per tutti e due
|
|
{
|
|
// prova...se non ha dati relativa mostra n/a - not available
|
|
|
|
DateTime Ora = DateTime.Now;
|
|
|
|
valProd.Text = "1H: ";
|
|
string emptyVal = "n/a <br />";
|
|
int numPezzi = 0;
|
|
// prova l'ultima ora
|
|
try
|
|
{
|
|
// conto num pezzi e divido 1h/pezzi
|
|
numPezzi = DataLayer.obj.taTempiCicloRilevati.getByMacchinaPeriodo(IdxMacchina, Ora.AddHours(-1), Ora).Rows.Count;
|
|
if (numPezzi > 0)
|
|
{
|
|
valProd.Text += String.Format("{0:#.00}m <br />", Math.Round((double)60 / numPezzi, 3));
|
|
}
|
|
else
|
|
{
|
|
valProd.Text += emptyVal;
|
|
}
|
|
}
|
|
|
|
catch
|
|
{
|
|
valProd.Text += emptyVal;
|
|
}
|
|
|
|
// prova le ultime 8 ore
|
|
|
|
valProd.Text += "8H: ";
|
|
numPezzi = 0;
|
|
try
|
|
{
|
|
// conto num pezzi e divido 1h/pezzi
|
|
numPezzi = DataLayer.obj.taTempiCicloRilevati.getByMacchinaPeriodo(IdxMacchina, Ora.AddHours(-8), Ora).Rows.Count;
|
|
if (numPezzi > 0)
|
|
{
|
|
valProd.Text += String.Format("{0:#.00}m ", Math.Round((double)480 / numPezzi, 3));
|
|
}
|
|
else
|
|
{
|
|
valProd.Text += emptyVal;
|
|
}
|
|
}
|
|
|
|
catch
|
|
{
|
|
valProd.Text += emptyVal;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// rimanda alla pagina di dettaglio della macchina scelta
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lnkMacchina_Click(object sender, EventArgs e)
|
|
{
|
|
if (linkActive)
|
|
{
|
|
memLayer.ML.setSessionVal("IdxMacchina", IdxMacchina);
|
|
Response.Redirect(string.Format("~/DettaglioMacchina?IdxMacchina={0}", IdxMacchina));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// aggiorna il layout grafico
|
|
/// </summary>
|
|
private void updateLayout()
|
|
{
|
|
if (_IdxMacchina != "nd")
|
|
{
|
|
try
|
|
{
|
|
// in base allo stato recupero il colore...
|
|
string codColore = resoconti.mngr.semaforoDaIdxStato(resoconti.mngr.statoMacchina(_IdxMacchina));
|
|
pnlMacchina.CssClass = codColore;
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// sistema hyperLink
|
|
/// </summary>
|
|
private void updateHL()
|
|
{
|
|
bool answ = false;
|
|
int minuti = memLayer.ML.CRI("keepAliveMin");
|
|
// controllo se il keep alive è oltre il termine...
|
|
DateTime lastKA = DateTime.Now.AddMinutes(-minuti);
|
|
if (_IdxMacchina != "nd")
|
|
{
|
|
string nomeVar = string.Format("KeepAlive:{0}", _IdxMacchina);
|
|
string redKey = memLayer.ML.redHash(nomeVar);
|
|
var _lastKA = memLayer.ML.getRSV(redKey);
|
|
if (_lastKA == null)
|
|
{
|
|
answ = true;
|
|
//cerco su DB...
|
|
try
|
|
{
|
|
var tabDati = DataLayer.obj.taKeepAlive.getByIdxMacchina(_IdxMacchina);
|
|
if (tabDati.Rows.Count > 0)
|
|
{
|
|
lastKA = tabDati[0].DataOraServer;
|
|
answ = (lastKA.AddMinutes(minuti) < DateTime.Now);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Eccezione in updateHL per IdxMacchina {IdxMacchina} - locazione {locazione}{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
}
|
|
hlComWarning.Visible = answ;
|
|
}
|
|
/// <summary>
|
|
/// metto a posto l'immagine
|
|
/// </summary>
|
|
protected void updateImg()
|
|
{
|
|
string urlMacchina;
|
|
if (_IdxMacchina != "nd")
|
|
{
|
|
urlMacchina = string.Format("~/images/macchine/{0}", resoconti.mngr.urlMacchina(IdxMacchina));
|
|
if (urlMacchina == "thumb_")
|
|
{
|
|
urlMacchina = "~/images/empty.png";
|
|
}
|
|
else
|
|
{
|
|
imgThumb.ToolTip = resoconti.mngr.nomeMacchina(IdxMacchina);
|
|
}
|
|
imgThumb.ImageUrl = urlMacchina;
|
|
}
|
|
else
|
|
{
|
|
urlMacchina = "~/images/empty.png";
|
|
imgThumb.ImageUrl = urlMacchina;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region area public
|
|
|
|
/// <summary>
|
|
/// Idx della macchina controllata
|
|
/// </summary>
|
|
public string IdxMacchina
|
|
{
|
|
get
|
|
{
|
|
return _IdxMacchina;
|
|
}
|
|
set
|
|
{
|
|
if (resoconti.mngr == null)
|
|
{
|
|
resoconti.mngr = new resoconti();
|
|
}
|
|
_IdxMacchina = value;
|
|
_locazione = resoconti.mngr.locazioneDaIdx(_IdxMacchina);
|
|
updateMe();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// stringa locazione macchina in tabella
|
|
/// </summary>
|
|
public string locazione
|
|
{
|
|
get
|
|
{
|
|
return _locazione;
|
|
}
|
|
set
|
|
{
|
|
if (resoconti.mngr == null)
|
|
{
|
|
resoconti.mngr = new resoconti();
|
|
}
|
|
_locazione = value;
|
|
try
|
|
{
|
|
_IdxMacchina = resoconti.mngr.idxDaLocazione(_locazione);
|
|
updateMe();
|
|
}
|
|
catch
|
|
{
|
|
_IdxMacchina = "nd";
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// definisce se sia attivo il link della pagina
|
|
/// </summary>
|
|
public bool linkActive
|
|
{
|
|
get
|
|
{
|
|
return _linkActive;
|
|
}
|
|
set
|
|
{
|
|
_linkActive = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |