2b4cad4234
- Inserito filtro in offerte in base allo stato
201 lines
5.7 KiB
C#
201 lines
5.7 KiB
C#
using EgwCoreLib.Razor;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Lux.UI.Components.Compo.Contatti
|
|
{
|
|
public partial class CustomerMan
|
|
{
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<CustomerModel?> EC_EditReq { get; set; }
|
|
|
|
[Parameter]
|
|
public List<CustomerModel> CustomerList { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string SearchVal { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (CustomerList != null && CustomerList.Count > 0)
|
|
{
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private int currPage = 1;
|
|
|
|
private CustomerModel? editRecord = null;
|
|
|
|
private bool isLoading = false;
|
|
public List<CustomerModel> ListFiltCustomer { get; set; } = null!;
|
|
|
|
private List<CustomerModel> ListRecords = new List<CustomerModel>();
|
|
|
|
private List<OfferModel> OfferList = new List<OfferModel>();
|
|
|
|
private List<OrderModel> OrderList = new List<OrderModel>();
|
|
|
|
private int numRecord = 10;
|
|
|
|
private CustomerModel? 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<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IOfferService OfferService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IOrderService OrderService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private string checkSel(CustomerModel curRec)
|
|
{
|
|
return (selRecord != null && curRec.CustomerID == selRecord.CustomerID) ? "table-info" : "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
private async Task DoDelete(CustomerModel selRec)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Sicuro di voler eliminare il record?\n ";
|
|
if (string.IsNullOrEmpty(selRec.CompanyName))
|
|
{
|
|
mMessage = mMessage + $"Dettagli: {selRec.FirstName} | {selRec.LastName} | {selRec.VAT}";
|
|
}
|
|
else
|
|
{
|
|
mMessage = mMessage + $"Dettagli: {selRec.CompanyName} | {selRec.VAT}";
|
|
}
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
//// esegue eliminazione del record...
|
|
//await CService.DeleteAsync(selRec);
|
|
|
|
editRecord = null;
|
|
selRecord = null;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit cliente selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private Task DoEdit(CustomerModel curRec)
|
|
{
|
|
editRecord = curRec;
|
|
selRecord = curRec;
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
private Task DoReset()
|
|
{
|
|
selRecord = null;
|
|
editRecord = null;
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
private int NumOffer(int id)
|
|
{
|
|
int ans = 0;
|
|
if (OfferList != null && OfferList.Count > 0)
|
|
ans = OfferList.Count(x => x.CustomerID == id);
|
|
return ans;
|
|
}
|
|
|
|
private int NumOrder(int id)
|
|
{
|
|
int ans = 0;
|
|
if (OrderList != null && OrderList.Count > 0)
|
|
ans = OrderList.Count(x => x.CustomerID == id);
|
|
return ans;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
ListFiltCustomer = CustomerList;
|
|
IEnumerable<CustomerModel> query = CustomerList;
|
|
|
|
if (!string.IsNullOrEmpty(SearchVal) && SearchVal.Length >= 3)
|
|
{
|
|
query = query.Where(x => x.FirstName.Contains(SearchVal, StringComparison.OrdinalIgnoreCase) || x.LastName.Contains(SearchVal, StringComparison.OrdinalIgnoreCase) || x.CompanyName.Contains(SearchVal, StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
// effettuo search
|
|
ListFiltCustomer = query.ToList();
|
|
|
|
OfferList = await OfferService.GetAllAsync();
|
|
//OrderList = await OrderService.GetAllAsync();
|
|
|
|
totalCount = ListFiltCustomer.Count;
|
|
}
|
|
|
|
private void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
UpdateTable();
|
|
}
|
|
|
|
private void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = ListFiltCustomer
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |