diff --git a/REMAN/NKC.Data/Controllers/NKCController.cs b/REMAN/NKC.Data/Controllers/NKCController.cs index 9a30725..52835b4 100644 --- a/REMAN/NKC.Data/Controllers/NKCController.cs +++ b/REMAN/NKC.Data/Controllers/NKCController.cs @@ -76,6 +76,22 @@ namespace NKC.Data.Controllers return dbResult; } + public List MovMagGetFilt(int RemnId, int numShow) + { + List dbResult = new List(); + using (NKCContext localDbCtx = new NKCContext(_configuration)) + { + dbResult = localDbCtx + .DbSetMovMag + .Where(x => x.RemnID==RemnId) + .OrderByDescending(o => o.DtRec) + //.Include(m => m.RemnantNav) + .Take(numShow) + .ToList(); + } + return dbResult; + } + public List RemnantsGetAll() { List dbResult = new List(); diff --git a/REMAN/REMAN/Components/CodeReader.razor b/REMAN/REMAN/Components/CodeReader.razor index 0738cd1..37eff9d 100644 --- a/REMAN/REMAN/Components/CodeReader.razor +++ b/REMAN/REMAN/Components/CodeReader.razor @@ -1,16 +1,4 @@ - -@using Microsoft.AspNetCore.Components.Authorization -@using NKC.Data.DbModels -@using REMAN.Components -@using REMAN.Data -@using static JsFunctions - -@inject AuthenticationStateProvider AuthStateProvider -@inject IJSRuntime JSRuntime -@inject RDataService DataService - -@Title - +@Title
@@ -65,138 +53,4 @@
-@code { - [Parameter] - public string Title { get; set; } = "Pick/Deposit"; - - [Parameter] - public bool IsPickup { get; set; } = true; - - private ElementReference CodeInput; - - private bool processing = false; - private string alertMessage = ""; - private string lastMessage = ""; - private MarkupString alertMsg - { - get => (MarkupString)alertMessage; - } - private MarkupString lastMsg - { - get => (MarkupString)lastMessage; - } - - private RemnantsModel currRecord = null; - - private string lastCmd = ""; - - private string inputValue - { - get - { - return ""; - } - set - { - var pUpd = Task.Run(async () => - { - await processInput(value.Trim()); - }); - pUpd.Wait(); - } - } - - protected override async Task OnInitializedAsync() - { - await ReloadData(); - } - - protected async override Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - await SetFocusAsync(); - } - } - - public async Task SetFocusAsync() - { - await CodeInput.FocusAsync(JSRuntime); - } - - protected async Task processInput(string newVal) - { - processing = true; - alertMessage = ""; - lastMessage = ""; - var remnRecord = await DataService.SearchQrRemnant(newVal); - if (remnRecord != null && remnRecord.MatID > 0 && remnRecord.RemDtmx == newVal) - { - currRecord = remnRecord; - lastCmd = newVal; - lastMessage = $"{remnRecord.MaterialNav.MatExtCode} {remnRecord.MaterialNav.MatDesc}
{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.TMm:N3}
"; - } - else - { - alertMessage = $"Error: code {newVal} not valid / not found"; - lastCmd = ""; - } - processing = false; - } - - - - private async Task ReloadData() - { - currRecord = null; - alertMessage = ""; - lastMessage = ""; - lastCmd = ""; - await Task.Delay(1); - } - - protected string currUserId - { - get - { - string userName = ""; - var authState = AuthStateProvider.GetAuthenticationStateAsync().Result; - var user = authState.User; - if (user != null && user.Identity != null) - { - if (user.Identity.IsAuthenticated) - { - userName = $"{user.Identity.Name}"; - } - else - { - userName = "N.A."; - } - } - return userName; - } - } - - protected async Task Reset() - { - await ReloadData(); - await SetFocusAsync(); - } - protected async Task ConfirmOperation() - { - //if (!await JSRuntime.InvokeAsync("confirm", "Confirm operation?")) - // return; - - int qtyMov = IsPickup ? -1 : 1; - await DataService.RemnantsMovMag(currRecord, currUserId, qtyMov); - alertMessage = ""; - lastCmd = ""; - lastMessage = $"

Operation Confirmed!

{qtyMov} x {currRecord.MaterialNav.MatExtCode} {currRecord.MaterialNav.MatDesc}
{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.TMm:N3}
"; - await Task.Delay(1); - StateHasChanged(); - await Task.Delay(3000); - await ReloadData(); - await SetFocusAsync(); - } -} diff --git a/REMAN/REMAN/Components/CodeReader.razor.cs b/REMAN/REMAN/Components/CodeReader.razor.cs new file mode 100644 index 0000000..96552d6 --- /dev/null +++ b/REMAN/REMAN/Components/CodeReader.razor.cs @@ -0,0 +1,180 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.JSInterop; +using NKC.Data.DbModels; +using REMAN.Data; + +namespace REMAN.Components +{ + public partial class CodeReader + { + #region Private Fields + + private string alertMessage = ""; + + private ElementReference CodeInput; + + private RemnantsModel currRecord = null; + + private string lastCmd = ""; + + private string lastMessage = ""; + + private bool processing = false; + + #endregion Private Fields + + #region Private Properties + + private MarkupString alertMsg { get => (MarkupString)alertMessage; } + + [Inject] + private AuthenticationStateProvider AuthStateProvider { get; set; } + + [Inject] + private RDataService DataService { get; set; } + + private string inputValue + { + get + { + return ""; + } + + set + { + var pUpd = Task.Run(async () => + { + await processInput(value.Trim()); + }); + pUpd.Wait(); + } + } + + [Inject] + private IJSRuntime JSRuntime { get; set; } + + private MarkupString lastMsg { get => (MarkupString)lastMessage; } + + #endregion Private Properties + + #region Protected Properties + + protected string currUserId + { + get + { + string userName = ""; + var authState = AuthStateProvider.GetAuthenticationStateAsync().Result; + var user = authState.User; + if (user != null && user.Identity != null) + { + if (user.Identity.IsAuthenticated) + { + userName = $"{user.Identity.Name}"; + } + else + { + userName = "N.A."; + } + } + + return userName; + } + } + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public bool IsPickup { get; set; } = true; + + [Parameter] + public string Title { get; set; } = "Pick/Deposit"; + + #endregion Public Properties + + #region Private Methods + + private async Task ReloadData() + { + currRecord = null; + alertMessage = ""; + lastMessage = ""; + lastCmd = ""; + await Task.Delay(1); + } + + #endregion Private Methods + + #region Protected Methods + + protected async Task ConfirmOperation() + { + //if (!await JSRuntime.InvokeAsync("confirm", "Confirm operation?")) + // return; + int qtyMov = IsPickup ? -1 : 1; + await DataService.RemnantsMovMag(currRecord, currUserId, qtyMov); + alertMessage = ""; + lastCmd = ""; + lastMessage = $"

Operation Confirmed!

{qtyMov} x {currRecord.MaterialNav.MatExtCode} {currRecord.MaterialNav.MatDesc}
{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.TMm:N3}
"; + await Task.Delay(1); + StateHasChanged(); + await Task.Delay(3000); + await ReloadData(); + await SetFocusAsync(); + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await SetFocusAsync(); + } + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + protected async Task processInput(string newVal) + { + processing = true; + alertMessage = ""; + lastMessage = ""; + var remnRecord = await DataService.SearchQrRemnant(newVal); + if (remnRecord != null && remnRecord.MatID > 0 && remnRecord.RemDtmx == newVal) + { + currRecord = remnRecord; + lastCmd = newVal; + lastMessage = $"{remnRecord.MaterialNav.MatExtCode} {remnRecord.MaterialNav.MatDesc}
{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.TMm:N3}
"; + } + else + { + alertMessage = $"Error: code {newVal} not valid / not found"; + lastCmd = ""; + } + + processing = false; + } + + protected async Task Reset() + { + await ReloadData(); + await SetFocusAsync(); + } + + #endregion Protected Methods + + #region Public Methods + + public async Task SetFocusAsync() + { + await CodeInput.FocusAsync(JSRuntime); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/REMAN/REMAN/Components/MovMagDetail.razor b/REMAN/REMAN/Components/MovMagDetail.razor new file mode 100644 index 0000000..6feb07b --- /dev/null +++ b/REMAN/REMAN/Components/MovMagDetail.razor @@ -0,0 +1,65 @@ + +
+
+
+
+
+
+ +
+
+
Movements Log
+
+
+
+
+ last +
+
+
+
+ @if (ListRecords == null) + { + + } + else if (totalCount == 0) + { +
No Record Found
+ } + else + { +
+
+ + + + + + + + + + @foreach (var record in ListRecords) + { + + + + + + } + +
DateQtyOperator
+ @record.DtRec + + @record.QtyRec + + @record.UserId +
+
+
+ } +
+ +
diff --git a/REMAN/REMAN/Components/MovMagDetail.razor.cs b/REMAN/REMAN/Components/MovMagDetail.razor.cs new file mode 100644 index 0000000..dba9764 --- /dev/null +++ b/REMAN/REMAN/Components/MovMagDetail.razor.cs @@ -0,0 +1,140 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using NKC.Data.DbModels; +using REMAN.Data; + +namespace REMAN.Components +{ + public partial class MovMagDetail + { + #region Private Fields + + private List ListRecords; + + private int _maxRec = 100; + private int maxRec + { + get + { + return _maxRec; + } + set + { + _maxRec = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + + 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 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(); + } + } + } + + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected RDataService DataService { get; set; } + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + protected int totalCount + { + get + { + int answ = 0; + if (SearchRecords != null) + { + answ = SearchRecords.Count; + } + return answ; + } + } + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public int RemnID { get; set; } = 0; + + #endregion Public Properties + + #region Private Methods + + private async Task ReloadData() + { + isLoading = true; + SearchRecords = await DataService.MovMagGetFilt(RemnID, maxRec); + ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + isLoading = false; + } + + #endregion Private Methods + + #region Protected Methods + + protected void ForceReload(int newNum) + { + numRecord = newNum; + } + + protected void ForceReloadPage(int newNum) + { + currPage = newNum; + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + [Parameter] + public EventCallback DataReset { get; set; } + + protected async Task Close() + { + await DataReset.InvokeAsync(0); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/REMAN/REMAN/Data/RDataService.cs b/REMAN/REMAN/Data/RDataService.cs index b0d881d..28d381f 100644 --- a/REMAN/REMAN/Data/RDataService.cs +++ b/REMAN/REMAN/Data/RDataService.cs @@ -1,12 +1,10 @@ -using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using Newtonsoft.Json; using NKC.Data.DbModels; using NKC.Data.DTO; using NLog; using System.Diagnostics; -using System.Security.Claims; using System.Text; namespace REMAN.Data @@ -19,7 +17,6 @@ namespace REMAN.Data private static ILogger _logger; private static JsonSerializerSettings? JSSettings; - private List cachedDataList = new List(); private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); //private readonly IEmailSender _emailSender; @@ -27,6 +24,7 @@ namespace REMAN.Data private readonly IDistributedCache distributedCache; private readonly IMemoryCache memoryCache; + private List cachedDataList = new List(); /// /// Durata assoluta massima della cache IN SECONDI @@ -44,8 +42,8 @@ namespace REMAN.Data #region Protected Fields protected const string rKeyMaterials = "Cache:Materials"; - protected const string rKeyRemnants = "Cache:Remnants"; protected const string rKeyQrRemnants = "Cache:QrRemnants"; + protected const string rKeyRemnants = "Cache:Remnants"; protected static string connStringBBM = ""; #endregion Protected Fields @@ -106,6 +104,21 @@ namespace REMAN.Data dbController.Dispose(); } + /// + /// invalida tutta la cache in caso di update + /// + /// + public async Task InvalidateAllCache() + { + await distributedCache.RemoveAsync(rKeyMaterials); + await distributedCache.RemoveAsync(rKeyRemnants); + foreach (var item in cachedDataList) + { + await distributedCache.RemoveAsync(item); + } + cachedDataList = new List(); + } + public async Task> MaterialsGetAll() { List dbResult = new List(); @@ -131,6 +144,18 @@ namespace REMAN.Data return await Task.FromResult(dbResult); } + public async Task> MovMagGetFilt(int RemnId, int numShow) + { + List dbResult = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.MovMagGetFilt(RemnId, numShow); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per MovMagGetFilt: {ts.TotalMilliseconds} ms"); + return await Task.FromResult(dbResult); + } + public async Task> RemnantsGetFilt(int matId, int minQty) { List dbResult = new List(); @@ -162,6 +187,7 @@ namespace REMAN.Data } return await Task.FromResult(dbResult); } + public async Task RemnantsIsDupl(RemnantsModel currItem) { bool answ = false; @@ -173,6 +199,31 @@ namespace REMAN.Data return await Task.FromResult(answ); } + public async Task RemnantsMovMag(RemnantsModel currItem, string userId, int deltaQty) + { + bool done = false; + try + { + // recupero item da DB + var currRecord = dbController.RemnantGetByid(currItem.RemnID); + if (currRecord != null && currRecord.RemnID == currItem.RemnID) + { + // modifico qty entro limiti >=0.. + if (currRecord.QtyAvail + deltaQty >= 0) + { + currRecord.QtyAvail = currRecord.QtyAvail + deltaQty; + done = dbController.RemnantsUpsert(currRecord, userId); + await InvalidateAllCache(); + } + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in RemnantsMovMag:{Environment.NewLine}{exc}"); + } + return await Task.FromResult(done); + } + public async Task RemnantsUpsert(RemnantsModel currItem, string userId) { bool done = false; @@ -187,29 +238,10 @@ namespace REMAN.Data } return await Task.FromResult(done); } - public async Task RemnantsMovMag(RemnantsModel currItem, string userId, int deltaQty) + + public void rollBackEdit(object item) { - bool done = false; - try - { - // recupero item da DB - var currRecord = dbController.RemnantGetByid(currItem.RemnID); - if (currRecord != null && currRecord.RemnID == currItem.RemnID) - { - // modifico qty entro limiti >=0.. - if (currRecord.QtyAvail + deltaQty >= 0) - { - currRecord.QtyAvail = currRecord.QtyAvail+ deltaQty; - done = dbController.RemnantsUpsert(currRecord, userId); - await InvalidateAllCache(); - } - } - } - catch (Exception exc) - { - Log.Error($"Eccezione in RemnantsMovMag:{Environment.NewLine}{exc}"); - } - return await Task.FromResult(done); + dbController.rollBackEntity(item); } public async Task SearchQrRemnant(string QrCode) @@ -217,7 +249,7 @@ namespace REMAN.Data RemnantsModel answ = new RemnantsModel(); string rawData = ""; string cacheKey = $"{rKeyQrRemnants}:{QrCode}"; - // cerco in redis + // cerco in redis var redisData = await distributedCache.GetAsync(cacheKey); if (redisData != null) { @@ -244,27 +276,6 @@ namespace REMAN.Data return await Task.FromResult(answ); } - /// - /// invalida tutta la cache in caso di update - /// - /// - public async Task InvalidateAllCache() - { - await distributedCache.RemoveAsync(rKeyMaterials); - await distributedCache.RemoveAsync(rKeyRemnants); - foreach (var item in cachedDataList) - { - await distributedCache.RemoveAsync(item); - } - cachedDataList = new List(); - } - - - public void rollBackEdit(object item) - { - dbController.rollBackEntity(item); - } - #endregion Public Methods } } \ No newline at end of file diff --git a/REMAN/REMAN/Pages/Materials.razor.cs b/REMAN/REMAN/Pages/Materials.razor.cs index dab339c..475a295 100644 --- a/REMAN/REMAN/Pages/Materials.razor.cs +++ b/REMAN/REMAN/Pages/Materials.razor.cs @@ -1,33 +1,20 @@ -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 REMAN; -using REMAN.Shared; -using REMAN.Components; -using NKC.Data.DbModels; -using REMAN.Data; using NKC.Data.DTO; +using REMAN.Data; namespace REMAN.Pages { public partial class Materials : ComponentBase, IDisposable { + #region Private Fields - private List SearchRecords; private List ListRecords; + private List SearchRecords; - [Inject] - protected MessageService AppMService { get; set; } + #endregion Private Fields + + #region Private Properties private int _currPage { get; set; } = 1; @@ -46,8 +33,24 @@ namespace REMAN.Pages } } } + private bool isLoading { get; set; } = false; + private int MatIdSel + { + get + { + return AppMService.MatIdSel; + } + set + { + AppMService.MatIdSel = value; + } + } + + [Inject] + private NavigationManager NavManager { get; set; } + private int numRecord { get => _numRecord; @@ -62,17 +65,12 @@ namespace REMAN.Pages } } - private int MatIdSel - { - get - { - return AppMService.MatIdSel; - } - set - { - AppMService.MatIdSel = value; - } - } + #endregion Private Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } [Inject] protected RDataService DataService { get; set; } @@ -80,9 +78,6 @@ namespace REMAN.Pages [Inject] protected IJSRuntime JSRuntime { get; set; } - [Inject] - private NavigationManager NavManager { get; set; } - protected int totalCount { get @@ -96,6 +91,10 @@ namespace REMAN.Pages } } + #endregion Protected Properties + + #region Private Methods + private async Task ReloadData() { isLoading = true; @@ -104,6 +103,10 @@ namespace REMAN.Pages isLoading = false; } + #endregion Private Methods + + #region Protected Methods + protected void ForceReload(int newNum) { numRecord = newNum; @@ -125,6 +128,11 @@ namespace REMAN.Pages await ReloadData(); } + protected void ResetData() + { + //DataService.rollBackEdit(currRecord); + } + protected void Select(MaterialDTO selRecord) { MatIdSel = selRecord.MatID; @@ -132,14 +140,15 @@ namespace REMAN.Pages NavManager.NavigateTo($"Remnants"); } - protected void ResetData() - { - //DataService.rollBackEdit(currRecord); - } + #endregion Protected Methods + + #region Public Methods public void Dispose() { //AppMService.EA_SearchUpdated -= OnSeachUpdated; } + + #endregion Public Methods } } \ No newline at end of file diff --git a/REMAN/REMAN/Pages/Remnants.razor b/REMAN/REMAN/Pages/Remnants.razor index dfaa737..03ed03a 100644 --- a/REMAN/REMAN/Pages/Remnants.razor +++ b/REMAN/REMAN/Pages/Remnants.razor @@ -10,7 +10,7 @@

Remnants

-width
+ width
@if (processing) { ...working... @@ -63,7 +63,7 @@ width
else {
-
+
@@ -79,7 +79,7 @@ width
@foreach (var record in ListRecords) { - +
@@ -112,8 +112,8 @@ width
@record.RemDtmx
- @record.MaterialNav.MatExtCode - @record.MaterialNav.MatDesc + @record.MaterialNav.MatExtCode + @record.MaterialNav.MatDesc
@@ -143,6 +143,12 @@ width
+ @if (showDetail) + { +
+ +
+ }
}
diff --git a/REMAN/REMAN/Pages/Remnants.razor.cs b/REMAN/REMAN/Pages/Remnants.razor.cs index 2df051e..3d045e5 100644 --- a/REMAN/REMAN/Pages/Remnants.razor.cs +++ b/REMAN/REMAN/Pages/Remnants.razor.cs @@ -21,7 +21,7 @@ namespace REMAN.Pages #region Protected Fields - //protected int _SelMatID = 0; + protected int RemnIdSel = 0; protected bool processing = false; #endregion Protected Fields @@ -46,6 +46,14 @@ namespace REMAN.Pages } } + private bool showDetail + { + get + { + return RemnIdSel > 0; + } + } + private bool isLoading { get; set; } = false; private int numRecord @@ -203,6 +211,7 @@ namespace REMAN.Pages protected void Clone(RemnantsModel selRecord) { + RemnIdSel = 0; currRecord = new RemnantsModel() { MatID = selRecord.MatID, @@ -219,6 +228,7 @@ namespace REMAN.Pages protected void Edit(RemnantsModel selRecord) { + RemnIdSel = 0; currRecord = selRecord; } @@ -232,6 +242,21 @@ namespace REMAN.Pages currPage = newNum; } + public string checkSelect(int RemnId) + { + string answ = ""; + if (currRecord != null) + { + try + { + answ = (currRecord.RemnID == RemnId) ? "table-info" : ""; + } + catch + { } + } + return answ; + } + protected override async Task OnInitializedAsync() { //SelMatID = 0; @@ -263,16 +288,19 @@ namespace REMAN.Pages { DataService.rollBackEdit(currRecord); currRecord = null; + RemnIdSel = 0; } protected void Select(RemnantsModel selRecord) { - currRecord = selRecord; + //currRecord = selRecord; + RemnIdSel = selRecord.RemnID; } protected async Task UpdateData() { currRecord = null; + RemnIdSel = 0; await ReloadData(); }