Update registrazione allarmi GWMS
This commit is contained in:
@@ -30,6 +30,61 @@ namespace GWMS.Data.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Recupero elenco allarmi (ultimi?)
|
||||
/// </summary>
|
||||
/// <param name="PlantId"></param>
|
||||
/// <param name="skipRec"></param>
|
||||
/// <param name="numRec"></param>
|
||||
/// <returns></returns>
|
||||
public List<AlarmLogModel> AlarmLogGetFilt(int PlantId, int skipRec, int numRec)
|
||||
{
|
||||
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserimento di un record AlarmLog
|
||||
/// </summary>
|
||||
/// <param name="PlantLogModel">Record da inserire (senza ID...)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calcola DataOra arrotondata per eccesso secondo intervallo minuti indicato
|
||||
/// </summary>
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace GWMS.Data
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public virtual DbSet<AlarmLogModel> DbAlarmLog { get; set; }
|
||||
|
||||
public virtual DbSet<RebootLogModel> DbRebootLog { get; set; }
|
||||
|
||||
public virtual DbSet<AlarmLogModel> DbSetAlarmLog { get; set; }
|
||||
|
||||
public virtual DbSet<ConfigModel> DbSetConfig { get; set; }
|
||||
|
||||
public virtual DbSet<ItemModel> DbSetItems { get; set; }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -513,6 +513,23 @@ namespace GWMS.UI.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
public async Task<List<AlarmLogModel>> 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<bool> AlarmLogInsert(AlarmLogModel newItem)
|
||||
{
|
||||
bool fatto = await dbController.AlarmLogInsert(newItem);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// effettua verifica x tutti i plant, se livello > livello riordino e NON ci sono ordini APERTI in arrivo --> lancia ordine
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user