367 lines
10 KiB
C#
367 lines
10 KiB
C#
using MapoDb;
|
|
using System;
|
|
|
|
namespace MoonPro.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;
|
|
protected DS_applicazione.KeepAliveDataTable tabKeepAlive;
|
|
/// <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 (IdxMacchina != "")
|
|
{
|
|
//DateTime tick = DateTime.Now;
|
|
// effettua update visualizzazione
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
pnlMacchina.Visible = false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// recupera i dati
|
|
/// </summary>
|
|
private void retrieveData()
|
|
{
|
|
try
|
|
{
|
|
// popolazione tabelle
|
|
tabMSE = MapoDb.DataLayer.obj.taMSE.getByIdxMacchina(IdxMacchina);
|
|
|
|
tabAnagStati = MapoDb.DataLayer.obj.taAnagStati.GetData();
|
|
tabKeepAlive = MapoDb.DataLayer.obj.taKeepAlive.GetData();
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
/// <summary>
|
|
/// sistema il testo
|
|
/// </summary>
|
|
private void updateText()
|
|
{
|
|
if (_IdxMacchina != "nd" && _IdxMacchina != "")
|
|
{
|
|
// labels
|
|
lblCodArticolo.Text = "Articolo";
|
|
lblStato.Text = "Stato";
|
|
lblProd.Text = "T.Ciclo medio"; // 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
|
|
{
|
|
MapoDb.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)
|
|
{
|
|
Session["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 hiperLink
|
|
/// </summary>
|
|
private void updateHL()
|
|
{
|
|
bool answ = false;
|
|
if (_IdxMacchina != "nd")
|
|
{
|
|
int minuti = SteamWare.memLayer.ML.confReadInt("keepAliveMin");
|
|
// controllo se il keep alive è oltre il termine...
|
|
DateTime lastKA = DateTime.Now.AddMinutes(-minuti);
|
|
try
|
|
{
|
|
lastKA = tabKeepAlive.FindByIdxMacchina(IdxMacchina).DataOraServer;
|
|
}
|
|
catch
|
|
{ }
|
|
if (lastKA.AddMinutes(minuti) < DateTime.Now)
|
|
{
|
|
answ = true;
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
/// <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);
|
|
}
|
|
catch
|
|
{
|
|
_IdxMacchina = "nd";
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// definisce se sia attivo il link della pagina
|
|
/// </summary>
|
|
public bool linkActive
|
|
{
|
|
get
|
|
{
|
|
return _linkActive;
|
|
}
|
|
set
|
|
{
|
|
_linkActive = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |