From 5864eb448a2e3effed2b10f1ec6ff41655566b4f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 19 Nov 2021 09:55:41 +0100 Subject: [PATCH] Modifica con filtro remnant e + solo se selezionato --- REMAN/NKC.Data/Controllers/NKCController.cs | 27 +++++- REMAN/REMAN/Components/RemnantEdit.razor | 49 +++++++++++ REMAN/REMAN/Components/RemnantEdit.razor.cs | 93 +++++++++++++++++++++ REMAN/REMAN/Data/RDataService.cs | 54 +++++++++--- REMAN/REMAN/Pages/Remnants.razor | 32 ++++++- REMAN/REMAN/Pages/Remnants.razor.cs | 42 +++++++++- 6 files changed, 282 insertions(+), 15 deletions(-) create mode 100644 REMAN/REMAN/Components/RemnantEdit.razor create mode 100644 REMAN/REMAN/Components/RemnantEdit.razor.cs diff --git a/REMAN/NKC.Data/Controllers/NKCController.cs b/REMAN/NKC.Data/Controllers/NKCController.cs index 5e6d8f5..5b20874 100644 --- a/REMAN/NKC.Data/Controllers/NKCController.cs +++ b/REMAN/NKC.Data/Controllers/NKCController.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using NKC.Data.DbModels; using NLog; using System; @@ -82,5 +83,29 @@ namespace NKC.Data.Controllers return answ; } + /// + /// Annulla modifiche su una specifica entity (cancel update) + /// + /// + /// + public bool rollBackEntity(object item) + { + bool answ = false; + using (NKCContext localDbCtx = new NKCContext(_configuration)) + { + try + { + if (localDbCtx.Entry(item).State == EntityState.Deleted || localDbCtx.Entry(item).State == EntityState.Modified) + { + localDbCtx.Entry(item).Reload(); + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}"); + } + } + return answ; + } } } diff --git a/REMAN/REMAN/Components/RemnantEdit.razor b/REMAN/REMAN/Components/RemnantEdit.razor new file mode 100644 index 0000000..6d2619a --- /dev/null +++ b/REMAN/REMAN/Components/RemnantEdit.razor @@ -0,0 +1,49 @@ +
+
+ Modifica +
+
+ + +
+
+ @**@ +
+
+
+
+ @_currItem.MaterialNav.MatExtCode +
+
+ @_currItem.MaterialNav.MatDesc +
+
+ @*
+
+
+
+ +
+ +
+ Act: @_currItem.value +
+
+
+
*@ + @*
+
+ +
+
*@ +
+
+ +
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/REMAN/REMAN/Components/RemnantEdit.razor.cs b/REMAN/REMAN/Components/RemnantEdit.razor.cs new file mode 100644 index 0000000..63cc0ae --- /dev/null +++ b/REMAN/REMAN/Components/RemnantEdit.razor.cs @@ -0,0 +1,93 @@ +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 NLog; +using NKC.Data.DbModels; +using REMAN.Data; + +namespace REMAN.Components +{ + public partial class RemnantEdit + { + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + protected RemnantsModel _currItem = new RemnantsModel(); + + + [Inject] + protected RDataService DataService { get; set; } + + [Parameter] + public RemnantsModel currItem + { + get + { + return _currItem; + } + set + { + _currItem = value; + } + } + + [Inject] + private IJSRuntime JSRuntime { get; set; } + + [Parameter] + public EventCallback DataReset { get; set; } + + [Parameter] + public EventCallback DataUpdated { get; set; } + + private async Task cancelUpdate() + { + await DataReset.InvokeAsync(0); + } + + private async Task ReloadData() + { + //ListRecords = null; + //try + //{ + // ListRecords = await DataService.ParamSetGetFilt(PlantId, ParamUid); + //} + //catch (Exception exc) + //{ + // Log.Error($"Eccezione in ReloadData:{Environment.NewLine}{exc}"); + //} + } + + private async Task saveUpdate() + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler inviare il valore per parametro richiesto?")) + return; + + if (_currItem != null) + { + //await DataService.updateMachineParameter(IdxMacchina, _currItem.uid, _currItem.reqValue); + await DataUpdated.InvokeAsync(0); + } + else + { + Console.WriteLine("Record null!"); + } + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + } +} \ No newline at end of file diff --git a/REMAN/REMAN/Data/RDataService.cs b/REMAN/REMAN/Data/RDataService.cs index b5b6561..d73d744 100644 --- a/REMAN/REMAN/Data/RDataService.cs +++ b/REMAN/REMAN/Data/RDataService.cs @@ -10,12 +10,16 @@ namespace REMAN.Data { public class RDataService : IDisposable { + #region Private Fields + private static IConfiguration _configuration; private static ILogger _logger; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + //private readonly IEmailSender _emailSender; //private readonly UserManager _userManager; private readonly IDistributedCache distributedCache; + private readonly IMemoryCache memoryCache; /// @@ -29,12 +33,24 @@ namespace REMAN.Data /// private int chSliExp = 60 * 1; + #endregion Private Fields + #region Protected Fields + + protected const string rKeyMaterials = "REMAN:Materials"; + protected const string rKeyRemnants = "REMAN:Remnants"; protected static string connStringBBM = ""; + #endregion Protected Fields + + #region Public Fields public static NKC.Data.Controllers.NKCController dbController; + #endregion Public Fields + + #region Public Constructors + public RDataService(IConfiguration configuration, ILogger logger, IMemoryCache memoryCache, IDistributedCache distributedCache) { _logger = logger; @@ -54,8 +70,27 @@ namespace REMAN.Data } } - protected const string rKeyMaterials = "REMAN:Materials"; - protected const string rKeyRemnants = "REMAN:Remnants"; + #endregion Public Constructors + + #region Private Methods + + private DistributedCacheEntryOptions cacheOpt(bool fastCache) + { + var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10; + var numSecSliExp = fastCache ? chSliExp : chSliExp * 10; + return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); + } + + #endregion Private Methods + + #region Public Methods + + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + } + public async Task> MaterialsGetAll() { List dbResult = new List(); @@ -107,16 +142,11 @@ namespace REMAN.Data return await Task.FromResult(dbResult); } - public void Dispose() + public void rollBackEdit(object item) { - // Clear database controller - dbController.Dispose(); - } - private DistributedCacheEntryOptions cacheOpt(bool fastCache) - { - var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10; - var numSecSliExp = fastCache ? chSliExp : chSliExp * 10; - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); + dbController.rollBackEntity(item); } + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/REMAN/REMAN/Pages/Remnants.razor b/REMAN/REMAN/Pages/Remnants.razor index 78178bf..bce899c 100644 --- a/REMAN/REMAN/Pages/Remnants.razor +++ b/REMAN/REMAN/Pages/Remnants.razor @@ -11,11 +11,41 @@

Remnants

- filtro sel materiale +
+
+ + + +
+ +
+ @if (SelMatID > 0) + { + + } + else + { + + } +
+
+ @if (currRecord != null) + { + + } @if (ListRecords == null) { diff --git a/REMAN/REMAN/Pages/Remnants.razor.cs b/REMAN/REMAN/Pages/Remnants.razor.cs index 0a3d44e..6e4e91f 100644 --- a/REMAN/REMAN/Pages/Remnants.razor.cs +++ b/REMAN/REMAN/Pages/Remnants.razor.cs @@ -21,10 +21,12 @@ namespace REMAN.Pages { public partial class Remnants : ComponentBase, IDisposable { + private List MaterialsList; private List SearchRecords; private List ListRecords; + private RemnantsModel currRecord; private int _currPage { get; set; } = 1; @@ -81,6 +83,7 @@ namespace REMAN.Pages private async Task ReloadData() { isLoading = true; + MaterialsList = await DataService.MaterialsGetAll(); SearchRecords = await DataService.RemnantsGetFilt(0, 0); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; @@ -110,10 +113,47 @@ namespace REMAN.Pages protected void Select(RemnantsModel selRecord) { } + protected void Edit(RemnantsModel selRecord) + { + currRecord = selRecord; + } + + protected void AddNew() + { + // recupero il materiale selezionato + var currMat = MaterialsList + .Where(x => x.MatID == SelMatID) + .FirstOrDefault(); + if (currMat != null) + { + // creo record da materiale... + currRecord = new RemnantsModel() + { + MatID = currMat.MatID, + DtMod = DateTime.Now, + Location = "MAG", + QtyAvail = 0, + LMm = currMat.LMm, + TMm = currMat.TMm, + WMm = currMat.WMm, + Note = "", + MaterialNav=currMat + }; + } + } + + protected int SelMatID = 0; protected void ResetData() { - //DataService.rollBackEdit(currRecord); + DataService.rollBackEdit(currRecord); + currRecord = null; + } + + protected async Task UpdateData() + { + currRecord = null; + await ReloadData(); } public void Dispose()