using EgwCoreLib.Lux.Core.Generic; using Lux.UI.Components.Pages; namespace Lux.UI.Components.Compo.WorkLoad { public partial class RawPartSelector { #region Public Properties [Parameter] public List BomListAll { get; set; } = null!; [Parameter] public Dictionary> ItemAvailDict { get; set; } = null!; [Parameter] public EventCallback>> EC_ReqCalcProd { get; set; } [Parameter] public EventCallback EC_ReqClose { get; set; } [Parameter] public List DefaultValSet { get; set; } = null!; #endregion Public Properties #region Protected Methods protected override void OnParametersSet() { isLoading = true; UpdateTable(); } #endregion Protected Methods #region Private Fields private KeyValuePair>? CurrBomItem = null; private Dictionary>? ListRecords = null; private int currPage = 1; private bool isLoading = false; private int numRecord = 10; private int totalCount = 0; #endregion Private Fields #region Private Properties private ItemSel.FiltSelect CurrFilt { get; set; } = new ItemSel.FiltSelect(); private string mainColCss => CurrBomItem == null ? "col-12" : "col-6"; private bool canSend { get => ItemAvailDict.Any(x => x.Value.Any(y => y.Qty > 0)); } #endregion Private Properties #region Private Methods private string checkSel(string curKey) { string answ = CurrBomItem != null && CurrBomItem.Value.Key == curKey ? "table-info" : ""; return answ; } private async Task DoClose(MouseEventArgs args) { await EC_ReqClose.InvokeAsync(true); } private async Task DoSendCalc(MouseEventArgs args) { await EC_ReqCalcProd.InvokeAsync(ItemAvailDict); } /// /// Selezione record x inserimento tipo RawMat da impiegare /// /// private void DoSelect(KeyValuePair> selEntry) { CurrFilt = new ItemSel.FiltSelect() { //SelCodGroup = selRec.ClassCode, SearchVal = selEntry.Key }; CurrBomItem = selEntry; } /// /// Aggiunge un set standard /// /// private async Task DoAddStdSet(KeyValuePair> 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 }); } } } } /// /// Aggiunta set std x tutti i record /// 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 }); } } } } } /// /// Rimozione della misura indicata /// /// /// 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; } private void SaveNumRec(int newNum) { isLoading = true; numRecord = newNum; UpdateTable(); } private void SavePage(int newNum) { isLoading = true; currPage = newNum; UpdateTable(); } private 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; } private string marginCss(List rawList, ItemRawDTO item) { string ans = ""; if (rawList.Count() > 1 && rawList.LastOrDefault() != item) { ans = "mb-1"; } return ans; } #endregion Private Methods } }