299 lines
9.2 KiB
C#
299 lines
9.2 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using Microsoft.JSInterop;
|
|
using MP.AppAuth.DTO;
|
|
using MP.AppAuth.Models;
|
|
using MP.AppAuth.Services;
|
|
using MP.Land.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Land.Components
|
|
{
|
|
public partial class CompareAnagKeyVal
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<string> EC_reqAct { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<string> EC_reqReload { get; set; }
|
|
|
|
[Parameter]
|
|
public List<AnagKeyValueModel> ListAnagKeyValLoc { get; set; } = new List<AnagKeyValueModel>();
|
|
|
|
[Parameter]
|
|
public List<AnagKeyValueModel> ListAnagKeyValRem { get; set; } = new List<AnagKeyValueModel>();
|
|
|
|
[Parameter]
|
|
public bool ShowDetail { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected List<CompAnagKeyVal> ListCompare = new List<CompAnagKeyVal>();
|
|
|
|
protected List<CompAnagKeyVal> ListCompareAll = new List<CompAnagKeyVal>();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected CmpCompType.Display currFilt { get; set; } = new CmpCompType.Display();
|
|
|
|
[Inject]
|
|
protected AppAuthService DataService { get; set; }
|
|
[Inject]
|
|
protected LMessageService AppMServ { get; set; } = null!;
|
|
|
|
public string searchVal
|
|
{
|
|
get => AppMServ.SearchVal;
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected int numLoc { get; set; } = 0;
|
|
|
|
protected int numRem { get; set; } = 0;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string genClass(CompAnagKeyVal currItem)
|
|
{
|
|
string answ = currItem.IsEqual ? "text-dark" : currItem.SrcExist && currItem.DestExist ? "text-warning" : currItem.SrcExist ? "text-success" : "text-danger";
|
|
return answ;
|
|
}
|
|
|
|
protected async Task LocalAdd(CompAnagKeyVal currItem)
|
|
{
|
|
//if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler aggiungere il record?"))
|
|
// return;
|
|
|
|
bool fatto = false;
|
|
if (currItem != null)
|
|
{
|
|
fatto = await DataService.AnagKeyValAdd(currItem.Source);
|
|
}
|
|
if (fatto)
|
|
{
|
|
await ReqReload();
|
|
}
|
|
}
|
|
|
|
protected async Task LocalRem(CompAnagKeyVal currItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
|
|
bool fatto = false;
|
|
if (currItem != null)
|
|
{
|
|
fatto = await DataService.AnagKeyValDelete(currItem.Dest.NomeVar);
|
|
}
|
|
if (fatto)
|
|
{
|
|
await ReqReload();
|
|
}
|
|
}
|
|
|
|
protected async Task LocalUpd(CompAnagKeyVal currItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler aggiungere il record?"))
|
|
return;
|
|
|
|
bool fatto = false;
|
|
if (currItem != null)
|
|
{
|
|
fatto = await DataService.AnagKeyValUpd(currItem.Source);
|
|
}
|
|
if (fatto)
|
|
{
|
|
await ReqReload();
|
|
}
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ForceReload();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Report evento richiesta confronto AnagKeyVal
|
|
/// </summary>
|
|
protected async Task ReqCompare()
|
|
{
|
|
await EC_reqAct.InvokeAsync("AnagKeyVal");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Report evento richiesta confronto AnagKeyVal
|
|
/// </summary>
|
|
protected async Task ReqReload()
|
|
{
|
|
await EC_reqReload.InvokeAsync("AnagKeyVal");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Report evento richiesta reset confronto
|
|
/// </summary>
|
|
protected async Task ResetCompare()
|
|
{
|
|
await EC_reqAct.InvokeAsync("");
|
|
}
|
|
|
|
protected void SetFilter(CmpCompType.Display filtDisplay)
|
|
{
|
|
currFilt = filtDisplay;
|
|
ForceReload();
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await InvokeAsync(UpdPaging);
|
|
await Task.Delay(1);
|
|
isLoading = false;
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
isLoading = true;
|
|
currPage = newNum;
|
|
await InvokeAsync(UpdPaging);
|
|
await Task.Delay(1);
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord { get; set; } = 10;
|
|
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void ForceReload()
|
|
{
|
|
numLoc = ListAnagKeyValLoc != null ? ListAnagKeyValLoc.Count : 0;
|
|
numRem = ListAnagKeyValRem != null ? ListAnagKeyValRem.Count : 0;
|
|
// predispongo lista comparazione...
|
|
ListCompareAll = new List<CompAnagKeyVal>();
|
|
int cIdx = 0;
|
|
// filtro EQUAL
|
|
if (currFilt.Equal)
|
|
{
|
|
foreach (var item in ListAnagKeyValRem)
|
|
{
|
|
CompAnagKeyVal newRec = new CompAnagKeyVal()
|
|
{
|
|
Idx = cIdx++,
|
|
NomeVar = item.NomeVar,
|
|
Source = item,
|
|
Dest = ListAnagKeyValLoc.Find(x => x.NomeVar == item.NomeVar)
|
|
};
|
|
if (newRec.IsEqual)
|
|
{
|
|
ListCompareAll.Add(newRec);
|
|
}
|
|
}
|
|
}
|
|
|
|
// ciclo valori src...
|
|
if (currFilt.Diff)
|
|
{
|
|
foreach (var item in ListAnagKeyValRem)
|
|
{
|
|
CompAnagKeyVal newRec = new CompAnagKeyVal()
|
|
{
|
|
Idx = cIdx++,
|
|
NomeVar = item.NomeVar,
|
|
Source = item,
|
|
Dest = ListAnagKeyValLoc.Find(x => x.NomeVar == item.NomeVar)
|
|
};
|
|
if (!newRec.IsEqual && currFilt.Diff && newRec.SrcExist && newRec.DestExist)
|
|
{
|
|
ListCompareAll.Add(newRec);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (currFilt.Sx)
|
|
{
|
|
foreach (var item in ListAnagKeyValRem)
|
|
{
|
|
// se non c'è...
|
|
if (ListAnagKeyValLoc.Where(x => x.NomeVar == item.NomeVar).Count() == 0)
|
|
{
|
|
CompAnagKeyVal newRec = new CompAnagKeyVal()
|
|
{
|
|
Idx = cIdx++,
|
|
NomeVar = item.NomeVar,
|
|
Source = item,
|
|
Dest = ListAnagKeyValLoc.Find(x => x.NomeVar == item.NomeVar)
|
|
};
|
|
if (!newRec.IsEqual)
|
|
{
|
|
ListCompareAll.Add(newRec);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (currFilt.Dx)
|
|
{
|
|
// cerco eventuali record SOLO locali...
|
|
foreach (var item in ListAnagKeyValLoc)
|
|
{
|
|
// se non c'è...
|
|
if (ListAnagKeyValRem.Where(x => x.NomeVar == item.NomeVar).Count() == 0)
|
|
{
|
|
CompAnagKeyVal newRec = new CompAnagKeyVal()
|
|
{
|
|
Idx = cIdx++,
|
|
NomeVar = item.NomeVar,
|
|
Source = null,
|
|
Dest = item
|
|
};
|
|
ListCompareAll.Add(newRec);
|
|
}
|
|
}
|
|
}
|
|
// filtro sui dati chiave e note
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
ListCompareAll = ListCompareAll
|
|
.Where(x => x.Source.NomeVar.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.Source.Descrizione.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
totalCount = ListCompareAll.Count;
|
|
// riordino...
|
|
ListCompareAll = ListCompareAll.OrderBy(x => x.NomeVar).ToList();
|
|
// ciclo eventuali record locali rimasti
|
|
UpdPaging();
|
|
}
|
|
|
|
private void UpdPaging()
|
|
{
|
|
ListCompare = ListCompareAll.Skip((currPage - 1) * numRecord).Take(numRecord).ToList();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |