212 lines
6.0 KiB
C#
212 lines
6.0 KiB
C#
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Compo.JobTask
|
|
{
|
|
public partial class ResourcesMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string CurrSearch { get; set; } = string.Empty;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected List<ResourceModel> AllRecords = new List<ResourceModel>();
|
|
protected List<CostDriverModel> ListCostDriver = new List<CostDriverModel>();
|
|
protected List<ResourceModel> ListRecords = new List<ResourceModel>();
|
|
protected List<ResourceModel> SearchRecords = new List<ResourceModel>();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadBaseData();
|
|
ReloadData();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private int currPage = 1;
|
|
|
|
private ResourceModel? editRecord = null;
|
|
|
|
private bool isLoading = false;
|
|
|
|
private int numRecord = 10;
|
|
|
|
private ResourceModel? 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 ICostDriverService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
private string mainCss
|
|
{
|
|
get => selRecord == null ? "col-6" : "col-4";
|
|
}
|
|
|
|
[Inject]
|
|
private IResourceService ResService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Check selezione riga item
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
/// <returns></returns>
|
|
private string checkSel(ResourceModel curRec)
|
|
{
|
|
string answ = "";
|
|
if (selRecord != null)
|
|
{
|
|
answ = curRec.ResourceID == selRecord.ResourceID ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async Task DoAdd()
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Confermi di voler aggiungere un nuovo record risorsa?";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
isLoading = true;
|
|
var newRecord = new ResourceModel()
|
|
{
|
|
Name = $"Nuova Risorsa | {DateTime.Now:yyyy.MM.dd-HH.mm.ss}",
|
|
CostDriverID = 1
|
|
};
|
|
|
|
await ResService.UpsertAsync(newRecord);
|
|
AllRecords = new List<ResourceModel>();
|
|
await Task.Delay(100);
|
|
await ReloadBaseData();
|
|
ReloadData();
|
|
}
|
|
|
|
private async Task DoDelete(ResourceModel rec2del)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = $"Confermi di voler eliminare il record {rec2del.Name}?";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
isLoading = true;
|
|
// elimino e ricarico...
|
|
await ResService.DeleteAsync(rec2del);
|
|
await ReloadBaseData();
|
|
ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
private async Task DoReset()
|
|
{
|
|
editRecord = null;
|
|
selRecord = null;
|
|
await ReloadBaseData();
|
|
ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private void DoSelect(ResourceModel curRec)
|
|
{
|
|
selRecord = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue gestione updated
|
|
/// </summary>
|
|
/// <param name="updRec"></param>
|
|
/// <returns></returns>
|
|
private async Task DoUpdate(ResourceModel? updRec)
|
|
{
|
|
var tmpSel = selRecord;
|
|
// se non nullo salvo!
|
|
if (updRec != null)
|
|
{
|
|
await ResService.UpsertAsync(updRec);
|
|
}
|
|
await ReloadBaseData();
|
|
ReloadData();
|
|
selRecord = tmpSel;
|
|
}
|
|
|
|
private async Task ReloadBaseData()
|
|
{
|
|
AllRecords = await ResService.GetAllAsync();
|
|
ListCostDriver = await CDService.GetAllAsync();
|
|
}
|
|
|
|
private void ReloadData()
|
|
{
|
|
isLoading = true;
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (!string.IsNullOrEmpty(CurrSearch))
|
|
{
|
|
SearchRecords = AllRecords
|
|
.Where(x => x.Name.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = AllRecords;
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
// fix paginazione
|
|
ListRecords = SearchRecords
|
|
.OrderBy(x => x.CodResource)
|
|
.ThenBy(x => x.Name)
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |