179 lines
5.2 KiB
C#
179 lines
5.2 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using SHERPA.BBM.CORE.DbModels;
|
|
using SHERPA.BBM.UI.Data;
|
|
|
|
namespace SHERPA.BBM.UI.Components
|
|
{
|
|
public partial class CustExtList : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public PagInfo CurrPagInfo { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> E_DataUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> E_UpdateCount { get; set; }
|
|
|
|
[Parameter]
|
|
public string SearchVal { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public bool ShowOnlyMissing { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
MServ.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await checkAndReload();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected BBM_EFService BBMService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task ImportCliExt(CustDecodModel currRecord)
|
|
{
|
|
await Task.Delay(1);
|
|
CustomersModel newCust = new CustomersModel()
|
|
{
|
|
RagSoc = currRecord.RagSoc,
|
|
CF = currRecord.CF.Trim(),
|
|
PI = currRecord.PI.Trim(),
|
|
Descript = $"Imported | {currRecord.CustExtId}"
|
|
};
|
|
await BBMService.CustomerUpdate(newCust);
|
|
// cerco nuovo customer e aggiorno i dati in decodifica...
|
|
var allCust = await BBMService.CustomersGetAll("");
|
|
var insRec = allCust
|
|
.Where(x => x.CF == currRecord.CF && x.PI == currRecord.PI && x.RagSoc == currRecord.RagSoc)
|
|
.FirstOrDefault();
|
|
if (insRec != null)
|
|
{
|
|
int custId = insRec.CustomerId;
|
|
// chiamo stored fix
|
|
await BBMService.CustDecodedFixCod(currRecord.CustExtId, custId);
|
|
}
|
|
await E_DataUpdated.InvokeAsync(true);
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
MServ.EA_SearchUpdated += OnSeachUpdated;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await checkAndReload();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string lastSearchVal = "";
|
|
|
|
private int TotalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int CurrPage
|
|
{
|
|
get => CurrPagInfo.CurrPage;
|
|
set => CurrPagInfo.CurrPage = value;
|
|
}
|
|
|
|
private bool isLoading { get; set; } = true;
|
|
|
|
private PagInfo lastPagInfo { get; set; } = new PagInfo();
|
|
|
|
private string lastSearch { get; set; } = "";
|
|
|
|
private List<CustDecodModel> ListRecords { get; set; } = null!;
|
|
|
|
private int NumRecord
|
|
{
|
|
get => CurrPagInfo.NumRec;
|
|
set => CurrPagInfo.NumRec = value;
|
|
}
|
|
|
|
private List<CustDecodModel> SearchRecords { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task checkAndReload()
|
|
{
|
|
isLoading = true;
|
|
bool needReload = false;
|
|
if (!CurrPagInfo.Equals(lastPagInfo))
|
|
{
|
|
lastPagInfo = CurrPagInfo.Clone();
|
|
needReload = true;
|
|
}
|
|
if (SearchVal != lastSearchVal)
|
|
{
|
|
lastSearchVal = SearchVal;
|
|
needReload = true;
|
|
}
|
|
if (!MServ.SearchVal.Equals(lastSearch))
|
|
{
|
|
lastSearch = MServ.SearchVal;
|
|
needReload = true;
|
|
}
|
|
if (needReload)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await BBMService.CustDecodedGetAll();
|
|
if (ShowOnlyMissing)
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => (x.BillExtNav.Count() > 0) && (x.CustomerId == 0))
|
|
.ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(lastSearch))
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.RagSoc.Contains(lastSearch, StringComparison.InvariantCultureIgnoreCase) || x.CF.Contains(lastSearch, StringComparison.InvariantCultureIgnoreCase) || x.PI.Contains(lastSearch, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
TotalCount = SearchRecords.Count;
|
|
ListRecords = SearchRecords
|
|
.Skip(NumRecord * (CurrPage - 1))
|
|
.Take(NumRecord).ToList();
|
|
isLoading = false;
|
|
await InvokeAsync(() => E_UpdateCount.InvokeAsync(TotalCount));
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |