diff --git a/MP.Data/Controllers/MpMonController.cs b/MP.Data/Controllers/MpMonController.cs new file mode 100644 index 00000000..83cde8de --- /dev/null +++ b/MP.Data/Controllers/MpMonController.cs @@ -0,0 +1,119 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using NLog; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MP.Data.Controllers +{ + public class MpMonController : IDisposable + { + #region Private Fields + + private static IConfiguration _configuration; + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Public Constructors + + public MpMonController(IConfiguration configuration) + { + _configuration = configuration; + Log.Info("Avviata classe MpMonController"); + } + + #endregion Public Constructors + + #region Public Methods + + /// + /// Elenco tabella Articoli da filtro + /// + /// + /// + /// + public List ArticoliGetSearch(int numRecord, string searchVal = "") + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetArticoli + .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; + } + + public void Dispose() + { + } + + /// + /// Elenco da tabella Macchine + /// + /// + public List MacchineGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetMacchine + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco da tabella MappaStatoExpl + /// + /// + public List MseGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetMSE + .OrderBy(x => x.RowNum) + .ToList(); + } + return dbResult; + } + + /// + /// Annulla modifiche su una specifica entity (cancel update) + /// + /// + /// + 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; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/MappaStatoExpl.cs b/MP.Data/DatabaseModels/MappaStatoExpl.cs new file mode 100644 index 00000000..e529b4ea --- /dev/null +++ b/MP.Data/DatabaseModels/MappaStatoExpl.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; + +namespace MP.Data.DatabaseModels +{ + public partial class MappaStatoExpl + { + public int RowNum { get; set; } + public DateTime? LastUpdate { get; set; } + public string IdxMacchina { get; set; } + public string CodMacchina { get; set; } + public string Nome { get; set; } + public string Url { get; set; } + public int? IdxOdl { get; set; } + public string CodArticolo { get; set; } + public string Disegno { get; set; } + public int? NumPezzi { get; set; } + public decimal? Tcassegnato { get; set; } + public DateTime? DataInizioOdl { get; set; } + public string Semaforo { get; set; } + public int? IdxStato { get; set; } + public string DescrizioneStato { get; set; } + public double? Durata { get; set; } + public int? PezziProd { get; set; } + public int? PezziConf { get; set; } + public decimal? TempoOn { get; set; } + public decimal? TempoAuto { get; set; } + public decimal? TempoRun { get; set; } + public decimal? Tcmedio { get; set; } + public decimal? Tclav { get; set; } + public decimal? Tceff { get; set; } + public decimal? TcmedioRt { get; set; } + public decimal? TclavRt { get; set; } + public decimal? TceffRt { get; set; } + } +} diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs new file mode 100644 index 00000000..40b2ed1c --- /dev/null +++ b/MP.Data/MoonProContext.cs @@ -0,0 +1,213 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.Extensions.Configuration; +using MP.Data.DatabaseModels; +using NLog; + +#nullable disable + +namespace MP.Data +{ + public partial class MoonProContext : DbContext + { + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfiguration _configuration; + + #endregion Private Fields + + #region Public Constructors + + public MoonProContext(IConfiguration configuration) + { + _configuration = configuration; + } + + public MoonProContext(DbContextOptions options) : base(options) + { + } + + #endregion Public Constructors + + #region Public Properties + + public virtual DbSet DbSetArticoli { get; set; } + public virtual DbSet DbSetMacchine { get; set; } + public virtual DbSet DbSetMSE { 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.Mon"); + + optionsBuilder.UseSqlServer(connString); + //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(entity => + { + entity.HasNoKey(); + + entity.ToView("v_UI_AnagArticoli"); + + entity.Property(e => e.CodArticolo) + .IsRequired() + .HasMaxLength(50); + + entity.Property(e => e.DescArticolo) + .IsRequired() + .HasMaxLength(250); + + entity.Property(e => e.Disegno) + .IsRequired() + .HasMaxLength(50); + + entity.Property(e => e.Tipo) + .IsRequired() + .HasMaxLength(50); + }); + + modelBuilder.Entity(entity => + { + entity.HasNoKey(); + + entity.ToView("Macchine"); + + entity.Property(e => e.CodMacchina).HasMaxLength(50); + + entity.Property(e => e.Descrizione).HasMaxLength(50); + + entity.Property(e => e.IdxMacchina) + .IsRequired() + .HasMaxLength(50); + + entity.Property(e => e.Nome).HasMaxLength(50); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.RowNum); + + entity.ToTable("MappaStatoExpl"); + + entity.Property(e => e.CodArticolo) + .HasMaxLength(50) + .HasDefaultValueSql("('-')"); + + entity.Property(e => e.CodMacchina).HasMaxLength(50); + + entity.Property(e => e.DataInizioOdl) + .HasColumnType("datetime") + .HasColumnName("DataInizioODL"); + + entity.Property(e => e.DescrizioneStato) + .HasMaxLength(50) + .HasDefaultValueSql("('n.d.')"); + + entity.Property(e => e.Disegno) + .HasMaxLength(50) + .HasDefaultValueSql("('')"); + + entity.Property(e => e.Durata) + .HasColumnName("durata") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.IdxMacchina).HasMaxLength(50); + + entity.Property(e => e.IdxOdl).HasColumnName("idxODL"); + + entity.Property(e => e.IdxStato) + .HasColumnName("idxStato") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.LastUpdate) + .HasColumnType("datetime") + .HasColumnName("lastUpdate"); + + entity.Property(e => e.Nome).HasMaxLength(50); + + entity.Property(e => e.PezziConf).HasDefaultValueSql("((0))"); + + entity.Property(e => e.PezziProd).HasDefaultValueSql("((0))"); + + entity.Property(e => e.Semaforo) + .HasMaxLength(50) + .HasDefaultValueSql("('')"); + + entity.Property(e => e.Tcassegnato) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCAssegnato") + .HasDefaultValueSql("((1))"); + + entity.Property(e => e.Tceff) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCEff") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.TceffRt) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCEffRT") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.Tclav) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCLav") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.TclavRt) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCLavRT") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.Tcmedio) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCMedio") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.TcmedioRt) + .HasColumnType("decimal(18, 8)") + .HasColumnName("TCMedioRT") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.TempoAuto) + .HasColumnType("decimal(18, 8)") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.TempoOn) + .HasColumnType("decimal(18, 8)") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.TempoRun) + .HasColumnType("decimal(18, 8)") + .HasDefaultValueSql("((0))"); + + entity.Property(e => e.Url) + .HasMaxLength(250) + .HasColumnName("url"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Mon/Data/MpDataService.cs b/MP.Mon/Data/MpDataService.cs index a2f0b60a..44777b89 100644 --- a/MP.Mon/Data/MpDataService.cs +++ b/MP.Mon/Data/MpDataService.cs @@ -9,7 +9,7 @@ namespace MP.Mon.Data private static IConfiguration _configuration; private static ILogger _logger; - public static MP.Data.Controllers.MpStatsController dbController; + public static MP.Data.Controllers.MpMonController dbController; public MpDataService(IConfiguration configuration, ILogger logger) @@ -24,7 +24,7 @@ namespace MP.Mon.Data } else { - dbController = new MP.Data.Controllers.MpStatsController(configuration); + dbController = new MP.Data.Controllers.MpMonController(configuration); StringBuilder sb = new StringBuilder(); sb.AppendLine($"DbController OK"); //sb.AppendLine($"CST: {dbController.CustomersCount()} | CNT: {dbController.CountersCount()} | BSK: {dbController.BasketsCount()} | NGT: {dbController.NegotiationsCount()} | DOC: {dbController.DocsCount()} | ITM: {dbController.ItemsCount()} | RES: {dbController.ResourcesCount()}"); @@ -41,5 +41,10 @@ namespace MP.Mon.Data { return Task.FromResult(dbController.MacchineGetAll().ToList()); } + + public Task> MseGetAll() + { + return Task.FromResult(dbController.MseGetAll().ToList()); + } } } diff --git a/MP.Mon/Pages/Index.razor b/MP.Mon/Pages/Index.razor index 414ac22b..3f9202cf 100644 --- a/MP.Mon/Pages/Index.razor +++ b/MP.Mon/Pages/Index.razor @@ -1,5 +1,6 @@ @page "/" -@using Components + + Index @@ -11,13 +12,13 @@ Welcome to your new app. - @if (ListMacchine == null) + @if (ListMSE == null) {
} - else if (ListMacchine.Count == 0) + else if (ListMSE.Count == 0) {
@@ -27,7 +28,7 @@ } else { - foreach (var macchina in ListMacchine) + foreach (var macchina in ListMSE) {
@macchina.CodMacchina diff --git a/MP.Mon/Pages/Index.razor.cs b/MP.Mon/Pages/Index.razor.cs index 5b7556f9..3ae92d10 100644 --- a/MP.Mon/Pages/Index.razor.cs +++ b/MP.Mon/Pages/Index.razor.cs @@ -15,11 +15,28 @@ using MP.Mon; using MP.Mon.Shared; using MP.Mon.Components; using MP.Data.DatabaseModels; +using MP.Mon.Components; +using MP.Mon.Data; namespace MP.Mon.Pages { public partial class Index { - protected List? ListMacchine = null; + protected List? ListMSE = null; + + protected override async Task OnInitializedAsync() + { + await reloadData(); + //return base.OnInitializedAsync(); + } + + [Inject] + protected MpDataService MMDataService { get; set; } + + private async Task reloadData() + { + ListMSE = await MMDataService.MseGetAll(); + } + } } \ No newline at end of file diff --git a/MP.Mon/appsettings.json b/MP.Mon/appsettings.json index 6a0146a5..f83e95f8 100644 --- a/MP.Mon/appsettings.json +++ b/MP.Mon/appsettings.json @@ -8,7 +8,8 @@ "AllowedHosts": "*", "CodApp": "MP.MON", "ConnectionStrings": { - "MP.Mon": "Server=SQL2016DEV;Database=MonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", + "MP.Mon": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", + "MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", "Redis": "localhost:6379,DefaultDatabase=13,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" } }