diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 1eddded3..2e9cd40a 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -6,7 +6,6 @@ using NLog; using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; namespace MP.Data.Controllers @@ -99,6 +98,25 @@ namespace MP.Data.Controllers return ListValuesFilt("AnagArticoli", "Tipo"); } + /// + /// Elenco codice articoli che abbiano dati Dossier + /// + /// + public List ArticleWithDossier() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetDossiers + .AsNoTracking() + .Select(i => i.OdlNav.CodArticolo) + .Distinct() + .ToList(); + } + return dbResult; + } + /// /// Eliminazione Record /// @@ -192,26 +210,6 @@ namespace MP.Data.Controllers return dbResult; } - /// - /// Statistiche ODL calcolate (da stored stp_STAT_ODL) - /// - /// - public async Task> StatOdl(int IdxOdl) - { - List dbResult = new List(); - 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; - } - /// /// Update Record /// @@ -421,7 +419,7 @@ namespace MP.Data.Controllers .FirstOrDefault(); if (currRec != null) { - currRec.Valore= editRec.Valore; + currRec.Valore = editRec.Valore; dbCtx.Entry(currRec).State = EntityState.Modified; } else @@ -440,6 +438,7 @@ namespace MP.Data.Controllers } return fatto; } + /// /// Elenco valori link (x home e navMenu laterale) /// @@ -449,6 +448,32 @@ namespace MP.Data.Controllers return ListLinkFilt("SpecLink"); } + /// + /// Aggiunta record EventList + /// + /// + /// + public async Task 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; + } + /// /// Elenco ultimi n record flux log dato macchina e flusso (ordinato x data registrazione) /// @@ -497,14 +522,14 @@ namespace MP.Data.Controllers /// Data inizio /// Data fine /// - public List ListODLFilt(bool inCorso, string codArt, string keyRichPart, DateTime startDate, DateTime endDate) + public List ListODLFilt(bool inCorso, string codArt, string keyRichPart, string IdxMacchina, DateTime startDate, DateTime endDate) { List dbResult = new List(); 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 == "*") && (codArt == "*" || x.CodArticolo.Contains(codArt))) + .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) @@ -595,25 +620,6 @@ namespace MP.Data.Controllers return dbResult; } - /// - /// Elenco codice articoli che abbiano dati Dossier - /// - /// - public List ArticleWithDossier() - { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(_configuration)) - { - dbResult = dbCtx - .DbSetDossiers - .AsNoTracking() - .Select(i => i.OdlNav.CodArticolo) - .Distinct() - .ToList(); - } - return dbResult; - } - /// /// Elenco da tabella MappaStatoExpl /// @@ -634,6 +640,107 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Chiusura ODL con eventuale conferma pezzi + /// + /// idx odl da chiudere + /// idx macchina + /// matricola operatore + /// indica se confermare i pezzi prima di chiudere ODL + /// Conferma con rettifica (ev 121) x pezzi lasciati in macchina + /// Modo conferma produzione (0=periodo, 1=giorno, 2=turno) + /// + public async Task 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; + } + + /// + /// Recupero odl data chiave + /// + /// + /// + /// + 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; + } + /// /// Elenco parametri validi x una data macchina /// @@ -655,6 +762,55 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Avvio setup ODL da PODL + /// + /// + /// + /// + /// + /// + /// + public async Task PODL_startSetup(PODLModel editRec, int matrOpr, double tcRich, int pzPallet, string note) + { + ODLModel dbResult = new ODLModel(); + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + var currRec = dbCtx + .DbSetPODL + .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); + + // recupero info su ODL corrente + dbResult = await dbCtx + .DbSetODL + .Where(x => x.IdxMacchina == editRec.IdxMacchina && x.DataInizio != null && x.DataFine == null) + .FirstOrDefaultAsync(); + } + } + catch (Exception exc) + { + Log.Error($"Eccezione durante PODL_doSetup{Environment.NewLine}{exc}"); + } + } + await Task.Delay(1); + return dbResult; + } + /// /// Eliminazione Record /// @@ -755,6 +911,49 @@ namespace MP.Data.Controllers return answ; } + /// + /// Statistiche ODL calcolate (da stored stp_STAT_ODL) + /// + /// + public async Task> StatOdl(int IdxOdl) + { + List dbResult = new List(); + 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; + } + + /// + /// Stato prod macchina + /// + /// + /// + 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; + } + #endregion Public Methods #region Private Fields diff --git a/MP.Data/DatabaseModels/EventListModel.cs b/MP.Data/DatabaseModels/EventListModel.cs new file mode 100644 index 00000000..fc9e4558 --- /dev/null +++ b/MP.Data/DatabaseModels/EventListModel.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + + +#nullable disable +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DatabaseModels +{ + [Table("EventList")] + public partial class EventListModel + { + #region Public Properties + + [MaxLength(50)] + public string IdxMacchina { get; set; } = "NA"; + public DateTime? InizioStato { get; set; } = DateTime.Now; + public int IdxTipo { get; set; } = 0; + + [MaxLength(50)] + public string CodArticolo { get; set; } = ""; + + [MaxLength(250)] + public string Value { get; set; } = ""; + + public int MatrOpr { get; set; } = 0; + + [MaxLength(20)] + public string pallet { get; set; } = ""; + + /// + /// Navigazione oggetto Machine + /// + [ForeignKey("IdxMacchina")] + public virtual Macchine MachineNav { get; set; } = null!; + /// + /// Navigazione oggetto Articolo + /// + [ForeignKey("CodArticolo")] + public virtual AnagArticoli ArticoloNav { get; set; } = null!; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/StatoProdModel.cs b/MP.Data/DatabaseModels/StatoProdModel.cs new file mode 100644 index 00000000..4072485e --- /dev/null +++ b/MP.Data/DatabaseModels/StatoProdModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +#nullable disable +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DatabaseModels +{ + public partial class StatoProdModel + { + [Key] + public string idxMacchina { get; set; } = "NA"; + public int pezziNonConfermati { get; set; } = 0; + public DateTime DataFrom { get; set; } = DateTime.Now; + public DateTime DataTo { get; set; } = DateTime.Now; + } +} diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index e35a351e..99ddb37e 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -49,6 +49,8 @@ namespace MP.Data public virtual DbSet DbSetFluxLog { get; set; } public virtual DbSet DbSetDossiers { get; set; } public virtual DbSet DbSetStatOdl { get; set; } + public virtual DbSet DbSetStatoProd { get; set; } + public virtual DbSet DbSetEvList { get; set; } #endregion Public Properties @@ -299,6 +301,12 @@ namespace MP.Data }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.IdxMacchina, e.InizioStato, e.IdxTipo}); + + }); + OnModelCreatingPartial(modelBuilder); } diff --git a/MP.SPEC/Components/ListODL.razor b/MP.SPEC/Components/ListODL.razor index 0a1ecb65..8937c9d6 100644 --- a/MP.SPEC/Components/ListODL.razor +++ b/MP.SPEC/Components/ListODL.razor @@ -12,10 +12,26 @@ else if (totalCount == 0) else {
+ @if (currRecord != null && !showStats && isCurrOdl) + { +
+
+
+ @*
+ + + +
*@ + +
+ }
+ @@ -28,6 +44,17 @@ else @foreach (var record in ListRecords) { + + @@ -91,7 +118,7 @@ else }
+ + Articolo Fase Macchina
+ @if (isCurrOdl) + { + + } + else + { + + } + @record.CodArticolo
@record.ArticoloNav.DescArticolo
@@ -83,7 +110,7 @@ else @record.DurataMinuti
- +
-