diff --git a/MapoDb/AlarmsArchive.cs b/MapoDb/AlarmsArchive.cs index 4b58aead..692b1d01 100644 --- a/MapoDb/AlarmsArchive.cs +++ b/MapoDb/AlarmsArchive.cs @@ -6,78 +6,96 @@ using System.Collections.Generic; namespace MapoDb { - /// - /// Classe gestione ALLARMI come eventi speciali (documenti registrati su MongoDb) - /// - public class AlarmsArchive - { - - /// - /// Database corrente MongoDB + /// Classe gestione ALLARMI come eventi speciali (documenti registrati su MongoDb) /// - IMongoDatabase database; - /// - /// Oggetto privato datalayer - /// - DataLayer DataLayerObj; - - /// - /// Classe gestione archivio allarmi - /// - public AlarmsArchive() + public class AlarmsArchive { - database = memLayer.ML.getMongoDatabase("MAPO"); - DataLayerObj = new DataLayer(); + #region Public Fields + + /// + /// Singleton gestione istanza AlarmsManager + /// + public static AlarmsArchive man = new AlarmsArchive(); + + #endregion Public Fields + + #region Public Constructors + + /// + /// Classe gestione archivio allarmi + /// + public AlarmsArchive() + { + database = memLayer.ML.getMongoDatabase("MAPO"); + DataLayerObj = new DataLayer(); + } + + #endregion Public Constructors + + #region Public Methods + + /// + /// Crea una registrazione incidente su MongoDB + /// + /// + /// + /// numero di minuti precedenti di dati FluxLog da includere + /// + public int createAlarmEvent(string idxMacchina, List elencoAllarmi, int lastMinutes) + { + int answ = 0; + string currDateStr = ""; + int startYMD = 0; + DateTime adesso = DateTime.Now; + int anno = adesso.Year; + currDateStr = adesso.ToString("yyyyMMdd"); + int.TryParse(currDateStr, out startYMD); + // in primis recupero contatore allarmi correnti, lo incremento salvandolo e genero + // nuovo documento... + var collAlarmStats = database.GetCollection("AlarmStats"); + var builderAlarmStat = Builders.Filter; + var filtThisYear = builderAlarmStat.Eq(u => u.year, anno); + + var datiCorrenti = collAlarmStats.Find(filtThisYear); + var collAlarmEvents = database.GetCollection("AlarmEvents"); + + List lastFluxLog = new List(); + DS_applicazione.FluxLogDataTable tabDati = DataLayerObj.taFL.getFiltOrd(idxMacchina, adesso.AddMinutes(-lastMinutes), adesso, true, ""); + if (tabDati.Count > 0) + { + // chiamo procedura x conversione + lastFluxLog = FluxArchive.man.convertTable(tabDati, adesso, timeWindow.free); + } + alarmEvent nuovoAllarme = new alarmEvent() + { + yCurr = anno, + yCounter = answ, + dateYMD = startYMD, + started = DateTime.Now, + blackBoxData = lastFluxLog, + activeConditions = elencoAllarmi + }; + + collAlarmEvents.InsertOne(nuovoAllarme); + + return answ; + } + + #endregion Public Methods + + #region Private Fields + + /// + /// Database corrente MongoDB + /// + private IMongoDatabase database; + + /// + /// Oggetto privato datalayer + /// + private DataLayer DataLayerObj; + + #endregion Private Fields } - /// - /// Singleton gestione istanza AlarmsManager - /// - public static AlarmsArchive man = new AlarmsArchive(); - /// - /// Crea una registrazione incidente su MongoDB - /// - /// - /// - /// numero di minuti precedenti di dati FluxLog da includere - /// - public int createAlarmEvent(string idxMacchina, List elencoAllarmi, int lastMinutes) - { - int answ = 0; - string currDateStr = ""; - int startYMD = 0; - DateTime adesso = DateTime.Now; - int anno = adesso.Year; - currDateStr = adesso.ToString("yyyyMMdd"); - int.TryParse(currDateStr, out startYMD); - // in primis recupero contatore allarmi correnti, lo incremento salvandolo e genero nuovo documento... - var collAlarmStats = database.GetCollection("AlarmStats"); - var builderAlarmStat = Builders.Filter; - var filtThisYear = builderAlarmStat.Eq(u => u.year, anno); - - var datiCorrenti = collAlarmStats.Find(filtThisYear); - var collAlarmEvents = database.GetCollection("AlarmEvents"); - - List lastFluxLog = new List(); - DS_applicazione.FluxLogDataTable tabDati = DataLayerObj.taFL.getFiltOrd(idxMacchina, adesso.AddMinutes(-lastMinutes), adesso, true, ""); - if (tabDati.Count > 0) - { - // chiamo procedura x conversione - lastFluxLog = FluxArchive.man.convertTable(tabDati, adesso, timeWindow.free); - } - alarmEvent nuovoAllarme = new alarmEvent() - { - yCurr = anno, - yCounter = answ, - dateYMD = startYMD, - started = DateTime.Now, - blackBoxData = lastFluxLog, - activeConditions = elencoAllarmi - }; - - collAlarmEvents.InsertOne(nuovoAllarme); - - return answ; - } - } -} +} \ No newline at end of file diff --git a/MapoDb/Constants.cs b/MapoDb/Constants.cs index ee336a86..5c855c57 100644 --- a/MapoDb/Constants.cs +++ b/MapoDb/Constants.cs @@ -1,26 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MapoDb +namespace MapoDb { public class Constants { #region Public Fields - - public static readonly string BROADCAST_M_PIPE = $"BroadCastMsg"; - public static readonly string BROADCAST_CURR_KEY = $"{BASE_HASH}:Current:BroadCast"; - // dati conf REDIS Cache public static readonly string BASE_HASH = "MAPO"; - - private const string redisBaseAddr = "MP:"; + public static readonly string BROADCAST_CURR_KEY = $"{BASE_HASH}:Current:BroadCast"; + public static readonly string BROADCAST_M_PIPE = $"BroadCastMsg"; public static readonly string redisActionReq = redisBaseAddr + "IO:Action:Req"; #endregion Public Fields + + #region Private Fields + + private const string redisBaseAddr = "MP:"; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/MapoDb/DisplayAction.cs b/MapoDb/DisplayAction.cs index 68bb40a4..b0168a79 100644 --- a/MapoDb/DisplayAction.cs +++ b/MapoDb/DisplayAction.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MapoDb { @@ -15,12 +11,12 @@ namespace MapoDb public DateTime DtReq { get; set; } = DateTime.Now; public bool IsActive { get; set; } = false; public string Message { get; set; } = "New Message"; + public string Parameter { get; set; } = ""; public bool ShowCancel { get; set; } = true; public bool ShowClose { get; set; } = true; public bool ShowConfirm { get; set; } = true; public string Topic { get; set; } = "New Topic"; - public string Parameter { get; set; } = ""; #endregion Public Properties } -} +} \ No newline at end of file diff --git a/MapoDb/FluxArchive.cs b/MapoDb/FluxArchive.cs index d190747a..b792f76f 100644 --- a/MapoDb/FluxArchive.cs +++ b/MapoDb/FluxArchive.cs @@ -44,20 +44,6 @@ namespace MapoDb /// public class FluxArchive { - #region Private Fields - - /// - /// Database corrente MongoDB - /// - private IMongoDatabase database; - - /// - /// Oggetto datalayer - /// - private DataLayer DataLayerObj = new DataLayer(); - - #endregion Private Fields - #region Public Fields public static FluxArchive man = new FluxArchive(); @@ -84,85 +70,6 @@ namespace MapoDb #endregion Public Constructors - #region Protected Methods - - /// - /// Calcola statistiche per i dati giornalieri processati - /// - /// - /// - protected histData getStats(List datiGiornalieri) - { - // init oggetti - histData currHist; - varStats currStat; - List statistiche = new List(); - int sampleNumRec = 1; - float sampleTotal = 0; - float sampleMinVal = 0; - float sampleMaxVal = 0; - float sampleAvg = 0; - float currVal = 0; - bool fatto = false; - string macName = ""; - int dateYMD = 0; - // ciclo x ogni variabile - foreach (var item in datiGiornalieri) - { - if (item.samples != null) - { - if (string.IsNullOrEmpty(macName)) - { - macName = item.macName; - dateYMD = item.dateYMD; - } - // reset vabiabili - sampleTotal = 0; - sampleMinVal = 0; - sampleMaxVal = 0; - sampleAvg = 0; - // calcolo statistiche - sampleNumRec = item.samples.Count; - foreach (var sample in item.samples) - { - fatto = float.TryParse(sample.value, out currVal); - if (fatto) - { - sampleTotal += currVal; - sampleMaxVal = sampleMaxVal < currVal ? currVal : sampleMaxVal; - sampleMinVal = sampleMinVal > currVal ? currVal : sampleMinVal; - } - } - if (sampleNumRec > 0) - { - sampleAvg = sampleTotal / sampleNumRec; - } - // salvo statistica - currStat = new varStats() - { - varName = item.varName, - numRec = sampleNumRec, - avg = sampleAvg, - min = sampleMinVal, - max = sampleMaxVal - }; - statistiche.Add(currStat); - } - } - currHist = new histData() - { - macName = macName, - varType = plcDataType.Real, - dateYMD = dateYMD, - period = timeWindow.day, - stats = statistiche - }; - // restituisco... - return currHist; - } - - #endregion Protected Methods - #region Public Methods /// @@ -170,7 +77,9 @@ namespace MapoDb /// /// Tabelal dei dati RAW registrati /// Data di riferimento - /// Periodo del campionamento desiderato (e passato coi dati che sono relativi a tale periodo...) + /// + /// Periodo del campionamento desiderato (e passato coi dati che sono relativi a tale periodo...) + /// public List convertTable(DS_applicazione.FluxLogDataTable tabDati, DateTime tStamp, timeWindow periodo) { // init oggetti @@ -309,5 +218,98 @@ namespace MapoDb } #endregion Public Methods + + #region Protected Methods + + /// + /// Calcola statistiche per i dati giornalieri processati + /// + /// + /// + protected histData getStats(List datiGiornalieri) + { + // init oggetti + histData currHist; + varStats currStat; + List statistiche = new List(); + int sampleNumRec = 1; + float sampleTotal = 0; + float sampleMinVal = 0; + float sampleMaxVal = 0; + float sampleAvg = 0; + float currVal = 0; + bool fatto = false; + string macName = ""; + int dateYMD = 0; + // ciclo x ogni variabile + foreach (var item in datiGiornalieri) + { + if (item.samples != null) + { + if (string.IsNullOrEmpty(macName)) + { + macName = item.macName; + dateYMD = item.dateYMD; + } + // reset vabiabili + sampleTotal = 0; + sampleMinVal = 0; + sampleMaxVal = 0; + sampleAvg = 0; + // calcolo statistiche + sampleNumRec = item.samples.Count; + foreach (var sample in item.samples) + { + fatto = float.TryParse(sample.value, out currVal); + if (fatto) + { + sampleTotal += currVal; + sampleMaxVal = sampleMaxVal < currVal ? currVal : sampleMaxVal; + sampleMinVal = sampleMinVal > currVal ? currVal : sampleMinVal; + } + } + if (sampleNumRec > 0) + { + sampleAvg = sampleTotal / sampleNumRec; + } + // salvo statistica + currStat = new varStats() + { + varName = item.varName, + numRec = sampleNumRec, + avg = sampleAvg, + min = sampleMinVal, + max = sampleMaxVal + }; + statistiche.Add(currStat); + } + } + currHist = new histData() + { + macName = macName, + varType = plcDataType.Real, + dateYMD = dateYMD, + period = timeWindow.day, + stats = statistiche + }; + // restituisco... + return currHist; + } + + #endregion Protected Methods + + #region Private Fields + + /// + /// Database corrente MongoDB + /// + private IMongoDatabase database; + + /// + /// Oggetto datalayer + /// + private DataLayer DataLayerObj = new DataLayer(); + + #endregion Private Fields } } \ No newline at end of file diff --git a/MapoDb/IntServTrData.cs b/MapoDb/IntServTrData.cs index b4cec2a6..b146635f 100644 --- a/MapoDb/IntServTrData.cs +++ b/MapoDb/IntServTrData.cs @@ -2,16 +2,20 @@ namespace MapoDb { - /// - /// Struttura - /// - public class ISTD_OrderColcom - { - public string CodOrdine; - public string CodArticolo; - public string DescrArticolo; - public DateTime DataConsegna; - public Decimal Qta; - public string KitCode; - } -} + /// + /// Struttura + /// + public class ISTD_OrderColcom + { + #region Public Fields + + public string CodArticolo; + public string CodOrdine; + public DateTime DataConsegna; + public string DescrArticolo; + public string KitCode; + public Decimal Qta; + + #endregion Public Fields + } +} \ No newline at end of file diff --git a/MapoDb/MapoDb.cs b/MapoDb/MapoDb.cs index ba373c8d..160cb690 100644 --- a/MapoDb/MapoDb.cs +++ b/MapoDb/MapoDb.cs @@ -2,28 +2,17 @@ using MapoDb.DS_ProdTempiTableAdapters; using MapoSDK; using SteamWare; using System; -using System.Collections.Generic; using System.Data; namespace MapoDb { public class MapoDb { - #region Protected Fields - - protected string _connectionString = ""; - protected string _separatore = ","; - - #endregion Protected Fields - #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 @@ -35,27 +24,16 @@ namespace MapoDb 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 @@ -72,102 +50,6 @@ namespace MapoDb #endregion Public Constructors - #region Private Methods - - /// - /// avvio i table adapter della classe - /// - 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(); - } - - /// - /// metodo privato x fornire cognome-nome dalla matricola - /// - /// - /// - 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; - } - - /// - /// metodo privato x fornire matricola che è correntemente sulla macchina - /// - /// - /// - private int getMatrOpMacc(string idxMacchina) - { - int matr = -1; - try - { - matr = (taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0]).MatrOpr; - } - catch - { - } - return matr; - } - - /// - /// forza la connString x i vari table adapters - /// - 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 - #region Public Methods /// @@ -235,7 +117,8 @@ namespace MapoDb } /// - /// Dichiara esplicitamente produzione e tempo ciclo rilevato per il numero di pezzi indicati (real time, NON confermati) + /// Dichiara esplicitamente produzione e tempo ciclo rilevato per il numero di pezzi + /// indicati (real time, NON confermati) /// /// /// @@ -299,7 +182,8 @@ namespace MapoDb } /// - /// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto cercato tutti delimitati da separatore + /// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto + /// cercato tutti delimitati da separatore /// /// /// @@ -318,7 +202,8 @@ namespace MapoDb } /// - /// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto cercato tutti delimitati da separatore + /// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto + /// cercato tutti delimitati da separatore /// /// /// @@ -336,7 +221,8 @@ namespace MapoDb } /// - /// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto cercato tutti delimitati da separatore + /// Restituisce una stringa su 2 righe con intestazione colonne e valore dell'oggetto + /// cercato tutti delimitati da separatore /// /// /// @@ -618,22 +504,24 @@ namespace MapoDb return answ; } - /// verifica che il bar code sia un barcode nomeMacchina + /// + /// verifica che il bar code sia un barcode nomeMacchina /// - /// Bar code da verificare - /// true se bar code per operatore + /// Bar code da verificare + /// true se bar code per operatore public bool isNomeMacchina(string codice) { - // FARE!!! controllare quale codice ci vuole - // controlli validità bar code nomeMacchina : deve cominciare con O maiuscola + // FARE!!! controllare quale codice ci vuole controlli validità bar code nomeMacchina : + // deve cominciare con O maiuscola bool check = codice.StartsWith("C#"); return check; } - /// verifica che il bar code sia un barcode Operatore + /// + /// verifica che il bar code sia un barcode Operatore /// - /// Bar code da verificare - /// true se bar code per operatore + /// Bar code da verificare + /// true se bar code per operatore public bool isOperatore(string codice) { // controlli validità bar code operatore : deve cominciare con O maiuscola @@ -669,7 +557,6 @@ namespace MapoDb } /// - /// /// /// /// @@ -735,7 +622,8 @@ namespace MapoDb { logger.lg.scriviLog($"Scrittura keep alive! IdxMacchina: {IdxMacchina}"); } - // 2017.07.11 se richiesto di NON usare singleton... riporto FUORI la gestione NUOVO oggetto + // 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" @@ -825,7 +713,8 @@ namespace MapoDb } /// - /// effettua verifica del codice barcode e restituisce un oggetto inputComandoMapo che indica come proseguire + /// effettua verifica del codice barcode e restituisce un oggetto inputComandoMapo che + /// indica come proseguire /// /// /// @@ -838,5 +727,108 @@ namespace MapoDb } #endregion Public Methods + + #region Protected Fields + + protected string _connectionString = ""; + protected string _separatore = ","; + + #endregion Protected Fields + + #region Private Methods + + /// + /// avvio i table adapter della classe + /// + 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(); + } + + /// + /// metodo privato x fornire cognome-nome dalla matricola + /// + /// + /// + 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; + } + + /// + /// metodo privato x fornire matricola che è correntemente sulla macchina + /// + /// + /// + private int getMatrOpMacc(string idxMacchina) + { + int matr = -1; + try + { + matr = (taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0]).MatrOpr; + } + catch + { + } + return matr; + } + + /// + /// forza la connString x i vari table adapters + /// + 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 } } \ No newline at end of file diff --git a/MapoDb/MessagePipe.cs b/MapoDb/MessagePipe.cs index 02503dc4..8c0dcdd7 100644 --- a/MapoDb/MessagePipe.cs +++ b/MapoDb/MessagePipe.cs @@ -3,9 +3,6 @@ using StackExchange.Redis; using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MapoDb { @@ -130,6 +127,7 @@ namespace MapoDb #endregion Private Methods } + public class PubSubEventArgs : EventArgs { #region Public Constructors @@ -147,4 +145,4 @@ namespace MapoDb #endregion Public Properties } -} +} \ No newline at end of file diff --git a/MapoDb/MtcDataModelArchive.cs b/MapoDb/MtcDataModelArchive.cs index 51bc2786..4d539ef9 100644 --- a/MapoDb/MtcDataModelArchive.cs +++ b/MapoDb/MtcDataModelArchive.cs @@ -10,15 +10,22 @@ namespace MapoDb /// public class MtcDataModelArchive { + #region Public Fields + /// - /// Database corrente MongoDB + /// Singleton gestione istanza AlarmsManager /// - IMongoDatabase database; + public static MtcDataModelArchive man = new MtcDataModelArchive(); + /// /// Dizionario conf macchine /// public Dictionary> machineDataItems = new Dictionary>(); + #endregion Public Fields + + #region Public Constructors + /// /// Classe gestione archivio allarmi /// @@ -26,10 +33,11 @@ namespace MapoDb { database = memLayer.ML.getMongoDatabase("MAPO"); } - /// - /// Singleton gestione istanza AlarmsManager - /// - public static MtcDataModelArchive man = new MtcDataModelArchive(); + + #endregion Public Constructors + + #region Public Methods + /// /// Salva i dataItems della macchina indicata /// @@ -60,5 +68,16 @@ namespace MapoDb { } return answ; } + + #endregion Public Methods + + #region Private Fields + + /// + /// Database corrente MongoDB + /// + private IMongoDatabase database; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/MapoDb/reportExporter.cs b/MapoDb/reportExporter.cs index 6214469d..0f5406fe 100644 --- a/MapoDb/reportExporter.cs +++ b/MapoDb/reportExporter.cs @@ -8,100 +8,123 @@ using System.Data; /// public class reportExporter { - /// - /// mimeType del report - /// - public string mimeType; - /// - /// encoding dei dati - /// - public string encoding; - /// - /// nome estensione - /// - public string fileNameExtension; - /// - /// steam di bytes del report - /// - public byte[] renderedBytes; - /// - /// metodo protected - /// - public reportExporter() - { - } - /// - /// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) - /// - /// report ammessi: RichiestaIntervento - /// num int mtz - /// tabella dati - private DataTable caricaDati(reportRichiesto tipoReport, string idxObj) - { - // calcolo idxODL - int idxOdl = 0; - try - { - idxOdl = Convert.ToInt32(idxObj); - } - catch - { } - DataTable tab = new DataTable(); - MapoDb.DataLayer DataLayerObj = new MapoDb.DataLayer(); - switch (tipoReport) - { - case reportRichiesto.SchedaODL: - tab = (DataTable)DataLayerObj.taODL.getByIdx(idxOdl, false); - break; - //case reportRichiesto.RichiestaIntervento: - // tab = (DataTable)TA_app.obj.taInterventiMtz.getByIdx(Convert.ToInt32(idxObj)); - // break; - //default: - // break; - } - return tab; - } - /// - /// renderizza il report in pdf - /// - /// report ammessi: RichiestaIntervento - /// idx della richiesta (numIntMtz) - /// - public void popolaPdfStream(reportRichiesto tipoReport, string parametro) - { - LocalReport report = new LocalReport(); - devInfoParam deviceInfo = new devInfoParam("PDF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); - switch (tipoReport) - { - case reportRichiesto.SchedaODL: - report.ReportPath = @".\Reports\Donati_ODL.rdlc"; - report.DataSources.Add(new ReportDataSource("MoonPro", caricaDati(tipoReport, parametro))); // OCCHIO!!! va messa sorgente dati CORRETTA - deviceInfo = new devInfoParam("PDF", "29.7cm", "21cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); - break; - default: - break; - } - createPdfStream(report, deviceInfo.xmlParam); - } - /// - /// crea il vero e proprio stream pdf - /// - /// - /// - private void createPdfStream(LocalReport report, string deviceInfo) - { - // export in PDF - string reportType = "PDF"; - Warning[] warnings; - string[] streams; - renderedBytes = report.Render( - reportType, - deviceInfo, - out mimeType, - out encoding, - out fileNameExtension, - out streams, - out warnings); - } + #region Public Fields -} + /// + /// encoding dei dati + /// + public string encoding; + + /// + /// nome estensione + /// + public string fileNameExtension; + + /// + /// mimeType del report + /// + public string mimeType; + + /// + /// steam di bytes del report + /// + public byte[] renderedBytes; + + #endregion Public Fields + + #region Public Constructors + + /// + /// metodo protected + /// + public reportExporter() + { + } + + #endregion Public Constructors + + #region Public Methods + + /// + /// renderizza il report in pdf + /// + /// report ammessi: RichiestaIntervento + /// idx della richiesta (numIntMtz) + /// + public void popolaPdfStream(reportRichiesto tipoReport, string parametro) + { + LocalReport report = new LocalReport(); + devInfoParam deviceInfo = new devInfoParam("PDF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); + switch (tipoReport) + { + case reportRichiesto.SchedaODL: + report.ReportPath = @".\Reports\Donati_ODL.rdlc"; + report.DataSources.Add(new ReportDataSource("MoonPro", caricaDati(tipoReport, parametro))); // OCCHIO!!! va messa sorgente dati CORRETTA + deviceInfo = new devInfoParam("PDF", "29.7cm", "21cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); + break; + + default: + break; + } + createPdfStream(report, deviceInfo.xmlParam); + } + + #endregion Public Methods + + #region Private Methods + + /// + /// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) + /// + /// report ammessi: RichiestaIntervento + /// num int mtz + /// tabella dati + private DataTable caricaDati(reportRichiesto tipoReport, string idxObj) + { + // calcolo idxODL + int idxOdl = 0; + try + { + idxOdl = Convert.ToInt32(idxObj); + } + catch + { } + DataTable tab = new DataTable(); + MapoDb.DataLayer DataLayerObj = new MapoDb.DataLayer(); + switch (tipoReport) + { + case reportRichiesto.SchedaODL: + tab = (DataTable)DataLayerObj.taODL.getByIdx(idxOdl, false); + break; + //case reportRichiesto.RichiestaIntervento: + // tab = (DataTable)TA_app.obj.taInterventiMtz.getByIdx(Convert.ToInt32(idxObj)); + // break; + //default: + // break; + } + return tab; + } + + /// + /// crea il vero e proprio stream pdf + /// + /// + /// + private void createPdfStream(LocalReport report, string deviceInfo) + { + // export in PDF + string reportType = "PDF"; + Warning[] warnings; + string[] streams; + renderedBytes = report.Render( + reportType, + deviceInfo, + out mimeType, + out encoding, + out fileNameExtension, + out streams, + out warnings); + } + + #endregion Private Methods +} \ No newline at end of file diff --git a/MapoDb/reportPrinter.cs b/MapoDb/reportPrinter.cs index f12b8c32..e4d3a48b 100644 --- a/MapoDb/reportPrinter.cs +++ b/MapoDb/reportPrinter.cs @@ -22,10 +22,16 @@ public enum reportRichiesto /// public class reportPrinter { - #region area codice da non modificare + #region Public Fields - private int m_currentPageIndex; - private IList m_streams; + /// + /// singleton pubblico + /// + public static reportPrinter obj = new reportPrinter(); + + #endregion Public Fields + + #region Public Methods /// /// dispone l'applicazione e rilascia le risorse @@ -40,6 +46,92 @@ public class reportPrinter } } + /// + /// Crea un report locale da file rdlc, carica i dati, esporta report come EMF file e quindi lo + /// invia alla stampante + /// + /// report ammessi: ElencoMacchine / RichiestaIntervento + /// nome completo stampante (rispetto al server) + /// numIntMtz (codice numero richiesta) + public void printReport(reportRichiesto tipoReport, string printerName, string parametro) + { + LocalReport report = new LocalReport(); + devInfoParam deviceInfo = new devInfoParam("EMF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); + switch (tipoReport) + { + case reportRichiesto.SchedaODL: + report.ReportPath = @".\Reports\Donati_ODL.rdlc"; + report.DataSources.Add(new ReportDataSource("MoonPro", caricaDati(tipoReport, parametro))); + deviceInfo = new devInfoParam("EMF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); + break; + //case reportRichiesto.RichiestaIntervento: + // report.ReportPath = @".\Reports\RichiestaIntervento.rdlc"; + // report.DataSources.Add(new ReportDataSource("WebGim", caricaDati(tipoReport, parametro))); + // deviceInfo = new devInfoParam("EMF", "29.7cm", "21cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); + // break; + //default: + // break; + } + doEmfPrint(printerName, report, deviceInfo.xmlParam); + } + + #endregion Public Methods + + #region Protected Constructors + + /// + /// oggetto protected + /// + /// + protected reportPrinter() + { + } + + #endregion Protected Constructors + + #region Private Fields + + private int m_currentPageIndex; + private IList m_streams; + + #endregion Private Fields + + #region Private Methods + + /// + /// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) + /// + /// report ammessi: ElencoMacchine / RichiestaIntervento + /// + /// oggetto che contiene data inizio e data fine dell'analisi richiesta per il report + /// + /// tabella dati + private DataTable caricaDati(reportRichiesto tipoReport, string idxObj) + { + DataLayer DataLayerObj = new DataLayer(); + // calcolo idxODL + int idxOdl = 0; + try + { + idxOdl = Convert.ToInt32(idxObj); + } + catch + { } + DataTable tab = new DataTable(); + switch (tipoReport) + { + case reportRichiesto.SchedaODL: + tab = (DataTable)DataLayerObj.taODL.getByIdx(idxOdl, false); + break; + //case reportRichiesto.RichiestaIntervento: + // tab = (DataTable)TA_app.obj.taInterventiMtz.getByIdx(Convert.ToInt32(idxObj)); + // break; + //default: + // break; + } + return tab; + } + /// /// ciclo da fornire al renderizzatore dei report, per salvare 1 immagine da ogni pagina del report /// @@ -56,6 +148,23 @@ public class reportPrinter return stream; } + /// + /// esegue print vero e proprio + /// + /// + /// + /// + private void doEmfPrint(string printerName, LocalReport report, string deviceInfo) + { + // export in EMF + Export(report, deviceInfo); + m_currentPageIndex = 0; + // stampo + Print(printerName); + // do dispose? + Dispose(); + } + /// /// Export del report come EMF (Enhanced Metafile) file. /// @@ -101,99 +210,5 @@ public class reportPrinter ev.HasMorePages = (m_currentPageIndex < m_streams.Count); } - #endregion area codice da non modificare - - #region area codice da modificare - - /// - /// singleton pubblico - /// - public static reportPrinter obj = new reportPrinter(); - - /// - /// oggetto protected - /// - /// - protected reportPrinter() - { - } - - /// - /// Crea un report locale da file rdlc, carica i dati, esporta report come EMF file e quindi lo invia alla stampante - /// - /// report ammessi: ElencoMacchine / RichiestaIntervento - /// nome completo stampante (rispetto al server) - /// numIntMtz (codice numero richiesta) - public void printReport(reportRichiesto tipoReport, string printerName, string parametro) - { - LocalReport report = new LocalReport(); - devInfoParam deviceInfo = new devInfoParam("EMF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); - switch (tipoReport) - { - case reportRichiesto.SchedaODL: - report.ReportPath = @".\Reports\Donati_ODL.rdlc"; - report.DataSources.Add(new ReportDataSource("MoonPro", caricaDati(tipoReport, parametro))); - deviceInfo = new devInfoParam("EMF", "21cm", "29.7cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); - break; - //case reportRichiesto.RichiestaIntervento: - // report.ReportPath = @".\Reports\RichiestaIntervento.rdlc"; - // report.DataSources.Add(new ReportDataSource("WebGim", caricaDati(tipoReport, parametro))); - // deviceInfo = new devInfoParam("EMF", "29.7cm", "21cm", "0.2cm", "0.2cm", "0.2cm", "0.2cm"); - // break; - //default: - // break; - } - doEmfPrint(printerName, report, deviceInfo.xmlParam); - } - - /// - /// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) - /// - /// report ammessi: ElencoMacchine / RichiestaIntervento - /// oggetto che contiene data inizio e data fine dell'analisi richiesta per il report - /// tabella dati - private DataTable caricaDati(reportRichiesto tipoReport, string idxObj) - { - DataLayer DataLayerObj = new DataLayer(); - // calcolo idxODL - int idxOdl = 0; - try - { - idxOdl = Convert.ToInt32(idxObj); - } - catch - { } - DataTable tab = new DataTable(); - switch (tipoReport) - { - case reportRichiesto.SchedaODL: - tab = (DataTable)DataLayerObj.taODL.getByIdx(idxOdl, false); - break; - //case reportRichiesto.RichiestaIntervento: - // tab = (DataTable)TA_app.obj.taInterventiMtz.getByIdx(Convert.ToInt32(idxObj)); - // break; - //default: - // break; - } - return tab; - } - - /// - /// esegue print vero e proprio - /// - /// - /// - /// - private void doEmfPrint(string printerName, LocalReport report, string deviceInfo) - { - // export in EMF - Export(report, deviceInfo); - m_currentPageIndex = 0; - // stampo - Print(printerName); - // do dispose? - Dispose(); - } - - #endregion area codice da modificare + #endregion Private Methods } \ No newline at end of file diff --git a/MapoDb/resoconti.cs b/MapoDb/resoconti.cs index 3e0c7223..66d8032c 100644 --- a/MapoDb/resoconti.cs +++ b/MapoDb/resoconti.cs @@ -98,27 +98,6 @@ public struct objTempiCiclo //} public class resoconti { - #region Protected Fields - - protected DS_applicazione.AnagArticoliDataTable _AnagArt; - protected DS_applicazione.AnagraficaOperatoriDataTable _AnagOpr; - protected DS_applicazione.AnagraficaEventiDataTable _AnagraficaEventi; - protected DS_applicazione.DiarioDiBordoDataTable _DiarioDiBordo; - protected DS_applicazione.MacchineDataTable _Macchine; - protected DS_applicazione.AnagraficaStatiDataTable _Stati; - protected DS_applicazione.StatoMacchineDataTable _StatoMacchine; - protected MapoDb.DS_applicazioneTableAdapters.AnagArticoliTableAdapter taAnagArt; - protected MapoDb.DS_applicazioneTableAdapters.AnagraficaOperatoriTableAdapter taAnagOpr; - protected MapoDb.DS_applicazioneTableAdapters.AnagraficaEventiTableAdapter taAnagraficaEventi; - protected MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter taDiarioDiBordo; - protected MapoDb.DS_applicazioneTableAdapters.MacchineTableAdapter taMacchine; - protected MapoDb.DS_applicazioneTableAdapters.ParetoDurateTableAdapter taParetoDurate; - protected MapoDb.DS_applicazioneTableAdapters.AnagraficaStatiTableAdapter taStati; - protected MapoDb.DS_applicazioneTableAdapters.StatoMacchineTableAdapter taStatoMacchine; - protected MapoDb.DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter taTempiCiclo; - - #endregion Protected Fields - #region Public Fields /// @@ -138,423 +117,6 @@ public class resoconti #endregion Public Constructors - #region Protected Properties - - protected DS_applicazione.AnagraficaOperatoriDataTable AnagOpr - { - get - { - if (!memLayer.ML.isInCacheObject("AnagOpr")) - { - _AnagOpr = taAnagOpr.GetData(); - string serVal = JsonConvert.SerializeObject(_AnagOpr); - memLayer.ML.setCacheVal("AnagOpr", serVal, true); - } - else - { - string redKey = memLayer.ML.redHash("AnagOpr"); - string serVal = memLayer.ML.getRSV(redKey); - _AnagOpr = JsonConvert.DeserializeObject(serVal); - } - return _AnagOpr; - } - } - - /// - /// Dizionario codici colore (chiave = idxStato), valore = codice colore - /// - protected Dictionary codColore - { - get - { - Dictionary answ = new Dictionary(); - if (memLayer.ML.isInCacheObject("codColore")) - { - string redKey = memLayer.ML.redHash("codColore"); - string serVal = memLayer.ML.getRSV(redKey); - answ = JsonConvert.DeserializeObject>(serVal); - } - else - { - string _colore = ""; - foreach (DS_applicazione.AnagraficaStatiRow item in Stati) - { - switch (item.Semaforo) - { - case "sGi": // giallo - _colore = "#ffec00"; - break; - - case "sRo": // rosso - _colore = "#e2001a"; - break; - - case "sGr": // grigio - spenta - _colore = "#bcbcbc"; - break; - - case "sVe": // verde - _colore = "#009036"; - break; - - case "sBl": // blu - _colore = "#3690FF"; - break; - - default: - break; - } - answ.Add(item.IdxStato, _colore); - } - string serVal = JsonConvert.SerializeObject(answ); - memLayer.ML.setCacheVal("codColore", serVal, true); - } - return answ; - } - } - - /// - /// Dizionario codici semaforo (chiave = idxStato), valore = codice semaforo - /// - protected Dictionary codSemaforo - { - get - { - Dictionary answ = new Dictionary(); - if (memLayer.ML.isInCacheObject("codSemaforo")) - { - string redKey = memLayer.ML.redHash("codSemaforo"); - string serVal = memLayer.ML.getRSV(redKey); - answ = JsonConvert.DeserializeObject>(serVal); - } - else - { - foreach (DS_applicazione.AnagraficaStatiRow item in Stati) - { - answ.Add(item.IdxStato, item.Semaforo); - } - string serVal = JsonConvert.SerializeObject(answ); - memLayer.ML.setCacheVal("codSemaforo", serVal, true); - } - return answ; - } - } - - protected DS_applicazione.AnagraficaStatiDataTable Stati - { - get - { - if (!memLayer.ML.isInCacheObject("Stati")) - { - _Stati = taStati.GetData(); - string serVal = JsonConvert.SerializeObject(_Stati); - memLayer.ML.setCacheVal("Stati", serVal, true); - } - else - { - string redKey = memLayer.ML.redHash("Stati"); - string serVal = memLayer.ML.getRSV(redKey); - _Stati = JsonConvert.DeserializeObject(serVal); - } - return _Stati; - } - } - - #endregion Protected Properties - - #region Public Properties - - protected DS_applicazione.AnagArticoliDataTable AnagArt - { - get - { - if (!memLayer.ML.isInCacheObject("AnagArt")) - { - _AnagArt = taAnagArt.GetData(); - string serVal = JsonConvert.SerializeObject(_AnagArt); - memLayer.ML.setCacheVal("AnagArt", serVal, true); - } - else - { - string redKey = memLayer.ML.redHash("AnagArt"); - string serVal = memLayer.ML.getRSV(redKey); - _AnagArt = JsonConvert.DeserializeObject(serVal); - } - return _AnagArt; - } - } - - protected DS_applicazione.AnagraficaEventiDataTable AnagraficaEventi - { - get - { - if (!memLayer.ML.isInCacheObject("AnagraficaEventi")) - { - _AnagraficaEventi = taAnagraficaEventi.GetData(); - string serVal = JsonConvert.SerializeObject(_AnagraficaEventi); - memLayer.ML.setCacheVal("AnagraficaEventi", serVal, true); - } - else - { - string redKey = memLayer.ML.redHash("AnagraficaEventi"); - string serVal = memLayer.ML.getRSV(redKey); - _AnagraficaEventi = JsonConvert.DeserializeObject(serVal); - } - return _AnagraficaEventi; - } - } - - protected DS_applicazione.DiarioDiBordoDataTable DiarioDiBordo - { - get - { - if (_DiarioDiBordo == null) - { - _DiarioDiBordo = taDiarioDiBordo.GetData(); - } - return _DiarioDiBordo; - } - } - - protected DS_applicazione.MacchineDataTable Macchine - { - get - { - if (!memLayer.ML.isInCacheObject("Macchine")) - { - _Macchine = taMacchine.GetData(); - string serVal = JsonConvert.SerializeObject(_Macchine); - memLayer.ML.setCacheVal("Macchine", serVal, true); - } - else - { - string redKey = memLayer.ML.redHash("Macchine"); - string serVal = memLayer.ML.getRSV(redKey); - _Macchine = JsonConvert.DeserializeObject(serVal); - } - return _Macchine; - } - } - - protected DS_applicazione.StatoMacchineDataTable StatoMacchine - { - get - { - if (!memLayer.ML.isInCacheObject("StatoMacchine")) - { - _StatoMacchine = taStatoMacchine.GetData(); - string serVal = JsonConvert.SerializeObject(_StatoMacchine); - memLayer.ML.setCacheVal("StatoMacchine", serVal, true); - } - else - { - string redKey = memLayer.ML.redHash("StatoMacchine"); - string serVal = memLayer.ML.getRSV(redKey); - _StatoMacchine = JsonConvert.DeserializeObject(serVal); - } - return _StatoMacchine; - } - } - - #endregion Public Properties - - #region Private Methods - - /// - /// avvio i table adapter della classe - /// - private void AvviaTabAdapt() - { - taMacchine = new MapoDb.DS_applicazioneTableAdapters.MacchineTableAdapter(); - taStatoMacchine = new MapoDb.DS_applicazioneTableAdapters.StatoMacchineTableAdapter(); - taStati = new MapoDb.DS_applicazioneTableAdapters.AnagraficaStatiTableAdapter(); - taDiarioDiBordo = new MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter(); - taParetoDurate = new MapoDb.DS_applicazioneTableAdapters.ParetoDurateTableAdapter(); - taAnagraficaEventi = new MapoDb.DS_applicazioneTableAdapters.AnagraficaEventiTableAdapter(); - taAnagArt = new MapoDb.DS_applicazioneTableAdapters.AnagArticoliTableAdapter(); - taAnagOpr = new MapoDb.DS_applicazioneTableAdapters.AnagraficaOperatoriTableAdapter(); - taTempiCiclo = new MapoDb.DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter(); - } - - /// - /// recupera sequenza x una SINGOLA macchina - /// - /// - /// - /// - /// - /// - private List seqSingleMachine(string idxMacchina, intervalloDate _intervallo, int numSplit, int index) - { - List sequenza = new List(); - Stopwatch stopwatch = new Stopwatch(); - DateTime start = DateTime.Now; - // leggo i dati e costituisco una collezione... - int i = index; - if (idxMacchina != null && idxMacchina != "") - { - logger.lg.scriviLog("inizio WS"); - stopwatch.Restart(); - // seleziono i dati... - DS_applicazione.DiarioDiBordoDataTable tabSeq = taDiarioDiBordo.GetSequenza(idxMacchina, _intervallo.inizio, _intervallo.fine); - logger.lg.scriviLog(string.Format("Letta tabella: {0} rec, {1} msec", tabSeq.Rows.Count, stopwatch.ElapsedMilliseconds)); - - // se ho troppi dati faccio la riduzione dei dati, MAX numSplit... - if (tabSeq.Rows.Count > numSplit) - { - double sogliaMin = _intervallo.fine.Subtract(_intervallo.inizio).TotalMinutes / numSplit; - tabSeq = riduciSeq(tabSeq, sogliaMin); - } - logger.lg.scriviLog(string.Format("Riduzione seq fatta: {0} rec, {1} msec", tabSeq.Count, stopwatch.ElapsedMilliseconds)); - // ora converto in oggetto definitivo x vis.js - sequenza = tabSeq.AsEnumerable().Select(riga => new visjsDsItem - { - //id = i, - content = "",//riga.CodArticolo, - start = riga.InizioStato.ToString("yyyy-MM-dd HH:mm:ss"), - end = riga.FineStato.ToString("yyyy-MM-dd HH:mm:ss"), - group = riga.IdxMacchina,// "1", // per mostrare multi macchine - type = "background", // importante x non vedere bordi... - className = semaforoDaIdxStato(riga.IdxStato) - }).ToList(); - - foreach (var item in sequenza) - { - //item.content = i.ToString(); - item.id = i; - i++; - } - logger.lg.scriviLog(string.Format("Conversione oggetto eseguita: {0} rec, {1} msec", sequenza.Count, stopwatch.ElapsedMilliseconds)); - } - - return sequenza; - } - - /// - /// forza la connString x i vari table adapters - /// - private void setConnString() - { - string _connectionString = memLayer.ML.confReadString("MoonProConnectionString"); - taMacchine.Connection.ConnectionString = _connectionString; - taStatoMacchine.Connection.ConnectionString = _connectionString; - taStati.Connection.ConnectionString = _connectionString; - taDiarioDiBordo.Connection.ConnectionString = _connectionString; - taParetoDurate.Connection.ConnectionString = _connectionString; - taAnagraficaEventi.Connection.ConnectionString = _connectionString; - taAnagArt.Connection.ConnectionString = _connectionString; - taAnagOpr.Connection.ConnectionString = _connectionString; - taTempiCiclo.Connection.ConnectionString = _connectionString; - } - - #endregion Private Methods - - #region Protected Methods - - /// - /// Effettua riduzione per accorpamento valori - /// - /// - /// - protected DS_applicazione.DiarioDiBordoDataTable riduciSeq(DS_applicazione.DiarioDiBordoDataTable original, double sogliaMin) - { - DS_applicazione.DiarioDiBordoDataTable copia = new DS_applicazione.DiarioDiBordoDataTable(); - //DS_applicazione.DiarioDiBordoRow currRow; - // valori x setup - double minVerde = 0.5; - double minRosso = 0.5; - double minSpento = 0.5; - - double valRigaCum = 0.0; - double valR = 0.0; - double valG = 0.0; - double valV = 0.0; - double valB = 0.0; - double valS = 0.0; - DateTime _t_0 = new DateTime(9999, 1, 1); - string _mostCodArticolo = ""; - int _maxVal = 0; - foreach (var riga in original) - { - // salvo prima data... - if (riga.InizioStato < _t_0) - { - _t_0 = riga.InizioStato; - } - if (riga.DurataMinuti > _maxVal) - { - _maxVal = Convert.ToInt32(riga.DurataMinuti); - _mostCodArticolo = riga.CodArticolo; - } - valRigaCum = valRigaCum + riga.DurataMinuti; - // accumulo valori... - switch (semaforoDaIdxStato(riga.IdxStato)) - { - case "sVe": - valV = valV + riga.DurataMinuti; - break; - - case "sGi": - valG = valG + riga.DurataMinuti; - break; - - case "sRo": - valR = valR + riga.DurataMinuti; - break; - - case "sBl": - valB = valB + riga.DurataMinuti; - break; - - case "sGr": - valS = valS + riga.DurataMinuti; - break; - } - // se è maggiore plotto... - if (valRigaCum >= sogliaMin) - { - // determino il colore... - if (valV / valRigaCum >= minVerde) - { - valV = 0.0; - } - else if (valR / valRigaCum >= minRosso) - { - valR = 0.0; - } - else if (valS / valRigaCum >= minSpento) - { - valS = 0.0; - } - else if (valB / valRigaCum >= minSpento) - { - valB = 0.0; - } - else - { - valG = 0.0; - } - // modifico riga corrente... - riga.DurataMinuti = valRigaCum; - riga.CodArticolo = _mostCodArticolo; - //riga.InizioStato = _t_0; - copia.ImportRow(riga); - // modifico inizio stato... - ((DS_applicazione.DiarioDiBordoRow)copia.Rows[copia.Rows.Count - 1]).InizioStato = _t_0; - // reset dei contatori... - valRigaCum = 0.0; - - _t_0 = new DateTime(9999, 1, 1); - _mostCodArticolo = ""; - _maxVal = 0; - } - } - // restituisco valori "ridotti" - return copia; - } - - #endregion Protected Methods - #region Public Methods /// @@ -795,7 +357,8 @@ public class resoconti logger.lg.scriviLog(string.Format("FINE calcolo dati per {0} {1}", idxMacchina, rKey)); // salvo sequenza in REDIS... string rData = JsonConvert.SerializeObject(_sequenza); - // salvo in sessione l'oggetto... secondo durata impostata in web.config.. moltiplicata x numero gg... + // salvo in sessione l'oggetto... secondo durata impostata in web.config.. + // moltiplicata x numero gg... memLayer.ML.setRSV(rKey, rData, 60 * memLayer.ML.CRI("seqCacheDurMin") * (int)numGG); logger.lg.scriviLog(string.Format("Salvato legacySeq in REDIS {0} {1}", idxMacchina, rKey)); } @@ -1002,6 +565,440 @@ public class resoconti } #endregion Public Methods + + #region Protected Fields + + protected DS_applicazione.AnagArticoliDataTable _AnagArt; + protected DS_applicazione.AnagraficaOperatoriDataTable _AnagOpr; + protected DS_applicazione.AnagraficaEventiDataTable _AnagraficaEventi; + protected DS_applicazione.DiarioDiBordoDataTable _DiarioDiBordo; + protected DS_applicazione.MacchineDataTable _Macchine; + protected DS_applicazione.AnagraficaStatiDataTable _Stati; + protected DS_applicazione.StatoMacchineDataTable _StatoMacchine; + protected MapoDb.DS_applicazioneTableAdapters.AnagArticoliTableAdapter taAnagArt; + protected MapoDb.DS_applicazioneTableAdapters.AnagraficaOperatoriTableAdapter taAnagOpr; + protected MapoDb.DS_applicazioneTableAdapters.AnagraficaEventiTableAdapter taAnagraficaEventi; + protected MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter taDiarioDiBordo; + protected MapoDb.DS_applicazioneTableAdapters.MacchineTableAdapter taMacchine; + protected MapoDb.DS_applicazioneTableAdapters.ParetoDurateTableAdapter taParetoDurate; + protected MapoDb.DS_applicazioneTableAdapters.AnagraficaStatiTableAdapter taStati; + protected MapoDb.DS_applicazioneTableAdapters.StatoMacchineTableAdapter taStatoMacchine; + protected MapoDb.DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter taTempiCiclo; + + #endregion Protected Fields + + #region Protected Properties + + protected DS_applicazione.AnagArticoliDataTable AnagArt + { + get + { + if (!memLayer.ML.isInCacheObject("AnagArt")) + { + _AnagArt = taAnagArt.GetData(); + string serVal = JsonConvert.SerializeObject(_AnagArt); + memLayer.ML.setCacheVal("AnagArt", serVal, true); + } + else + { + string redKey = memLayer.ML.redHash("AnagArt"); + string serVal = memLayer.ML.getRSV(redKey); + _AnagArt = JsonConvert.DeserializeObject(serVal); + } + return _AnagArt; + } + } + + protected DS_applicazione.AnagraficaOperatoriDataTable AnagOpr + { + get + { + if (!memLayer.ML.isInCacheObject("AnagOpr")) + { + _AnagOpr = taAnagOpr.GetData(); + string serVal = JsonConvert.SerializeObject(_AnagOpr); + memLayer.ML.setCacheVal("AnagOpr", serVal, true); + } + else + { + string redKey = memLayer.ML.redHash("AnagOpr"); + string serVal = memLayer.ML.getRSV(redKey); + _AnagOpr = JsonConvert.DeserializeObject(serVal); + } + return _AnagOpr; + } + } + + protected DS_applicazione.AnagraficaEventiDataTable AnagraficaEventi + { + get + { + if (!memLayer.ML.isInCacheObject("AnagraficaEventi")) + { + _AnagraficaEventi = taAnagraficaEventi.GetData(); + string serVal = JsonConvert.SerializeObject(_AnagraficaEventi); + memLayer.ML.setCacheVal("AnagraficaEventi", serVal, true); + } + else + { + string redKey = memLayer.ML.redHash("AnagraficaEventi"); + string serVal = memLayer.ML.getRSV(redKey); + _AnagraficaEventi = JsonConvert.DeserializeObject(serVal); + } + return _AnagraficaEventi; + } + } + + /// + /// Dizionario codici colore (chiave = idxStato), valore = codice colore + /// + protected Dictionary codColore + { + get + { + Dictionary answ = new Dictionary(); + if (memLayer.ML.isInCacheObject("codColore")) + { + string redKey = memLayer.ML.redHash("codColore"); + string serVal = memLayer.ML.getRSV(redKey); + answ = JsonConvert.DeserializeObject>(serVal); + } + else + { + string _colore = ""; + foreach (DS_applicazione.AnagraficaStatiRow item in Stati) + { + switch (item.Semaforo) + { + case "sGi": // giallo + _colore = "#ffec00"; + break; + + case "sRo": // rosso + _colore = "#e2001a"; + break; + + case "sGr": // grigio - spenta + _colore = "#bcbcbc"; + break; + + case "sVe": // verde + _colore = "#009036"; + break; + + case "sBl": // blu + _colore = "#3690FF"; + break; + + default: + break; + } + answ.Add(item.IdxStato, _colore); + } + string serVal = JsonConvert.SerializeObject(answ); + memLayer.ML.setCacheVal("codColore", serVal, true); + } + return answ; + } + } + + /// + /// Dizionario codici semaforo (chiave = idxStato), valore = codice semaforo + /// + protected Dictionary codSemaforo + { + get + { + Dictionary answ = new Dictionary(); + if (memLayer.ML.isInCacheObject("codSemaforo")) + { + string redKey = memLayer.ML.redHash("codSemaforo"); + string serVal = memLayer.ML.getRSV(redKey); + answ = JsonConvert.DeserializeObject>(serVal); + } + else + { + foreach (DS_applicazione.AnagraficaStatiRow item in Stati) + { + answ.Add(item.IdxStato, item.Semaforo); + } + string serVal = JsonConvert.SerializeObject(answ); + memLayer.ML.setCacheVal("codSemaforo", serVal, true); + } + return answ; + } + } + + protected DS_applicazione.DiarioDiBordoDataTable DiarioDiBordo + { + get + { + if (_DiarioDiBordo == null) + { + _DiarioDiBordo = taDiarioDiBordo.GetData(); + } + return _DiarioDiBordo; + } + } + + protected DS_applicazione.MacchineDataTable Macchine + { + get + { + if (!memLayer.ML.isInCacheObject("Macchine")) + { + _Macchine = taMacchine.GetData(); + string serVal = JsonConvert.SerializeObject(_Macchine); + memLayer.ML.setCacheVal("Macchine", serVal, true); + } + else + { + string redKey = memLayer.ML.redHash("Macchine"); + string serVal = memLayer.ML.getRSV(redKey); + _Macchine = JsonConvert.DeserializeObject(serVal); + } + return _Macchine; + } + } + + protected DS_applicazione.AnagraficaStatiDataTable Stati + { + get + { + if (!memLayer.ML.isInCacheObject("Stati")) + { + _Stati = taStati.GetData(); + string serVal = JsonConvert.SerializeObject(_Stati); + memLayer.ML.setCacheVal("Stati", serVal, true); + } + else + { + string redKey = memLayer.ML.redHash("Stati"); + string serVal = memLayer.ML.getRSV(redKey); + _Stati = JsonConvert.DeserializeObject(serVal); + } + return _Stati; + } + } + + protected DS_applicazione.StatoMacchineDataTable StatoMacchine + { + get + { + if (!memLayer.ML.isInCacheObject("StatoMacchine")) + { + _StatoMacchine = taStatoMacchine.GetData(); + string serVal = JsonConvert.SerializeObject(_StatoMacchine); + memLayer.ML.setCacheVal("StatoMacchine", serVal, true); + } + else + { + string redKey = memLayer.ML.redHash("StatoMacchine"); + string serVal = memLayer.ML.getRSV(redKey); + _StatoMacchine = JsonConvert.DeserializeObject(serVal); + } + return _StatoMacchine; + } + } + + #endregion Protected Properties + + #region Protected Methods + + /// + /// Effettua riduzione per accorpamento valori + /// + /// + /// + protected DS_applicazione.DiarioDiBordoDataTable riduciSeq(DS_applicazione.DiarioDiBordoDataTable original, double sogliaMin) + { + DS_applicazione.DiarioDiBordoDataTable copia = new DS_applicazione.DiarioDiBordoDataTable(); + //DS_applicazione.DiarioDiBordoRow currRow; + // valori x setup + double minVerde = 0.5; + double minRosso = 0.5; + double minSpento = 0.5; + + double valRigaCum = 0.0; + double valR = 0.0; + double valG = 0.0; + double valV = 0.0; + double valB = 0.0; + double valS = 0.0; + DateTime _t_0 = new DateTime(9999, 1, 1); + string _mostCodArticolo = ""; + int _maxVal = 0; + foreach (var riga in original) + { + // salvo prima data... + if (riga.InizioStato < _t_0) + { + _t_0 = riga.InizioStato; + } + if (riga.DurataMinuti > _maxVal) + { + _maxVal = Convert.ToInt32(riga.DurataMinuti); + _mostCodArticolo = riga.CodArticolo; + } + valRigaCum = valRigaCum + riga.DurataMinuti; + // accumulo valori... + switch (semaforoDaIdxStato(riga.IdxStato)) + { + case "sVe": + valV = valV + riga.DurataMinuti; + break; + + case "sGi": + valG = valG + riga.DurataMinuti; + break; + + case "sRo": + valR = valR + riga.DurataMinuti; + break; + + case "sBl": + valB = valB + riga.DurataMinuti; + break; + + case "sGr": + valS = valS + riga.DurataMinuti; + break; + } + // se è maggiore plotto... + if (valRigaCum >= sogliaMin) + { + // determino il colore... + if (valV / valRigaCum >= minVerde) + { + valV = 0.0; + } + else if (valR / valRigaCum >= minRosso) + { + valR = 0.0; + } + else if (valS / valRigaCum >= minSpento) + { + valS = 0.0; + } + else if (valB / valRigaCum >= minSpento) + { + valB = 0.0; + } + else + { + valG = 0.0; + } + // modifico riga corrente... + riga.DurataMinuti = valRigaCum; + riga.CodArticolo = _mostCodArticolo; + //riga.InizioStato = _t_0; + copia.ImportRow(riga); + // modifico inizio stato... + ((DS_applicazione.DiarioDiBordoRow)copia.Rows[copia.Rows.Count - 1]).InizioStato = _t_0; + // reset dei contatori... + valRigaCum = 0.0; + + _t_0 = new DateTime(9999, 1, 1); + _mostCodArticolo = ""; + _maxVal = 0; + } + } + // restituisco valori "ridotti" + return copia; + } + + #endregion Protected Methods + + #region Private Methods + + /// + /// avvio i table adapter della classe + /// + private void AvviaTabAdapt() + { + taMacchine = new MapoDb.DS_applicazioneTableAdapters.MacchineTableAdapter(); + taStatoMacchine = new MapoDb.DS_applicazioneTableAdapters.StatoMacchineTableAdapter(); + taStati = new MapoDb.DS_applicazioneTableAdapters.AnagraficaStatiTableAdapter(); + taDiarioDiBordo = new MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter(); + taParetoDurate = new MapoDb.DS_applicazioneTableAdapters.ParetoDurateTableAdapter(); + taAnagraficaEventi = new MapoDb.DS_applicazioneTableAdapters.AnagraficaEventiTableAdapter(); + taAnagArt = new MapoDb.DS_applicazioneTableAdapters.AnagArticoliTableAdapter(); + taAnagOpr = new MapoDb.DS_applicazioneTableAdapters.AnagraficaOperatoriTableAdapter(); + taTempiCiclo = new MapoDb.DS_ProdTempiTableAdapters.TempiCicloRilevatiTableAdapter(); + } + + /// + /// recupera sequenza x una SINGOLA macchina + /// + /// + /// + /// + /// + /// + private List seqSingleMachine(string idxMacchina, intervalloDate _intervallo, int numSplit, int index) + { + List sequenza = new List(); + Stopwatch stopwatch = new Stopwatch(); + DateTime start = DateTime.Now; + // leggo i dati e costituisco una collezione... + int i = index; + if (idxMacchina != null && idxMacchina != "") + { + logger.lg.scriviLog("inizio WS"); + stopwatch.Restart(); + // seleziono i dati... + DS_applicazione.DiarioDiBordoDataTable tabSeq = taDiarioDiBordo.GetSequenza(idxMacchina, _intervallo.inizio, _intervallo.fine); + logger.lg.scriviLog(string.Format("Letta tabella: {0} rec, {1} msec", tabSeq.Rows.Count, stopwatch.ElapsedMilliseconds)); + + // se ho troppi dati faccio la riduzione dei dati, MAX numSplit... + if (tabSeq.Rows.Count > numSplit) + { + double sogliaMin = _intervallo.fine.Subtract(_intervallo.inizio).TotalMinutes / numSplit; + tabSeq = riduciSeq(tabSeq, sogliaMin); + } + logger.lg.scriviLog(string.Format("Riduzione seq fatta: {0} rec, {1} msec", tabSeq.Count, stopwatch.ElapsedMilliseconds)); + // ora converto in oggetto definitivo x vis.js + sequenza = tabSeq.AsEnumerable().Select(riga => new visjsDsItem + { + //id = i, + content = "",//riga.CodArticolo, + start = riga.InizioStato.ToString("yyyy-MM-dd HH:mm:ss"), + end = riga.FineStato.ToString("yyyy-MM-dd HH:mm:ss"), + group = riga.IdxMacchina,// "1", // per mostrare multi macchine + type = "background", // importante x non vedere bordi... + className = semaforoDaIdxStato(riga.IdxStato) + }).ToList(); + + foreach (var item in sequenza) + { + //item.content = i.ToString(); + item.id = i; + i++; + } + logger.lg.scriviLog(string.Format("Conversione oggetto eseguita: {0} rec, {1} msec", sequenza.Count, stopwatch.ElapsedMilliseconds)); + } + + return sequenza; + } + + /// + /// forza la connString x i vari table adapters + /// + private void setConnString() + { + string _connectionString = memLayer.ML.confReadString("MoonProConnectionString"); + taMacchine.Connection.ConnectionString = _connectionString; + taStatoMacchine.Connection.ConnectionString = _connectionString; + taStati.Connection.ConnectionString = _connectionString; + taDiarioDiBordo.Connection.ConnectionString = _connectionString; + taParetoDurate.Connection.ConnectionString = _connectionString; + taAnagraficaEventi.Connection.ConnectionString = _connectionString; + taAnagArt.Connection.ConnectionString = _connectionString; + taAnagOpr.Connection.ConnectionString = _connectionString; + taTempiCiclo.Connection.ConnectionString = _connectionString; + } + + #endregion Private Methods } /// diff --git a/MapoDb/selData.cs b/MapoDb/selData.cs index 2d1d600b..416df2ca 100644 --- a/MapoDb/selData.cs +++ b/MapoDb/selData.cs @@ -5,142 +5,159 @@ using System; public class selData { + #region Public Fields - /// - /// Durata standard cache info - /// - protected int cacheDuration = 5; - protected DataLayer DataLayerObj; - /// - /// classe accesso tabelle selettori - /// - public selData() - { - DataLayerObj = new DataLayer(); - } + public static selData mng = new selData(); - public static selData mng = new selData(); + #endregion Public Fields - /// - /// Tabella elenco Articoli - /// NB: mantenuta in cache redis x evitare continue letture... - /// - /// - /// - public DS_ProdTempi.AnagArticoliDataTable getSelAllArticoli() - { - return DataLayerObj.taAnagArt.GetData(); - } - /// - /// Riga dettaglio singolo articolo - /// NB: mantenuta in cache redis x evitare continue letture... - /// - /// - /// - public DS_ProdTempi.AnagArticoliRow rigaArt(string codArt) - { - DS_ProdTempi.AnagArticoliRow answ = null; - // cerco in REDIS... - string redKey = memLayer.ML.redHash("Cache:Art:" + codArt); - string serVal = memLayer.ML.getRSV(redKey); - if (serVal != null && serVal != "") + #region Public Constructors + + /// + /// classe accesso tabelle selettori + /// + public selData() { - try - { - DS_ProdTempi.AnagArticoliDataTable tab = JsonConvert.DeserializeObject(serVal); - if (tab.Rows.Count > 0) + DataLayerObj = new DataLayer(); + } + + #endregion Public Constructors + + #region Public Methods + + /// + /// Tabella elenco Articoli + /// NB: mantenuta in cache redis x evitare continue letture... + /// + /// + /// + public DS_ProdTempi.AnagArticoliDataTable getSelAllArticoli() + { + return DataLayerObj.taAnagArt.GetData(); + } + + /// + /// Invalida e svuota la cache di selezione post update vari... + /// + /// + public bool invalidateCache() + { + bool answ = false; + try { - answ = tab[0]; + string redKey = memLayer.ML.redHash("Cache:Art:"); + memLayer.ML.redFlushKey(redKey); + redKey = memLayer.ML.redHash("Cache:StatoMacc:"); + memLayer.ML.redFlushKey(redKey); + answ = true; } - } - catch (Exception exc) - { + catch + { } + return answ; + } - logger.lg.scriviLog(string.Format("rigaArt|Errore in deserializzazione chiave {0}{1}{2}", codArt, Environment.NewLine, exc), tipoLog.EXCEPTION); - } - } - else + /// + /// Riga dettaglio singolo articolo + /// NB: mantenuta in cache redis x evitare continue letture... + /// + /// + /// + public DS_ProdTempi.AnagArticoliRow rigaArt(string codArt) { - // se non trovo --> DB! - try - { - DS_ProdTempi.AnagArticoliDataTable tab = DataLayerObj.taAnagArt.getByCod(codArt); - if (tab.Rows.Count > 0) + DS_ProdTempi.AnagArticoliRow answ = null; + // cerco in REDIS... + string redKey = memLayer.ML.redHash("Cache:Art:" + codArt); + string serVal = memLayer.ML.getRSV(redKey); + if (serVal != null && serVal != "") { - answ = tab[0]; + try + { + DS_ProdTempi.AnagArticoliDataTable tab = JsonConvert.DeserializeObject(serVal); + if (tab.Rows.Count > 0) + { + answ = tab[0]; + } + } + catch (Exception exc) + { + logger.lg.scriviLog(string.Format("rigaArt|Errore in deserializzazione chiave {0}{1}{2}", codArt, Environment.NewLine, exc), tipoLog.EXCEPTION); + } } - serVal = JsonConvert.SerializeObject(tab); - memLayer.ML.setRSV(redKey, serVal, cacheDuration); - } - catch - { } + else + { + // se non trovo --> DB! + try + { + DS_ProdTempi.AnagArticoliDataTable tab = DataLayerObj.taAnagArt.getByCod(codArt); + if (tab.Rows.Count > 0) + { + answ = tab[0]; + } + serVal = JsonConvert.SerializeObject(tab); + memLayer.ML.setRSV(redKey, serVal, cacheDuration); + } + catch + { } + } + return answ; } - return answ; - } - /// - /// Riga STATO macchina - /// NB: mantenuta in cache redis x evitare continue letture... - /// - /// - /// - public DS_applicazione.StatoMacchineRow rigaStato(string idxMacc) - { - DS_applicazione.StatoMacchineRow answ = null; - // cerco in REDIS... - string redKey = memLayer.ML.redHash("Cache:StatoMacc:" + idxMacc); - string serVal = memLayer.ML.getRSV(redKey); - if (serVal != null && serVal != "") - { - try - { - DS_applicazione.StatoMacchineDataTable tab = JsonConvert.DeserializeObject(serVal); - if (tab.Rows.Count > 0) - { - answ = tab[0]; - } - } - catch (Exception exc) - { - logger.lg.scriviLog(string.Format("rigaStato|Errore in deserializzazione chiave {0}{1}{2}", idxMacc, Environment.NewLine, exc), tipoLog.EXCEPTION); - } - } - else + /// + /// Riga STATO macchina + /// NB: mantenuta in cache redis x evitare continue letture... + /// + /// + /// + public DS_applicazione.StatoMacchineRow rigaStato(string idxMacc) { - // se non trovo --> DB! - try - { - DS_applicazione.StatoMacchineDataTable tab = DataLayerObj.taStatoMacchine.GetDataByIdxMacchina(idxMacc); - if (tab.Rows.Count > 0) + DS_applicazione.StatoMacchineRow answ = null; + // cerco in REDIS... + string redKey = memLayer.ML.redHash("Cache:StatoMacc:" + idxMacc); + string serVal = memLayer.ML.getRSV(redKey); + if (serVal != null && serVal != "") { - answ = tab[0]; + try + { + DS_applicazione.StatoMacchineDataTable tab = JsonConvert.DeserializeObject(serVal); + if (tab.Rows.Count > 0) + { + answ = tab[0]; + } + } + catch (Exception exc) + { + logger.lg.scriviLog(string.Format("rigaStato|Errore in deserializzazione chiave {0}{1}{2}", idxMacc, Environment.NewLine, exc), tipoLog.EXCEPTION); + } } - serVal = JsonConvert.SerializeObject(tab); - memLayer.ML.setRSV(redKey, serVal, cacheDuration); - } - catch - { } + else + { + // se non trovo --> DB! + try + { + DS_applicazione.StatoMacchineDataTable tab = DataLayerObj.taStatoMacchine.GetDataByIdxMacchina(idxMacc); + if (tab.Rows.Count > 0) + { + answ = tab[0]; + } + serVal = JsonConvert.SerializeObject(tab); + memLayer.ML.setRSV(redKey, serVal, cacheDuration); + } + catch + { } + } + return answ; } - return answ; - } - /// - /// Invalida e svuota la cache di selezione post update vari... - /// - /// - public bool invalidateCache() - { - bool answ = false; - try - { - string redKey = memLayer.ML.redHash("Cache:Art:"); - memLayer.ML.redFlushKey(redKey); - redKey = memLayer.ML.redHash("Cache:StatoMacc:"); - memLayer.ML.redFlushKey(redKey); - answ = true; - } - catch - { } - return answ; - } -} + #endregion Public Methods + + #region Protected Fields + + /// + /// Durata standard cache info + /// + protected int cacheDuration = 5; + + protected DataLayer DataLayerObj; + + #endregion Protected Fields +} \ No newline at end of file diff --git a/MapoDb/selDataVoc.cs b/MapoDb/selDataVoc.cs index a7c9ee85..356de5fc 100644 --- a/MapoDb/selDataVoc.cs +++ b/MapoDb/selDataVoc.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MapoDb +namespace MapoDb { public class selDataVoc { diff --git a/MapoDb/utility.cs b/MapoDb/utility.cs index 8461f7ea..b53a006e 100644 --- a/MapoDb/utility.cs +++ b/MapoDb/utility.cs @@ -7,226 +7,240 @@ using System; /// public class utility { - MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter taStati; - MapoDb.DS_applicazioneTableAdapters.EventListTableAdapter taEventi; - MapoDb.DS_UtilityTableAdapters.StatoMacchineTableAdapter taSM; + #region Public Fields + /// + /// oggetto static per fare chiamate sul magazzino + /// + public static utility obj = new utility(); - /// - /// effettua primo step - /// * se 13,4,17 --> (da lavora a cambioPallet) pulizia righe tab elenco stati x caber 1 e 2 (cambio pallet "instabile" su lavorazione) - /// - /// - /// - /// - /// - public void ripulisciStepOne(string idxMacchina, int idxStatoFrom, int idxStatoTo, int idxEventoTo) - { - // recupero SOLO le righe delle caber,1 alla volta... - DS_applicazione.DiarioDiBordoDataTable tabella = taStati.GetShortChanging(idxMacchina, 1, idxStatoFrom); // prendo solo le lavorazioni... - foreach (DS_applicazione.DiarioDiBordoRow riga in tabella) + #endregion Public Fields + + #region Public Methods + + /// + /// Effettua la masking di un valore (INT) rispetto ad una BitMask (INT) + /// + /// Valore da filtrare + /// BitMask (espresso in valore INT: es 1001 --> 9) + /// + public static int bMaskInt(int valore, int bitMask) { - // modifico lavorazione in cambiopallet... - taStati.UpdateStato(idxStatoTo, riga.IdxMacchina, riga.InizioStato); - taEventi.UpdateTipo(idxEventoTo, riga.IdxMacchina, riga.InizioStato); + return valore & bitMask; } - } - /// - /// effettua secondo step (eliminazione e ricalcolo durate) pulizia righe tab elenco stati - /// * 14 --> x caber 1 e 2 (cambio pallet "instabile" su lavorazione) - /// - /// - /// - public void ripulisciStepTwo(string idxMacchina, int idxStato2reduce) - { - DS_applicazione.DiarioDiBordoDataTable tabella = taStati.GetData(); - // inizializzo riga... - DS_applicazione.DiarioDiBordoRow rigaCumulo = (DS_applicazione.DiarioDiBordoRow)tabella.Rows[0]; - // controllo ogni riga, salvo i valori cumsum e start dalla prima, cancello corrente ed infine inserisco riga di sunto delle contigue... - double durata; - foreach (DS_applicazione.DiarioDiBordoRow riga in tabella) + /// + /// restituisce stringa formattata in HH:mm:ss + /// + /// + /// + public static string durataEventoHMS(double durataMinuti) { - // verifico se sia identica alla precedente... - if (rigaCumulo.IdxStato == idxStato2reduce && riga.IdxStato == idxStato2reduce && rigaCumulo.CodArticolo == riga.CodArticolo) - { - if (riga.InizioStato != rigaCumulo.InizioStato) + string durataFormattata = ""; + try { - - durata = riga.FineStato.Subtract(rigaCumulo.InizioStato).TotalMinutes; - taStati.UpdateFineDurata(riga.FineStato, (float)durata, rigaCumulo.IdxMacchina, rigaCumulo.InizioStato); - // cancello riga duplicata - taStati.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + DateTime tempo = new DateTime(); + tempo = tempo.AddMinutes(durataMinuti); + durataFormattata = string.Format("{0:00}:{1:00}:{2:00}", tempo.Hour, tempo.Minute, tempo.Second); } - } - else - { - rigaCumulo = riga; - } - } - } - - /// - /// effettua terzo step (eliminazione e ricalcolo durate) pulizia righe tab elenco eventi - /// * 17 --> x caber 1 e 2 (cambio pallet "instabile" su lavorazione) - /// - /// - /// - public void ripulisciStepThree(string idxMacchina, int idxEvento2del) - { - // adesso svuoto i duplicati dalla tab eventi... - DS_applicazione.EventListRow[] righe = (DS_applicazione.EventListRow[])taEventi.GetDataFiltered(idxMacchina, new DateTime(1999, 1, 1), new DateTime(9999, 1, 1)).Select("", "InizioStato ASC"); - DS_applicazione.EventListRow rigaEvPrev = righe[0]; - foreach (DS_applicazione.EventListRow riga in righe) - { - if (riga.IdxTipo == idxEvento2del && rigaEvPrev.IdxTipo == idxEvento2del && riga.CodArticolo == rigaEvPrev.CodArticolo) - { - if (riga.InizioStato != rigaEvPrev.InizioStato) + catch { - taEventi.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + logger.lg.scriviLog(string.Format("errore calcolo durata: durataMinuti {0}", durataMinuti), tipoLog.EXCEPTION); } - } - else - { - rigaEvPrev = riga; - } + return durataFormattata; } - } - /// - /// effettua terzo step (eliminazione e ricalcolo durate) pulizia righe tab elenco eventi - /// * 16/17 --> x caber 1 e 2 (cambio pallet "instabile" su lavorazione) - /// - /// - /// - public void ripulisciStepFour(string idxMacchina, int idxEventoPre, int idxEvento2del) - { - // adesso svuoto i duplicati dalla tab eventi... - DS_applicazione.EventListRow[] righe = (DS_applicazione.EventListRow[])taEventi.GetDataFiltered(idxMacchina, new DateTime(1999, 1, 1), new DateTime(9999, 1, 1)).Select("", "InizioStato ASC"); - DS_applicazione.EventListRow rigaEvPrev = righe[0]; - foreach (DS_applicazione.EventListRow riga in righe) + /// + /// effettua reset del db + /// + public void resetDb() { - if (riga.IdxTipo == idxEvento2del && rigaEvPrev.IdxTipo == idxEventoPre && riga.CodArticolo == rigaEvPrev.CodArticolo) - { - if (riga.InizioStato != rigaEvPrev.InizioStato) + taSM.stp_ZZZ_riallineaDateDb(); + } + + /// + /// effettua ultimo step (eliminazione eventi) * 16/15 --> x Syntesy L11 (HW - machining / HW + /// - power on) elimino se è (15/16) ed i 2 prec sono 15+16... + /// + /// + /// + /// + public void ripulisciStepFive(string idxMacchina, int idxEvento1, int idxEvento2) + { + // adesso svuoto i duplicati dalla tab eventi... + DS_applicazione.EventListRow[] righe = (DS_applicazione.EventListRow[])taEventi.GetDataFiltered(idxMacchina, new DateTime(1999, 1, 1), new DateTime(9999, 1, 1)).Select("", "InizioStato ASC"); + DS_applicazione.EventListRow rigaMenoUno = righe[0]; + DS_applicazione.EventListRow rigaMenoDue = righe[1]; + foreach (DS_applicazione.EventListRow riga in righe) { - taEventi.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + if (riga.InizioStato > rigaMenoDue.InizioStato) + { + if (riga.IdxTipo == idxEvento1 || riga.IdxTipo == idxEvento2) + { + if ((rigaMenoUno.IdxTipo == idxEvento1 && rigaMenoDue.IdxTipo == idxEvento2) || (rigaMenoUno.IdxTipo == idxEvento2 && rigaMenoDue.IdxTipo == idxEvento1)) + { + taEventi.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + } + } + rigaMenoDue = rigaMenoUno; + rigaMenoUno = riga; + } } - } - else - { - rigaEvPrev = riga; - } } - } - /// - /// effettua ultimo step (eliminazione eventi) * 16/15 --> x Syntesy L11 - /// (HW - machining / HW - power on) - /// elimino se è (15/16) ed i 2 prec sono 15+16... - /// - /// - /// - /// - public void ripulisciStepFive(string idxMacchina, int idxEvento1, int idxEvento2) - { - // adesso svuoto i duplicati dalla tab eventi... - DS_applicazione.EventListRow[] righe = (DS_applicazione.EventListRow[])taEventi.GetDataFiltered(idxMacchina, new DateTime(1999, 1, 1), new DateTime(9999, 1, 1)).Select("", "InizioStato ASC"); - DS_applicazione.EventListRow rigaMenoUno = righe[0]; - DS_applicazione.EventListRow rigaMenoDue = righe[1]; - foreach (DS_applicazione.EventListRow riga in righe) + /// + /// effettua terzo step (eliminazione e ricalcolo durate) pulizia righe tab elenco eventi + /// * 16/17 --> x caber 1 e 2 (cambio pallet "instabile" su lavorazione) + /// + /// + /// + public void ripulisciStepFour(string idxMacchina, int idxEventoPre, int idxEvento2del) { - if (riga.InizioStato > rigaMenoDue.InizioStato) - { - if (riga.IdxTipo == idxEvento1 || riga.IdxTipo == idxEvento2) + // adesso svuoto i duplicati dalla tab eventi... + DS_applicazione.EventListRow[] righe = (DS_applicazione.EventListRow[])taEventi.GetDataFiltered(idxMacchina, new DateTime(1999, 1, 1), new DateTime(9999, 1, 1)).Select("", "InizioStato ASC"); + DS_applicazione.EventListRow rigaEvPrev = righe[0]; + foreach (DS_applicazione.EventListRow riga in righe) { - if ((rigaMenoUno.IdxTipo == idxEvento1 && rigaMenoDue.IdxTipo == idxEvento2) || (rigaMenoUno.IdxTipo == idxEvento2 && rigaMenoDue.IdxTipo == idxEvento1)) - { - taEventi.DeleteQuery(riga.IdxMacchina, riga.InizioStato); - } + if (riga.IdxTipo == idxEvento2del && rigaEvPrev.IdxTipo == idxEventoPre && riga.CodArticolo == rigaEvPrev.CodArticolo) + { + if (riga.InizioStato != rigaEvPrev.InizioStato) + { + taEventi.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + } + } + else + { + rigaEvPrev = riga; + } } - rigaMenoDue = rigaMenoUno; - rigaMenoUno = riga; - } } - } - /// - /// effettua reset del db - /// - public void resetDb() - { - taSM.stp_ZZZ_riallineaDateDb(); - } - /// - /// restituisce stringa formattata in HH:mm:ss - /// - /// - /// - public static string durataEventoHMS(double durataMinuti) - { - string durataFormattata = ""; - try + /// + /// effettua primo step + /// * se 13,4,17 --> (da lavora a cambioPallet) pulizia righe tab elenco stati x caber 1 e 2 + /// (cambio pallet "instabile" su lavorazione) + /// + /// + /// + /// + /// + public void ripulisciStepOne(string idxMacchina, int idxStatoFrom, int idxStatoTo, int idxEventoTo) { - DateTime tempo = new DateTime(); - tempo = tempo.AddMinutes(durataMinuti); - durataFormattata = string.Format("{0:00}:{1:00}:{2:00}", tempo.Hour, tempo.Minute, tempo.Second); + // recupero SOLO le righe delle caber,1 alla volta... + DS_applicazione.DiarioDiBordoDataTable tabella = taStati.GetShortChanging(idxMacchina, 1, idxStatoFrom); // prendo solo le lavorazioni... + foreach (DS_applicazione.DiarioDiBordoRow riga in tabella) + { + // modifico lavorazione in cambiopallet... + taStati.UpdateStato(idxStatoTo, riga.IdxMacchina, riga.InizioStato); + taEventi.UpdateTipo(idxEventoTo, riga.IdxMacchina, riga.InizioStato); + } } - catch + + /// + /// effettua terzo step (eliminazione e ricalcolo durate) pulizia righe tab elenco eventi + /// * 17 --> x caber 1 e 2 (cambio pallet "instabile" su lavorazione) + /// + /// + /// + public void ripulisciStepThree(string idxMacchina, int idxEvento2del) { - logger.lg.scriviLog(string.Format("errore calcolo durata: durataMinuti {0}", durataMinuti), tipoLog.EXCEPTION); + // adesso svuoto i duplicati dalla tab eventi... + DS_applicazione.EventListRow[] righe = (DS_applicazione.EventListRow[])taEventi.GetDataFiltered(idxMacchina, new DateTime(1999, 1, 1), new DateTime(9999, 1, 1)).Select("", "InizioStato ASC"); + DS_applicazione.EventListRow rigaEvPrev = righe[0]; + foreach (DS_applicazione.EventListRow riga in righe) + { + if (riga.IdxTipo == idxEvento2del && rigaEvPrev.IdxTipo == idxEvento2del && riga.CodArticolo == rigaEvPrev.CodArticolo) + { + if (riga.InizioStato != rigaEvPrev.InizioStato) + { + taEventi.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + } + } + else + { + rigaEvPrev = riga; + } + } } - return durataFormattata; - } - /// - /// Effettua la masking di un valore (INT) rispetto ad una BitMask (INT) - /// - /// Valore da filtrare - /// BitMask (espresso in valore INT: es 1001 --> 9) - /// - public static int bMaskInt(int valore, int bitMask) - { - return valore & bitMask; - } + /// + /// effettua secondo step (eliminazione e ricalcolo durate) pulizia righe tab elenco stati + /// * 14 --> x caber 1 e 2 (cambio pallet "instabile" su lavorazione) + /// + /// + /// + public void ripulisciStepTwo(string idxMacchina, int idxStato2reduce) + { + DS_applicazione.DiarioDiBordoDataTable tabella = taStati.GetData(); + // inizializzo riga... + DS_applicazione.DiarioDiBordoRow rigaCumulo = (DS_applicazione.DiarioDiBordoRow)tabella.Rows[0]; + // controllo ogni riga, salvo i valori cumsum e start dalla prima, cancello corrente ed + // infine inserisco riga di sunto delle contigue... + double durata; + foreach (DS_applicazione.DiarioDiBordoRow riga in tabella) + { + // verifico se sia identica alla precedente... + if (rigaCumulo.IdxStato == idxStato2reduce && riga.IdxStato == idxStato2reduce && rigaCumulo.CodArticolo == riga.CodArticolo) + { + if (riga.InizioStato != rigaCumulo.InizioStato) + { + durata = riga.FineStato.Subtract(rigaCumulo.InizioStato).TotalMinutes; + taStati.UpdateFineDurata(riga.FineStato, (float)durata, rigaCumulo.IdxMacchina, rigaCumulo.InizioStato); + // cancello riga duplicata + taStati.DeleteQuery(riga.IdxMacchina, riga.InizioStato); + } + } + else + { + rigaCumulo = riga; + } + } + } - #region Inizializzazione + #endregion Public Methods + #region Protected Constructors - /// - /// init dei table adapters - /// - protected void initTA() - { - // istanzio oggetto - taStati = new MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter(); - taEventi = new MapoDb.DS_applicazioneTableAdapters.EventListTableAdapter(); - taSM = new MapoDb.DS_UtilityTableAdapters.StatoMacchineTableAdapter(); - } - /// - /// effettua setup dei connection strings da web.config delal singola applicazione - /// - protected virtual void setupConnectionStringBase() - { - // connections del db - string _connectionString = memLayer.ML.confReadString("MoonProConnectionString"); - taStati.Connection.ConnectionString = _connectionString; - taEventi.Connection.ConnectionString = _connectionString; - taSM.Connection.ConnectionString = _connectionString; - } + protected utility() + { + initTA(); + setupConnectionStringBase(); + } + #endregion Protected Constructors - protected utility() - { - initTA(); - setupConnectionStringBase(); - } + #region Protected Methods - /// - /// oggetto static per fare chiamate sul magazzino - /// - public static utility obj = new utility(); + /// + /// init dei table adapters + /// + protected void initTA() + { + // istanzio oggetto + taStati = new MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter(); + taEventi = new MapoDb.DS_applicazioneTableAdapters.EventListTableAdapter(); + taSM = new MapoDb.DS_UtilityTableAdapters.StatoMacchineTableAdapter(); + } - #endregion + /// + /// effettua setup dei connection strings da web.config delal singola applicazione + /// + protected virtual void setupConnectionStringBase() + { + // connections del db + string _connectionString = memLayer.ML.confReadString("MoonProConnectionString"); + taStati.Connection.ConnectionString = _connectionString; + taEventi.Connection.ConnectionString = _connectionString; + taSM.Connection.ConnectionString = _connectionString; + } -} + #endregion Protected Methods + + #region Private Fields + + private MapoDb.DS_applicazioneTableAdapters.EventListTableAdapter taEventi; + private MapoDb.DS_UtilityTableAdapters.StatoMacchineTableAdapter taSM; + private MapoDb.DS_applicazioneTableAdapters.DiarioDiBordoTableAdapter taStati; + + #endregion Private Fields +} \ No newline at end of file