Files
lux/Lux.UI/Components/Compo/WorkLoad/TimeEstim.razor.cs
T
2026-06-29 12:30:05 +02:00

372 lines
11 KiB
C#

using EgwCoreLib.Lux.Core.Generic;
using EgwCoreLib.Razor;
namespace Lux.UI.Components.Compo.WorkLoad
{
public partial class TimeEstim
{
#region Public Properties
[Parameter]
public List<ProductionGroupModel>? AllProdGroup { get; set; }
[Parameter]
public WorkLoadDetailDTO DetailRecord { get; set; } = null!;
[Parameter]
public EventCallback<bool> EC_ClosePopup { get; set; }
[Parameter]
public EventCallback<DirectAssignReqDto> EC_DirectAssign { get; set; }
[Parameter]
public EventCallback<bool> EC_ReRunReq { get; set; }
[Parameter]
public EventCallback<int> EC_ResetAssign { get; set; }
[Parameter]
public EventCallback<BalanceReqDto> EC_RunBalance { get; set; }
[Parameter]
public OrderRowModel OrderRowRecord { get; set; } = null!;
#endregion Public Properties
#region Public Enums
public enum SetMode
{
/// <summary>
/// Modalit non definita
/// </summary>
None = 0,
/// <summary>
/// Modalit preparazione richiesta balance
/// </summary>
Balance,
/// <summary>
/// Assegnazione diretta pezzi OK
/// </summary>
AssignOk,
/// <summary>
/// Assegnazione pezzi non lavorabili
/// </summary>
AssignUnwork
}
#endregion Public Enums
#region Protected Methods
protected override Task OnParametersSetAsync()
{
return ReloadDataAsync();
}
#endregion Protected Methods
#region Private Fields
private List<string> BalancePlantList = new();
private BalanceReqDto cBalanceReq = new();
/// <summary>
/// Gestione modalit assegnazione Parts a macchine
/// </summary>
private SetMode CurrMode = SetMode.None;
private string mMessage = "";
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
private BootstrapModal Modal = new();
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
private string mTitle = "";
private string selUid = "";
#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<string, double> DictPercReq
{
get => cBalanceReq.MachineBalance;
set => cBalanceReq.MachineBalance = value;
}
[Inject]
private IDataLayerServices DLService { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
private List<ProductionGroupModel> GroupOkList
{
get
{
List<ProductionGroupModel> ans = new();
if (AllProdGroup != null && AllProdGroup.Count > 0)
{
ans = AllProdGroup.Where(x => x.NumParts == DetailRecord.NumOk).ToList() ?? new();
}
return ans;
}
}
private List<ProductionGroupModel> GroupOkVincList
{
get
{
List<ProductionGroupModel> ans = new();
if (AllProdGroup != null && AllProdGroup.Count > 0)
{
ans = AllProdGroup.Where(x => x.NumParts == DetailRecord.NumOkVin).ToList() ?? new();
}
return ans;
}
}
private List<ProductionGroupModel> GroupKoList
{
get
{
List<ProductionGroupModel> ans = new();
if (AllProdGroup != null && AllProdGroup.Count > 0)
{
ans = AllProdGroup.Where(x => x.NumParts == DetailRecord.NumKo).ToList() ?? new();
}
return ans;
}
}
private string TitleTableCss
{
get
{
string ans = "";
if (GroupOkList != null && GroupOkList.Count > 0 && (GroupOkList.Count > 1 || GroupOkList.FirstOrDefault()?.WorkGroupList.Count() > 1))
ans = "text-secondary";
return ans;
}
}
#endregion Private Properties
#region Private Methods
private Task ClosePopup()
{
return EC_ClosePopup.InvokeAsync(true);
}
//private Task DirectAssign()
//{
// return Task.Delay(200);
//}
private string DisplayDurata(decimal TotalEstimTime)
{
string ans = "";
int ore = (int)TotalEstimTime / 3600;
int min = (int)(TotalEstimTime % 3600) / 60;
int sec = (int)TotalEstimTime % 60;
// Tempo in formato HH:MM:SS
ans = $"{ore:D2}:{min:D2}:{sec:D2}";
if (AllProdGroup != null && AllProdGroup.Count > 1)
ans = ans + " / " + ($"{TotMaxTimeRatio(TotalEstimTime):P1}");
return ans;
}
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<bool>())
return;
await EC_ResetAssign.InvokeAsync(OrderRowRecord.OrderRowID);
}
private double NumPartRatio(int numPart)
{
return DetailRecord.NumParts > 0 ? (double)numPart / DetailRecord.NumParts : 0.0;
}
private string NumParts(ProductionGroupModel prodGroup)
{
string ans = prodGroup.NumParts.ToString();
if (AllProdGroup != null && AllProdGroup.Count > 1)
ans = ans + " / " + ($"{NumPartRatio(prodGroup.NumParts):P1}");
return ans;
}
private void PrepareSendReq()
{
DictPercReq.Clear();
#if false
var cList = AllProdGroup;
#endif
var cList = BalancePlantList;
double stdPerc = 1.0;
if (cList != null && cList.Count > 1)
{
stdPerc = 1.0 / (cList.Count);
}
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, x => x != "EXT" ? stdPerc : 0.0);
break;
case SetMode.AssignOk:
DictPercReq = cList.ToDictionary(x => x, x => stdPerc);
break;
//case SetMode.AssignUnwork:
// DictPercReq = cList.ToDictionary(x => x.ProdPlantCod, x => x.ProdPlantCod == "EXT" ? 1.0 : 0.0);
// break;
default:
break;
}
}
}
/// <summary>
/// Rilettura dati da DB associazioni
/// </summary>
/// <returns></returns>
private Task ReloadDataAsync()
{
return Task.Delay(500);
}
private Task ReqBalance(BalanceReqDto currReq)
{
cBalanceReq = currReq;
return EC_RunBalance.InvokeAsync(cBalanceReq);
}
private Task ReRunJob()
{
return EC_ReRunReq.InvokeAsync(true);
}
/// <summary>
/// Assegnazione item unworkable a EXT
/// </summary>
/// <returns></returns>
private 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<bool>())
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;
}
}
private void AssignUnwork(List<ProductionGroupModel> currGroupList, SetMode reqMode)
{
// se era gia attivo --> chiude... altrimenti assegna!
CurrMode = CurrMode == reqMode ? SetMode.None : reqMode;
// ora imposto secondo modo...
if (CurrMode == reqMode && CurrMode != SetMode.None)
{
foreach (var currGroup in currGroupList)
{
cBalanceReq.TagList = currGroup.WorkGroupList.Values.FirstOrDefault()?.TagList ?? new();
BalancePlantList = currGroup.PlantList;
PrepareSendReq();
}
}
}
private void ToggleAssignMode(List<ProductionGroupModel> currGroupList, SetMode reqMode)
{
// se era gia attivo --> chiude... altrimenti assegna!
CurrMode = CurrMode == reqMode ? SetMode.None : reqMode;
// ora imposto secondo modo...
//if (CurrMode == reqMode && CurrMode != SetMode.None)
//{
// foreach (var currGroup in currGroupList)
// {
// cBalanceReq.TagList = currGroup.WorkGroupList.Values.FirstOrDefault()?.TagList ?? new();
// BalancePlantList = currGroup.PlantList;
// PrepareSendReq();
// }
//}
}
private void ToggleAssignMode(ProductionGroupModel currGroup, SetMode reqMode)
{
// se era gia attivo --> chiude... altrimenti assegna!
CurrMode = CurrMode == reqMode ? SetMode.None : reqMode;
// ora imposto secondo modo...
//if (CurrMode == reqMode)
//{
// cBalanceReq.TagList = currGroup.WorkGroupList.Values.FirstOrDefault()?.TagList ?? new();
// BalancePlantList = currGroup.PlantList;
// PrepareSendReq();
//}
}
private decimal TotMaxTimeRatio(decimal currTime)
{
return DetailRecord.TotMaxTime > 0 ? currTime / DetailRecord.TotMaxTime : (decimal)0.0;
}
#endregion Private Methods
}
}