Update decoder
- gestione nuovo tipo di allarmi - db doppia registrazione
This commit is contained in:
@@ -74,7 +74,7 @@ namespace MP.MONO.Data.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserimento di un record AlarmLog
|
||||
/// Inserimento di una lista record AlarmLog
|
||||
/// </summary>
|
||||
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
||||
/// <returns></returns>
|
||||
@@ -99,6 +99,214 @@ namespace MP.MONO.Data.Controllers
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco records anagrafica allarmi
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AlarmListModel> AlarmListGetAll()
|
||||
{
|
||||
List<AlarmListModel>? dbResult = new List<AlarmListModel>();
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetAlarmList
|
||||
.OrderBy(x => x.FullValue)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmListGetAll{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserimento di un record anagrafica allarmi (o se esiste restituisce quello esistente)
|
||||
/// </summary>
|
||||
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
||||
/// <returns></returns>
|
||||
public AlarmListModel? AlarmListInsert(string alarmText)
|
||||
{
|
||||
AlarmListModel? foundRec = new AlarmListModel();
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
// verifico che NON esista con pèari descrizione...
|
||||
foundRec = localDbCtx
|
||||
.DbSetAlarmList
|
||||
.FirstOrDefault(x => x.FullValue == alarmText);
|
||||
// se non c'è aggiungo
|
||||
if (foundRec == null)
|
||||
{
|
||||
foundRec = new AlarmListModel()
|
||||
{
|
||||
FullValue = alarmText
|
||||
};
|
||||
localDbCtx
|
||||
.DbSetAlarmList
|
||||
.Add(foundRec);
|
||||
localDbCtx.SaveChanges();
|
||||
// rifaccio search
|
||||
foundRec = localDbCtx
|
||||
.DbSetAlarmList
|
||||
.FirstOrDefault(x => x.FullValue == alarmText);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmListInsert{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return foundRec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserimento di una lista record anagrafica allarmi
|
||||
/// </summary>
|
||||
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AlarmListInsertMany(List<AlarmListModel> newItems)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
await localDbCtx
|
||||
.DbSetAlarmList
|
||||
.AddRangeAsync(newItems);
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmListInsertMany{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Recupero elenco allarmi Rec (ultimi dato "skip")
|
||||
/// </summary>
|
||||
/// <param name="MachineId"></param>
|
||||
/// <param name="skipRec"></param>
|
||||
/// <param name="numRec"></param>
|
||||
/// <returns></returns>
|
||||
public List<AlarmRecModel> AlarmRecGetFilt(int MachineId, int skipRec, int numRec)
|
||||
{
|
||||
List<AlarmRecModel> dbResult = new List<AlarmRecModel>();
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.Where(x => x.MachineId == MachineId)
|
||||
.Include(m => m.MachineNav)
|
||||
.Include(m => m.AlarmListNav)
|
||||
.OrderByDescending(x => x.DtStart)
|
||||
.Skip(skipRec)
|
||||
.Take(numRec)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecGetFilt{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserimento di un record AlarmRec
|
||||
/// </summary>
|
||||
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AlarmRecInsert(AlarmRecModel newItem)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.Add(newItem);
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecInsert{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiude ultimo record dato Id (se fossero + di 1 chiude tutti...)
|
||||
/// </summary>
|
||||
/// <param name="AlarmId">Id Allarme</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AlarmRecCloseActive(int AlarmId)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
var candList = localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.Where(x => x.AlarmId==AlarmId)
|
||||
.ToList();
|
||||
foreach (var item in candList)
|
||||
{
|
||||
item.DtEnd = adesso;
|
||||
}
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecCloseActive{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserimento di una lista record AlarmRec
|
||||
/// </summary>
|
||||
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AlarmRecInsertMany(List<AlarmRecModel> newItems)
|
||||
{
|
||||
bool fatto = false;
|
||||
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
await localDbCtx
|
||||
.DbSetAlarmRec
|
||||
.AddRangeAsync(newItems);
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante AlarmRecInsertMany{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero record DataLog data condizione filtro
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user