diff --git a/MP.Data/Controllers/MpMonController.cs b/MP.Data/Controllers/MpMonController.cs index fd0ec868..c58f056c 100644 --- a/MP.Data/Controllers/MpMonController.cs +++ b/MP.Data/Controllers/MpMonController.cs @@ -36,13 +36,13 @@ namespace MP.Data.Controllers /// /// /// - public List ArticoliGetSearch(int numRecord, string searchVal = "") + public List ArticoliGetSearch(int numRecord, string searchVal = "") { - List dbResult = new List(); + List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { dbResult = dbCtx - .DbSetArticoli + .DbSetStatArticoli .AsNoTracking() .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) .OrderBy(x => x.CodArticolo) diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index 20c982fc..20921ed3 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -52,9 +52,9 @@ namespace MP.Data.Controllers /// /// /// - public List ArticoliGetSearch(int numRecord, string searchVal = "") + public List ArticoliGetSearch(int numRecord, string searchVal = "") { - List dbResult = new List(); + List dbResult = new List(); using (var dbCtx = new MoonPro_STATSContext(_configuration)) { dbResult = dbCtx diff --git a/MP.Data/DatabaseModels/StatsAnagArticoli.cs b/MP.Data/DatabaseModels/StatsAnagArticoli.cs new file mode 100644 index 00000000..02b6ad12 --- /dev/null +++ b/MP.Data/DatabaseModels/StatsAnagArticoli.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +#nullable disable + +namespace MP.Data.DatabaseModels +{ + public partial class StatsAnagArticoli + { + #region Public Properties + + public string CodArticolo { get; set; } + public string DescArticolo { get; set; } + public string Disegno { get; set; } + public string Tipo { get; set; } + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index 957d91ae..e0706089 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -34,6 +34,7 @@ namespace MP.Data #region Public Properties + public virtual DbSet DbSetStatArticoli { get; set; } public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetMSE { get; set; } @@ -53,7 +54,15 @@ namespace MP.Data { if (!optionsBuilder.IsConfigured) { - string connString = _configuration.GetConnectionString("Mp.Mon"); + string connString = _configuration.GetConnectionString("Mp.Data"); + if (string.IsNullOrEmpty(connString)) + { + connString = _configuration.GetConnectionString("Mp.Mon"); + } + if (string.IsNullOrEmpty(connString)) + { + connString = _configuration.GetConnectionString("Mp.STATS"); + } optionsBuilder.UseSqlServer(connString); //optionsBuilder.UseSqlServer("Server=SQL2016DEV;Database=MoonPro;Trusted_Connection=True;"); @@ -64,7 +73,7 @@ namespace MP.Data { modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.HasNoKey(); @@ -86,6 +95,32 @@ namespace MP.Data .IsRequired() .HasMaxLength(50); }); + modelBuilder.Entity(entity => + { + entity.HasNoKey(); + + entity.ToView("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); + + entity.Property(e => e.Azienda) + .IsRequired() + .HasMaxLength(50); + }); modelBuilder.Entity(entity => { diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index 02f17741..a2317345 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -34,7 +34,7 @@ namespace MP.Data #region Public Properties - public virtual DbSet DbSetArticoli { get; set; } + public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetAzioniUL { get; set; } public virtual DbSet DbSetControlli { get; set; } public virtual DbSet DbSetDdbTurni { get; set; } @@ -98,7 +98,7 @@ namespace MP.Data .HasMaxLength(5); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.HasNoKey(); diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 877f7b7d..09769a1a 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -26,7 +26,7 @@ namespace MP.SPEC.Data blinkPipe = new MessagePipe(redisConn, Constants.ACT_BLINK_KEY); // conf DB - string connStr = _configuration.GetConnectionString("Mp.Mon"); + string connStr = _configuration.GetConnectionString("Mp.Data"); if (string.IsNullOrEmpty(connStr)) { _logger.LogError("ConnString empty!"); @@ -80,7 +80,7 @@ namespace MP.SPEC.Data /// public Task> ArticoliGetSearch(int numRecord, string azienda, string searchVal) { - return Task.FromResult(dbController.ArticoliGetSearch(numRecord, searchVal)); + return Task.FromResult(dbController.ArticoliGetSearch(numRecord,azienda, searchVal)); } public void Dispose() diff --git a/MP.SPEC/Pages/Articoli.razor b/MP.SPEC/Pages/Articoli.razor index aabbcb01..dd703a0e 100644 --- a/MP.SPEC/Pages/Articoli.razor +++ b/MP.SPEC/Pages/Articoli.razor @@ -1,7 +1,69 @@ @page "/ART" -

Articoli

+@using MP.SPEC.Components -@code { - -} +
+
+ @* *@ +

Articoli

