Files
lux/Lux.UI/Components/Compo/WorkLoad/RawPartSelector.razor.cs
Samuele Locatelli 4d58189581 Async/Await fix vari
2026-03-25 16:13:40 +01:00

209 lines
6.1 KiB
C#

using EgwCoreLib.Lux.Core.Generic;
namespace Lux.UI.Components.Compo.WorkLoad
{
public partial class RawPartSelector
{
#region Public Properties
[Parameter]
public List<BomItemDTO> BomListAll { get; set; } = null!;
#if false
protected List<BomItemDTO>? ListRecords = null;
#endif
[Parameter]
public Dictionary<string, List<ItemRawDTO>> ItemAvailDict { get; set; } = null!;
[Parameter]
public EventCallback<Dictionary<string, List<ItemRawDTO>>> EC_ReqCalcProd { get; set; }
[Parameter]
public EventCallback<bool> EC_ReqClose { get; set; }
[Parameter]
public List<GenValueModel> DefaultValSet { get; set; } = null!;
#endregion Public Properties
#region Protected Fields
protected List<ItemGroupModel> ListItemGroup = new List<ItemGroupModel>();
protected Dictionary<string, List<ItemRawDTO>>? ListRecords = null;
#endregion Protected Fields
#region Protected Properties
protected ItemSel.FiltSelect CurrFilt { get; set; } = new ItemSel.FiltSelect();
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Selezione record x inserimento tipo RawMat da impiegare
/// </summary>
/// <param name="selRec"></param>
private void DoSelect(KeyValuePair<string, List<ItemRawDTO>> selEntry)
{
CurrFilt = new ItemSel.FiltSelect()
{
//SelCodGroup = selRec.ClassCode,
SearchVal = selEntry.Key
};
CurrBomItem = selEntry;
}
/// <summary>
/// Aggiunge un set standard
/// </summary>
/// <param name="selEntry"></param>
private async Task DoAddStdSet(KeyValuePair<string, List<ItemRawDTO>> selEntry)
{
// aggiungo se mancassero...
int cLenght = 0;
foreach (var item in DefaultValSet)
{
int.TryParse(item.ValString, out cLenght);
if (cLenght > 0)
{
if (!selEntry.Value.Any(x => x.Lenght == cLenght))
{
selEntry.Value.Add(new ItemRawDTO() { Lenght = cLenght, Qty = 999 });
}
}
}
}
/// <summary>
/// Aggiunta set std x tutti i record
/// </summary>
private async Task DoAddStdSetAll()
{
// aggiungo se mancassero...
int cLenght = 0;
foreach (var selEntry in ItemAvailDict)
{
foreach (var item in DefaultValSet)
{
int.TryParse(item.ValString, out cLenght);
if (cLenght > 0)
{
if (!selEntry.Value.Any(x => x.Lenght == cLenght))
{
selEntry.Value.Add(new ItemRawDTO() { Lenght = cLenght, Qty = 999 });
}
}
}
}
}
/// <summary>
/// Rimozione della misura indicata
/// </summary>
/// <param name="iKey"></param>
/// <param name="currItem"></param>
private void DoRemoveSize(string iKey, ItemRawDTO currItem)
{
// seleziono da key...
CurrBomItem = ItemAvailDict.FirstOrDefault(x => x.Key == iKey);
if (CurrBomItem.HasValue)
{
// cerco obj...
var reqObj = CurrBomItem.Value.Value.FirstOrDefault(x => (x.ItemID == currItem.ItemID && currItem.ItemID > 0) || (x.Lenght == currItem.Lenght));
if (reqObj != null)
{
CurrBomItem.Value.Value.Remove(reqObj);
}
UpdateTable();
}
CurrBomItem = null;
}
protected override void OnParametersSet()
{
isLoading = true;
UpdateTable();
}
protected void SaveNumRec(int newNum)
{
isLoading = true;
numRecord = newNum;
UpdateTable();
}
protected void SavePage(int newNum)
{
isLoading = true;
currPage = newNum;
UpdateTable();
}
protected void UpdateTable()
{
totalCount = ItemAvailDict.Count;
ListRecords = ItemAvailDict
.OrderBy(x => x.Key)
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToDictionary(x => x.Key, x => x.Value);
#if false
totalCount = BomListAll.Count;
ListRecords = BomListAll
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
#endif
isLoading = false;
}
#endregion Protected Methods
private string checkSel(string curKey)
{
string answ = CurrBomItem != null && CurrBomItem.Value.Key == curKey ? "table-info" : "";
return answ;
}
#region Private Fields
#if false
private BomItemDTO? CurrBomItem = null;
#endif
private KeyValuePair<string, List<ItemRawDTO>>? CurrBomItem = null;
private int currPage = 1;
private bool isLoading = false;
private int numRecord = 10;
private int totalCount = 0;
protected bool canSend
{
get => ItemAvailDict.Any(x => x.Value.Any(y => y.Qty > 0));
}
#endregion Private Fields
#region Private Properties
private string mainColCss => CurrBomItem == null ? "col-12" : "col-6";
#endregion Private Properties
#region Private Methods
private async Task DoClose(MouseEventArgs args)
{
await EC_ReqClose.InvokeAsync(true);
}
private async Task DoSendCalc(MouseEventArgs args)
{
await EC_ReqCalcProd.InvokeAsync(ItemAvailDict);
}
#endregion Private Methods
}
}