330441982b
- aggiunti metodi iniziali x recupero dati inventari + scansioni - DB aggiornato
1085 lines
40 KiB
C#
1085 lines
40 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.Data.DatabaseModels;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Controllers
|
|
{
|
|
public class MpSpecController : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MpSpecController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
Log.Info("Avviata classe MpSpecController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Elenco Gruppi tipo Azienda
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagGruppi> AnagGruppiAziende()
|
|
{
|
|
return AnagGruppiGetTipo("AZIENDA");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Gruppi tipo Fasi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagGruppi> AnagGruppiFase()
|
|
{
|
|
return AnagGruppiGetTipo("FASE");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Gruppi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagGruppi> AnagGruppiGetAll()
|
|
{
|
|
List<AnagGruppi> dbResult = new List<AnagGruppi>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetAnagGruppi
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.CodGruppo)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gruppi x tipo
|
|
/// </summary>
|
|
/// <param name="tipoGruppo"></param>
|
|
/// <returns></returns>
|
|
public List<AnagGruppi> AnagGruppiGetTipo(string tipoGruppo)
|
|
{
|
|
List<AnagGruppi> dbResult = new List<AnagGruppi>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetAnagGruppi
|
|
.Where(x => x.TipoGruppo == tipoGruppo)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.CodGruppo)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco valori ammessi x Stati commessa (es Yacht Baglietto)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ListValues> AnagStatiComm()
|
|
{
|
|
return ListValuesFilt("PODL", "StatoComm");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco valori ammessi x Tipo articoli
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ListValues> AnagTipoArtLV()
|
|
{
|
|
return ListValuesFilt("AnagArticoli", "Tipo");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco codice articoli che abbiano dati Dossier
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<string> ArticleWithDossier()
|
|
{
|
|
List<string> dbResult = new List<string>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetDossiers
|
|
.AsNoTracking()
|
|
.Select(i => i.CodArticolo)
|
|
.Distinct()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione Record
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ArticoliDeleteRecord(AnagArticoli currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currVal = dbCtx
|
|
.DbSetArticoli
|
|
.Where(x => x.CodArticolo == currRec.CodArticolo)
|
|
.FirstOrDefault();
|
|
dbCtx
|
|
.DbSetArticoli
|
|
.Remove(currVal);
|
|
await dbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ArticoliDeleteRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella Articoli da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<AnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
|
|
{
|
|
List<AnagArticoli> dbResult = new List<AnagArticoli>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetArticoli
|
|
.AsNoTracking()
|
|
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
|
.OrderBy(x => x.CodArticolo)
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella Articoli da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="azienda"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<AnagArticoli> ArticoliGetSearch(int numRecord, string azienda = "*", string searchVal = "")
|
|
{
|
|
List<AnagArticoli> dbResult = new List<AnagArticoli>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetArticoli
|
|
.AsNoTracking()
|
|
.Where(x => (x.Azienda == azienda || azienda == "*") && (x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal)))
|
|
.OrderBy(x => x.CodArticolo)
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella Articoli IMPIEGATI (da stored stp_ART_getUsed)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagArticoli> ArticoliGetUsed()
|
|
{
|
|
List<AnagArticoli> dbResult = new List<AnagArticoli>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetArticoli
|
|
.FromSqlRaw("EXEC stp_ART_getUsed")
|
|
.AsNoTracking()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update Record
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ArticoliUpdateRecord(AnagArticoli editRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetArticoli
|
|
.Where(x => x.CodArticolo == editRec.CodArticolo)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Disegno = editRec.Disegno;
|
|
currRec.DescArticolo = editRec.DescArticolo;
|
|
currRec.Tipo = editRec.Tipo;
|
|
currRec.Azienda = editRec.Azienda;
|
|
dbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
dbCtx
|
|
.DbSetArticoli
|
|
.Add(editRec);
|
|
}
|
|
await dbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ArticoliUpdateRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_configuration = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione di un dossier
|
|
/// </summary>
|
|
/// <param name="currRec">record dossier da eliminare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersDeleteRecord(DossierModel currRec)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currVal = dbCtx
|
|
.DbSetDossiers
|
|
.Where(x => x.IdxDossier == currRec.IdxDossier)
|
|
.FirstOrDefault();
|
|
dbCtx
|
|
.DbSetDossiers
|
|
.Remove(currVal);
|
|
await dbCtx.SaveChangesAsync();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DossiersDeleteRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ultimi n record DOssiers (che contengono ad esempio "salvataggi" di FLuxLog) dato
|
|
/// macchina (ordinato x data registrazione)
|
|
/// </summary>
|
|
/// <param name="IdxMacchina">* = tutte, altrimenti solo x una data macchina</param>
|
|
/// <param name="CodArticolo">* = tutti, altrimenti solo x un dato articolo</param>
|
|
/// <param name="DtStart">Data minima per estrazione records</param>
|
|
/// <param name="DtEnd">Data Massima per estrazione records</param>
|
|
/// <returns></returns>
|
|
public List<DossierModel> DossiersGetLastFilt(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd)
|
|
{
|
|
List<DossierModel> dbResult = new List<DossierModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetDossiers
|
|
.AsNoTracking()
|
|
.Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodArticolo == "*" || x.CodArticolo == CodArticolo) && (x.DtRif >= DtStart && x.DtRif <= DtEnd))
|
|
.Include(m => m.MachineNav)
|
|
//.Include(o => o.OdlNav)
|
|
.Include(a => a.ArticoloNav)
|
|
.OrderByDescending(x => x.DtRif)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// insert di un record Dossier
|
|
/// </summary>
|
|
/// <param name="editRec">record dossier da modificare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersInsert(DossierModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbCtx
|
|
.DbSetDossiers
|
|
.Add(newRec);
|
|
await dbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DossiersInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio snapshot parametri (con stored) + svuota eventuale cache redis
|
|
/// </summary>
|
|
/// <param name="idxMacchina">macchina</param>
|
|
/// <param name="maxSec">Num massimo secondi per recuperare dati correnti</param>
|
|
/// <param name="dtRif">DataOra riferimento x cui prendere valori antecedenti</param>
|
|
public bool DossiersTakeParamsSnapshot(string idxMacchina, int maxSec, DateTime dtRif)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var pMaxSec = new SqlParameter("@MaxSec", maxSec);
|
|
var pDtRif = new SqlParameter("@DtRif", dtRif);
|
|
|
|
var dbResult = dbCtx
|
|
.Database
|
|
.ExecuteSqlRaw("EXEC stp_FL_TakeSnapshot @IdxMacchina,@MaxSec,@DtRif", pIdxMacchina, pMaxSec, pDtRif);
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio snapshot parametri (con stored) + svuota eventuale cache redis
|
|
/// </summary>
|
|
/// <param name="idxMacchina">macchina</param>
|
|
/// <param name="dtMin">Data min x selezione</param>
|
|
/// <param name="dtMax">Data MAX x selezione</param>
|
|
public bool DossiersTakeParamsSnapshotLast(string idxMacchina, DateTime dtMin, DateTime dtMax)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var pDtMin = new SqlParameter("@DtMin", dtMin);
|
|
var pDtMax = new SqlParameter("@DtMax", dtMax);
|
|
|
|
var dbResult = dbCtx
|
|
.Database
|
|
.ExecuteSqlRaw("EXEC stp_FL_TakeSnapshotLast @IdxMacchina,@DtMin,@DtMax", pIdxMacchina, pDtMin, pDtMax);
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update del campo VALORE di un dossier (che contiene json flux log serializzati)
|
|
/// </summary>
|
|
/// <param name="editRec">record dossier da modificare</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DossiersUpdateValore(DossierModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetDossiers
|
|
.Where(x => x.IdxDossier == editRec.IdxDossier)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Valore = editRec.Valore;
|
|
dbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
dbCtx
|
|
.DbSetDossiers
|
|
.Add(editRec);
|
|
}
|
|
await dbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DossiersUpdateRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco valori link (x home e navMenu laterale)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<LinkMenu> ElencoLink()
|
|
{
|
|
return ListLinkFilt("SpecLink");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta record EventList
|
|
/// </summary>
|
|
/// <param name="newRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> EvListInsert(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 EvListInsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
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<FluxLog> FluxLogGetLastFilt(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec)
|
|
{
|
|
List<FluxLog> dbResult = new List<FluxLog>();
|
|
using (var dbCtx = new MoonProContext(_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;
|
|
}
|
|
|
|
public List<LinkMenu> ListLinkFilt(string tipoLink)
|
|
{
|
|
List<LinkMenu> dbResult = new List<LinkMenu>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetLinkMenu
|
|
.Where(x => x.TipoLink == tipoLink)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.ordine)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco ODL filtrati x stato, articolo, KeyRich (che contiene stato)
|
|
/// </summary>
|
|
/// <param name="inCorso">Stato ODL: true=in corso/completato</param>
|
|
/// <param name="codArt">Cod articolo</param>
|
|
/// <param name="keyRichPart">KeyRich (parziale) da cercare (es cod stato x yacht)</param>
|
|
/// <param name="startDate">Data inizio</param>
|
|
/// <param name="endDate">Data fine</param>
|
|
/// <returns></returns>
|
|
public List<ODLModel> ListODLFilt(bool inCorso, string codArt, string keyRichPart, string IdxMacchina, DateTime startDate, DateTime endDate)
|
|
{
|
|
List<ODLModel> dbResult = new List<ODLModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetODL
|
|
.Where(x => ((inCorso && x.DataFine == null) || ((!inCorso && x.DataFine != null) && x.DataInizio >= startDate && x.DataInizio <= endDate)) && (x.KeyRichiesta.Contains(keyRichPart) || keyRichPart == "*") && (x.IdxMacchina.Contains(IdxMacchina) || IdxMacchina == "*") && (codArt == "*" || x.CodArticolo.Contains(codArt)))
|
|
.AsNoTracking()
|
|
.Include(m => m.MachineNav)
|
|
.Include(a => a.ArticoloNav)
|
|
.OrderByDescending(x => x.IdxOdl)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco PODL non avviati filtrati x articolo, KeyRich (che contiene stato)
|
|
/// </summary>
|
|
/// <param name="codArt">Cod articolo</param>
|
|
/// <param name="keyRichPart">KeyRich (parziale) da cercare (es cod stato x yacht)</param>
|
|
/// <returns></returns>
|
|
public List<PODLModel> ListPODLFilt(string codArt, string keyRichPart)
|
|
{
|
|
List<PODLModel> dbResult = new List<PODLModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetPODL
|
|
.Where(x => (x.IdxOdl == 0) && (x.KeyRichiesta.Contains(keyRichPart) || keyRichPart == "*") && (codArt == "*" || x.CodArticolo.Contains(codArt)))
|
|
.AsNoTracking()
|
|
.Include(m => m.MachineNav)
|
|
.Include(a => a.ArticoloNav)
|
|
.OrderByDescending(x => x.InsertDate)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco valori ammessi x tabella/colonna
|
|
/// </summary>
|
|
/// <param name="tabName"></param>
|
|
/// <param name="fieldName"></param>
|
|
/// <returns></returns>
|
|
public List<ListValues> ListValuesFilt(string tabName, string fieldName)
|
|
{
|
|
List<ListValues> dbResult = new List<ListValues>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetListValues
|
|
.Where(x => x.TableName == tabName && x.FieldName == fieldName)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.ordinal)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella Macchine
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Macchine> MacchineGetAll()
|
|
{
|
|
List<Macchine> dbResult = new List<Macchine>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetMacchine
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco id Macchine che abbiano dati FLuxLog, nel periodo indicato
|
|
/// </summary>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<string>> MacchineWithFlux(DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
List<string> dbResult = new List<string>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = await dbCtx
|
|
.DbSetFluxLog
|
|
.AsNoTracking()
|
|
.Where(x => x.dtEvento >= dtStart && x.dtEvento <= dtEnd)
|
|
.Select(i => i.IdxMacchina)
|
|
.Distinct()
|
|
.ToListAsync();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco da tabella MappaStatoExpl
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<MappaStatoExpl> MseGetAll(int maxAge = 2000)
|
|
{
|
|
List<MappaStatoExpl> dbResult = new List<MappaStatoExpl>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetMSE
|
|
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiusura ODL con eventuale conferma pezzi
|
|
/// </summary>
|
|
/// <param name="idxOdl">idx odl da chiudere</param>
|
|
/// <param name="idxMacchina">idx macchina</param>
|
|
/// <param name="matrOpr">matricola operatore</param>
|
|
/// <param name="confPezzi">indica se confermare i pezzi prima di chiudere ODL</param>
|
|
/// <param name="confRett">Conferma con rettifica (ev 121) x pezzi lasciati in macchina</param>
|
|
/// <param name="modoConfProd">Modo conferma produzione (0=periodo, 1=giorno, 2=turno)</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ODLClose(int idxOdl, string idxMacchina, int matrOpr, bool confPezzi, bool confRett, int modoConfProd)
|
|
{
|
|
bool fatto = false;
|
|
if (idxOdl > 0)
|
|
{
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
// preparo i parametri
|
|
var IdxODL = new SqlParameter("@IdxODL", idxOdl);
|
|
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
|
|
// FARE FIXME TODO !!! da valutare casi setup/autoconferma...
|
|
#if false
|
|
// controllo se HO pezzi da confermare...
|
|
var statoProd = StatoProdMacchina(idxMacchina);
|
|
if (statoProd.pezziNonConfermati < 1)
|
|
{ }
|
|
#endif
|
|
|
|
// se richiesto confermo produzione
|
|
if (confPezzi)
|
|
{
|
|
var MatrApp = new SqlParameter("@MatrApp", idxMacchina);
|
|
|
|
/* ----------------------------------
|
|
* CONFERMA PEZZI
|
|
*
|
|
* condizioni da verificare:
|
|
* - gestione rettifica (ev121) / pezzi da LASCIARE in macchina
|
|
* - conferma a zero pezzi (setup) oppure con i pezzi fatti e non ancora confermati
|
|
*
|
|
*
|
|
*
|
|
* */
|
|
|
|
// recupero i dati dei pezzi da confermare... con DbSetPzProd + exec
|
|
// stp_PzProd_getByMacchina 'SIMUL_01'
|
|
|
|
// stp_ConfermaProduzCompletaFull
|
|
/*
|
|
* @idxMacchina NVARCHAR(50),
|
|
@MatrApp INT,
|
|
@dataFrom DATETIME,
|
|
@dataTo DATETIME,
|
|
@pezziConf INT,
|
|
@pezziLasciati INT, -- pezzi lasciati = evento 121 (-) pre conferma e (+) dopo --> da lasciare in macchina post conferma
|
|
@pezziScar INT = 0, -- pezzi scartati (registrati da 2016.11.20) DA INDICARE COME VALORE > 0!!! sennò faccio ABS...
|
|
@TipoConf INT = 0, -- Tipo intervallo conferma: 0 = periodo intero, 1 = per giorni, 2 = per turni
|
|
@DataOraApp DATETIME = NULL, -- di norma GETDATE() nel programma - serve per ricalcolo
|
|
@TestConferma BIT = 1 -- TestConferma : 1 = verifica conf. duplicata e inserisci in ElencoConfermeProd, 0 = nessuna verifica e inserimento ( per ricalcolo )
|
|
*/
|
|
}
|
|
|
|
// ora chiudo ODL
|
|
try
|
|
{
|
|
var dbResult = await dbCtx
|
|
.DbSetStatOdl
|
|
.FromSqlRaw("EXEC stp_ODL_fineProd @IdxODL, @IdxMacchina", IdxODL, IdxMacchina)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ODLClose{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero odl data chiave
|
|
/// </summary>
|
|
/// <param name="idxOdl"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public ODLModel OdlGetByKey(int idxOdl)
|
|
{
|
|
ODLModel dbResult = new ODLModel();
|
|
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetODL
|
|
.FirstOrDefault(x => x.IdxOdl == idxOdl);
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero Odl CORRENTI
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ODLModel> OdlGetCurrent()
|
|
{
|
|
List<ODLModel> dbResult = new List<ODLModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetODL
|
|
.Where(x => x.DataInizio != null && x.DataFine == null)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<StatODLModel>> OdlStart(int IdxOdl)
|
|
{
|
|
List<StatODLModel> dbResult = new List<StatODLModel>();
|
|
if (IdxOdl > 0)
|
|
{
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxODL = new SqlParameter("@IdxODL", IdxOdl);
|
|
|
|
dbResult = await dbCtx
|
|
.DbSetStatOdl
|
|
.FromSqlRaw("EXEC stp_STAT_ODL @IdxODL", IdxODL)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco parametri validi x una data macchina
|
|
/// </summary>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <returns></returns>
|
|
public List<string> ParametriGetFilt(string IdxMacchina)
|
|
{
|
|
List<string> dbResult = new List<string>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetFluxLog
|
|
.AsNoTracking()
|
|
.Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina))
|
|
.Take(1000)
|
|
.Select(i => i.CodFlux)
|
|
.Distinct()
|
|
.OrderBy(x => x)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero PODL da chiave
|
|
/// </summary>
|
|
/// <param name="idxPODL"></param>
|
|
/// <returns></returns>
|
|
public async Task<PODLModel> PODL_getByKey(int idxPODL)
|
|
{
|
|
PODLModel dbResult = new PODLModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetPODL
|
|
.AsNoTracking()
|
|
.Where(x => x.IdxPromessa == idxPODL)
|
|
.FirstOrDefault();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PODL_getByKey{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return dbResult;
|
|
}
|
|
/// <summary>
|
|
/// Recupero PODL da IdxOdl
|
|
/// </summary>
|
|
/// <param name="idxPODL"></param>
|
|
/// <returns></returns>
|
|
public PODLModel PODL_getByOdl(int idxODL)
|
|
{
|
|
PODLModel dbResult = new PODLModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetPODL
|
|
.AsNoTracking()
|
|
.Where(x => x.IdxOdl == idxODL)
|
|
.FirstOrDefault();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PODL_getByOdl{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Avvio setup ODL da PODL
|
|
/// </summary>
|
|
/// <param name="editRec"></param>
|
|
/// <param name="matrOpr"></param>
|
|
/// <param name="tcRich"></param>
|
|
/// <param name="pzPallet"></param>
|
|
/// <param name="note"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PODL_startSetup(PODLModel editRec, int matrOpr, double tcRich, int pzPallet, string note)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetPODL
|
|
.AsNoTracking()
|
|
.Where(x => x.IdxPromessa == editRec.IdxPromessa)
|
|
.FirstOrDefault();
|
|
|
|
if (currRec != null)
|
|
{
|
|
// eseguo stored attrezzaggio
|
|
var IdxPromessa = new SqlParameter("@idxPromessa", editRec.IdxPromessa);
|
|
var MatrOpr = new SqlParameter("@MatrOpr", matrOpr);
|
|
var IdxMacchina = new SqlParameter("@IdxMacchina", editRec.IdxMacchina);
|
|
var TCRichAttr = new SqlParameter("@TCRichAttr", tcRich);
|
|
var PzPallet = new SqlParameter("@PzPallet", pzPallet);
|
|
var Note = new SqlParameter("@Note", note);
|
|
var callResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("EXEC stp_ODL_inizioSetupPromessa @idxPromessa, @MatrOpr, @IdxMacchina, @TCRichAttr, @PzPallet, @Note", IdxPromessa, MatrOpr, IdxMacchina, TCRichAttr, PzPallet, Note);
|
|
|
|
answ = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PODL_doSetup{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione Record
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PODLDeleteRecord(PODLModel currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currVal = dbCtx
|
|
.DbSetPODL
|
|
.Where(x => x.IdxPromessa == currRec.IdxPromessa)
|
|
.FirstOrDefault();
|
|
dbCtx
|
|
.DbSetPODL
|
|
.Remove(currVal);
|
|
await dbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PODLDeleteRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update Record
|
|
/// </summary>
|
|
/// <param name="currRec"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> PODLUpdateRecord(PODLModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = dbCtx
|
|
.DbSetPODL
|
|
.Where(x => x.IdxPromessa == editRec.IdxPromessa)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.CodGruppo = editRec.CodGruppo;
|
|
currRec.CodArticolo = editRec.CodArticolo;
|
|
currRec.IdxMacchina = editRec.IdxMacchina;
|
|
currRec.KeyBCode = editRec.KeyBCode;
|
|
currRec.KeyRichiesta = editRec.KeyRichiesta;
|
|
currRec.NumPezzi = editRec.NumPezzi;
|
|
currRec.Tcassegnato = editRec.Tcassegnato;
|
|
currRec.Attivabile = editRec.Attivabile;
|
|
currRec.Note = editRec.Note;
|
|
dbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
dbCtx
|
|
.DbSetPODL
|
|
.Add(editRec);
|
|
}
|
|
await dbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante PODLUpdateRecord{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <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>
|
|
/// Stato prod macchina
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <returns></returns>
|
|
public StatoProdModel StatoProdMacchina(string idxMacchina)
|
|
{
|
|
StatoProdModel dbResult = new StatoProdModel();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var IdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
dbResult = dbCtx
|
|
.DbSetStatoProd
|
|
.FromSqlRaw("EXEC stp_PzProd_getByMacchina @IdxMacchina", IdxMacchina)
|
|
.AsNoTracking()
|
|
.FirstOrDefault();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Vocabolario (completo)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<VocabolarioModel> VocabolarioGetAll()
|
|
{
|
|
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
|
using (var dbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = dbCtx
|
|
.DbSetVocabolario
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Lemma)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |