From b1fef48b1c488428bf0e22af8056d703efdf7931 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 3 Sep 2021 16:29:55 +0200 Subject: [PATCH] Completata prima integrazione lettura dati dal DB --- MP.FileData/Controllers/FileController.cs | 50 +++++++++ MP.Prog/Data/FileArchDataService.cs | 10 ++ MP.Prog/Pages/Archive.razor | 121 ++++++++++------------ MP.Prog/Pages/Archive.razor.cs | 78 +++++++++----- 4 files changed, 167 insertions(+), 92 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index c40c6c55..2f6956c2 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -88,12 +88,62 @@ namespace MP.FileData.Controllers #region Public Methods + /// + /// Elenco tabella Articoli (FILTRATO!!!) + /// + /// + /// + /// + public List ArtGetFilt(string searchVal, int maxNum = 100) + { + maxNum = maxNum <= 0 ? 100 : maxNum; + List dbResult = new List(); + + int totRecord = dbCtx + .DbSetArticoli + .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal)) + .Count(); + if (totRecord > maxNum) + { + dbResult = dbCtx + .DbSetArticoli + .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal)) + .OrderBy(x => x.DescArticolo) + .Take(maxNum) + .ToList(); + dbResult.Add(new DatabaseModels.ArticoloModel() { CodArticolo = "#####", DescArticolo = $"... +{totRecord - maxNum} rec ..." }); + } + else + { + dbResult = dbCtx + .DbSetArticoli + .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal)) + .OrderBy(x => x.DescArticolo) + .ToList(); + } + + return dbResult; + } + public void Dispose() { // Clear database context dbCtx.Dispose(); } + public List FileGetFilt(string IdxMacchina, string CodArticolo, string SearchVal = "") + { + List dbResult = new List(); + + dbResult = dbCtx + .DbSetProgFile + .Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") || (x.CodArticolo == CodArticolo || CodArticolo == "ND")) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal))) + .OrderBy(x => x.Name) + .ToList(); + + return dbResult; + } + /// /// Elenco tabella Macchine /// diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 14a13a91..204e4f72 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -185,12 +185,22 @@ namespace MP.Prog.Data #region Public Methods + public Task> ArticoliGetFilt(string SearchVal) + { + return Task.FromResult(dbController.ArtGetFilt(SearchVal, 20).ToList()); + } + public void Dispose() { // Clear database controller dbController.Dispose(); } + public Task> FileGetFilt(string IdxMacchina, string CodArticolo, string SearchVal) + { + return Task.FromResult(dbController.FileGetFilt(IdxMacchina, CodArticolo, SearchVal).ToList()); + } + public Task> MacchineGetAll() { return Task.FromResult(dbController.MacchineGetAll().ToList()); diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index a938d3e6..8326cbc8 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -3,80 +3,65 @@
-
+
Elenco Programmi
-
-
-
+
+
+
- + +
+
+
+
+
+ + + +
+ +
+
+
+
+
+ + + +
+ + +
+ +
+
+
+
+
+
-
- @*
-
-
-
- inizio: -
- -
-
-
-
-
- fine: -
- -
-
-
*@ -
-
- @*
-
-
-
- - - -
- -
-
-
-
-
- - - -
- -
-
-
*@ -
@@ -87,7 +72,7 @@ } @if (ListRecords == null) { - @**@ + } else if (totalCount == 0) { diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 77bab15a..e02867e0 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -21,6 +21,12 @@ namespace MP.Prog.Pages #endregion Private Fields + #region Protected Fields + + protected string _SearchArt = "###"; + + #endregion Protected Fields + #region Private Properties private int _currPage { get; set; } = 1; @@ -117,6 +123,33 @@ namespace MP.Prog.Pages [Inject] protected NavigationManager NavManager { get; set; } + protected string SearchArt + { + get + { + return _SearchArt; + } + set + { + isLoading = true; + _SearchArt = value; + // se son > 3 char... debounce... + if (string.IsNullOrEmpty(value)) + { + _SearchArt = "###"; + } + if (value.Length >= 3) + { + var pUpd = Task.Run(async () => + { + ArtList = await DataService.ArticoliGetFilt(SearchArt); + }); + pUpd.Wait(); + } + isLoading = false; + } + } + protected int totalCount { get @@ -137,10 +170,8 @@ namespace MP.Prog.Pages private async Task ReloadData() { isLoading = true; -#if false - SearchRecords = await DataService.OrdersGetFilt(AppMService.Order_Filter); + SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.SearchVal); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); -#endif isLoading = false; } @@ -157,6 +188,16 @@ namespace MP.Prog.Pages #endif } + protected async Task ForceCheck() + { + // !!!FARE + currRecord = null; + SearchRecords = null; + ListRecords = null; + AppMService.File_Filter = SelectData.Init(5, 10); + await ReloadAllData(); + } + protected void ForceReload(int newNum) { numRecord = newNum; @@ -180,27 +221,10 @@ namespace MP.Prog.Pages protected async Task ReloadAllData() { isLoading = true; -#if false - SuppliersList = await DataService.SuppliersGetAll(); - SelIdxMacc = 0; - PlantsList = null; - await GetClaimsData(); - // se ho un plantId valido --> altrimenti non abilitato - if (ClaimPlantId == 0) - { - PlantsList = await DataService.PlantsGetAll(); - } - else if (ClaimPlantId > 0) - { - var rawData = await DataService.PlantsGetAll(); - PlantsList = rawData.Where(x => x.PlantId == ClaimPlantId).ToList(); - SelIdxMacc = ClaimPlantId; - } - else - { - PlantsList = new List(); - } -#endif + MacList = await DataService.MacchineGetAll(); + SelIdxMacc = "0"; + ArtList = await DataService.ArticoliGetFilt(SearchArt); + SelCodArt = "###"; isLoading = false; await ReloadData(); } @@ -217,9 +241,15 @@ namespace MP.Prog.Pages SearchRecords = null; ListRecords = null; AppMService.File_Filter = SelectData.Init(5, 10); + SearchArt = "###"; await ReloadAllData(); } + protected void ResetSearchArt() + { + SearchArt = "###"; + } + protected void Select(FileModel selRecord) { // applico filtro da selezione