233 lines
8.5 KiB
C#
233 lines
8.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using SteamWare;
|
|
|
|
/// <summary>
|
|
/// Metodi di gestione della manutenzione programmata
|
|
/// </summary>
|
|
public class mtzProgr
|
|
{
|
|
#region table adapters
|
|
|
|
public GIM_dataLayer.DS_applicazioneTableAdapters.MtzProgrammataTableAdapter taMtzProg;
|
|
public GIM_dataLayer.DS_applicazioneTableAdapters.MtzProgPendingTableAdapter taMtzPend;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// avvio componente
|
|
/// </summary>
|
|
protected mtzProgr()
|
|
{
|
|
initTA();
|
|
setupConnectionString();
|
|
}
|
|
|
|
private void initTA()
|
|
{
|
|
taMtzPend = new GIM_dataLayer.DS_applicazioneTableAdapters.MtzProgPendingTableAdapter();
|
|
taMtzProg = new GIM_dataLayer.DS_applicazioneTableAdapters.MtzProgrammataTableAdapter();
|
|
}
|
|
/// <summary>
|
|
/// effettua setup dei connection strings da web.config della singola applicazione
|
|
/// </summary>
|
|
protected virtual void setupConnectionString()
|
|
{
|
|
// connections del db
|
|
string connString = memLayer.ML.confReadString("AppConnectionString");
|
|
taMtzPend.Connection.ConnectionString = connString;
|
|
taMtzProg.Connection.ConnectionString = connString;
|
|
}
|
|
/// <summary>
|
|
/// singleton accesso ai metodi di manutenzione programmata
|
|
/// </summary>
|
|
public static mtzProgr obj = new mtzProgr();
|
|
/// <summary>
|
|
/// anticipa l'intervneto indicato e genera il successivo a scadenza normale
|
|
/// </summary>
|
|
public void anticipaIntervento(int numIntMtzPend)
|
|
{
|
|
DateTime nextDate = DateTime.Now;
|
|
int richInserted = 0;
|
|
GIM_dataLayer.DS_applicazione.MtzProgrammataRow rigaTemp;
|
|
// genero l'intervento
|
|
logger.lg.scriviLog(string.Format("Anticipata la richiesta di manutenzione (programmata) num {0}", numIntMtzPend), tipoLog.INFO);
|
|
foreach (GIM_dataLayer.DS_applicazione.MtzProgPendingRow rigaMtz in taMtzPend.getByIdx(numIntMtzPend))
|
|
{
|
|
richInserted = insRich(rigaMtz);
|
|
nextDate = rigaMtz.data;
|
|
// inserisco trasformandoli in richieste ...
|
|
if (richInserted != 0 || true) // se va a buon fine TOGLIERE TRUE!!!
|
|
{
|
|
logger.lg.scriviLog(string.Format("Accodata la richiesta di manutenzione (programmata) num {0}", richInserted), tipoLog.INFO);
|
|
// recupero intervento "generatore" x verificare periodicità...
|
|
rigaTemp = taMtzProg.getByKey(rigaMtz.idxIntPro)[0];
|
|
// modifico intervento pending portando avanti secondo schedulazione...
|
|
switch (rigaTemp.codFrequenza)
|
|
{
|
|
case "dd":
|
|
nextDate = nextDate.AddDays(rigaTemp.cadenza);
|
|
break;
|
|
case "ww":
|
|
nextDate = nextDate.AddDays(rigaTemp.cadenza * 7);
|
|
break;
|
|
case "MM":
|
|
nextDate = nextDate.AddMonths(rigaTemp.cadenza);
|
|
break;
|
|
case "yy":
|
|
nextDate = nextDate.AddYears(rigaTemp.cadenza);
|
|
break;
|
|
}
|
|
taMtzPend.updDataScad(numIntMtzPend, nextDate, false);
|
|
logger.lg.scriviLog(string.Format("Generata nuova scadenza di manutenzione (programmata) num {0} alla data {1}", numIntMtzPend, nextDate), tipoLog.INFO);
|
|
}
|
|
else
|
|
{
|
|
logger.lg.scriviLog(string.Format("Non è stato possibile accodare la richiesta di manutenzione programmata cod {0} relativa alla macchina {1}", rigaMtz.idxIntPro, rigaMtz.idxMacchina), tipoLog.ERROR);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// verifica se ci siano interventi pending ed eventualmente li accoda
|
|
/// </summary>
|
|
public void processaCodaMtzPro()
|
|
{
|
|
// cerco eventuali interventi scaduti
|
|
insertPending();
|
|
// metto in coda tutte le ricorrenze non presenti...
|
|
rebuildPending();
|
|
}
|
|
/// <summary>
|
|
/// inserisce nelle richieste attuali gli interventi programmati scaduti
|
|
/// </summary>
|
|
private void insertPending()
|
|
{
|
|
int richInserted = 0;
|
|
//recupero solo gli interventi già "scaduti"
|
|
foreach (GIM_dataLayer.DS_applicazione.MtzProgPendingRow rigaMtz in taMtzPend.getByDataScad(DateTime.Now))
|
|
{
|
|
richInserted = insRich(rigaMtz);
|
|
// inserisco trasformandoli in richieste ...
|
|
if (richInserted != 0) // se va a buon fine
|
|
{
|
|
logger.lg.scriviLog(string.Format("Accodata la richiesta di manutenzione (programmata) num {0}", richInserted), tipoLog.INFO);
|
|
// ...e li tolgo dall'elenco pending
|
|
taMtzPend.Delete(rigaMtz.idxPending);
|
|
}
|
|
else
|
|
{
|
|
logger.lg.scriviLog(string.Format("Non è stato possibile accodare la richiesta di manutenzione programmata cod {0} relativa alla macchina {1}", rigaMtz.idxIntPro, rigaMtz.idxMacchina), tipoLog.ERROR);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ricostruisce la coda degli intervneti pending
|
|
/// </summary>
|
|
private void rebuildPending()
|
|
{
|
|
int multiplo = 0;
|
|
int stimaIniz = 0;
|
|
double ggEquiv = 0;
|
|
TimeSpan distDate;
|
|
DateTime adesso = DateTime.Now;
|
|
DateTime dataProp;
|
|
foreach (GIM_dataLayer.DS_applicazione.MtzProgrammataRow rigaMtz in taMtzProg.getNotScheduled())
|
|
{
|
|
dataProp = rigaMtz.inizio;
|
|
// proseguo SOLO se inizio interventi <= data odierna...)
|
|
if (rigaMtz.inizio < adesso)
|
|
{
|
|
//calcolo l'intervallo timeSpan tra inizio interventi e data odierna
|
|
distDate = adesso.Subtract(rigaMtz.inizio);
|
|
// in base al tipo di intervallo faccio un calcolo grezzo del periodo trascorso...
|
|
ggEquiv = distDate.TotalDays;
|
|
switch (rigaMtz.codFrequenza)
|
|
{
|
|
case "dd":
|
|
stimaIniz = (int)Math.Floor(ggEquiv / rigaMtz.cadenza);
|
|
break;
|
|
case "ww":
|
|
stimaIniz = (int)Math.Floor(ggEquiv / (rigaMtz.cadenza * 7));
|
|
break;
|
|
case "MM":
|
|
stimaIniz = (int)Math.Floor(ggEquiv / (rigaMtz.cadenza * 30));
|
|
break;
|
|
case "yy":
|
|
stimaIniz = (int)Math.Floor(ggEquiv / (rigaMtz.cadenza * 365));
|
|
break;
|
|
}
|
|
// parto con la stima iniziale decrementata (se >0...)
|
|
if (stimaIniz == 0)
|
|
{
|
|
multiplo = 0;
|
|
}
|
|
else
|
|
{
|
|
multiplo = stimaIniz - 1;
|
|
}
|
|
// ciclo fino a quando la data indicata non è successiva all'adesso...
|
|
while (dataProp < adesso)
|
|
{
|
|
// aggiorno la data di riferimento
|
|
switch (rigaMtz.codFrequenza)
|
|
{
|
|
case "dd":
|
|
dataProp = rigaMtz.inizio.AddDays(rigaMtz.cadenza * multiplo);
|
|
break;
|
|
case "ww":
|
|
dataProp = rigaMtz.inizio.AddDays(rigaMtz.cadenza * 7 * multiplo);
|
|
break;
|
|
case "MM":
|
|
dataProp = rigaMtz.inizio.AddMonths(rigaMtz.cadenza * multiplo);
|
|
break;
|
|
case "yy":
|
|
dataProp = rigaMtz.inizio.AddYears(rigaMtz.cadenza * multiplo);
|
|
break;
|
|
}
|
|
multiplo++;
|
|
}
|
|
// salvo la data trovata...
|
|
rigaMtz.inizio = dataProp;
|
|
}
|
|
// infine inserisco intervento...
|
|
insMtzPend(rigaMtz);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// inserisce l'intervento della riga indicata tra quelli "pending"
|
|
/// </summary>
|
|
/// <param name="riga"></param>
|
|
protected void insMtzPend(GIM_dataLayer.DS_applicazione.MtzProgrammataRow riga)
|
|
{
|
|
mtzProgr.obj.taMtzPend.Insert(riga.idxIntPro, riga.idxMacchina, riga.inizio, riga.descrizione, riga.idxPriorita, riga.isFermo, riga.idxTipo, riga.idxCausale);
|
|
}
|
|
/// <summary>
|
|
/// genera la richiesta di manutenzione dalla richiesta pending associata
|
|
/// </summary>
|
|
/// <param name="riga"></param>
|
|
/// <returns></returns>
|
|
protected int insRich(GIM_dataLayer.DS_applicazione.MtzProgPendingRow riga)
|
|
{
|
|
int? answ = 0;
|
|
// calcolo date riferimento...
|
|
DateTime adesso = DateTime.Now;
|
|
int shift = memLayer.ML.confReadInt("shiftTurno");
|
|
int durataTurno = memLayer.ML.confReadInt("durataTurno");
|
|
int turno = Convert.ToInt32(Math.Ceiling((double)Convert.ToDouble(DateTime.Now.AddHours(-shift + 1).Hour) / durataTurno));
|
|
int idxAmbito = 7; //mtz programmata...
|
|
int idxImpianto = 0;
|
|
try
|
|
{
|
|
idxImpianto = TA_app.obj.taMacchine.getByIdxMacchina(riga.idxMacchina)[0].idxImpianto;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Errore nel recuperare impianto relativo alla macchina {0}, eccezione {1}", riga.idxMacchina, e), tipoLog.EXCEPTION);
|
|
}
|
|
// inserisco
|
|
TA_app.obj.taInterventiMtz.insRichiesta(adesso, adesso.AddHours(-shift + 1), turno, "PROG", riga.data, idxAmbito, riga.idxPriorita, riga.isFermo, riga.idxTipo, idxImpianto, riga.idxMacchina, riga.descrizione, riga.idxCausale, true, riga.idxIntPro, ref answ);
|
|
return (int)answ;
|
|
}
|
|
}
|