using EgwCoreLib.Razor; namespace Lux.UI.Components.Compo.Config { public partial class GlassMan { #region Protected Properties [Inject] protected IConfGlassService CGService { get; set; } = null!; [Inject] protected IDataLayerServices DLService { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected string SearchVal { get => searchVal; set { if (searchVal != value) { searchVal = value; UpdateTable(); } } } #endregion Protected Properties #region Protected Methods /// /// imposta record x eliminazione /// /// protected async Task DoDelete(GlassModel selRec) { mTitle = "Attenzione"; mMessage = "Sicuro di voler eliminare il record?\n" + $"Dettagli: {selRec.GlassID} | {selRec.Description} | {selRec.Thickness}"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; // esegue eliminazione del record... await CGService.DeleteAsync(selRec); EditRecord = null; SelRecord = null; await ReloadDataAsync(); UpdateTable(); } /// /// Edit articolo selezionato /// /// protected void DoEdit(GlassModel curRec) { EditRecord = curRec; } /// /// Reset selezione /// protected void DoReset() { EditRecord = null; } /// /// Selezione articolo x display info /// /// protected void DoSelect(GlassModel curRec) { SelRecord = curRec; } protected override async Task OnParametersSetAsync() { await ReloadDataAsync(); UpdateTable(); } protected void ResetSearch() { SearchVal = ""; } protected void SaveNumRec(int newNum) { numRecord = newNum; UpdateTable(); } protected void SavePage(int newNum) { currPage = newNum; UpdateTable(); } #endregion Protected Methods #region Private Fields private List AllRecords = new(); private List SearchRecords = new(); private int currPage = 1; private GlassModel? EditRecord = null; private bool isLoading = false; private List ListRecords = new(); private int numRecord = 5; private GlassModel? SelRecord = null; private int totalCount = 0; 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 string searchVal { get; set; } = string.Empty; #endregion Private Properties #region Private Methods private Task DoAdd() { // aggiungo un nuovo record in coda... EditRecord = new GlassModel() { Description = "New Glass", Code = "", Thickness = 30 }; return DoSave(EditRecord); } private async Task DoSave(GlassModel currRec) { // salvo await CGService.UpsertAsync(currRec); await ReloadDataAsync(); EditRecord = null; SelRecord = null; UpdateTable(); } private async Task ReloadDataAsync() { isLoading = true; AllRecords = await CGService.GetAllAsync(); } /// /// Filtro e paginazione /// private void UpdateTable() { // se ho ricerca testuale faccio filtro ulteriore... if (string.IsNullOrEmpty(SearchVal)) { SearchRecords = AllRecords .OrderBy(x => x.Description) .ToList(); } else { SearchRecords = AllRecords .Where(x => x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.Code.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(x => x.Description) .ToList(); } totalCount = SearchRecords.Count; // fix paginazione ListRecords = SearchRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }