106 lines
2.9 KiB
C#
106 lines
2.9 KiB
C#
using Liman.CadCam.DbModel;
|
|
using Liman.CadCam.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LiMan.UI.Components
|
|
{
|
|
public partial class CadCamSearchProd
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string searchVal { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected CadCamService CCService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Properties
|
|
|
|
private List<ProductModel> AllRecords { get; set; } = new List<ProductModel>();
|
|
|
|
private int currPage { get; set; } = 1;
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private List<ProductModel> ListRecords { get; set; } = new List<ProductModel>();
|
|
private int numRecord { get; set; } = 5;
|
|
private List<ProductModel> SearchRecords { get; set; } = new List<ProductModel>();
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadAllData();
|
|
// aggiorno
|
|
}
|
|
|
|
protected void setNumPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
ReloadAllData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected void setNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
ReloadAllData();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
private void ReloadAllData()
|
|
{
|
|
// rileggo i dati
|
|
isLoading = true;
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
SearchRecords = AllRecords
|
|
.Where(x => (!string.IsNullOrEmpty(x.ProductName) && x.ProductName.Contains(searchVal, StringComparison.CurrentCultureIgnoreCase))
|
|
|| x.ProductNumber.ToString().Contains(searchVal, StringComparison.CurrentCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = new List<ProductModel>();
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
// paginazione!
|
|
ListRecords = SearchRecords
|
|
.Skip((currPage - 1) * numRecord)
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await CCService.ProductsGetAll();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |