Files
gwms/GWMS.UI/Components/ParamSet.razor.cs
2026-03-13 10:10:54 +01:00

187 lines
4.5 KiB
C#

using GWMS.Data.DatabaseModels;
using GWMS.UI.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using NLog;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GWMS.UI.Components
{
public partial class ParamSet
{
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private ParamSetModel currRecord = null;
private List<ParamSetModel> ListRecords;
#endregion Private Fields
#region Protected Fields
protected string _paramUid = "";
protected int _plantId = 0;
#endregion Protected Fields
#region Private Properties
private bool isLoading { get; set; } = false;
[Inject]
private IJSRuntime JSRuntime { get; set; }
#endregion Private Properties
#region Protected Properties
[Inject]
protected GWMSDataService DataService { get; set; }
protected int totalCount
{
get
{
int answ = 0;
if (ListRecords != null)
{
answ = ListRecords.Count;
}
return answ;
}
}
#endregion Protected Properties
#region Public Properties
[Parameter]
public string ParamUidSel
{
get
{
return _paramUid;
}
set
{
_paramUid = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
[Parameter]
public int PlantIdSel
{
get
{
return _plantId;
}
set
{
_plantId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
#endregion Public Properties
#region Private Methods
/// <summary>
/// Aggiunta nuovo record
/// </summary>
private async void AddNew()
{
// creo un nuovo evento su oggi...
var newRecord = new ParamSetModel()
{
ParamUid = ParamUidSel,
PlantId = PlantIdSel,
Scadenza = DateTime.Today.AddDays(1),
TargetVal = 0,
Note = "Nuovo record"
};
await DataService.ParamSetUpdateAsync(newRecord);
await ReloadData();
}
private async Task ReloadData()
{
isLoading = true;
ListRecords = null;
try
{
ListRecords = await DataService.ParamSetGetFiltAsync(PlantIdSel, ParamUidSel);
}
catch (Exception exc)
{
Log.Error($"Eccezione in ReloadData:{Environment.NewLine}{exc}");
}
isLoading = false;
}
#endregion Private Methods
#region Protected Methods
protected void Edit(ParamSetModel selRecord)
{
currRecord = selRecord;
}
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task RemoveItem(ParamSetModel selRecord)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler rimuovere il parametro progammato {selRecord.ParamUid} in data ({selRecord.Scadenza:yyyy.MM.dd})?"))
return;
if (selRecord != null)
{
await DataService.ParamSetDeleteAsync(selRecord);
}
await ReloadData();
}
protected void ResetData()
{
DataService.rollBackEdit(currRecord);
currRecord = null;
}
protected async Task UpdateData()
{
currRecord = null;
//await DataService.ParamSetUpdateAsync(currRecord);
await ReloadData();
}
#endregion Protected Methods
#region Public Methods
public string checkSelect(int ParamSetId)
{
string answ = "";
if (currRecord != null)
{
try
{
answ = (currRecord.ParamSetId == ParamSetId) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
#endregion Public Methods
}
}