789 lines
28 KiB
C#
789 lines
28 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using MP.MONO.Core.DTO;
|
|
using MP.MONO.Data.DbModels;
|
|
using NLog;
|
|
|
|
namespace MP.MONO.Data.Controllers
|
|
{
|
|
public class MpDbController : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MpDbController()
|
|
{ }
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Recupero elenco allarmi (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public List<AlarmLogModel> AlarmLogGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<AlarmLogModel> dbResult = new List<AlarmLogModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAlarmLog
|
|
.Where(x => x.MachineId == MachineId)
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.AlarmLogId)
|
|
.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="newItem">Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmLogInsert(AlarmLogModel newItem)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetAlarmLog
|
|
.Add(newItem);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un record AlarmLog
|
|
/// </summary>
|
|
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmLogInsertMany(List<AlarmLogModel> newItems)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
await localDbCtx
|
|
.DbSetAlarmLog
|
|
.AddRangeAsync(newItems);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante AlarmLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero record DataLog data condizione filtro
|
|
/// </summary>
|
|
/// <param name="machineId"></param>
|
|
/// <param name="fluxType"></param>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <returns></returns>
|
|
public List<DataLogModel> DataLogGetFilt(int machineId, string fluxType, DateTime inizio, DateTime fine)
|
|
{
|
|
List<DataLogModel> dbResult = new List<DataLogModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetDataLog
|
|
.Where(x => x.MachineId == machineId && x.FluxType == fluxType && x.DtRif >= inizio && x.DtRif <= fine)
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.DataLogId)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un SET di record DataLog (post aggregazione base VC)
|
|
/// </summary>
|
|
/// <param name="newItems">Lista Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DataLogInsertMany(List<DataLogModel> newItems)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
await localDbCtx
|
|
.DbSetDataLog
|
|
.AddRangeAsync(newItems);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero record DataStAg (aggregati) data condizione filtro
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="FluxType"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public List<DataStAgModel> DataStAgGetFilt(int MachineId, string FluxType, int skipRec, int numRec)
|
|
{
|
|
List<DataStAgModel> dbResult = new List<DataStAgModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetDataStAg
|
|
.Where(x => x.MachineId == MachineId && x.FluxType == FluxType)
|
|
.Include(m => m.MachineNav)
|
|
.OrderByDescending(x => x.DataStAgId)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataLogGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento di un record DataStAg (aggregati) - creati da ANALYZER che effettua compattazione
|
|
/// </summary>
|
|
/// <param name="newItem">Record da inserire (senza ID...)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DataStAgInsert(DataStAgModel newItem)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetDataStAg
|
|
.Add(newItem);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DataStAgInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Riabilitazione task disabilitato
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PMTaskEnableRecord(PrevMaintTaskModel currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
var currVal = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == currRec.PMTaskId)
|
|
.FirstOrDefault();
|
|
// se effettivo delete
|
|
if (currRec.IsDisabled)
|
|
{
|
|
currVal.IsDisabled = false;
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMTaskEnableRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione Record
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <param name="forceDelete"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PMTaskDeleteRecord(PrevMaintTaskModel currRec, bool forceDelete)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
var currVal = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == currRec.PMTaskId)
|
|
.FirstOrDefault();
|
|
// se effettivo delete
|
|
if (forceDelete)
|
|
{
|
|
localDbCtx
|
|
.DbSetPMTask
|
|
.Remove(currVal);
|
|
}
|
|
else
|
|
{
|
|
currVal.IsDisabled = true;
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMTaskDeleteRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
//Log.Info("Dispose di GWMSController");
|
|
}
|
|
|
|
public List<DisplayDataDTO> MachineGetDisplay()
|
|
{
|
|
List<DisplayDataDTO> answ = new List<DisplayDataDTO>();
|
|
|
|
// !!!FIXME TODO... è fake...
|
|
|
|
Random rand = new Random();
|
|
double currVal = 0;
|
|
currVal = rand.Next(10, 120) * 100;
|
|
DisplayDataDTO displ01 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "SPEED",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N0"),
|
|
Type = "SPEED-5000-10000"
|
|
};
|
|
answ.Add(displ01);
|
|
|
|
currVal = rand.Next(10, 100) * 100;
|
|
DisplayDataDTO displ02 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "FEED",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N0"),
|
|
Type = "FEED-3000-5000"
|
|
};
|
|
answ.Add(displ02);
|
|
|
|
currVal = rand.NextDouble() * 1.2;
|
|
DisplayDataDTO displ03 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "SPINDLE LOAD",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("P0"),
|
|
Type = "ORDER"
|
|
};
|
|
answ.Add(displ03);
|
|
|
|
currVal = rand.NextDouble() * 5000;
|
|
DisplayDataDTO displ04 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "X POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ04);
|
|
|
|
currVal = rand.NextDouble() * 10000;
|
|
DisplayDataDTO displ05 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Y POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ05);
|
|
|
|
currVal = rand.NextDouble() * -3000;
|
|
DisplayDataDTO displ06 = new DisplayDataDTO()
|
|
{
|
|
Order = 0,
|
|
Title = "Z POS",
|
|
ValueNum = currVal,
|
|
IsNumeric = true,
|
|
Value = currVal.ToString("N1"),
|
|
Type = "POS"
|
|
};
|
|
answ.Add(displ06);
|
|
|
|
Task.Delay(200).Wait();
|
|
|
|
return answ;
|
|
}
|
|
|
|
public ProductionDTO MachineGetProd()
|
|
{
|
|
// !!!FIXME TODO... è fake...
|
|
|
|
Random rand = new Random();
|
|
int stdCycle = 5;
|
|
|
|
ProductionDTO currMachDto = new ProductionDTO()
|
|
{
|
|
Order = "ODL Test",
|
|
ItemCode = "ART.0000123",
|
|
ProgName = "P000012",
|
|
CurrQty = DateTime.Now.Minute + rand.Next(1, 40),
|
|
OrderQty = 100,
|
|
CycleTimeMin = rand.NextDouble() * stdCycle,
|
|
Message = "...simulated data..."
|
|
};
|
|
|
|
Task.Delay(400).Wait();
|
|
|
|
return currMachDto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco contatori ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<CounterModel> PMCounterModelGetAll()
|
|
{
|
|
List<CounterModel> dbResult = new List<CounterModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetCounter
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMCounterModelGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco Gruppi Macchina PM ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PMMGroupModel> PMMachGroupGetAll()
|
|
{
|
|
List<PMMGroupModel> dbResult = new List<PMMGroupModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPMMachGroup
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMMachGroupGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco Topics PM ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PMTaskTopicModel> PMTaskTopicGetAll()
|
|
{
|
|
List<PMTaskTopicModel> dbResult = new List<PMTaskTopicModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPMTopic
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMTaskTopicGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco User Team PM ammessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PMUTModel> PMUTeamGetAll()
|
|
{
|
|
List<PMUTModel> dbResult = new List<PMUTModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetUTeam
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PMUTeamGetAll{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue update del record
|
|
/// </summary>
|
|
/// <param name="editRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PrevMaintTaskUpdate(PrevMaintTaskModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == editRec.PMTaskId)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.CCode = editRec.CCode;
|
|
currRec.ExpiryVal = editRec.ExpiryVal;
|
|
currRec.ExtIdx = editRec.ExtIdx;
|
|
currRec.PMMGCode = editRec.PMMGCode;
|
|
currRec.PMTCode = editRec.PMTCode;
|
|
currRec.PMUTCode = editRec.PMUTCode;
|
|
currRec.JobDescription = editRec.JobDescription;
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
// se nuovo (user edit) --> NON protetto!
|
|
editRec.Protected = false;
|
|
localDbCtx
|
|
.DbSetPMTask
|
|
.Add(editRec);
|
|
}
|
|
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PrevMaintTaskUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco Task Manut Prev Previsti/Configurati (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="skipRec"></param>
|
|
/// <param name="numRec"></param>
|
|
/// <returns></returns>
|
|
public List<PrevMaintTaskModel> PrevMaintTaskGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<PrevMaintTaskModel> dbResult = new List<PrevMaintTaskModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.MachineId == MachineId)
|
|
.Include(m => m.CounterNav)
|
|
.Include(m => m.MachGroupNav)
|
|
.Include(m => m.MachineNav)
|
|
.Include(m => m.TopicNav)
|
|
.Include(m => m.UserTeamNav)
|
|
.OrderBy(x => x.ExtIdx)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PrevMaintTaskGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// genera elenco Task Schedulati missing da schema + attualmente presenti...
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> SchedMaintTaskCreateMissing(int MachineId)
|
|
{
|
|
bool answ = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
List<PrevMaintTaskModel> missTask = new List<PrevMaintTaskModel>();
|
|
|
|
// elenco dei task NON disattivati
|
|
List<PrevMaintTaskModel>? allTask = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.MachineId == MachineId && !x.IsDisabled)
|
|
.Include(i => i.CounterNav)
|
|
.ToList();
|
|
|
|
// analizzo task per idx del PMTask
|
|
var reqTask = allTask
|
|
.Select(x => x.PMTaskId)
|
|
.ToList();
|
|
|
|
var openTask = localDbCtx
|
|
.DbSetSMTask
|
|
.Where(x => x.DtExecution == DateTime.MinValue)
|
|
.Include(m => m.PMTaskeNav)
|
|
.ToList();
|
|
|
|
var currTask = openTask
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId)
|
|
.Select(x => x.PMTaskId)
|
|
.ToList();
|
|
|
|
// elenco dei SOLI task presenti
|
|
var listTaskOk = currTask.Intersect(reqTask).ToList();
|
|
|
|
// dall'elenco di quelli originali elimino presenti --> ho elenco mancanti...
|
|
foreach (var iTask in allTask)
|
|
{
|
|
// se non nell'elenco aggiungo...
|
|
if (!listTaskOk.Exists(x => x == iTask.PMTaskId))
|
|
{
|
|
missTask.Add(iTask);
|
|
}
|
|
}
|
|
|
|
var newRecs = missTask.Select(x => new ScheduledMaintModel()
|
|
{
|
|
CCode = x.CCode,
|
|
DtCreation = DateTime.Now,
|
|
ExpiryVal = x.ExpiryVal,
|
|
PMTaskId = x.PMTaskId,
|
|
CountStartVal = x.CounterNav.ActualVal
|
|
}).ToList();
|
|
|
|
localDbCtx
|
|
.DbSetSMTask
|
|
.AddRange(newRecs);
|
|
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco Task Schedulati dati Macchina ed intervento "master"
|
|
/// </summary>
|
|
/// <param name="MachineId">Macchina selezionata</param>
|
|
/// <param name="PMTaskId">ID del PMTask parent</param>
|
|
/// <param name="skipRec">Num record da saltare</param>
|
|
/// <param name="numRec">num rec da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<ScheduledMaintModel> SchedMaintTaskGetByPMTask(int MachineId, int PMTaskId, int skipRec, int numRec)
|
|
{
|
|
List<ScheduledMaintModel> dbResult = new List<ScheduledMaintModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetSMTask
|
|
.Include(i => i.CounterNav)
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.PMTaskId == PMTaskId && x.DtExecution > DateTime.MinValue)
|
|
.Include(m => m.PMTaskeNav.MachGroupNav)
|
|
.Include(m => m.CounterNav)
|
|
.Include(m => m.PMTaskeNav.MachineNav)
|
|
.Include(m => m.PMTaskeNav.TopicNav)
|
|
.Include(m => m.PMTaskeNav.UserTeamNav)
|
|
.OrderByDescending(x => x.DtCreation)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskGetByPMTask{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero elenco Task Schedulati (ultimi dato "skip")
|
|
/// </summary>
|
|
/// <param name="MachineId">Macchina selezionata</param>
|
|
/// <param name="skipRec">Num record da saltare</param>
|
|
/// <param name="numRec">num rec da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<ScheduledMaintModel> SchedMaintTaskGetFilt(int MachineId, int skipRec, int numRec)
|
|
{
|
|
List<ScheduledMaintModel> dbResult = new List<ScheduledMaintModel>();
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetSMTask
|
|
.Include(i => i.CounterNav)
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.DtExecution == DateTime.MinValue)
|
|
.Include(m => m.PMTaskeNav.MachGroupNav)
|
|
.Include(m => m.CounterNav)
|
|
.Include(m => m.PMTaskeNav.MachineNav)
|
|
.Include(m => m.PMTaskeNav.TopicNav)
|
|
.Include(m => m.PMTaskeNav.UserTeamNav)
|
|
.OrderBy(x => x.PMTaskeNav.ExtIdx)
|
|
.Skip(skipRec)
|
|
.Take(numRec)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registro esecuzione task schedualto
|
|
/// </summary>
|
|
/// <param name="MachineId"></param>
|
|
/// <param name="SMTaskId"></param>
|
|
/// <param name="ExecDT"></param>
|
|
/// <param name="ExecUser"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> SchedMaintTaskSetDone(int MachineId, int SMTaskId, DateTime ExecDT, string ExecUser)
|
|
{
|
|
bool answ = false;
|
|
using (MapoMonoContext localDbCtx = new MapoMonoContext())
|
|
{
|
|
try
|
|
{
|
|
// Aggiorno il task schedulato
|
|
var dbResult = localDbCtx
|
|
.DbSetSMTask
|
|
.Include(i => i.CounterNav)
|
|
.Where(x => x.PMTaskeNav.MachineId == MachineId && x.SMTaskId == SMTaskId)
|
|
.FirstOrDefault();
|
|
if (dbResult != null)
|
|
{
|
|
// aggiorno il record
|
|
dbResult.DtExecution = ExecDT;
|
|
dbResult.UserCode = ExecUser;
|
|
dbResult.ElapsedVal = dbResult.CounterNav.ActualVal - dbResult.CountStartVal;
|
|
|
|
// aggiorno il task parent col numero di task eseguiti...
|
|
int numDone = localDbCtx
|
|
.DbSetSMTask
|
|
.Where(x => x.PMTaskId == dbResult.PMTaskId)
|
|
.Count();
|
|
var parentRecord = localDbCtx
|
|
.DbSetPMTask
|
|
.Where(x => x.PMTaskId == dbResult.PMTaskId)
|
|
.FirstOrDefault();
|
|
if (parentRecord != null)
|
|
{
|
|
parentRecord.NumTaskDone = numDone;
|
|
}
|
|
|
|
// eseguo salvataggi!
|
|
localDbCtx.SaveChanges();
|
|
// segno fatto!
|
|
answ = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SchedMaintTaskSetDone{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |