From 6a7cb4aaa85f6df862651669d0a3fc8d72be8db6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 28 Oct 2021 12:59:06 +0200 Subject: [PATCH] Update registrazione allarmi GWMS --- GWMS.Data/Controllers/GWMSController.cs | 55 +++++++++++++++++++++++++ GWMS.Data/GWMSContext.cs | 4 +- GWMS.UI/Controllers/IOBController.cs | 12 +++++- GWMS.UI/Data/GWMSDataService.cs | 17 ++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/GWMS.Data/Controllers/GWMSController.cs b/GWMS.Data/Controllers/GWMSController.cs index d3adc0a..fc92526 100644 --- a/GWMS.Data/Controllers/GWMSController.cs +++ b/GWMS.Data/Controllers/GWMSController.cs @@ -30,6 +30,61 @@ namespace GWMS.Data.Controllers #region Public Methods + /// + /// Recupero elenco allarmi (ultimi?) + /// + /// + /// + /// + /// + public List AlarmLogGetFilt(int PlantId, int skipRec, int numRec) + { + List dbResult = new List(); + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + try + { + dbResult = localDbCtx + .DbSetAlarmLog + .Where(x => x.PlantId == PlantId) + .Skip(skipRec) + .Take(numRec) + .ToList(); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante AlarmLogGetFilt{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + + /// + /// Inserimento di un record AlarmLog + /// + /// Record da inserire (senza ID...) + /// + public async Task AlarmLogInsert(AlarmLogModel newItem) + { + bool fatto = false; + using (GWMSContext localDbCtx = new GWMSContext(_configuration)) + { + try + { + localDbCtx + .DbSetAlarmLog + .Add(newItem); + await localDbCtx.SaveChangesAsync(); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}"); + } + } + return fatto; + } + /// /// Calcola DataOra arrotondata per eccesso secondo intervallo minuti indicato /// diff --git a/GWMS.Data/GWMSContext.cs b/GWMS.Data/GWMSContext.cs index 7def491..d71a763 100644 --- a/GWMS.Data/GWMSContext.cs +++ b/GWMS.Data/GWMSContext.cs @@ -47,10 +47,10 @@ namespace GWMS.Data #region Public Properties - public virtual DbSet DbAlarmLog { get; set; } - public virtual DbSet DbRebootLog { get; set; } + public virtual DbSet DbSetAlarmLog { get; set; } + public virtual DbSet DbSetConfig { get; set; } public virtual DbSet DbSetItems { get; set; } diff --git a/GWMS.UI/Controllers/IOBController.cs b/GWMS.UI/Controllers/IOBController.cs index b25b578..1fceb3d 100644 --- a/GWMS.UI/Controllers/IOBController.cs +++ b/GWMS.UI/Controllers/IOBController.cs @@ -876,8 +876,18 @@ namespace GWMS.UI.Controllers } else { + // recupero plant... var currPlant = await _DataService.PlantsGetByCode(id); - answ = (currPlant != null && currPlant.PlantId > 0) ? "OK" : "NO"; + AlarmLogModel newAlarm = new AlarmLogModel() + { + PlantId = currPlant.PlantId, + DtEvent = DateTime.Now, + MemAddress = memAddr, + Index = index, + Status = currStatus + }; + var done = await _DataService.AlarmLogInsert(newAlarm); + answ = done ? "OK" : "NO"; } return answ; } diff --git a/GWMS.UI/Data/GWMSDataService.cs b/GWMS.UI/Data/GWMSDataService.cs index 4bb891a..de079fe 100644 --- a/GWMS.UI/Data/GWMSDataService.cs +++ b/GWMS.UI/Data/GWMSDataService.cs @@ -513,6 +513,23 @@ namespace GWMS.UI.Data return answ; } + public async Task> AlarmLogGetFilt(int PlantId, int skipRec, int numRec) + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + var dbResult = dbController.AlarmLogGetFilt(PlantId, skipRec, numRec); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB AlarmLogGetFilt: {ts.TotalMilliseconds} ms"); + return await Task.FromResult(dbResult); + } + + public async Task AlarmLogInsert(AlarmLogModel newItem) + { + bool fatto = await dbController.AlarmLogInsert(newItem); + return fatto; + } + /// /// effettua verifica x tutti i plant, se livello > livello riordino e NON ci sono ordini APERTI in arrivo --> lancia ordine ///