diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index 029298b6..9f91a030 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using System.Configuration; using NLog; using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; +using Microsoft.Data.SqlClient; namespace MP.Data.Controllers { @@ -138,18 +140,31 @@ namespace MP.Data.Controllers /// /// Elenco tabella scarti da filtro /// - /// - /// + /// + /// + /// + /// /// - public List StatScartiGetAll(int numRecord, string searchVal = "") + public List StatScartiGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) { List dbResult = new List(); + //dbResult = dbCtx + // .DbSetScarti + // .Where(x => x.KeyRichiesta.Contains(searchVal) || x.Descrizione.Contains(searchVal) || x.CodArticolo.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) + // .OrderByDescending(x => x.DataOraRif) + // .Take(numRecord) + // .ToList(); + + var dataFrom = new SqlParameter("@dataFrom", DataStart); + var dataTo = new SqlParameter("@dataTo", DataEnd); + var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina); + var idxODL = new SqlParameter("@IdxODL", IdxODL); + var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta); + var codArticolo = new SqlParameter("@CodArticolo", CodArticolo); dbResult = dbCtx .DbSetScarti - .Where(x => x.KeyRichiesta.Contains(searchVal) || x.Descrizione.Contains(searchVal) || x.CodArticolo.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) - .OrderByDescending(x => x.DataOraRif) - .Take(numRecord) + .FromSqlRaw("EXEC stp_UI_RS_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo) .ToList(); return dbResult; diff --git a/MP.Stats/Components/InputDateTime.cs b/MP.Stats/Components/InputDateTime.cs new file mode 100644 index 00000000..2aa787fd --- /dev/null +++ b/MP.Stats/Components/InputDateTime.cs @@ -0,0 +1,119 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Rendering; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Stats.Components +{ + public class InputDateTime : InputDate + { + #region Private Fields + + private const string DateFormat = "yyyy-MM-ddTHH:mm"; + + #endregion Private Fields + + #region Private Methods + + private static bool TryParseDateTime(string value, out TValue result) + { + var success = BindConverter.TryConvertToDateTime(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue); + if (success) + { + result = (TValue)(object)parsedValue; + return true; + } + else + { + result = default; + return false; + } + } + + private static bool TryParseDateTimeOffset(string value, out TValue result) + { + var success = BindConverter.TryConvertToDateTimeOffset(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue); + if (success) + { + result = (TValue)(object)parsedValue; + return true; + } + else + { + result = default; + return false; + } + } + + #endregion Private Methods + + #region Protected Methods + + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "input"); + builder.AddMultipleAttributes(1, AdditionalAttributes); + builder.AddAttribute(2, "type", "datetime-local"); + builder.AddAttribute(3, "class", CssClass); + builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString)); + builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.CloseElement(); + } + + /// + protected override string FormatValueAsString(TValue value) + { + switch (value) + { + case DateTime dateTimeValue: + return BindConverter.FormatValue(dateTimeValue, DateFormat, CultureInfo.InvariantCulture); + + case DateTimeOffset dateTimeOffsetValue: + return BindConverter.FormatValue(dateTimeOffsetValue, DateFormat, CultureInfo.InvariantCulture); + + default: + return string.Empty; // Handles null for Nullable, etc. + } + } + + /// + protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) + { + // Unwrap nullable types. We don't have to deal with receiving empty values for nullable + // types here, because the underlying InputBase already covers that. + var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue); + + bool success; + if (targetType == typeof(DateTime)) + { + success = TryParseDateTime(value, out result); + } + else if (targetType == typeof(DateTimeOffset)) + { + success = TryParseDateTimeOffset(value, out result); + } + else + { + throw new InvalidOperationException($"The type '{targetType}' is not a supported date type."); + } + + if (success) + { + validationErrorMessage = null; + return true; + } + else + { + validationErrorMessage = string.Format(ParsingErrorMessage, FieldIdentifier.FieldName); + return false; + } + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Components/SelectionFilter.razor b/MP.Stats/Components/SelectionFilter.razor new file mode 100644 index 00000000..8d277f2b --- /dev/null +++ b/MP.Stats/Components/SelectionFilter.razor @@ -0,0 +1,35 @@ + +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+ + +
+
+
+
\ No newline at end of file diff --git a/MP.Stats/Components/SelectionFilter.razor.cs b/MP.Stats/Components/SelectionFilter.razor.cs new file mode 100644 index 00000000..b9b00a3e --- /dev/null +++ b/MP.Stats/Components/SelectionFilter.razor.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using MP.Stats.Components; +using MP.Stats.Data; + +namespace MP.Stats.Components +{ + public partial class SelectionFilter + { + #region Protected Properties + + protected string CodArticolo + { + get + { + return SelFilter.CodArticolo; + } + set + { + bool doReport = (!SelFilter.CodArticolo.Equals(value)); + SelFilter.CodArticolo = value; + if (doReport) + { + reportChange(); + } + } + } + + protected DateTime DateEnd + { + get + { + return SelFilter.DateEnd; + } + set + { + bool doReport = (!SelFilter.DateEnd.Equals(value)); + SelFilter.DateEnd = value; + if (doReport) + { + reportChange(); + } + } + } + + protected DateTime DateStart + { + get + { + return SelFilter.DateStart; + } + set + { + bool doReport = (!SelFilter.DateStart.Equals(value)); + SelFilter.DateStart = value; + if (doReport) + { + reportChange(); + } + } + } + + protected string IdxMacchina + { + get + { + return SelFilter.IdxMacchina; + } + set + { + bool doReport = (!SelFilter.IdxMacchina.Equals(value)); + SelFilter.IdxMacchina = value; + if (doReport) + { + reportChange(); + } + } + } + + protected string KeyRichiesta + { + get + { + return SelFilter.KeyRichiesta; + } + set + { + bool doReport = (!SelFilter.KeyRichiesta.Equals(value)); + SelFilter.KeyRichiesta = value; + if (doReport) + { + reportChange(); + } + } + } + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public EventCallback filterChanged { get; set; } + + [Parameter] + public SelectData SelFilter { get; set; } + + #endregion Public Properties + + #region Private Methods + + private void reportChange() + { + filterChanged.InvokeAsync(SelFilter); + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Data/MpStatsService.cs b/MP.Stats/Data/MpStatsService.cs index 8bc879e9..619b6e5e 100644 --- a/MP.Stats/Data/MpStatsService.cs +++ b/MP.Stats/Data/MpStatsService.cs @@ -84,9 +84,10 @@ namespace MP.Stats.Data return Task.FromResult(dbController.StatOdlGetAll(numRecord, searchVal).ToArray()); } - public Task StatScartiGetAll(int numRecord, string searchVal = "") + public Task StatScartiGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, int numRecord, string searchVal = "") { - return Task.FromResult(dbController.StatScartiGetAll(numRecord, searchVal).ToArray()); + // filtra e restituisce SOLO i primi record... + return Task.FromResult(dbController.StatScartiGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).Take(numRecord).ToArray()); } public Task StatUserLogGetAll(int numRecord, string searchVal = "") diff --git a/MP.Stats/Data/SelectData.cs b/MP.Stats/Data/SelectData.cs new file mode 100644 index 00000000..05be9c99 --- /dev/null +++ b/MP.Stats/Data/SelectData.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Stats.Data +{ + public class SelectData + { + #region Public Properties + + public string CodArticolo { get; set; } = "*"; + public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1); + public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7); + public string IdxMacchina { get; set; } = "*"; + public int IdxOdl { get; set; } = -999; + public string KeyRichiesta { get; set; } = "*"; + + #endregion Public Properties + + #region Public Methods + + public override bool Equals(object obj) + { + if (!(obj is SelectData item)) + return false; + + if (CodArticolo != item.CodArticolo) + return false; + if (DateEnd != item.DateEnd) + return false; + if (DateStart != item.DateStart) + return false; + if (IdxMacchina != item.IdxMacchina) + return false; + if (IdxOdl != item.IdxOdl) + return false; + if (KeyRichiesta != item.KeyRichiesta) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 455c5433..794cdd30 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -25,10 +25,6 @@ - - - - diff --git a/MP.Stats/Pages/Index.razor b/MP.Stats/Pages/Index.razor index f87d3dda..3e38a5bf 100644 --- a/MP.Stats/Pages/Index.razor +++ b/MP.Stats/Pages/Index.razor @@ -26,9 +26,9 @@
Main Topics
- - - + + + @**@ diff --git a/MP.Stats/Pages/ReportODL.razor.cs b/MP.Stats/Pages/ReportODL.razor.cs index f77a086f..c7aade73 100644 --- a/MP.Stats/Pages/ReportODL.razor.cs +++ b/MP.Stats/Pages/ReportODL.razor.cs @@ -77,7 +77,7 @@ namespace MP.Stats.Pages { try { - answ = (currRecord.IdxODL == IdxODL) ? "table-info" : ""; + answ = (currRecord.IdxOdl == IdxODL) ? "table-info" : ""; } catch { } diff --git a/MP.Stats/Pages/Scarti.razor b/MP.Stats/Pages/Scarti.razor index eca78837..d493a385 100644 --- a/MP.Stats/Pages/Scarti.razor +++ b/MP.Stats/Pages/Scarti.razor @@ -4,7 +4,14 @@ @using MP.Stats.Data
-
Scarti
+
+
+
Scarti
+
+ +
+
+
@if (currRecord != null) { diff --git a/MP.Stats/Pages/Scarti.razor.cs b/MP.Stats/Pages/Scarti.razor.cs index a9f103a7..769fc8cb 100644 --- a/MP.Stats/Pages/Scarti.razor.cs +++ b/MP.Stats/Pages/Scarti.razor.cs @@ -18,6 +18,7 @@ namespace MP.Stats.Pages #region Private Properties + private SelectData currFilter { get; set; } private int numRecord { get; set; } = 10; #endregion Private Properties @@ -38,20 +39,36 @@ namespace MP.Stats.Pages #endregion Protected Properties + #region Private Methods + + private async Task reloadData() + { + ListRecords = await StatService.StatScartiGetAll(currFilter.DateStart, currFilter.DateEnd, currFilter.IdxMacchina, currFilter.IdxOdl, currFilter.KeyRichiesta, currFilter.CodArticolo, numRecord, MessageService.SearchVal); + } + + #endregion Private Methods + #region Protected Methods + protected async Task DoFilter(SelectData newFilter) + { + currFilter = newFilter; + await reloadData(); + } + protected async Task ForceReload(int newNum) { numRecord = newNum; - ListRecords = await StatService.StatScartiGetAll(numRecord, MessageService.SearchVal); + await reloadData(); } protected override async Task OnInitializedAsync() { numRecord = 10; + currFilter = new SelectData(); MessageService.ShowSearch = true; MessageService.EA_SearchUpdated += OnSeachUpdated; - ListRecords = await StatService.StatScartiGetAll(numRecord, MessageService.SearchVal); + await reloadData(); } protected void ResetData() @@ -63,7 +80,7 @@ namespace MP.Stats.Pages protected async Task UpdateData() { currRecord = null; - ListRecords = await StatService.StatScartiGetAll(numRecord, MessageService.SearchVal); + await reloadData(); } #endregion Protected Methods diff --git a/MP.Stats/Shared/NavMenu.razor b/MP.Stats/Shared/NavMenu.razor index 5b846d8b..71e774ac 100644 --- a/MP.Stats/Shared/NavMenu.razor +++ b/MP.Stats/Shared/NavMenu.razor @@ -14,12 +14,12 @@