using EgwCoreLib.Lux.Core.Generic; using EgwCoreLib.Razor; namespace Lux.UI.Components.Compo.WorkLoad { public partial class TimeEstim { #region Public Properties [Parameter] public List? AllProdGroup { get; set; } [Parameter] public WorkLoadDetailDTO DetailRecord { get; set; } = null!; [Parameter] public EventCallback EC_ClosePopup { get; set; } [Parameter] public EventCallback EC_DirectAssign { get; set; } [Parameter] public EventCallback EC_ReRunReq { get; set; } [Parameter] public EventCallback EC_ResetAssign { get; set; } [Parameter] public EventCallback EC_RunBalance { get; set; } [Parameter] public OrderRowModel OrderRowRecord { get; set; } = null!; #endregion Public Properties #region Protected Enums protected enum SetMode { /// /// Modalità non definita /// None = 0, /// /// Modalità preparazione richiesta balance /// Balance, /// /// Assegnazione diretta pezzi OK /// AssignOk, /// /// Assegnazione pezzi non lavorabili /// AssignUnwork } #endregion Protected Enums #region Protected Properties [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected override Task OnParametersSetAsync() { return ReloadDataAsync(); } /// /// Rilettura dati da DB associazioni /// /// protected Task ReloadDataAsync() { return Task.Delay(500); } protected Task ReqBalance() { return EC_RunBalance.InvokeAsync(cBalanceReq); } protected Task ReRunJob() { return EC_ReRunReq.InvokeAsync(true); } /// /// Assegnazione item unworkable a EXT /// /// protected async Task SendUnworkExt(int ProdAssignId) { mTitle = "Attenzione"; mMessage = $"Confermi assegnazione Ext/Manual per {DetailRecord.NumKo} articoli?"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; if (OrderRowRecord.OrderRowID > 0 && ProdAssignId > 0) { // recupero elenco e converto in Dict var dictPartUnwokr = DetailRecord .ListUnWorkable .ToDictionary(x => x, x => 0.0); DirectAssignReqDto assignReq = new DirectAssignReqDto() { OrderRowID = OrderRowRecord.OrderRowID, ProdAssignID = ProdAssignId, DictPartAssign = dictPartUnwokr }; await EC_DirectAssign.InvokeAsync(assignReq); CurrMode = SetMode.None; } } protected void ToggleAssignMode(List listTag, SetMode reqMode) { // se era già attivo --> chiude... altrimenti assegna! CurrMode = CurrMode == reqMode ? SetMode.None : reqMode; // ora imposto secondo modo... if (CurrMode == reqMode) { cBalanceReq.TagList = listTag; PrepareSendReq(); } } #endregion Protected Methods #region Private Fields private BalanceReqDto cBalanceReq = new BalanceReqDto(); /// /// Gestione modalità assegnazione Parts a macchine /// private SetMode CurrMode = SetMode.None; private string selUid = ""; private BootstrapModal Modal = new(); private string mTitle = ""; private string mMessage = ""; private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND; private Dictionary modalOpt = new Dictionary(); #endregion Private Fields #region Private Properties private int BarLenght { get => cBalanceReq.BarLenght; set => cBalanceReq.BarLenght = value; } private bool checkSend { get => DictPercReq != null && DictPercReq.Count > 0 && DictPercReq.Sum(x => x.Value) == 1; } private Dictionary DictPercReq { get => cBalanceReq.MachineBalance; set => cBalanceReq.MachineBalance = value; } [Inject] private IDataLayerServices DLService { get; set; } = null!; private string MainCss { get => string.IsNullOrEmpty(selUid) ? "col-12" : "col-6"; } #endregion Private Properties #region Private Methods private Task ClosePopup() { return EC_ClosePopup.InvokeAsync(true); } private Task DirectAssign() { return Task.Delay(200); } private async Task ForceResetAssign() { mTitle = "Attenzione"; mMessage = "Confermi di vole resettare tutte le assegnazioni per gli articoli?"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; await EC_ResetAssign.InvokeAsync(OrderRowRecord.OrderRowID); } private double NumPartRatio(int numPart) { return DetailRecord.NumParts > 0 ? (double)numPart / DetailRecord.NumParts : 0.0; } private void PrepareSendReq() { DictPercReq.Clear(); var cList = AllProdGroup; double stdPerc = 1.0; if (cList != null && cList.Count > 1) { stdPerc = 1.0 / (cList.Count - 1); } // da rivedere #if false //if (cList != null) //{ // // valutare se determinare EXT/manuale in modo diverso da ProdPlantModel // switch (CurrMode) // { // case SetMode.None: // break; // case SetMode.Balance: // DictPercReq = cList.ToDictionary(x => x.ProdPlantCod, x => x.ProdPlantCod != "EXT" ? stdPerc : 0.0); // break; // case SetMode.AssignOk: // DictPercReq = cList.ToDictionary(x => x.ProdPlantCod, x => 0.0); // break; // case SetMode.AssignUnwork: // DictPercReq = cList.ToDictionary(x => x.ProdPlantCod, x => x.ProdPlantCod == "EXT" ? 1.0 : 0.0); // break; // default: // break; // } //} #endif } private decimal TotMaxTimeRatio(decimal currTime) { return DetailRecord.TotMaxTime > 0 ? currTime / DetailRecord.TotMaxTime : (decimal)0.0; } #endregion Private Methods } }