839 lines
32 KiB
C#
839 lines
32 KiB
C#
using MapoDb.DS_ProdTempiTableAdapters;
|
|
using MapoSDK;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
|
|
namespace MapoDb
|
|
{
|
|
public class MapoDb
|
|
{
|
|
#region Public Fields
|
|
|
|
public DS_applicazioneTableAdapters.AnagraficaEventiTableAdapter taAnagEv;
|
|
public DS_applicazioneTableAdapters.AnagraficaStatiTableAdapter taAnagSt;
|
|
public DS_applicazioneTableAdapters.AnagraficaOperatoriTableAdapter taAnOpr;
|
|
public DS_applicazioneTableAdapters.DatiMacchineTableAdapter taDatiMacch;
|
|
|
|
// area tempi ciclo
|
|
public DS_ProdTempiTableAdapters.DatiMacchineTableAdapter taDatiMacchine;
|
|
|
|
public DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter taDiario;
|
|
|
|
// area applicazione
|
|
public DS_applicazioneTableAdapters.EventListTableAdapter taEvList;
|
|
|
|
public DS_applicazioneTableAdapters.KeepAliveTableAdapter taKeepAlive;
|
|
public DS_ProdTempiTableAdapters.Macchine2SlaveTableAdapter taM2S;
|
|
public DS_applicazioneTableAdapters.MacchineTableAdapter taMacchine;
|
|
public DS_applicazioneTableAdapters.MSFDTableAdapter taMSFD;
|
|
public DS_applicazioneTableAdapters.MicroStatoMacchinaTableAdapter taMSM;
|
|
public DS_ProdTempiTableAdapters.ODLTableAdapter taODL;
|
|
public DS_applicazioneTableAdapters.RemoteRebootLogTableAdapter taRRL;
|
|
public DS_applicazioneTableAdapters.StatoMacchineTableAdapter taStatoMacchine;
|
|
public DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter taTCRilevati;
|
|
public DS_applicazioneTableAdapters.TransizioneEventiTableAdapter taTranEv;
|
|
public DS_applicazioneTableAdapters.TransizioneIngressiTableAdapter taTransIngr;
|
|
public DS_applicazioneTableAdapters.TransizioneStatiTableAdapter taTranSt;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// avvio della classe
|
|
/// </summary>
|
|
public MapoDb()
|
|
{
|
|
AvviaTabAdapt();
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Testituisce tabella con riga dell'ODL attivo (iniziato e NON concluso)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public DS_ProdTempi.ODLDataTable currODLTab(string idxMacchina)
|
|
{
|
|
DS_ProdTempi.ODLDataTable answ = null;
|
|
logger.lg.scriviLog("Recupero currODLTab da DB!", tipoLog.INFO);
|
|
try
|
|
{
|
|
//2020.01.31 nuovo obj x evitare singleton
|
|
DataLayer man = new DataLayer();
|
|
answ = man.taODL.getByMacchina(idxMacchina);
|
|
//answ = DataLayer.obj.taODL.getByMacchina(idxMacchina);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Eccezione in recupero currODLTab{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
|
}
|
|
// restituisco!
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce tabella con riga stato macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public DS_applicazione.StatoMacchineDataTable currStatoMaccTab(string idxMacchina)
|
|
{
|
|
DS_applicazione.StatoMacchineDataTable answ = null;
|
|
logger.lg.scriviLog("Recupero currStatoMaccTab da DB!", tipoLog.INFO);
|
|
try
|
|
{
|
|
// 2020.01.31 creo nuovo obj x lettura
|
|
DataLayer man = new DataLayer();
|
|
answ = man.taStatoMacchine.GetDataByIdxMacchina(idxMacchina);
|
|
//answ = DataLayer.obj.taStatoMacchine.GetDataByIdxMacchina(idxMacchina);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Eccezione in recupero currStatoMaccTab{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
|
}
|
|
// restituisco!
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// cancella tutti gli eventi
|
|
/// </summary>
|
|
public void deleteAllEventi()
|
|
{
|
|
taEvList.DeleteAll();
|
|
}
|
|
|
|
/// <summary>
|
|
/// cancella tutti gli stati
|
|
/// </summary>
|
|
public void deleteAllStati()
|
|
{
|
|
taDiario.DeleteAll();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dichiara esplicitamente produzione e tempo ciclo rilevato per il numero di pezzi
|
|
/// indicati (real time, NON confermati)
|
|
/// </summary>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="CodArticolo"></param>
|
|
/// <param name="tempoRilevato"></param>
|
|
/// <param name="numPz"></param>
|
|
/// <param name="eventTime"></param>
|
|
/// <param name="currentTime"></param>
|
|
public void dichiaraProduzTempoCiclo(string IdxMacchina, string CodArticolo, decimal tempoRilevato, int numPz, DateTime eventTime, DateTime currentTime)
|
|
{
|
|
// calcolo dataOra reale (evento + delta(ora server - ora remota)
|
|
DateTime dataOra = eventTime.Add(DateTime.Now - currentTime);
|
|
// scrivo il dato del TC rilevato
|
|
taTCRilevati.Insert(IdxMacchina, CodArticolo, dataOra, tempoRilevato, numPz);
|
|
}
|
|
|
|
/// <summary>
|
|
/// fornisce tabella elenco eventi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DS_applicazione.EventListDataTable elencoEventi()
|
|
{
|
|
return taEvList.GetData();
|
|
}
|
|
|
|
public DS_applicazione.EventListDataTable elencoEventiImpianto(string idxMacchina)
|
|
{
|
|
return taEvList.GetDataByIdxMacchina(idxMacchina);
|
|
}
|
|
|
|
public DS_applicazione.EventListDataTable elencoEventiImpiantoPeriodo(string idxMacchina, DateTime dal, DateTime al)
|
|
{
|
|
return taEvList.GetByMacchinaPeriodo(idxMacchina, dal, al);
|
|
}
|
|
|
|
/// <summary>
|
|
/// fornisce tabella elenco stati (DiarioDiBordo)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DS_applicazione.DiarioDiBordoDataTable elencoStati()
|
|
{
|
|
return taDiario.GetData();
|
|
}
|
|
|
|
public DS_applicazione.DiarioDiBordoDataTable elencoStatiImpianto(string idxMacchina)
|
|
{
|
|
return taDiario.GetDataByIdxMacchina(idxMacchina);
|
|
}
|
|
|
|
public DS_applicazione.DiarioDiBordoDataTable elencoStatiImpiantoPeriodo(string idxMacchina, DateTime dal, DateTime al)
|
|
{
|
|
DS_applicazione.DiarioDiBordoDataTable answ = new DS_applicazione.DiarioDiBordoDataTable();
|
|
try
|
|
{
|
|
answ = taDiario.GetByMacchinaPeriodo(idxMacchina, dal, al);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Eccezione recupero elencoStatiImpiantoPeriodo:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto
|
|
/// cercato tutti delimitati da separatore
|
|
/// </summary>
|
|
/// <param name="chiave"></param>
|
|
/// <returns></returns>
|
|
public string getAnagEventi(string chiave)
|
|
{
|
|
int IdxTipo = Convert.ToInt32(chiave);
|
|
string _nomi = "";
|
|
string _valori = "";
|
|
DS_applicazione.AnagraficaEventiDataTable tabella = taAnagEv.GetByIdx(IdxTipo);
|
|
foreach (System.Data.DataColumn colonna in tabella.Columns)
|
|
{
|
|
_nomi += string.Format("{0}{1}", colonna.ColumnName, _separatore);
|
|
_valori += string.Format("{0}{1}", tabella[0][colonna.ColumnName], _separatore);
|
|
}
|
|
return string.Format("{0}\n\r{1}\n\r", _nomi, _valori);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto
|
|
/// cercato tutti delimitati da separatore
|
|
/// </summary>
|
|
/// <param name="chiave"></param>
|
|
/// <returns></returns>
|
|
public string getAnagMacchine(string chiave)
|
|
{
|
|
string _nomi = "";
|
|
string _valori = "";
|
|
DS_applicazione.MacchineDataTable tabella = taMacchine.GetByIdx(chiave);
|
|
foreach (System.Data.DataColumn colonna in tabella.Columns)
|
|
{
|
|
_nomi += string.Format("{0}{1}", colonna.ColumnName, _separatore);
|
|
_valori += string.Format("{0}{1}", tabella[0][colonna.ColumnName], _separatore);
|
|
}
|
|
return string.Format("{0}\n\r{1}\n\r", _nomi, _valori);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto
|
|
/// cercato tutti delimitati da separatore
|
|
/// </summary>
|
|
/// <param name="chiave"></param>
|
|
/// <returns></returns>
|
|
public string getAnagStati(string chiave)
|
|
{
|
|
int IdxStato = Convert.ToInt32(chiave);
|
|
string _nomi = "";
|
|
string _valori = "";
|
|
DS_applicazione.AnagraficaStatiDataTable tabella = taAnagSt.GetByIdx(IdxStato);
|
|
foreach (System.Data.DataColumn colonna in tabella.Columns)
|
|
{
|
|
_nomi += string.Format("{0}{1}", colonna.ColumnName, _separatore);
|
|
_valori += string.Format("{0}{1}", tabella[0][colonna.ColumnName], _separatore);
|
|
}
|
|
return string.Format("{0}\n\r{1}\n\r", _nomi, _valori);
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce cognome nome dell'operatore data la sua matricola
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public string getCognomeNomeDaMatr(int matrOpr)
|
|
{
|
|
return getGeneralitDaMatr(matrOpr);
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce cognome nome dell'operatore data idx macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public string getCognomeNomeOprMacchina(string idxMacchina)
|
|
{
|
|
string cognNome = "";
|
|
try
|
|
{
|
|
cognNome = getGeneralitDaMatr(getMatrOpMacc(idxMacchina));
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return cognNome;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce la stringa del colore della macchina (1 char, V/G/R)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public string getColoreMacchina(string idxMacchina)
|
|
{
|
|
string colore = "";
|
|
// cerco stato macchina...
|
|
DS_applicazione.StatoMacchineRow rigaStato;
|
|
try
|
|
{
|
|
rigaStato = taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0];
|
|
// cerco il colore...
|
|
try
|
|
{
|
|
colore = taAnagSt.GetByIdx(rigaStato.IdxStato)[0].Semaforo;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return colore;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce l'oggetto tipizzato che rappresenta i dati del setup di una macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public DS_applicazione.DatiMacchineRow getDatiMacchina(string idxMacchina)
|
|
{
|
|
DS_applicazione.DatiMacchineRow answ = null;
|
|
try
|
|
{
|
|
answ = taDatiMacch.GetByIdx(idxMacchina)[0];
|
|
}
|
|
catch
|
|
{
|
|
SteamWare.logger.lg.scriviLog(string.Format("Non sono riuscito a leggere la conf della macchina {0}", idxMacchina), SteamWare.tipoLog.ERROR);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce la matricola dell'operatore sulla macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public int getMatrOprMacchina(string idxMacchina)
|
|
{
|
|
return getMatrOpMacc(idxMacchina);
|
|
}
|
|
|
|
/// <summary>
|
|
/// fornisce il prossimo IdxMicroStato della macchina a stati della gestione segnali in input
|
|
/// </summary>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="IdxMicroStato"></param>
|
|
/// <param name="ValoreIngresso"></param>
|
|
/// <returns></returns>
|
|
public hwMachineState getNextMicroStato(string IdxMacchina, int IdxMicroStato, int ValoreIngresso)
|
|
{
|
|
hwMachineState valori = new hwMachineState();
|
|
valori.IdxTipoEvento = -1;
|
|
valori.next_IdxMicroStato = IdxMicroStato; // se non trovo un nuovo stato, resto in questo
|
|
// provo a recuperare i dati...
|
|
DS_applicazione.TransizioneIngressiRow rigaIngr;
|
|
try
|
|
{
|
|
rigaIngr = taTransIngr.GetNextStatus(IdxMacchina, IdxMicroStato, ValoreIngresso)[0];
|
|
valori.IdxTipoEvento = rigaIngr.IdxTipoEvento;
|
|
valori.next_IdxMicroStato = rigaIngr.next_IdxMicroStato;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return valori;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce la stringa del pallet correntemente in lavorazione sulla macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public string getPalletMacchina(string idxMacchina)
|
|
{
|
|
string pallet = "";
|
|
try
|
|
{
|
|
pallet = (taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0]).pallet;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return pallet;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce una riga di dati relativa ad una macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public DS_applicazione.MacchineRow getRigaMacchina(string idxMacchina)
|
|
{
|
|
return taMacchine.GetByIdx(idxMacchina)[0];
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce una riga di dati relativa ad una macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public DS_applicazione.StatoMacchineRow getRigaStatoMacchina(string idxMacchina)
|
|
{
|
|
return taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0];
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce la riga di transizione del comando...
|
|
/// </summary>
|
|
/// <param name="descrComando"></param>
|
|
/// <returns></returns>
|
|
public DS_applicazione.TransizioneEventiRow getRigaTransizioneDaDescrComando(string descrComando)
|
|
{
|
|
return taTranEv.getByDescrComando(descrComando)[0];
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce la stringa di connessione al db
|
|
/// </summary>
|
|
public string getStringaConnessione()
|
|
{
|
|
return _connectionString;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce boolean se la macchina sia abilitata x inserimento dati (tab DatiMacchine)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public bool insEnabled(string idxMacchina)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
answ = taDatiMacch.GetByIdx(idxMacchina)[0].insEnabled;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica un codice se sia di tipo "comando"
|
|
/// </summary>
|
|
/// <param name="comando"></param>
|
|
/// <returns></returns>
|
|
public inputComandoMapo isComando(string comando)
|
|
{
|
|
inputComandoMapo answ = new inputComandoMapo();
|
|
answ.isValid = false;
|
|
DS_applicazione.TransizioneEventiDataTable tabTransEv = new DS_applicazione.TransizioneEventiDataTable();
|
|
try
|
|
{
|
|
tabTransEv = taTranEv.GetDataByCodInviato(comando);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
if (tabTransEv.Rows.Count != 0)
|
|
{
|
|
answ.isValid = true;
|
|
answ.idxTipoEvento = tabTransEv[0].IdxTipoEvento;
|
|
answ.precInput = tabTransEv[0].prec_codInviato;
|
|
answ.text2show = tabTransEv[0].text2show;
|
|
try
|
|
{
|
|
answ.descrComando = tabTransEv[0].descrComando;
|
|
}
|
|
catch
|
|
{
|
|
answ.descrComando = "-";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il valore booleano se la macchina sia di tipo MASTER (ODL)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public bool isMaster(string idxMacchina)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
// 2017.07.11 se richiesto di NON usare singleton... riporto FUORI la gestione NUOVO oggetto
|
|
if (memLayer.ML.CRB("disable_singleton"))
|
|
{
|
|
taM2S = new Macchine2SlaveTableAdapter();
|
|
}
|
|
answ = taM2S.getByMaster(idxMacchina).Rows.Count > 1;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il valore booleano se la macchina sia di tipo MULTI (con pi� state machine x INGRESSI)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public bool isMulti(string idxMacchina)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
// 2017.07.11 se richiesto di NON usare singleton... riporto FUORI la gestione NUOVO oggetto
|
|
if (memLayer.ML.CRB("disable_singleton"))
|
|
{
|
|
//2017.06.09 forzo inizializzazione oggetto..
|
|
taMSFD = new DS_applicazioneTableAdapters.MSFDTableAdapter();
|
|
}
|
|
answ = taMSFD.getByIdxMacc(idxMacchina)[0].Multi == 1;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica che il bar code sia un barcode nomeMacchina
|
|
/// </summary>
|
|
/// <param name="codice">Bar code da verificare</param>
|
|
/// <returns>true se bar code per operatore</returns>
|
|
public bool isNomeMacchina(string codice)
|
|
{
|
|
// FARE!!! controllare quale codice ci vuole controlli validit� bar code nomeMacchina :
|
|
// deve cominciare con O maiuscola
|
|
bool check = codice.StartsWith("C#");
|
|
return check;
|
|
}
|
|
|
|
/// <summary>
|
|
/// verifica che il bar code sia un barcode Operatore
|
|
/// </summary>
|
|
/// <param name="codice">Bar code da verificare</param>
|
|
/// <returns>true se bar code per operatore</returns>
|
|
public bool isOperatore(string codice)
|
|
{
|
|
// controlli validit� bar code operatore : deve cominciare con O maiuscola
|
|
bool check = codice.StartsWith("O");
|
|
return check;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il valore booleano se la macchina sia di tipo SLAVE (ODL)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public bool isSlave(string idxMacchina)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
// 2017.07.11 se richiesto di NON usare singleton... riporto FUORI la gestione NUOVO oggetto
|
|
if (memLayer.ML.CRB("disable_singleton"))
|
|
{
|
|
taM2S = new Macchine2SlaveTableAdapter();
|
|
}
|
|
answ = taM2S.getBySlave(idxMacchina).Rows.Count > 1;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
public DS_applicazione.DiarioDiBordoDataTable nextEventoImpiantoFrom(string idxMacchina, DateTime prevData)
|
|
{
|
|
return taDiario.getNextByMacchInizioStato(idxMacchina, prevData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="IPv4"></param>
|
|
/// <param name="agent"></param>
|
|
/// <param name="macAddr">mac address (inviato dalla macchina)</param>
|
|
/// <param name="num2keep">num record da mantenere x reboot</param>
|
|
/// <returns></returns>
|
|
public inputComandoMapo registraStartup(string idxMacchina, string IPv4, string agent, string macAddr, int num2keep)
|
|
{
|
|
if (memLayer.ML.CRI("_logLevel") > 6)
|
|
{
|
|
logger.lg.scriviLog(string.Format("{0}---------------------------{0}Richiesta registrazione (ri)avvio Macchina {1} - mac: {2}", Environment.NewLine, idxMacchina, macAddr), tipoLog.INFO);
|
|
}
|
|
// formatto output
|
|
inputComandoMapo answ = new inputComandoMapo();
|
|
// scrivo remote reboot alive!
|
|
scriviRemoteReboot(idxMacchina, IPv4, agent, macAddr, num2keep);
|
|
// scrivo PRIMO keep alive
|
|
scriviPrimoKeepAlive(idxMacchina, DateTime.Now);
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// scrive un evento di keepalive sulla tabella
|
|
/// </summary>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="oraMacchina"></param>
|
|
/// <returns></returns>
|
|
public void scriviKeepAlive(string IdxMacchina, DateTime oraMacchina)
|
|
{
|
|
string nomeVar = string.Format("KeepAlive:{0}", IdxMacchina);
|
|
// cerco se ho keep alive in redis,
|
|
bool keyPresent = false;
|
|
DateTime adesso = DateTime.Now;
|
|
try
|
|
{
|
|
keyPresent = memLayer.ML.redKeyPresentSz(memLayer.ML.redHash(nomeVar));
|
|
}
|
|
catch
|
|
{ }
|
|
// se NON presente salvo in REDIS con TTL 10 sec e sul DB...
|
|
if (!keyPresent)
|
|
{
|
|
memLayer.ML.setRSV(memLayer.ML.redHash(nomeVar), adesso.ToString("s"), 10);
|
|
try
|
|
{
|
|
if (memLayer.ML.CRB("resetConnKA"))
|
|
{
|
|
if (memLayer.ML.CRB("forceResetKeepAlive"))
|
|
{
|
|
taKeepAlive.Connection.Close();
|
|
taKeepAlive.Connection.Open();
|
|
}
|
|
else
|
|
{
|
|
if (taKeepAlive.Connection.State == ConnectionState.Closed)
|
|
{
|
|
taKeepAlive.Connection.Open();
|
|
}
|
|
}
|
|
}
|
|
if (memLayer.ML.CRI("_logLevel") > 6)
|
|
{
|
|
logger.lg.scriviLog($"Scrittura keep alive! IdxMacchina: {IdxMacchina}");
|
|
}
|
|
// 2017.07.11 se richiesto di NON usare singleton... riporto FUORI la gestione
|
|
// NUOVO oggetto
|
|
if (memLayer.ML.CRB("disable_singleton"))
|
|
{
|
|
// 2017.06.09 forzo init x errori "sovrapposizioni"
|
|
taKeepAlive = new DS_applicazioneTableAdapters.KeepAliveTableAdapter();
|
|
}
|
|
taKeepAlive.UpdateQueryNoStartTime(DateTime.Now, oraMacchina, IdxMacchina);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Errore in scrittura keep alive!{Environment.NewLine}oraMacchina: {oraMacchina} - IdxMacchina: {IdxMacchina}{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// scrive un evento di start di keepalive sulla tabella
|
|
/// </summary>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="oraMacchina"></param>
|
|
/// <returns></returns>
|
|
public void scriviPrimoKeepAlive(string IdxMacchina, DateTime oraMacchina)
|
|
{
|
|
// se non c'� riga macchina insert...
|
|
if (taKeepAlive.GetData().FindByIdxMacchina(IdxMacchina) == null)
|
|
{
|
|
taKeepAlive.Insert(IdxMacchina, DateTime.Now, oraMacchina, DateTime.Now);
|
|
}
|
|
else // altrimenti update!
|
|
{
|
|
taKeepAlive.UpdateQuery(DateTime.Now, oraMacchina, DateTime.Now, IdxMacchina);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registra un evento di RemoteReboot sulla tabella ed effettua pulizia dei duplicati
|
|
/// </summary>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="IPv4"></param>
|
|
/// <param name="macAddr"></param>
|
|
/// <param name="num2keep">num record da mantenere x reboot</param>
|
|
/// <returns></returns>
|
|
public void scriviRemoteReboot(string IdxMacchina, string IPv4, string agent, string macAddr, int num2keep)
|
|
{
|
|
taRRL.Insert(IdxMacchina, IPv4, agent, DateTime.Now, macAddr);
|
|
// chiama stored x ripulire dati
|
|
taRRL.KeepLatest(num2keep);
|
|
}
|
|
|
|
/// <summary>
|
|
/// imposta la stringa di connessione al db
|
|
/// </summary>
|
|
public bool setStringaConnessione(string valore)
|
|
{
|
|
_connectionString = valore;
|
|
setConnString();
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce boolean se la macchina sia abilitata x registrazione segnali in input (tab DatiMacchine)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public bool sLogEnabled(string idxMacchina)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
// 2017.07.11 se richiesto di NON usare singleton... riporto FUORI la gestione NUOVO oggetto
|
|
if (memLayer.ML.CRB("disable_singleton"))
|
|
{
|
|
//2017.06.09 forzo inizializzazione oggetto..
|
|
taDatiMacch = new DS_applicazioneTableAdapters.DatiMacchineTableAdapter();
|
|
}
|
|
answ = taDatiMacch.GetByIdx(idxMacchina)[0].sLogEnabled;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// converte la definizioen di stato nel suo valore
|
|
/// </summary>
|
|
/// <param name="idx"></param>
|
|
/// <returns></returns>
|
|
public string statoDaIdxStato(int idx)
|
|
{
|
|
return taAnagSt.GetByIdx(idx)[0].Descrizione;
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua verifica del codice barcode e restituisce un oggetto inputComandoMapo che
|
|
/// indica come proseguire
|
|
/// </summary>
|
|
/// <param name="barcodeValue"></param>
|
|
/// <returns></returns>
|
|
public inputComandoMapo tryBarcode(string barcodeValue)
|
|
{
|
|
inputComandoMapo answ = new inputComandoMapo();
|
|
// controllo...
|
|
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected string _connectionString = "";
|
|
protected string _separatore = ",";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// avvio i table adapter della classe
|
|
/// </summary>
|
|
private void AvviaTabAdapt()
|
|
{
|
|
taEvList = new DS_applicazioneTableAdapters.EventListTableAdapter();
|
|
taDiario = new DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter();
|
|
taAnagSt = new DS_applicazioneTableAdapters.AnagraficaStatiTableAdapter();
|
|
taAnagEv = new DS_applicazioneTableAdapters.AnagraficaEventiTableAdapter();
|
|
taMacchine = new DS_applicazioneTableAdapters.MacchineTableAdapter();
|
|
taTranEv = new DS_applicazioneTableAdapters.TransizioneEventiTableAdapter();
|
|
taTranSt = new DS_applicazioneTableAdapters.TransizioneStatiTableAdapter();
|
|
taStatoMacchine = new DS_applicazioneTableAdapters.StatoMacchineTableAdapter();
|
|
taKeepAlive = new DS_applicazioneTableAdapters.KeepAliveTableAdapter();
|
|
taRRL = new DS_applicazioneTableAdapters.RemoteRebootLogTableAdapter();
|
|
taTransIngr = new DS_applicazioneTableAdapters.TransizioneIngressiTableAdapter();
|
|
taAnOpr = new DS_applicazioneTableAdapters.AnagraficaOperatoriTableAdapter();
|
|
taDatiMacch = new DS_applicazioneTableAdapters.DatiMacchineTableAdapter();
|
|
taMSM = new DS_applicazioneTableAdapters.MicroStatoMacchinaTableAdapter();
|
|
taMSFD = new DS_applicazioneTableAdapters.MSFDTableAdapter();
|
|
taDatiMacchine = new DS_ProdTempiTableAdapters.DatiMacchineTableAdapter();
|
|
taODL = new DS_ProdTempiTableAdapters.ODLTableAdapter();
|
|
taTCRilevati = new DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter();
|
|
taM2S = new DS_ProdTempiTableAdapters.Macchine2SlaveTableAdapter();
|
|
}
|
|
|
|
/// <summary>
|
|
/// metodo privato x fornire cognome-nome dalla matricola
|
|
/// </summary>
|
|
/// <param name="matrOpr"></param>
|
|
/// <returns></returns>
|
|
private string getGeneralitDaMatr(int matrOpr)
|
|
{
|
|
string cognNome = "";
|
|
// cerco operatore...
|
|
DS_applicazione.AnagraficaOperatoriRow rigaOpr;
|
|
try
|
|
{
|
|
rigaOpr = taAnOpr.getByMatrOpr(matrOpr)[0];
|
|
cognNome = string.Format("{0} {1}", rigaOpr.Cognome, rigaOpr.Nome);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return cognNome;
|
|
}
|
|
|
|
/// <summary>
|
|
/// metodo privato x fornire matricola che � correntemente sulla macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
private int getMatrOpMacc(string idxMacchina)
|
|
{
|
|
int matr = -1;
|
|
try
|
|
{
|
|
matr = (taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0]).MatrOpr;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return matr;
|
|
}
|
|
|
|
/// <summary>
|
|
/// forza la connString x i vari table adapters
|
|
/// </summary>
|
|
private void setConnString()
|
|
{
|
|
_connectionString = SteamWare.memLayer.ML.confReadString("MoonProConnectionString");
|
|
taEvList.Connection.ConnectionString = _connectionString;
|
|
taDiario.Connection.ConnectionString = _connectionString;
|
|
taAnagEv.Connection.ConnectionString = _connectionString;
|
|
taAnagSt.Connection.ConnectionString = _connectionString;
|
|
taMacchine.Connection.ConnectionString = _connectionString;
|
|
taTranEv.Connection.ConnectionString = _connectionString;
|
|
taTranSt.Connection.ConnectionString = _connectionString;
|
|
taStatoMacchine.Connection.ConnectionString = _connectionString;
|
|
taKeepAlive.Connection.ConnectionString = _connectionString;
|
|
taRRL.Connection.ConnectionString = _connectionString;
|
|
taTransIngr.Connection.ConnectionString = _connectionString;
|
|
taAnOpr.Connection.ConnectionString = _connectionString;
|
|
taDatiMacch.Connection.ConnectionString = _connectionString;
|
|
taMSM.Connection.ConnectionString = _connectionString;
|
|
taMSFD.Connection.ConnectionString = _connectionString;
|
|
taDatiMacchine.Connection.ConnectionString = _connectionString;
|
|
taODL.Connection.ConnectionString = _connectionString;
|
|
taTCRilevati.Connection.ConnectionString = _connectionString;
|
|
taM2S.Connection.ConnectionString = _connectionString;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |