Files
Samuele E. Locatelli 2d83e27d89 Modifica model macchine
2025-06-28 09:20:48 +02:00

501 lines
17 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using MP.AppAuth.Models;
using NLog;
using System;
namespace MP.AppAuth
{
public partial class MoonProContext : DbContext
{
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private IConfiguration _configuration;
#endregion Private Fields
#region Public Constructors
[Obsolete("This constructor should never be used directly, and is only needed to generate entityframework stuff. Connection string can be adapted as pleased.")]
public MoonProContext()
{
}
public MoonProContext(IConfiguration configuration)
{
_configuration = configuration;
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
{
Log.Error(exc, "Exception during context initialization 01");
}
}
public MoonProContext(DbContextOptions<MoonProContext> options) : base(options)
{
try
{
// se non ci fosse... crea o migra!
Database.Migrate();
}
catch (Exception exc)
{
Log.Error(exc, "Exception during context initialization 02");
}
}
#endregion Public Constructors
#region Public Properties
public virtual DbSet<AnagArticoli> DbSetAnagArticoli { get; set; }
public virtual DbSet<AnagraficaEventi> DbSetAnagEventi { get; set; }
public virtual DbSet<AnagClassiTempo> DbSetAnagClassiTempo { get; set; }
public virtual DbSet<AnagraficaCausaliScarto> DbSetAnagCauSca { get; set; }
public virtual DbSet<AnagraficaIngressi> DbSetAnagIngressi { get; set; }
public virtual DbSet<AnagraficaMicroStati> DbSetAnagMicroStati { get; set; }
public virtual DbSet<AnagraficaStati> DbSetAnagStati { get; set; }
public virtual DbSet<AnagraficaOperatori> DbSetAnagOperatori { get; set; }
public virtual DbSet<ConfigModel> DbSetConfig { get; set; }
public virtual DbSet<DatiMacchine> DbSetDatiMacchine { get; set; }
public virtual DbSet<AnagKeyValueModel> DbSetAnagKeyValues { get; set; }
public virtual DbSet<FamigliaTipoIngressi> DbSetFamTipoIngressi { get; set; }
public virtual DbSet<FamiglieMacchine> DbSetFamMacchine { get; set; }
public virtual DbSet<KeepAlive> DbSetKeepAlive { get; set; }
public virtual DbSet<LinkMenuJqm> DbSetLinkMenuJqm { get; set; }
public virtual DbSet<ListValues> DbSetListValue { get; set; }
public virtual DbSet<MacchineModel> DbSetMacchine { get; set; }
public virtual DbSet<UpdMan> DbSetUpdMan { get; set; }
public virtual DbSet<VocabolarioModel> DbSetVocabolario { get; set; }
#endregion Public Properties
#region Private Methods
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
#endregion Private Methods
#region Protected Methods
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
string connString = _configuration.GetConnectionString("MP.Land");
if (!string.IsNullOrEmpty(connString))
{
optionsBuilder.UseSqlServer(connString);
}
else
{
optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;");
}
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS");
modelBuilder.Entity<AnagArticoli>(entity =>
{
entity.HasKey(e => e.CodArticolo);
entity.ToTable("AnagArticoli");
entity.Property(e => e.CodArticolo).HasMaxLength(50);
entity.Property(e => e.CurrRev)
.IsRequired()
.HasMaxLength(50)
.HasDefaultValueSql("('')");
entity.Property(e => e.DescArticolo)
.IsRequired()
.HasMaxLength(250)
.HasDefaultValueSql("('')");
entity.Property(e => e.Disegno)
.IsRequired()
.HasMaxLength(50)
.HasDefaultValueSql("('')");
entity.Property(e => e.FlagIsNew).HasComputedColumnSql("(case when [CurrRev]=[ProdRev] then CONVERT([bit],(0),(0)) else CONVERT([bit],(1),(0)) end)", false);
entity.Property(e => e.ProdRev)
.IsRequired()
.HasMaxLength(50)
.HasDefaultValueSql("('')");
entity.Property(e => e.Tipo)
.IsRequired()
.HasMaxLength(50)
.HasDefaultValueSql("('ART')")
.HasComment("Tipo di articolo: ART, KIT, ...");
});
modelBuilder.Entity<AnagClassiTempo>(entity =>
{
entity.HasKey(e => e.ClasseTempo);
entity.ToTable("AnagClassiTempo");
entity.Property(e => e.ClasseTempo).HasMaxLength(50);
entity.Property(e => e.Descrizione).HasMaxLength(500);
});
modelBuilder.Entity<AnagKeyValueModel>(entity =>
{
entity.HasKey(e => e.NomeVar);
entity.ToTable("AnagKeyValue");
entity.Property(e => e.NomeVar)
.HasMaxLength(50)
.HasColumnName("nomeVar");
entity.Property(e => e.Descrizione)
.HasMaxLength(250)
.HasColumnName("descrizione")
.HasDefaultValueSql("('-')");
entity.Property(e => e.ValFloat)
.HasColumnName("valFloat")
.HasDefaultValueSql("((0))");
entity.Property(e => e.ValInt)
.HasColumnName("valInt")
.HasDefaultValueSql("((0))");
entity.Property(e => e.ValString)
.HasMaxLength(250)
.HasColumnName("valString")
.HasDefaultValueSql("('')");
});
modelBuilder.Entity<AnagraficaCausaliScarto>(entity =>
{
entity.HasKey(e => e.Causale);
entity.ToTable("AnagraficaCausaliScarto");
entity.Property(e => e.Causale)
.HasMaxLength(50)
.HasDefaultValueSql("('ND')");
entity.Property(e => e.CssClass)
.IsRequired()
.HasMaxLength(50)
.HasColumnName("cssClass")
.HasDefaultValueSql("('')");
entity.Property(e => e.Descrizione)
.IsRequired()
.HasMaxLength(250)
.HasDefaultValueSql("('ND')");
entity.Property(e => e.Icona)
.IsRequired()
.HasMaxLength(50)
.HasColumnName("icona")
.HasDefaultValueSql("('')");
});
modelBuilder.Entity<AnagraficaIngressi>(entity =>
{
entity.HasKey(e => new { e.IdxFamigliaIngresso, e.ValoreIngresso });
entity.ToTable("AnagraficaIngressi");
entity.Property(e => e.Descrizione).HasMaxLength(50);
});
modelBuilder.Entity<AnagraficaMicroStati>(entity =>
{
entity.HasKey(e => new { e.IdxFamigliaIngresso, e.IdxMicroStato });
entity.ToTable("AnagraficaMicroStati");
entity.Property(e => e.Descrizione).HasMaxLength(250);
});
modelBuilder.Entity<AnagraficaOperatori>(entity =>
{
entity.HasKey(e => e.MatrOpr);
entity.ToTable("AnagraficaOperatori");
entity.Property(e => e.MatrOpr).ValueGeneratedNever();
entity.Property(e => e.AuthKey)
.HasMaxLength(50)
.HasColumnName("authKey")
.HasDefaultValueSql("('12345')");
entity.Property(e => e.CodOprExt)
.IsRequired()
.HasMaxLength(50)
.HasDefaultValueSql("('')")
.HasComment("Codice operatore per sistema esterno");
entity.Property(e => e.Cognome).HasMaxLength(50);
entity.Property(e => e.IsAdmin).HasColumnName("isAdmin");
entity.Property(e => e.Nome).HasMaxLength(50);
});
modelBuilder.Entity<ConfigModel>(entity =>
{
entity.HasKey(e => e.Chiave);
entity.ToTable("Config");
entity.Property(e => e.Chiave)
.HasMaxLength(50)
.HasColumnName("chiave");
entity.Property(e => e.Note).HasColumnName("note");
entity.Property(e => e.Valore).HasColumnName("valore");
entity.Property(e => e.ValoreStd)
.HasColumnName("valoreStd")
.HasComment("Valore di default/riferimento per la variabile");
});
modelBuilder.Entity<DatiMacchine>(entity =>
{
entity.HasKey(e => e.IdxMacchina);
entity.ToTable("DatiMacchine");
entity.Property(e => e.IdxMacchina)
.HasMaxLength(50)
.HasColumnName("idxMacchina");
entity.Property(e => e.CodArticoloA)
.HasMaxLength(50)
.HasColumnName("CodArticolo_A");
entity.Property(e => e.CodArticoloB)
.HasMaxLength(50)
.HasColumnName("CodArticolo_B");
entity.Property(e => e.HasCounter)
.HasColumnName("hasCounter")
.HasComment("Indica se la macchina abbia un COUNTER (assoluto) o meno, tipicamente true x IOB-WIN, false per IOB-PI");
entity.Property(e => e.InsEnabled)
.HasColumnName("insEnabled")
.HasDefaultValueSql("((1))")
.HasComment("definisce se l'INSERT sia abilitato per la macchina (disabilitato in fase di ricostruzione batch...)");
entity.Property(e => e.IsTrigerDbon)
.IsRequired()
.HasColumnName("isTrigerDBOn")
.HasDefaultValueSql("((1))")
.HasComment("Abilita o meno il trigger su DiarioDiBordo x ricalcolo eventi");
entity.Property(e => e.PalletChange).HasColumnName("palletChange");
entity.Property(e => e.RefreshPeriod).HasColumnName("refreshPeriod");
entity.Property(e => e.SLogEnabled)
.HasColumnName("sLogEnabled")
.HasComment("definisce se sia abilitata la registrazione di TUTTI gli invii di dati in ingresso da questa specifica macchina");
entity.Property(e => e.SerialPort)
.HasMaxLength(50)
.HasColumnName("serialPort");
entity.Property(e => e.SimplePallet).HasColumnName("simplePallet");
entity.Property(e => e.Simulazione).HasColumnName("simulazione");
});
modelBuilder.Entity<FamigliaTipoIngressi>(entity =>
{
entity.HasKey(e => e.IdxFamigliaIngresso);
entity.ToTable("FamigliaTipoIngressi");
entity.Property(e => e.IdxFamigliaIngresso).ValueGeneratedNever();
entity.Property(e => e.DescrizioneIngresso).HasMaxLength(250);
});
modelBuilder.Entity<FamiglieMacchine>(entity =>
{
entity.HasKey(e => e.IdxFamiglia);
entity.ToTable("FamiglieMacchine");
entity.Property(e => e.Descrizione)
.IsRequired()
.HasMaxLength(250);
entity.Property(e => e.HasIob)
.IsRequired()
.HasColumnName("HasIOB")
.HasDefaultValueSql("((1))")
.HasComment("Indica se la famiglia macchina prevede una IOB x alimentare dati in AUTOMATICO da impianto");
entity.Property(e => e.HasUdi)
.IsRequired()
.HasColumnName("HasUDI")
.HasDefaultValueSql("((1))")
.HasComment("Indica se la famiglia macchina prevede UserDataInput ovvero inserimento MANUALE informazioni");
});
modelBuilder.Entity<KeepAlive>(entity =>
{
entity.HasKey(e => e.IdxMacchina);
entity.ToTable("KeepAlive");
entity.Property(e => e.IdxMacchina).HasMaxLength(50);
entity.Property(e => e.DataOraMacchina).HasColumnType("datetime");
entity.Property(e => e.DataOraStart).HasColumnType("datetime");
});
modelBuilder.Entity<LinkMenuJqm>(entity =>
{
entity.HasKey(e => e.IdxLink)
.HasName("PK_linkMenuJQM");
entity.ToTable("LinkMenuJQM");
entity.Property(e => e.IdxLink).HasColumnName("idxLink");
entity.Property(e => e.Icona)
.HasMaxLength(50)
.HasColumnName("icona");
entity.Property(e => e.NavigateUrl).HasMaxLength(50);
entity.Property(e => e.Ordine).HasColumnName("ordine");
entity.Property(e => e.Testo).HasMaxLength(50);
entity.Property(e => e.TipoLink).HasMaxLength(50);
});
modelBuilder.Entity<ListValues>(entity =>
{
entity.HasKey(e => new { e.TableName, e.FieldName, e.Value });
entity.Property(e => e.TableName).HasMaxLength(50);
entity.Property(e => e.FieldName).HasMaxLength(50);
entity.Property(e => e.Value)
.HasMaxLength(50)
.HasColumnName("value");
entity.Property(e => e.Label)
.HasMaxLength(50)
.HasColumnName("label");
entity.Property(e => e.Ordinal).HasColumnName("ordinal");
});
modelBuilder.Entity<MacchineModel>(entity =>
{
entity.HasKey(e => e.IdxMacchina);
//entity.ToTable("Macchine");
entity.Property(e => e.IdxMacchina).HasMaxLength(50);
entity.Property(e => e.CodMacchina).HasMaxLength(50);
entity.Property(e => e.Css)
.IsRequired()
.HasMaxLength(50)
.HasColumnName("css")
.HasDefaultValueSql("('col text-center')")
.HasComment("Classe container standard (col, col-2, ...)");
entity.Property(e => e.Descrizione).HasMaxLength(50);
entity.Property(e => e.Locazione)
.HasMaxLength(50)
.HasColumnName("locazione");
entity.Property(e => e.Nome).HasMaxLength(50);
entity.Property(e => e.Note).HasMaxLength(50);
entity.Property(e => e.Url)
.HasMaxLength(250)
.HasColumnName("url");
});
modelBuilder.Entity<UpdMan>(entity =>
{
entity.HasKey(e => e.AppName)
.HasName("PK_UpdateMan");
entity.ToTable("DbSetUpdMan");
entity.Property(e => e.AppName).HasMaxLength(50);
entity.Property(e => e.AppUrl)
.IsRequired()
.HasMaxLength(250)
.HasDefaultValueSql("('')");
entity.Property(e => e.IsAuth)
.IsRequired()
.HasDefaultValueSql("((1))");
entity.Property(e => e.LicenseKey)
.IsRequired()
.HasDefaultValueSql("('')");
entity.Property(e => e.LocalRepo)
.IsRequired()
.HasMaxLength(250);
entity.Property(e => e.ManifestUrl)
.IsRequired()
.HasMaxLength(250);
entity.Property(e => e.PackName)
.IsRequired()
.HasMaxLength(50)
.HasDefaultValueSql("('')");
});
modelBuilder.Entity<VocabolarioModel>(entity =>
{
entity.HasKey(e => new { e.Lingua, e.Lemma });
entity.Property(e => e.Lingua).HasMaxLength(3);
entity.Property(e => e.Lemma).HasMaxLength(50);
entity.Property(e => e.Traduzione)
.IsRequired()
.HasMaxLength(500);
});
OnModelCreatingPartial(modelBuilder);
}
#endregion Protected Methods
}
}