Files
lux/Lux.UI/Components/Compo/JobTask/JobStepMan.razor.cs
T
2025-11-12 19:15:28 +01:00

305 lines
8.5 KiB
C#

using EgwCoreLib.Lux.Data.DbModel.Cost;
using EgwCoreLib.Lux.Data.DbModel.Task;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.UI.Components.Compo.JobTask
{
public partial class JobStepMan
{
#region Public Properties
[Parameter]
public JobTaskModel CurrJob { get; set; }
[Parameter]
public List<JobStepModel> CurrRecords { get; set; } = null!;
[Parameter]
public string CurrSearch { get; set; } = string.Empty;
[Parameter]
public EventCallback<JobStepModel?> EC_Selected { get; set; }
[Parameter]
public EventCallback<bool> EC_Updated { get; set; }
[Parameter]
public List<string> ListAllTags { get; set; } = new List<string>();
[Parameter]
public List<PhaseModel> ListPhases { get; set; }
[Parameter]
public List<ResourceModel> ListResources { get; set; }
#endregion Public Properties
#region Protected Fields
protected List<JobStepModel> FiltRecords = new List<JobStepModel>();
protected List<JobStepModel> ListRecords = new List<JobStepModel>();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
/// <summary>
/// Elenco ordinato fasi
/// </summary>
protected List<PhaseModel> ListPhasesOrd
{
get => ListPhases.OrderBy(x => x.CodPhase).ThenBy(x => x.Name).ToList();
}
/// <summary>
/// Elenco ordinato risorse
/// </summary>
protected List<ResourceModel> ListResourcesOrd
{
get => ListResources.OrderBy(x => x.CodResource).ThenBy(x => x.Name).ToList();
}
protected int PhaseId
{
get => newRecord != null ? newRecord.PhaseID : 0;
set
{
if (newRecord != null && newRecord.PhaseID != value)
{
newRecord.PhaseID = value;
}
}
}
protected decimal ProductivityRateProxy
{
get => editRecord != null ? Math.Round(editRecord.ProductivityRate, 3) : 0;
set
{
if (editRecord != null)
{
editRecord.ProductivityRate = Math.Round(value, 3);
}
}
}
protected int ResourceId
{
get => newRecord != null ? newRecord.ResourceID : 0;
set
{
if (newRecord != null && newRecord.ResourceID != value)
{
newRecord.ResourceID = value;
}
}
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Genera nuovo record e lo salva
/// </summary>
protected async Task DoAdd()
{
if (newRecord != null)
{
// verifico non sia duplicato...
var recExist = CurrRecords.Count(x => x.Description == newRecord.Description);
if (recExist > 0)
{
errorMsg = $"Errore: record già esistente | {newRecord.Description}";
}
else
{
errorMsg = "";
// faccio upsert record...
await DLService.JobStepUpsertAsync(newRecord);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
newRecord = null;
addVisible = false;
#if false
// rileggo
ReloadData();
#endif
}
}
}
/// <summary>
/// Annullamento salvataggio
/// </summary>
protected async void DoCancel()
{
editRecord = null;
selRecord = null;
await EC_Updated.InvokeAsync(true);
}
/// <summary>
/// Eliminazione record
/// </summary>
/// <param name="rec2del"></param>
protected async Task DoDelete(JobStepModel rec2del)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? {rec2del.Description} ({rec2del.JobStepID})"))
return;
// esegue eliminazione del record...
await DLService.JobStepDeleteAsync(rec2del);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
#if false
// rileggo
ReloadData();
#endif
}
/// <summary>
/// Edit articolo selezionato
/// </summary>
/// <param name="curRec"></param>
protected async void DoEdit(JobStepModel curRec)
{
editRecord = curRec;
selRecord = curRec;
#if false
await EC_Selected.InvokeAsync(curRec);
#endif
await Task.Delay(1);
}
/// <summary>
/// Reset selezione
/// </summary>
protected async void DoReset()
{
editRecord = null;
selRecord = null;
await EC_Selected.InvokeAsync(selRecord);
}
/// <summary>
/// Effettua salvataggio record
/// </summary>
/// <returns></returns>
protected async Task DoSave()
{
if (editRecord != null)
{
errorMsg = "";
// faccio upsert record...
await DLService.JobStepUpsertAsync(editRecord);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
editRecord = null;
addVisible = false;
}
}
/// <summary>
/// Selezione articolo x display info
/// </summary>
/// <param name="curRec"></param>
protected async void DoSelect(JobStepModel curRec)
{
selRecord = curRec;
await EC_Selected.InvokeAsync(curRec);
}
protected override void OnParametersSet()
{
ReloadData();
}
protected void ToggleAdd()
{
addVisible = !addVisible;
if (addVisible)
{
newRecord = new JobStepModel()
{
JobID = CurrJob.JobID,
Index = totalCount + 1,
Description = $"Fase {totalCount + 1}",
PhaseID = 0,
ResourceID = 0
};
}
}
#endregion Protected Methods
#region Private Fields
private bool addVisible = false;
private int currPage = 1;
private JobStepModel? editRecord = null;
private string errorMsg = "";
private JobStepModel? newRecord = null;
private int numRecord = 10;
private JobStepModel? selRecord = null;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
/// <summary>
/// Check selezione riga item
/// </summary>
/// <param name="curRec"></param>
/// <returns></returns>
private string checkSel(JobStepModel curRec)
{
string answ = "";
if (selRecord != null)
{
answ = curRec.JobStepID == selRecord.JobStepID ? "table-info" : "";
}
return answ;
}
private void ReloadData()
{
if (CurrRecords != null)
{
// se ho ricerca testuale faccio filtro ulteriore...
if (!string.IsNullOrEmpty(CurrSearch))
{
FiltRecords = CurrRecords
.Where(x => x.Description.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
else
{
FiltRecords = CurrRecords;
}
totalCount = FiltRecords.Count;
// fix paginazione
ListRecords = CurrRecords
.OrderBy(x => x.Index)
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
}
#endregion Private Methods
}
}