using EgwCoreLib.Razor; namespace Lux.UI.Components.Compo.Item { public partial class ItemMan { #region Public Properties [Parameter] public EventCallback EC_EditReq { get; set; } [Parameter] public List ListItemGroup { get; set; } = null!; [Parameter] public FiltSelect SelFilt { get; set; } = null!; #endregion Public Properties #region Protected Methods protected override async Task OnParametersSetAsync() { if (!SelFilt.Equals(actFilt) || true) { actFilt = SelFilt; currPage = 1; await ReloadDataAsync(); UpdateTable(); } } #endregion Protected Methods #region Private Fields private FiltSelect actFilt = new FiltSelect(); private List AllRecords = new List(); private int currPage = 1; private ItemModel? editRecord = null; private bool isLoading = false; private List ListRecords = new List(); private string mMessage = ""; private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND; private BootstrapModal Modal = new(); private Dictionary modalOpt = new Dictionary(); private string mTitle = ""; private int numRecord = 10; private ItemModel? selRecord = null; private int totalCount = 0; #endregion Private Fields #region Private Properties [Inject] private IDataLayerServices DLService { get; set; } = null!; [Inject] private IItemService IService { get; set; } = null!; [Inject] private IJSRuntime JSRuntime { get; set; } = null!; #endregion Private Properties #region Private Methods private string cloneBtnCss(ItemModel item) { return item.ItemType == Enums.ItemClassType.Bom ? "btn-warning" : "btn-success"; } /// /// Clona articolo /// /// private Task DoClone(ItemModel curRec) { editRecord = new ItemModel() { ItemIDParent = curRec.ItemType == Enums.ItemClassType.Bom ? curRec.ItemID : curRec.ItemIDParent, CodGroup = curRec.CodGroup, ItemType = curRec.ItemType == Enums.ItemClassType.Bom ? Enums.ItemClassType.BomAlt : curRec.ItemType, IsService = curRec.IsService, ItemCode = curRec.ItemCode, ExtItemCode = $"{curRec.ExtItemCode} - COPY", SupplCode = curRec.ItemType == Enums.ItemClassType.Bom ? $"{curRec.SupplCode} ALT" : curRec.SupplCode, Description = $"{curRec.Description} - COPY", Cost = curRec.Cost, Margin = curRec.Margin, QtyMin = curRec.QtyMin, QtyMax = curRec.QtyMax, UM = curRec.UM }; return EC_EditReq.InvokeAsync(editRecord); } /// /// impossta record x eliminazione /// /// private async Task DoDelete(ItemModel selRec) { mTitle = "Attenzione"; mMessage = "Sicuro di voler eliminare il record?\n" + $"Dettagli: {selRec.ItemID} | {selRec.CodGroup} | {selRec.ItemType} | {selRec.ExtItemCode}"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; //// esegue eliminazione del record... //await CDService.ItemDeleteAsync(selRec); editRecord = null; selRecord = null; await ReloadDataAsync(); UpdateTable(); } /// /// Edit articolo selezionato /// /// private Task DoEdit(ItemModel curRec) { editRecord = curRec; return EC_EditReq.InvokeAsync(editRecord); } /// /// Reset selezione /// private Task DoReset() { editRecord = null; return EC_EditReq.InvokeAsync(editRecord); } /// /// Selezione articolo x display info /// /// private void DoSelect(ItemModel curRec) { selRecord = curRec; } private async Task ReloadDataAsync() { isLoading = true; AllRecords = await IService.GetFiltAsync(actFilt.SelCodGroup, actFilt.SelType); // se ho ricerca testuale faccio filtro ulteriore... if (!string.IsNullOrEmpty(actFilt.SearchVal)) { AllRecords = AllRecords .Where(x => x.Description.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.ExtItemCode.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.SupplCode.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase)) .ToList(); } totalCount = AllRecords.Count; } private async Task ResetEdit() { // reset edit editRecord = null; await ReloadDataAsync(); await EC_EditReq.InvokeAsync(editRecord); } private void SaveNumRec(int newNum) { numRecord = newNum; UpdateTable(); } private void SavePage(int newNum) { currPage = newNum; UpdateTable(); } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }