Files
gwms/GWMS.UI/Components/OrderLoad.razor.cs
Samuele Locatelli 4fda312aac Avanzamento telemetria:
- altri metodi tracciati
- modifica json x prod
- aggiunta Async vari
2026-03-03 18:57:46 +01:00

224 lines
6.3 KiB
C#

using GWMS.Data.DatabaseModels;
using GWMS.Data.DTO;
using GWMS.UI.Data;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace GWMS.UI.Components
{
public partial class OrderLoad
{
#region Public Properties
public string _orderCode { get; set; } = "";
public int _plantId { get; set; } = 0;
[Parameter]
public OrderModel currItem
{
get
{
return _currItem;
}
set
{
_currItem = value;
}
}
[Parameter]
public EventCallback<bool> loadCompleted { get; set; }
[Parameter]
public string OrderCode
{
get
{
return _orderCode;
}
set
{
_orderCode = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
[Parameter]
public int PlantId
{
get
{
return _plantId;
}
set
{
_plantId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
#endregion Public Properties
#region Protected Fields
protected OrderModel _currItem = new OrderModel();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected GWMSDataService DataService { get; set; }
[Inject]
protected MessageService MServ { get; set; } = null;
/// <summary>
/// verifica correttezza plant/ordine
/// </summary>
protected bool plantCorrect
{
get
{
bool answ = !string.IsNullOrEmpty(_orderCode);
try
{
if (answ)
{
answ = _orderCode.StartsWith($"O{currPlantData.PlantCode}");
}
}
catch
{
answ = false;
}
return answ;
}
}
protected bool showEnd
{
get
{
bool answ = (PlantId > 0);
if (answ)
{
if (_currItem != null)
{
DateTime oggi = DateTime.Today;
answ = _currItem.DtExecStart.Year > 1 && _currItem.DtExecEnd.Year <= 1;
// se visibile --> calcolo valore execution!
if (answ && _currItem.ExecutionQty < 1)
{
_currItem.ExecutionQty = Math.Ceiling((currPlantData.LevelAct - _currItem.LevelStart) / 100) * 100;
}
}
}
return answ;
}
}
protected bool showStart
{
get
{
bool answ = (PlantId > 0);
if (answ)
{
if (_currItem != null)
{
answ = _currItem.DtExecStart.Year <= 1;
}
}
return answ;
}
}
#endregion Protected Properties
#region Protected Methods
protected async Task RefillEnd()
{
using var activity = StartTracing("RefillEnd");
//using var activity = UIActivitySource.StartActivity("RefillEnd");
if (currPlantData != null)
{
// aggiorno il record corrente con livello e dataora inizio carico...
_currItem.LevelEnd = currPlantData.LevelAct;
_currItem.DtExecEnd = DateTime.Now;
}
// salvo...
await DataService.OrderUpdateAsync(_currItem);
// telemetria!
activity?.SetStatus(ActivityStatusCode.Ok);
activity?.SetTag("order.code", _currItem.OrderCode);
activity?.SetTag("order.operator", MServ.UserName);
activity?.SetTag("order.level_start", _currItem.LevelStart);
activity?.SetTag("order.level_end", _currItem.LevelEnd);
activity?.SetTag("plant.level_act", currPlantData.LevelAct);
// segnalo completato
await loadCompleted.InvokeAsync(true);
}
protected async Task RefillStart()
{
//using var activity = ActivitySource.StartActivity("RefillEnd");
using var activity = StartTracing("RefillStart");
if (currPlantData != null)
{
// aggiorno il record corrente con livello e dataora inizio carico...
_currItem.LevelStart = currPlantData.LevelAct;
_currItem.DtExecStart = DateTime.Now;
}
// salvo...
await DataService.OrderUpdateAsync(_currItem);
// telemetria!
activity?.SetStatus(ActivityStatusCode.Ok);
activity?.SetTag("order.code", _currItem.OrderCode);
activity?.SetTag("order.operator", MServ.UserName);
activity?.SetTag("order.level_start", _currItem.LevelStart);
activity?.SetTag("plant.level_act", currPlantData.LevelAct);
}
#endregion Protected Methods
#region Private Fields
private PlantDTO currPlantData = null;
private List<PlantDTO> plantsData = new List<PlantDTO>();
#endregion Private Fields
#region Private Methods
private async Task ReloadData()
{
plantsData = await DataService.PlantDtoGetAllAsync();
// recupero dato del plant corrente
currPlantData = plantsData.Where(x => x.PlantId == PlantId).FirstOrDefault();
// solo se ho valore QR selezionato
if (!string.IsNullOrEmpty(OrderCode))
{
currItem = await DataService.OrderGetByCodeAsync(OrderCode);
}
else
{
currItem = null;
}
}
#endregion Private Methods
}
}