Aggiunto controller al DB di base x MoonPro (no stats)

This commit is contained in:
Samuele Locatelli
2022-04-13 08:20:42 +02:00
parent 1848fef640
commit f28f7ee815
7 changed files with 400 additions and 8 deletions
+119
View File
@@ -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
/// <summary>
/// Elenco tabella Articoli da filtro
/// </summary>
/// <param name="numRecord"></param>
/// <param name="searchVal"></param>
/// <returns></returns>
public List<DatabaseModels.AnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
{
List<DatabaseModels.AnagArticoli> dbResult = new List<DatabaseModels.AnagArticoli>();
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()
{
}
/// <summary>
/// Elenco da tabella Macchine
/// </summary>
/// <returns></returns>
public List<DatabaseModels.Macchine> MacchineGetAll()
{
List<DatabaseModels.Macchine> dbResult = new List<DatabaseModels.Macchine>();
using (var dbCtx = new MoonProContext(_configuration))
{
dbResult = dbCtx
.DbSetMacchine
.OrderBy(x => x.IdxMacchina)
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco da tabella MappaStatoExpl
/// </summary>
/// <returns></returns>
public List<DatabaseModels.MappaStatoExpl> MseGetAll()
{
List<DatabaseModels.MappaStatoExpl> dbResult = new List<DatabaseModels.MappaStatoExpl>();
using (var dbCtx = new MoonProContext(_configuration))
{
dbResult = dbCtx
.DbSetMSE
.OrderBy(x => x.RowNum)
.ToList();
}
return dbResult;
}
/// <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;
}
#endregion Public Methods
}
}
+36
View File
@@ -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; }
}
}
+213
View File
@@ -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<MoonProContext> options) : base(options)
{
}
#endregion Public Constructors
#region Public Properties
public virtual DbSet<AnagArticoli> DbSetArticoli { get; set; }
public virtual DbSet<Macchine> DbSetMacchine { get; set; }
public virtual DbSet<MappaStatoExpl> 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<AnagArticoli>(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<Macchine>(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<MappaStatoExpl>(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
}
}
+7 -2
View File
@@ -9,7 +9,7 @@ namespace MP.Mon.Data
private static IConfiguration _configuration;
private static ILogger<MpDataService> _logger;
public static MP.Data.Controllers.MpStatsController dbController;
public static MP.Data.Controllers.MpMonController dbController;
public MpDataService(IConfiguration configuration, ILogger<MpDataService> 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<List<MP.Data.DatabaseModels.MappaStatoExpl>> MseGetAll()
{
return Task.FromResult(dbController.MseGetAll().ToList());
}
}
}
+5 -4
View File
@@ -1,5 +1,6 @@
@page "/"
@using Components
<PageTitle>Index</PageTitle>
@@ -11,13 +12,13 @@
Welcome to your new app.
</div>
@if (ListMacchine == null)
@if (ListMSE == null)
{
<div class="col-12">
<LoadingData></LoadingData>
</div>
}
else if (ListMacchine.Count == 0)
else if (ListMSE.Count == 0)
{
<div class="col-12">
<div class="alert alert-warning">
@@ -27,7 +28,7 @@
}
else
{
foreach (var macchina in ListMacchine)
foreach (var macchina in ListMSE)
{
<div class="col">
<b>@macchina.CodMacchina</b>
+18 -1
View File
@@ -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<Macchine>? ListMacchine = null;
protected List<MappaStatoExpl>? 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();
}
}
}
+2 -1
View File
@@ -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"
}
}