256 lines
8.0 KiB
C#
256 lines
8.0 KiB
C#
using EgwCoreLib.Razor;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using NLog;
|
|
using static EgwCoreLib.Razor.Toggler;
|
|
|
|
namespace GPW.CORE.ADM.Components.Compo
|
|
{
|
|
public partial class OrarioMan : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CheckSel(AnagOrariModel curItem)
|
|
{
|
|
string answ = "";
|
|
if (RecordEdit != null)
|
|
{
|
|
answ = curItem.codOrario == RecordEdit.codOrario ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async void DoDelete(AnagOrariModel selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
|
|
isLoading = true;
|
|
bool fatto = await GDataServ.AnagOrarioDelete(selItem);
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private void AddNew()
|
|
{
|
|
RecordEdit = new AnagOrariModel()
|
|
{
|
|
codOrario = "_000h",
|
|
descOrario = "Nuovo Orario",
|
|
oreLun = 8,
|
|
oreMar = 8,
|
|
oreMer = 8,
|
|
oreGio = 8,
|
|
oreVen = 8,
|
|
autoCompOreOrd = true
|
|
};
|
|
}
|
|
|
|
protected void DoEdit(AnagOrariModel? selItem)
|
|
{
|
|
RecordEdit = selItem;
|
|
}
|
|
|
|
protected async Task ForceReload(bool force)
|
|
{
|
|
RecordEdit = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
CurrSearch = "";
|
|
AppMServ.SearchVal = "";
|
|
AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated;
|
|
numRecord = await AppMServ.NumRowGridGet(gridKey);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await AppMServ.NumRowGridSet(gridKey, newNum);
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SortRequested(Sorter.SortCallBack e)
|
|
{
|
|
sortField = e.ParamName;
|
|
sortAsc = e.IsAscending;
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private string gridKey = "OrariMan";
|
|
private AnagOrariModel? RecordEdit = null;
|
|
private bool sortAsc = true;
|
|
private string sortField = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
private string CurrSearch { get; set; } = "";
|
|
private bool isLoading { get; set; } = false;
|
|
private List<AnagOrariModel>? ListRecords { get; set; } = null;
|
|
private int numRecord { get; set; } = 10;
|
|
private List<AnagOrariModel>? SearchRecords { get; set; } = null;
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void AppMServ_EA_SearchUpdated()
|
|
{
|
|
CurrSearch = AppMServ.SearchVal;
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
try
|
|
{
|
|
SearchRecords = await GDataServ.AnagOrarioAll();
|
|
// verifico filtro per ricerca
|
|
if (!string.IsNullOrEmpty(CurrSearch))
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => x.descOrario.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase)).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error($"Eccezione in recupero dati{Environment.NewLine}{ex}");
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
SortTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void SortTable()
|
|
{
|
|
if (SearchRecords != null)
|
|
{
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "Cod":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.codOrario).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.codOrario).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Descrizione":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.descOrario).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.descOrario).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Ordin":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.oreOrdSett).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.oreOrdSett).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Straord":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.oreStraordAss).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.oreStraordAss).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Comp":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.autoCompOreOrd).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.autoCompOreOrd).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// filtro x display
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<AnagOrariModel>();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |