1347 lines
52 KiB
C#
1347 lines
52 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.Data.DbModels;
|
|
using MP.Data.DbModels.Anag;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Controllers
|
|
{
|
|
public class MpIocController : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MpIocController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
Log.Info("Avviata classe MpIocController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Insert record allarme
|
|
/// </summary>
|
|
/// <param name="dtRif">Data evento</param>
|
|
/// <param name="machineId">Id macchina</param>
|
|
/// <param name="memAddress">area memoria</param>
|
|
/// <param name="memAddress">indice memoria</param>
|
|
/// <param name="memAddress">valore status</param>
|
|
/// <param name="memAddress">valore decodificato</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> AlarmLogInsertAsync(DateTime dtRif, string machineId, string memAddress, int memIndex, int statusVal, string valDecoded)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var DtRif = new SqlParameter("@DtRif", dtRif);
|
|
var MachineId = new SqlParameter("@MachineId", machineId);
|
|
var MemAddress = new SqlParameter("@MemAddress", memAddress);
|
|
var MemIndex = new SqlParameter("@MemIndex", memIndex);
|
|
var StatusVal = new SqlParameter("@StatusVal", statusVal);
|
|
var ValDecoded = new SqlParameter("@ValDecoded", valDecoded);
|
|
|
|
var result = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("EXEC stp_AL_insertQuery @DtRif, @MachineId, @MemAddress, @MemIndex, @StatusVal, @ValDecoded, ", DtRif, MachineId, MemAddress, MemIndex, StatusVal, ValDecoded);
|
|
fatto = result != 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
/// <summary>
|
|
/// Restituisce l'anagrafica STATI per intero
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<AnagStatiModel>> AnagStatiGetAllAsync()
|
|
{
|
|
List<AnagStatiModel> dbResult = new List<AnagStatiModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = await dbCtx
|
|
.DbSetAnagStati
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella decodifica articoli / codice decimale
|
|
/// </summary>
|
|
/// <param name="codArt">Vuoto = tutti / Singolo CodArt</param>
|
|
/// <returns></returns>
|
|
public async Task<List<DecNumArticoliModel>> DecNumArtGetFiltAsync(string codArt = "")
|
|
{
|
|
List<DecNumArticoliModel> dbResult = new List<DecNumArticoliModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var query = dbCtx.DbSetDecNumArt
|
|
.AsNoTracking()
|
|
.AsQueryable();
|
|
|
|
if (!string.IsNullOrEmpty(codArt))
|
|
query = query.Where(x => x.CodArticolo == codArt);
|
|
|
|
dbResult = await query.ToListAsync();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella Config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ConfigModel> ConfigGetAll()
|
|
{
|
|
List<ConfigModel> dbResult = new List<ConfigModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetConfig
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Chiave)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update record config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool ConfigUpdate(ConfigModel updRec)
|
|
{
|
|
bool fatto = false;
|
|
ConfigModel dbResult = new ConfigModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetConfig
|
|
.Where(x => x.Chiave == updRec.Chiave)
|
|
.FirstOrDefault();
|
|
if (dbResult != null)
|
|
{
|
|
dbResult.Valore = updRec.Valore;
|
|
dbCtx.SaveChanges();
|
|
fatto = true;
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Intera tab dati macchina
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<DatiMacchineModel> DatiMacchineGetAll()
|
|
{
|
|
List<DatiMacchineModel> dbResult = new List<DatiMacchineModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetDatiMacchine
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserimento record in DDB
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="inizioStato"></param>
|
|
/// <param name="idxStato"></param>
|
|
/// <param name="codArt"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="matrOpr"></param>
|
|
/// <param name="pallet"></param>
|
|
/// <returns></returns>
|
|
public bool DDB_InsStatoBatch(string idxMacchina, DateTime inizioStato, int idxStato, string codArt, string value, int matrOpr, string pallet)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina);
|
|
var InizioStato = new SqlParameter("@InizioStato", inizioStato);
|
|
var IdxStato = new SqlParameter("@IdxStato", idxStato);
|
|
var CodArticolo = new SqlParameter("@CodArticolo", codArt);
|
|
var Value = new SqlParameter("@Value", value);
|
|
var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
|
|
var Pallet = new SqlParameter("@pallet", pallet);
|
|
|
|
var result = dbCtx
|
|
.Database
|
|
.ExecuteSqlRaw("exec dbo.stp_DDB_InsStatoBatch @pIdxMacchina, @InizioStato, @IdxStato, @CodArticolo, @Value, @MatrOpr, @pallet", IdxMacchina, InizioStato, IdxStato, CodArticolo, Value, MatrOpr, Pallet);
|
|
|
|
// indico eseguito!
|
|
fatto = result > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_configuration = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record EventList
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public bool EvListInsert(EventListModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetEvList
|
|
.Add(newRec);
|
|
dbCtx.SaveChanges();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante EvListInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record EventList
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> EvListInsertAsync(EventListModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetEvList
|
|
.Add(newRec);
|
|
await dbCtx.SaveChangesAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante EvListInsertAsync{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ultimi n record flux log dato macchina e flusso (ordinato x data registrazione)
|
|
/// </summary>
|
|
/// <param name="DtMax">Data massima x eventi</param>
|
|
/// <param name="DtMin">Data minima x eventi</param>
|
|
/// <param name="IdxMacchina">* = tutte, altrimenti solo x una data macchina</param>
|
|
/// <param name="CodFlux">*=tutti, altrimenti solo selezionato</param>
|
|
/// <param name="MaxRec">numero massimo record da restituire</param>
|
|
/// <returns></returns>
|
|
public List<FluxLogModel> FluxLogGetLastFilt(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec)
|
|
{
|
|
List<FluxLogModel> dbResult = new List<FluxLogModel>();
|
|
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetFluxLog
|
|
.AsNoTracking()
|
|
.Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux))
|
|
.OrderByDescending(x => x.dtEvento)
|
|
.Take(MaxRec)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record FluxLog
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public bool FluxLogInsert(FluxLogModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetFluxLog
|
|
.Add(newRec);
|
|
dbCtx.SaveChanges();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante FluxLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record FluxLog Async
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> FluxLogInsertAsync(FluxLogModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonPro_FluxContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetFluxLog
|
|
.Add(newRec);
|
|
await dbCtx.SaveChangesAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante FluxLogInsertAsync{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public bool KeepAliveUpsert(string IdxMacc, DateTime OraServer, DateTime OraMacc)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetKeepAlive
|
|
.Where(x => x.IdxMacchina == IdxMacc)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.DataOraServer = OraServer;
|
|
currRec.DataOraMacchina = OraMacc;
|
|
dbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
KeepAliveModel newRec = new KeepAliveModel()
|
|
{
|
|
IdxMacchina = IdxMacc,
|
|
DataOraMacchina = OraMacc,
|
|
DataOraServer = OraServer,
|
|
DataOraStart = DateTime.Now
|
|
};
|
|
dbCtx
|
|
.DbSetKeepAlive
|
|
.Add(newRec);
|
|
}
|
|
dbCtx.SaveChanges();
|
|
fatto = true;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public async Task<bool> KeepAliveUpsertAsync(string IdxMacc, DateTime OraServer, DateTime OraMacc)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var currRec = await dbCtx
|
|
.DbSetKeepAlive
|
|
.Where(x => x.IdxMacchina == IdxMacc)
|
|
.FirstOrDefaultAsync();
|
|
if (currRec != null)
|
|
{
|
|
currRec.DataOraServer = OraServer;
|
|
currRec.DataOraMacchina = OraMacc;
|
|
dbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
KeepAliveModel newRec = new KeepAliveModel()
|
|
{
|
|
IdxMacchina = IdxMacc,
|
|
DataOraMacchina = OraMacc,
|
|
DataOraServer = OraServer,
|
|
DataOraStart = DateTime.Now
|
|
};
|
|
dbCtx
|
|
.DbSetKeepAlive
|
|
.Add(newRec);
|
|
}
|
|
fatto = await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public List<LinkMenuModel> ListLinkFilt(string tipoLink)
|
|
{
|
|
List<LinkMenuModel> dbResult = new List<LinkMenuModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetLinkMenu
|
|
.Where(x => x.TipoLink == tipoLink)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Ordine)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Intera tabella relazione master/slave in machine (gestione setup master --> slave)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Macchine2SlaveModel> Macchine2Slave()
|
|
{
|
|
List<Macchine2SlaveModel> dbResult = new List<Macchine2SlaveModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetM2S
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record Macchine
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<MacchineModel> MacchineGetAll()
|
|
{
|
|
List<MacchineModel> dbResult = new List<MacchineModel>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetMacchine
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public MacchineModel? MacchineGetByIdx(string IdxMacchina)
|
|
{
|
|
MacchineModel dbResult = null;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetMacchine
|
|
.FirstOrDefault(x => x.IdxMacchina == IdxMacchina);
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella Macchine
|
|
/// </summary>
|
|
/// <param name="codGruppo"></param>
|
|
/// <returns></returns>
|
|
public List<MacchineModel> MacchineGetFilt(string codGruppo)
|
|
{
|
|
List<MacchineModel> dbResult = new List<MacchineModel>();
|
|
try
|
|
{
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
if (codGruppo == "*")
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetMacchine
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetGrp2Macc
|
|
.Where(g => g.CodGruppo == codGruppo)
|
|
.Join(dbCtx.DbSetMacchine,
|
|
g => g.IdxMacchina,
|
|
m => m.IdxMacchina,
|
|
(g, m) => m
|
|
)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in MacchineGetFilt{Environment.NewLine}{exc}");
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upsert Record Macchine
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool MacchineUpsert(MacchineModel entity)
|
|
{
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
// Recuperiamo l'entità tracciata dal context
|
|
var trackedEntity = localDbCtx.DbSetMacchine.FirstOrDefault(x => x.IdxMacchina == entity.IdxMacchina);
|
|
|
|
if (trackedEntity != null)
|
|
{
|
|
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
|
localDbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
|
}
|
|
else
|
|
{
|
|
localDbCtx.DbSetMacchine.Update(entity);
|
|
}
|
|
return localDbCtx.SaveChanges() > 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upsert Record Macchine ASYNC
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> MacchineUpsertAsync(MacchineModel entity)
|
|
{
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
// Recuperiamo l'entità tracciata dal context
|
|
var trackedEntity = await localDbCtx.DbSetMacchine.FirstOrDefaultAsync(x => x.IdxMacchina == entity.IdxMacchina);
|
|
|
|
if (trackedEntity != null)
|
|
{
|
|
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
|
localDbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
|
}
|
|
else
|
|
{
|
|
localDbCtx.DbSetMacchine.Update(entity);
|
|
}
|
|
return await localDbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella Macchine
|
|
/// </summary>
|
|
/// <param name="codGruppo"></param>
|
|
/// <returns></returns>
|
|
public List<MicroStatoMacchinaModel> MicroStatoMacchinaGetByIdxMacc(string IdxMacc)
|
|
{
|
|
List<MicroStatoMacchinaModel> dbResult = new List<MicroStatoMacchinaModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetMicroStatoMacc
|
|
.Where(x => x.IdxMacchina == IdxMacc)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
return dbResult;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamento record Microstato macchina
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public bool MicroStatoMacchinaUpsert(MicroStatoMacchinaModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var actRec = dbCtx
|
|
.DbSetMicroStatoMacc
|
|
.Where(x => x.IdxMacchina == newRec.IdxMacchina)
|
|
.AsNoTracking()
|
|
.FirstOrDefault();
|
|
if (actRec == null)
|
|
{
|
|
dbCtx
|
|
.DbSetMicroStatoMacc
|
|
.Add(newRec);
|
|
}
|
|
else
|
|
{
|
|
actRec.IdxMicroStato = newRec.IdxMicroStato;
|
|
actRec.InizioStato = newRec.InizioStato;
|
|
actRec.Value = newRec.Value;
|
|
|
|
dbCtx.Entry(actRec).State = EntityState.Modified;
|
|
}
|
|
fatto = dbCtx.SaveChanges() > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiornamento record Microstato macchina
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> MicroStatoMacchinaUpsertAsync(MicroStatoMacchinaModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var actRec = await dbCtx
|
|
.DbSetMicroStatoMacc
|
|
.Where(x => x.IdxMacchina == newRec.IdxMacchina)
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync();
|
|
if (actRec == null)
|
|
{
|
|
dbCtx
|
|
.DbSetMicroStatoMacc
|
|
.Add(newRec);
|
|
}
|
|
else
|
|
{
|
|
actRec.IdxMicroStato = newRec.IdxMicroStato;
|
|
actRec.InizioStato = newRec.InizioStato;
|
|
actRec.Value = newRec.Value;
|
|
|
|
dbCtx.Entry(actRec).State = EntityState.Modified;
|
|
}
|
|
fatto = await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella MappaStatoExplModel
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
|
{
|
|
List<MappaStatoExplModel> dbResult = new List<MappaStatoExplModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
|
|
|
dbResult = await dbCtx
|
|
.DbSetMSE
|
|
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generazione automatica ODL
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OdlAutoDayGenAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var DataInizio = new SqlParameter("@DataInizio", dataInizio);
|
|
var DataFine = new SqlParameter("@DataFine", dataFine);
|
|
var CodArticolo = new SqlParameter("@CodArticolo", codArticolo);
|
|
|
|
var result = dbCtx
|
|
.Database
|
|
.ExecuteSqlRaw("EXEC stp_ODL_AutoDayGener @IdxMacchina, @DataInizio, @DataFine, @CodArticolo", IdxMacchina, DataInizio, DataFine, CodArticolo);
|
|
|
|
// indico eseguito!
|
|
answ = result > 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante stp_ODL_AutoDayGener{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generazione automatica ODL completa
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> OdlAutoDayGenFullAsync(string idxMacchina, DateTime dataInizio, DateTime dataFine, string codArticolo, int? pzPODL, int? pzPallet, string? keyRichiesta, int? tcAssegnato, string? codGruppo, bool flgCreaPODL, bool flgCheckTC)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var DataInizio = new SqlParameter("@DataInizio", dataInizio);
|
|
var DataFine = new SqlParameter("@DataFine", dataFine);
|
|
var CodArticolo = new SqlParameter("@CodArticolo", codArticolo);
|
|
var PzPODL = new SqlParameter("@PzPODL", pzPODL);
|
|
var PzPallet = new SqlParameter("@PzPallet", pzPallet);
|
|
var KeyRichiesta = new SqlParameter("@KeyRichiesta", keyRichiesta);
|
|
var TCAssegnato = new SqlParameter("@TCAssegnato", tcAssegnato);
|
|
var CodGruppo = new SqlParameter("@CodGruppo", codGruppo);
|
|
var FlgCreaPODL = new SqlParameter("@flgCreaPODL", flgCreaPODL);
|
|
var FlgCheckTC = new SqlParameter("@flgCheckTC", flgCheckTC);
|
|
|
|
var result = dbCtx
|
|
.Database
|
|
.ExecuteSqlRaw("EXEC stp_ODL_AutoDayGenerFull @IdxMacchina, @DataInizio, @DataFine, @CodArticolo, @PzPODL, @PzPallet, @KeyRichiesta, @TCAssegnato, @CodGruppo, @flgCreaPODL, @flgCheckTC", IdxMacchina, DataInizio, DataFine, CodArticolo, PzPODL, PzPallet, KeyRichiesta, TCAssegnato, CodGruppo, FlgCreaPODL, FlgCheckTC);
|
|
|
|
// indico eseguito!
|
|
answ = result > 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante stp_ODL_AutoDayGenerFull{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ODL corrente macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public ODLExpModel OdlCurrByMacc(string idxMacchina)
|
|
{
|
|
ODLExpModel answ = new();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var dbRes = (dbCtx.DbSetODLExp
|
|
.FromSqlRaw("EXEC stp_ODL_getByMacchina @IdxMacchina", pIdxMacchina)
|
|
.AsNoTracking()
|
|
.ToList()) // Esegue la query e scarica i risultati in memoria
|
|
.FirstOrDefault(); // Prende il primo elemento dalla lista in RAM
|
|
answ = dbRes ?? new();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OdlCurrByMacc{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ODL corrente macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public async Task<ODLExpModel> OdlCurrByMaccAsync(string idxMacchina)
|
|
{
|
|
ODLExpModel answ = new();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
// attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!!
|
|
var dbRes = (await dbCtx.DbSetODLExp
|
|
.FromSqlRaw("EXEC stp_ODL_getByMacchina @IdxMacchina", pIdxMacchina)
|
|
.AsNoTracking()
|
|
.ToListAsync()) // Esegue la query e scarica i risultati in memoria
|
|
.FirstOrDefault(); // Prende il primo elemento dalla lista in RAM
|
|
answ = dbRes ?? new();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ODL corrente macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public async Task<ODLExpModel> OdlLastByMaccAsync(string idxMacchina)
|
|
{
|
|
ODLExpModel answ = new();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
// attenzione: se la stored resituisce una tabella, il primo elemento va recuperato in RAM!!!
|
|
var dbRes = (await dbCtx.DbSetODLExp
|
|
.FromSqlRaw("EXEC stp_ODL_getLastByMacchina @IdxMacchina", pIdxMacchina)
|
|
.AsNoTracking()
|
|
.ToListAsync()) // Esegue la query e scarica i risultati in memoria
|
|
.FirstOrDefault(); // Prende il primo elemento dalla lista in RAM
|
|
answ = dbRes ?? new();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OdlCurrByMaccAsync{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ODL data macchina e periodo
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public List<ODLExpModel> OdlListByMaccPeriodo(string idxMacchina, DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
List<ODLExpModel> dbResult = new List<ODLExpModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina);
|
|
var DataFrom = new SqlParameter("@dataFrom", dtStart);
|
|
var DataTo = new SqlParameter("@dataTo", dtEnd);
|
|
dbResult = dbCtx
|
|
.DbSetODLExp
|
|
.FromSqlRaw("EXEC stp_ODL_getByMacchinaPeriodo @pIdxMacchina, @dataFrom, @dataTo", IdxMacchina, DataFrom, DataTo)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OdlListByMaccPeriodo{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Conteggio PzProd Macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public PzProdModel PezziProdMacchina(string idxMacchina)
|
|
{
|
|
PzProdModel dbResult = new PzProdModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
dbResult = (dbCtx
|
|
.DbSetPzProd
|
|
.FromSqlRaw("EXEC stp_PzProd_getByMacchina @IdxMacchina", pIdxMacchina)
|
|
.AsNoTracking()
|
|
.ToList())
|
|
.FirstOrDefault(); // recupero da RAM
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Conteggio PzProd Macchina Async
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public async Task<PzProdModel> PezziProdMacchinaAsync(string idxMacchina)
|
|
{
|
|
PzProdModel dbResult = new PzProdModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
dbResult = (await dbCtx
|
|
.DbSetPzProd
|
|
.FromSqlRaw("EXEC stp_PzProd_getByMacchina @IdxMacchina", pIdxMacchina)
|
|
.AsNoTracking()
|
|
.ToListAsync())
|
|
.FirstOrDefault(); // recupero da RAM
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua ricalcolo MSE x macchina indicata
|
|
/// </summary>
|
|
/// <param name="idxMacchina">idx macchina da confermare</param>
|
|
/// <param name="maxAgeSec">Num massimo secondi di "vecchiaia" del dato</param>
|
|
/// <returns></returns>
|
|
public bool RecalcMse(string idxMacchina, int maxAgeSec)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
var rigaProd = StatoProdMacchina(idxMacchina, DateTime.Now);
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var MaxAgeSec = new SqlParameter("@maxAgeSec ", maxAgeSec);
|
|
var IdxMacchina = new SqlParameter("@idxMacchina", idxMacchina);
|
|
|
|
var result = dbCtx
|
|
.Database
|
|
.ExecuteSqlRaw("EXEC stp_MSE_recalc @maxAgeSec, @idxMacchina ", MaxAgeSec, IdxMacchina);
|
|
|
|
// indico eseguito!
|
|
answ = result > 0;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RicalcMse:{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registra controllo
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="matrOpr"></param>
|
|
/// <param name="esitoOk"></param>
|
|
/// <param name="note"></param>
|
|
/// <param name="dataOra"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RegControlliInsert(string idxMacchina, int matrOpr, bool esitoOk, string note, DateTime dataOra)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacc = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
|
|
var EsitoOk = new SqlParameter("@EsitoOk", esitoOk);
|
|
var Note = new SqlParameter("@Note", note);
|
|
var DataOra = new SqlParameter("@DataOra", dataOra);
|
|
|
|
var result = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("EXEC stp_RC_insert @IdxMacchina, @MatrOpr, @EsitoOk, @Note, @DataOra", IdxMacc, MatrOpr, EsitoOk, Note, DataOra);
|
|
fatto = result != 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record Registro Dichiarazioni
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RegDichiarInsert(RegistroDichiarazioniModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var TagCode = new SqlParameter("@TagCode", newRec.TagCode);
|
|
var IdxMacchina = new SqlParameter("@IdxMacchina", newRec.IdxMacchina);
|
|
var DtRec = new SqlParameter("@DtRec", newRec.DtRec);
|
|
var MatrOpr = new SqlParameter("@MatrOpr", newRec.MatrOpr);
|
|
var ValString = new SqlParameter("@ValString", newRec.ValString);
|
|
|
|
var result = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec dbo.stp_DD_insertQuery @TagCode, @IdxMacchina, @DtRec, @MatrOpr, @ValString", TagCode, IdxMacchina, DtRec, MatrOpr, ValString);
|
|
// indico eseguito!
|
|
fatto = result > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update record Registro Dichiarazioni
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RegDichiarUpdate(RegistroDichiarazioniModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var Original_IdxDich = new SqlParameter("@Original_IdxDich", newRec.IdxDich);
|
|
var DtRec = new SqlParameter("@DtRec", newRec.DtRec);
|
|
var TagCode = new SqlParameter("@TagCode", newRec.TagCode);
|
|
var ValString = new SqlParameter("@ValString", newRec.ValString);
|
|
var MatrOpr = new SqlParameter("@MatrOpr", newRec.MatrOpr);
|
|
|
|
var result = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec dbo.stp_DD_updateQuery @Original_IdxDich, @DtRec, @TagCode, @ValString, @MatrOpr", Original_IdxDich, DtRec, TagCode, ValString, MatrOpr);
|
|
// indico eseguito!
|
|
fatto = result > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record RegistroScarti
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RegScartiInsert(RegistroScartiModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@idxMacchina", newRec.IdxMacchina);
|
|
var DataOra = new SqlParameter("@DataOra", newRec.DataOra);
|
|
var Causale = new SqlParameter("@Causale", newRec.Causale);
|
|
var Qta = new SqlParameter("@Qta", newRec.Qta);
|
|
var Note = new SqlParameter("@Note", newRec.Note);
|
|
var MatrOpr = new SqlParameter("@MatrOpr", newRec.MatrOpr);
|
|
|
|
var result = await dbCtx
|
|
.DbSetRegWithCheck
|
|
.FromSqlRaw("exec dbo.stp_RS_Insert_withCheck @idxMacchina, @DataOra, @Causale, @Qta, @Note, @MatrOpr", IdxMacchina, DataOra, Causale, Qta, Note, MatrOpr)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
// indico eseguito!
|
|
// -1 = restituisce una select
|
|
fatto = result.Count > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record RemoteRebootLog
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> RemRebootLogAddAsync(RemoteRebootLogModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var dbResult = dbCtx
|
|
.DbSetRemRebLog
|
|
.Add(newRec);
|
|
fatto = await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera tutti i record di RemoteRebootLog
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetAllAsync()
|
|
{
|
|
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = await dbCtx
|
|
.DbSetRemRebLog
|
|
.AsNoTracking()
|
|
.OrderByDescending(x => x.IdxReboot)
|
|
.ToListAsync();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera ultimo record x ogni IdxMacchina x avere ultimo attivo
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<RemoteRebootLogModel>> RemRebootLogGetLastAsync()
|
|
{
|
|
List<RemoteRebootLogModel> dbResult = new List<RemoteRebootLogModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = await dbCtx
|
|
.DbSetRemRebLog
|
|
.FromSqlRaw("EXEC stp_RRL_getLast")
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera ultimo record x ogni IdxMacchina x avere ultimo attivo
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> RemRebootLogKeepLastAsync(int num2keep)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var Num2keep = new SqlParameter("@num2keep", num2keep);
|
|
var dbResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec dbo.stp_RRL_KeepLatest @num2keep", Num2keep);
|
|
answ = dbResult > 0;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annulla modifiche su una specifica entity (cancel update)
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public bool RollBackEntity(object item)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Deleted || dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Modified)
|
|
{
|
|
dbCtx.Entry(item).Reload();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record SignalLog
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public bool SignalLogInsert(SignalLogModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetSignalLog
|
|
.Add(newRec);
|
|
dbCtx.SaveChanges();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SignalLogInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record SignalLog Async
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> SignalLogInsertAsync(SignalLogModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetSignalLog
|
|
.Add(newRec);
|
|
await dbCtx.SaveChangesAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante SignalLogInsertAsync{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tabella state machine eventi 2 stati data macchina e tipo evento
|
|
/// </summary>
|
|
/// <param name="idxTipo"></param>
|
|
/// <returns></returns>
|
|
public List<TransizioneStatiModel> SMES_getHwTransitions(string idxMacchina, int idxTipo)
|
|
{
|
|
List<TransizioneStatiModel> dbResult = new List<TransizioneStatiModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina);
|
|
var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
|
|
dbResult = dbCtx
|
|
.DbSetSMES
|
|
.FromSqlRaw("exec dbo.stp_TS_getByIdxMacchIdxTipoEv @pIdxMacchina, @IdxTipo", IdxMacchina, IdxTipo)
|
|
.AsNoTracking()
|
|
.AsEnumerable()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tabella state machine eventi 2 stati data macchina e tipo evento
|
|
/// </summary>
|
|
/// <param name="idxTipo"></param>
|
|
/// <returns></returns>
|
|
public List<TransizioneStatiModel> SMES_getUserForced(string idxMacchina, int idxTipo)
|
|
{
|
|
List<TransizioneStatiModel> dbResult = new List<TransizioneStatiModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina);
|
|
var IdxTipo = new SqlParameter("@IdxTipo", idxTipo);
|
|
dbResult = dbCtx
|
|
.DbSetSMES
|
|
.FromSqlRaw("exec dbo.stp_TS_getUserForcedTrans @pIdxMacchina, @IdxTipo", IdxMacchina, IdxTipo)
|
|
.AsNoTracking()
|
|
.AsEnumerable()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Intera tabella state machine ingressi 2 eventi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<TransizioneIngressiModel> StateMachineIngressi(int idxFam)
|
|
{
|
|
List<TransizioneIngressiModel> dbResult = new List<TransizioneIngressiModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxFamIn = new SqlParameter("@IdxFamigliaIngresso", idxFam);
|
|
dbResult = dbCtx
|
|
.DbSetSMI
|
|
.FromSqlRaw("exec dbo.stp_TRI_getByIdxFamIng @IdxFamigliaIngresso", IdxFamIn)
|
|
.AsNoTracking()
|
|
.AsEnumerable()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stato prod macchina (completo)
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="dtReq"></param>
|
|
/// <returns></returns>
|
|
public StatoProdModel StatoProdMacchina(string idxMacchina, DateTime dtReq)
|
|
{
|
|
StatoProdModel dbResult = new StatoProdModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina);
|
|
var DataOra = new SqlParameter("@DataOra ", dtReq);
|
|
var rawData = dbCtx
|
|
.DbSetStatoProd
|
|
.FromSqlRaw("EXEC stp_StatoProd_getByMacchina @pIdxMacchina, @DataOra ", IdxMacchina, DataOra)
|
|
.AsNoTracking()
|
|
.AsEnumerable()
|
|
.ToList();
|
|
dbResult = rawData
|
|
.FirstOrDefault();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stato prod macchina (completo) Async
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="dtReq"></param>
|
|
/// <returns></returns>
|
|
public async Task<StatoProdModel> StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq)
|
|
{
|
|
StatoProdModel dbResult = new StatoProdModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacchina);
|
|
var DataOra = new SqlParameter("@DataOra ", dtReq);
|
|
dbResult = (await dbCtx
|
|
.DbSetStatoProd
|
|
.FromSqlRaw("EXEC stp_StatoProd_getByMacchina @pIdxMacchina, @DataOra ", IdxMacchina, DataOra)
|
|
.AsNoTracking()
|
|
.ToListAsync())
|
|
.FirstOrDefault();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Intera vista v_MSFD
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<VMSFDModel> VMSFDGetAll()
|
|
{
|
|
List<VMSFDModel> dbResult = new List<VMSFDModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetMSFD
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Vista v_MSFD x singola macchina (da stored) - singolo record
|
|
/// </summary>
|
|
/// <param name="idxMacc"></param>
|
|
/// <returns></returns>
|
|
public List<VMSFDModel> VMSFDGetByMacc(string idxMacc)
|
|
{
|
|
List<VMSFDModel> dbResult = new List<VMSFDModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacc);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetMSFD
|
|
.FromSqlRaw("exec dbo.stp_MSFD_getMacc @pIdxMacchina", IdxMacchina)
|
|
.AsNoTracking()
|
|
.AsEnumerable()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Vista v_MSFD delle machine MULTI filtrato x macchina (da stored)
|
|
/// </summary>
|
|
/// <param name="idxMacc"></param>
|
|
/// <returns></returns>
|
|
public List<VMSFDModel> VMSFDGetMultiByMacc(string idxMacc)
|
|
{
|
|
List<VMSFDModel> dbResult = new List<VMSFDModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@pIdxMacchina", idxMacc);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetMSFD
|
|
.FromSqlRaw("exec dbo.stp_MSFD_getMulti @pIdxMacchina", IdxMacchina)
|
|
.AsNoTracking()
|
|
.AsEnumerable()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |