using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using GWMS.UI.Components; using GWMS.UI.Data; using GWMS.Data.DatabaseModels; using GWMS.Data.DTO; namespace GWMS.UI.Components { public partial class OrderLoad : ComponentBase { #region Private Fields private PlantDTO currPlantData = null; private List plantsData = new List(); #endregion Private Fields #region Protected Fields protected OrderModel _currItem = new OrderModel(); #endregion Protected Fields #region Protected Properties [Inject] protected GWMSDataService DataService { get; set; } /// /// verifica correttezza plant/ordine /// 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 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 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 Private Methods private async Task ReloadData() { plantsData = await DataService.PlantDtoGetAll(); // 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.OrderGetByCode(OrderCode); } else { currItem = null; } } #endregion Private Methods #region Protected Methods protected async Task 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.OrderUpdate(_currItem); // segnalo completato await loadCompleted.InvokeAsync(true); } protected async Task 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.OrderUpdate(_currItem); } #endregion Protected Methods } }