diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs new file mode 100644 index 00000000..75829757 --- /dev/null +++ b/MP.Data/Controllers/MpSpecController.cs @@ -0,0 +1,165 @@ +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 MpSpecController : IDisposable + { + #region Private Fields + + private static IConfiguration _configuration; + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Public Constructors + + public MpSpecController(IConfiguration configuration) + { + _configuration = configuration; + Log.Info("Avviata classe MpSpecController"); + } + + #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 + .AsNoTracking() + .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; + } + + /// + /// Elenco tabella Articoli da filtro + /// + /// + /// + /// + /// + public List ArticoliGetSearch(int numRecord, string azienda = "", string searchVal = "") + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetArticoli + .AsNoTracking() + .Where(x => (x.Azienda == azienda || string.IsNullOrEmpty(azienda)) && 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 + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco da tabella Macchine + /// + /// + public List ConfigGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + dbResult = dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco da tabella MappaStatoExpl + /// + /// + public List MseGetAll(int maxAge = 2000) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge); + + dbResult = dbCtx + .DbSetMSE + .FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec) + .AsNoTracking() + .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/AnagArticoli.cs b/MP.Data/DatabaseModels/AnagArticoli.cs index 0480a0bb..ed8e5c3e 100644 --- a/MP.Data/DatabaseModels/AnagArticoli.cs +++ b/MP.Data/DatabaseModels/AnagArticoli.cs @@ -13,6 +13,7 @@ namespace MP.Data.DatabaseModels public string DescArticolo { get; set; } public string Disegno { get; set; } public string Tipo { get; set; } + public string Azienda { get; set; } #endregion Public Properties } diff --git a/MP.SPEC/Components/CmpTop.razor b/MP.SPEC/Components/CmpTop.razor index 5da6b026..e8c8b236 100644 --- a/MP.SPEC/Components/CmpTop.razor +++ b/MP.SPEC/Components/CmpTop.razor @@ -20,8 +20,8 @@ @code { - [CascadingParameter(Name = "ShowSearch")] - public bool ShowSearch { get; set; } = true; + [CascadingParameter(Name ="ShowSearch")] + protected bool ShowSearch { get; set; } private string userName = ""; diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 77ff1a71..877f7b7d 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -33,7 +33,7 @@ namespace MP.SPEC.Data } else { - dbController = new MP.Data.Controllers.MpMonController(configuration); + dbController = new MP.Data.Controllers.MpSpecController(configuration); StringBuilder sb = new StringBuilder(); sb.AppendLine($"DbController OK"); _logger.LogInformation(sb.ToString()); @@ -42,15 +42,17 @@ namespace MP.SPEC.Data // setup conf IOB da dizionario tryLoadIobTags(); +#if false // avvio timers... - startTimers(); + startTimers(); +#endif } #endregion Public Constructors #region Public Properties - public static MP.Data.Controllers.MpMonController dbController { get; set; } = null!; + public static MP.Data.Controllers.MpSpecController dbController { get; set; } = null!; public MessagePipe blinkPipe { get; set; } = null!; @@ -70,6 +72,17 @@ namespace MP.SPEC.Data return Task.FromResult(dbController.ConfigGetAll().ToList()); } + /// + /// Restitusice elenco articoli cercati + /// + /// + /// + /// + public Task> ArticoliGetSearch(int numRecord, string azienda, string searchVal) + { + return Task.FromResult(dbController.ArticoliGetSearch(numRecord, searchVal)); + } + public void Dispose() { // Clear database controller diff --git a/MP.SPEC/Data/WeatherForecast.cs b/MP.SPEC/Data/WeatherForecast.cs deleted file mode 100644 index e684756e..00000000 --- a/MP.SPEC/Data/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace MP.SPEC.Data -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} \ No newline at end of file diff --git a/MP.SPEC/Data/WeatherForecastService.cs b/MP.SPEC/Data/WeatherForecastService.cs deleted file mode 100644 index 35416f3c..00000000 --- a/MP.SPEC/Data/WeatherForecastService.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace MP.SPEC.Data -{ - public class WeatherForecastService - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - public Task GetForecastAsync(DateTime startDate) - { - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToArray()); - } - } -} \ No newline at end of file diff --git a/MP.SPEC/Pages/Articoli.razor b/MP.SPEC/Pages/Articoli.razor new file mode 100644 index 00000000..aabbcb01 --- /dev/null +++ b/MP.SPEC/Pages/Articoli.razor @@ -0,0 +1,7 @@ +@page "/ART" + +

Articoli

+ +@code { + +} diff --git a/MP.SPEC/Pages/Counter.razor b/MP.SPEC/Pages/Counter.razor deleted file mode 100644 index ef23cb31..00000000 --- a/MP.SPEC/Pages/Counter.razor +++ /dev/null @@ -1,18 +0,0 @@ -@page "/counter" - -Counter - -

Counter

- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/MP.SPEC/Pages/FetchData.razor b/MP.SPEC/Pages/FetchData.razor deleted file mode 100644 index 697e0b40..00000000 --- a/MP.SPEC/Pages/FetchData.razor +++ /dev/null @@ -1,48 +0,0 @@ -@page "/fetchdata" - -Weather forecast - -@using MP.SPEC.Data -@inject WeatherForecastService ForecastService - -

Weather forecast

- -

This component demonstrates fetching data from a service.

- -@if (forecasts == null) -{ -

Loading...

-} -else -{ - - - - - - - - - - - @foreach (var forecast in forecasts) - { - - - - - - - } - -
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
-} - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - forecasts = await ForecastService.GetForecastAsync(DateTime.Now); - } -} diff --git a/MP.SPEC/Pages/ODL.razor b/MP.SPEC/Pages/ODL.razor new file mode 100644 index 00000000..71321c43 --- /dev/null +++ b/MP.SPEC/Pages/ODL.razor @@ -0,0 +1,7 @@ +@page "/ODL" + +

ODL

+ +@code { + +} diff --git a/MP.SPEC/Shared/MainLayout.razor b/MP.SPEC/Shared/MainLayout.razor index a356945d..f1047b4d 100644 --- a/MP.SPEC/Shared/MainLayout.razor +++ b/MP.SPEC/Shared/MainLayout.razor @@ -9,7 +9,9 @@
- + + +
@Body @@ -19,3 +21,7 @@
+ +@code { + private bool ShowSearch = false; +} \ No newline at end of file diff --git a/MP.SPEC/Shared/NavMenu.razor b/MP.SPEC/Shared/NavMenu.razor index fbbf68ed..9ef77312 100644 --- a/MP.SPEC/Shared/NavMenu.razor +++ b/MP.SPEC/Shared/NavMenu.razor @@ -15,13 +15,13 @@