190 lines
5.0 KiB
C#
190 lines
5.0 KiB
C#
using GWMS.Data.DatabaseModels;
|
|
using GWMS.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.JSInterop;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using static GWMS.Data.IobObjects;
|
|
|
|
namespace GWMS.UI.Components
|
|
{
|
|
public partial class ParamEditor
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public objItem currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem;
|
|
}
|
|
set
|
|
{
|
|
_currItem = value;
|
|
ParamUid = _currItem.uid;
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> DataUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public string IdxMacchina { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public int PlantId
|
|
{
|
|
get
|
|
{
|
|
return _plantId;
|
|
}
|
|
set
|
|
{
|
|
_plantId = value;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IConfiguration _configuration { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
// fix arrotondamento
|
|
roundFactor = _configuration.GetValue<int>("RuntimeOpt:RoundFact", 10);
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task ReloadData()
|
|
{
|
|
ListRecords = null;
|
|
try
|
|
{
|
|
ListRecords = await DataService.ParamSetGetFiltAsync(PlantId, ParamUid);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in ReloadData:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private objItem _currItem = new objItem();
|
|
|
|
private int _plantId = 0;
|
|
|
|
private List<ParamSetModel> ListRecords;
|
|
|
|
private string ParamUid = "";
|
|
|
|
/// <summary>
|
|
/// fattore arrotondamento valori calcolati
|
|
/// </summary>
|
|
private int roundFactor = 100;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private decimal CalcVal
|
|
{
|
|
get
|
|
{
|
|
decimal answ = currItem.reqValDec;
|
|
if (totalCount > 0)
|
|
{
|
|
// prendo i 2 valori precedente e successivo
|
|
DateTime oggi = DateTime.Today;
|
|
var prevPar = ListRecords.Where(x => x.Scadenza <= oggi).OrderByDescending(x => x.Scadenza).FirstOrDefault();
|
|
var nextPar = ListRecords.Where(x => x.Scadenza >= oggi).OrderBy(x => x.Scadenza).FirstOrDefault();
|
|
// se ho valori
|
|
if (prevPar != null && nextPar != null)
|
|
{
|
|
double num = oggi.Subtract(prevPar.Scadenza).TotalDays;
|
|
double den = nextPar.Scadenza.Subtract(prevPar.Scadenza).TotalDays;
|
|
den = den != 0 ? den : 1;
|
|
answ = prevPar.TargetVal + (nextPar.TargetVal - prevPar.TargetVal) * (decimal)(num / den);
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
private GWMSDataService DataService { get; set; }
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; }
|
|
|
|
private int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (ListRecords != null)
|
|
{
|
|
answ = ListRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task cancelUpdate()
|
|
{
|
|
await DataReset.InvokeAsync(0);
|
|
}
|
|
|
|
private async Task ChildUpdated()
|
|
{
|
|
//await EC_DataReset.InvokeAsync(0);
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
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.UpdateMachineParameterAsync(IdxMacchina, _currItem.uid, _currItem.reqValue);
|
|
await DataUpdated.InvokeAsync(0);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Record null!");
|
|
}
|
|
}
|
|
|
|
private void setCalc()
|
|
{
|
|
currItem.reqValDec = Math.Round(CalcVal * roundFactor) / roundFactor;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |