Modifica con filtro remnant e + solo se selezionato
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Annulla modifiche su una specifica entity (cancel update)
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<div class="card">
|
||||
<div class="card-header bg-info text-light">
|
||||
<b>Modifica</b>
|
||||
</div>
|
||||
<div class="card-body p-1">
|
||||
<EditForm Model="@_currItem">
|
||||
<DataAnnotationsValidator />
|
||||
<div class="row">
|
||||
<div class="col-12 col-lg-5">
|
||||
@*<ParamSet PlantIdSel="@PlantId" ParamUidSel="@ParamUid"></ParamSet>*@
|
||||
</div>
|
||||
<div class="col-12 col-lg-5 align-items-center">
|
||||
<div class="d-flex">
|
||||
<div class="p-2">
|
||||
<b>@_currItem.MaterialNav.MatExtCode</b>
|
||||
</div>
|
||||
<div class="p-2 text-right">
|
||||
@_currItem.MaterialNav.MatDesc
|
||||
</div>
|
||||
</div>
|
||||
@*<div class="row">
|
||||
<div class="col">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<button @onclick="() => setCalc()" class="btn btn-primary">@CalcVal.ToString("N3") <i class="fas fa-arrow-alt-circle-right"></i></button>
|
||||
</div>
|
||||
<InputNumber @bind-Value="@_currItem.reqValDec" class="form-control text-right"></InputNumber>
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text" title="Valore Richiesto">Act: <b>@_currItem.value</b></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>*@
|
||||
@*<div class="row">
|
||||
<div class="col">
|
||||
<ParamSendEditor PlantIdSel="@PlantId" ParamUidSel="@ParamUid"></ParamSendEditor>
|
||||
</div>
|
||||
</div>*@
|
||||
</div>
|
||||
<div class="col-12 col-lg-2">
|
||||
<button type="button" class="btn btn-warning btn-block" value="Cancel" @onclick="cancelUpdate">Cancel <i class="fas fa-ban"></i></button>
|
||||
<div class="mt-2">
|
||||
<button type="button" class="btn btn-success btn-block" value="Save" @onclick="saveUpdate">Save <i class="far fa-save"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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<int> DataReset { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<int> 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<bool>("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,16 @@ namespace REMAN.Data
|
||||
{
|
||||
public class RDataService : IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
private static ILogger<RDataService> _logger;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
//private readonly IEmailSender _emailSender;
|
||||
//private readonly UserManager<IdentityUser> _userManager;
|
||||
private readonly IDistributedCache distributedCache;
|
||||
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
/// <summary>
|
||||
@@ -29,12 +33,24 @@ namespace REMAN.Data
|
||||
/// </summary>
|
||||
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<RDataService> 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<List<MaterialModel>> MaterialsGetAll()
|
||||
{
|
||||
List<MaterialModel> dbResult = new List<MaterialModel>();
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,41 @@
|
||||
<h2>Remnants</h2>
|
||||
</div>
|
||||
<div class="px-2">
|
||||
filtro sel materiale
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
<span class="fas fa-tree" aria-hidden="true"></span>
|
||||
</span>
|
||||
</div>
|
||||
<select @bind="@SelMatID" class="form-control" title="Material">
|
||||
<option value="0">--- ALL ---</option>
|
||||
@if (MaterialsList != null)
|
||||
{
|
||||
foreach (var item in MaterialsList)
|
||||
{
|
||||
<option value="@item.MatID">@item.MatExtCode | @item.MatDesc</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
@if (SelMatID > 0)
|
||||
{
|
||||
<button class="btn btn-success" @onclick="() => AddNew()"><i class="fas fa-plus-square"></i></button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="btn btn-secondary disabled"><i class="fas fa-plus-square"></i></span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (currRecord != null)
|
||||
{
|
||||
<RemnantEdit currItem="@currRecord" DataReset="ResetData" DataUpdated="UpdateData"></RemnantEdit>
|
||||
}
|
||||
@if (ListRecords == null)
|
||||
{
|
||||
<LoadingData></LoadingData>
|
||||
|
||||
@@ -21,10 +21,12 @@ namespace REMAN.Pages
|
||||
{
|
||||
public partial class Remnants : ComponentBase, IDisposable
|
||||
{
|
||||
private List<MaterialModel> MaterialsList;
|
||||
|
||||
private List<RemnantsModel> SearchRecords;
|
||||
private List<RemnantsModel> 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()
|
||||
|
||||
Reference in New Issue
Block a user