+
+
+ @if (ListRecords == null) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { +
+
+ + + + + + + + + + + + + + @foreach (var record in ListRecords) + { + @* + + + + + + + + *@ + } + +
MacchinaDataCommessa/ODLArticoloEsitoNoteOperatore
+
@record.CodMacchina
+
@record.IdxMacchina
+
+
@record.DataOra.ToString("yyyy.MM.dd")
+
@record.DataOra.ToString("ddd HH:mm.ss")
+
+
@record.KeyRichiesta
+
@record.IdxOdl
+
+ @record.CodArticolo +
@record.DescArticolo
+
@record.EsitoOk@record.Note@record.Cognome @record.Nome (@record.MatrOpr)
+
+
+ } +
+ +
\ No newline at end of file diff --git a/MP.SPEC/Pages/Articoli.razor.cs b/MP.SPEC/Pages/Articoli.razor.cs new file mode 100644 index 00000000..de2769f5 --- /dev/null +++ b/MP.SPEC/Pages/Articoli.razor.cs @@ -0,0 +1,260 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; +using MP.SPEC; +using MP.SPEC.Shared; +using MP.SPEC.Components; +using MP.SPEC.Data; + +namespace MP.SPEC.Pages +{ + public partial class Articoli : ComponentBase, IDisposable + { + #region Private Fields + + private MP.Data.DatabaseModels.AnagArticoli currRecord = null; + + private string fileName = "Controlli.csv"; + private List ListRecords; + private List SearchRecords; + + #endregion Private Fields + + #region Private Properties + + private int _currPage { get; set; } = 1; + + private int _numRecord { get; set; } = 10; + + private int currPage + { + get => _currPage; + set + { + if (_currPage != value) + { + _currPage = value; + var pUpd = Task.Run(async () => await reloadData()); + pUpd.Wait(); + } + } + } + + private string fullPath + { + get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}"; + } + + private bool isLoading { get; set; } = false; + + private int numRecord + { + get => _numRecord; + set + { + if (_numRecord != value) + { + _numRecord = value; + var pUpd = Task.Run(async () => await reloadData()); + pUpd.Wait(); + } + } + } + + private bool ShowCharts { get; set; } = false; + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected MessageService MessageService { get; set; } + + [Inject] + protected NavigationManager NavManager { get; set; } + + [Inject] + protected MpDataService MDService { get; set; } + + protected int totalCount + { + get + { + int answ = 0; + if (SearchRecords != null) + { + answ = SearchRecords.Count; + } + return answ; + } + } + + #endregion Protected Properties + + #region Public Properties + +#if false + [Parameter] + public SelectData currFilter + { + get + { + return MessageService.DetailFilter; + } + set + { + MessageService.DetailFilter = value; + } + } +#endif + + #endregion Public Properties + + #region Private Methods + + private async void clearFile() + { + await Task.Run(() => File.Delete(fullPath)); + } + + private async Task ExportCsv() + { + isLoading = true; + // salvo davvero! + await MP.Data.Utils.SaveToCsv(SearchRecords, fullPath); + isLoading = false; + } + + private async Task reloadData() + { + isLoading = true; + SearchRecords = await MDService.ArticoliGetSearch(100000, "", MessageService.SearchVal); + ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + isLoading = false; + } + + #endregion Private Methods + + #region Protected Methods + +#if false + protected async Task DoFilter(SelectData newFilter) + { + clearFile(); + SearchRecords = null; + ListRecords = null; + currFilter = newFilter; + await reloadData(); + } +#endif + + protected void ForceReload(int newNum) + { + numRecord = newNum; + } + + protected void ForceReloadPage(int newNum) + { + currPage = newNum; + } + + protected override async Task OnInitializedAsync() + { + clearFile(); + numRecord = 10; + MessageService.ShowSearch = false; +#if false + MessageService.PageName = "Registro Controlli"; + MessageService.PageIcon = "oi oi-beaker"; +#endif + MessageService.EA_SearchUpdated += OnSeachUpdated; + await reloadData(); + } + + protected void ResetData() + { + clearFile(); +#if false + MDService.rollBackEdit(currRecord); +#endif + currRecord = null; + } + +#if false + protected async Task ResetFilter(SelectData newFilter) + { + clearFile(); + currRecord = null; + SearchRecords = null; + ListRecords = null; + currFilter = SelectData.Init(5, 7); + await reloadData(); + } +#endif + +#if false + protected async Task ToggleChart(bool doShow) + { + ShowCharts = !ShowCharts; + if (ShowCharts) + { + await reloadData(); + } + } +#endif + + protected async Task UpdateData() + { + currRecord = null; + await reloadData(); + } + + #endregion Protected Methods + + #region Public Methods + + public string checkSelect(string CodArticolo) + { + string answ = ""; + if (currRecord != null) + { + try + { + answ = (currRecord.CodArticolo == CodArticolo) ? "table-info" : ""; + } + catch + { } + } + return answ; + } + + public void Dispose() + { + MessageService.EA_SearchUpdated -= OnSeachUpdated; + } + + public async void OnSeachUpdated() + { + await InvokeAsync(() => + { + Task task = UpdateData(); + StateHasChanged(); + }); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 46f2acde..fae8d42a 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -37,7 +37,6 @@ builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); builder.Services.AddScoped(); -builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/MP.SPEC/appsettings.Production.json b/MP.SPEC/appsettings.Production.json index a999044c..a5197b52 100644 --- a/MP.SPEC/appsettings.Production.json +++ b/MP.SPEC/appsettings.Production.json @@ -10,8 +10,7 @@ "AllowedHosts": "*", "CodApp": "MP.SPEC", "ConnectionStrings": { - "MP.Mon": "Server=localhost\\SQLEXPRESS;Database=MoonPro; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", - "MP.Stats": "Server=localhost\\SQLEXPRESS;Database=MoonPro_STATS; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", + "Mp.Data": "Server=localhost\\SQLEXPRESS;Database=MoonPro; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", "Redis": "localhost:6379,DefaultDatabase=13,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" } } diff --git a/MP.SPEC/appsettings.json b/MP.SPEC/appsettings.json index 37da0612..d5691442 100644 --- a/MP.SPEC/appsettings.json +++ b/MP.SPEC/appsettings.json @@ -8,8 +8,7 @@ "AllowedHosts": "*", "CodApp": "MP.SPEC", "ConnectionStrings": { - "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;", + "Mp.Data": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=Blazor.ServerApp;", "Redis": "localhost:6379,DefaultDatabase=1,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false" }, "ServerConf": { diff --git a/MP.SPEC/temp/.placeholder b/MP.SPEC/temp/.placeholder new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/MP.SPEC/temp/.placeholder @@ -0,0 +1 @@ + \ No newline at end of file