Files
Annamaria Sassi d3b2b9e329 Correzioni
2026-05-11 11:24:46 +02:00

309 lines
8.7 KiB
C#

using EgwCoreLib.Razor;
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 Methods
protected override void OnParametersSet()
{
ReloadData();
}
#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;
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 IDataLayerServices DLService { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
private IJobStepService JSService { get; set; } = null!;
/// <summary>
/// Elenco ordinato fasi
/// </summary>
private List<PhaseModel> ListPhasesOrd
{
get => ListPhases.OrderBy(x => x.CodPhase).ThenBy(x => x.Name).ToList();
}
/// <summary>
/// Elenco ordinato risorse
/// </summary>
private List<ResourceModel> ListResourcesOrd
{
get => ListResources.OrderBy(x => x.CodResource).ThenBy(x => x.Name).ToList();
}
private int PhaseId
{
get => newRecord != null ? newRecord.PhaseID : 0;
set
{
if (newRecord != null && newRecord.PhaseID != value)
{
newRecord.PhaseID = value;
}
}
}
private decimal ProductivityRateProxy
{
get => editRecord != null ? Math.Round(editRecord.ProductivityRate, 3) : 0;
set
{
if (editRecord != null)
{
editRecord.ProductivityRate = Math.Round(value, 3);
}
}
}
private int ResourceId
{
get => newRecord != null ? newRecord.ResourceID : 0;
set
{
if (newRecord != null && newRecord.ResourceID != value)
{
newRecord.ResourceID = value;
}
}
}
#endregion Private Properties
#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;
}
/// <summary>
/// Genera nuovo record e lo salva
/// </summary>
private 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 JSService.UpsertAsync(newRecord);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
newRecord = null;
addVisible = false;
}
}
}
/// <summary>
/// Annullamento salvataggio
/// </summary>
private Task DoCancel()
{
editRecord = null;
selRecord = null;
return EC_Updated.InvokeAsync(true);
}
/// <summary>
/// Eliminazione record
/// </summary>
/// <param name="rec2del"></param>
private async Task DoDelete(JobStepModel rec2del)
{;
mTitle = "Attenzione";
mMessage = $"Sicuro di voler eliminare il record? {rec2del.Description} ({rec2del.JobStepID})";
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 JSService.DeleteAsync(rec2del);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
}
/// <summary>
/// Edit articolo selezionato
/// </summary>
/// <param name="curRec"></param>
private Task DoEdit(JobStepModel curRec)
{
editRecord = curRec;
selRecord = curRec;
return Task.Delay(1);
}
/// <summary>
/// Reset selezione
/// </summary>
private Task DoReset()
{
editRecord = null;
selRecord = null;
return EC_Selected.InvokeAsync(selRecord);
}
/// <summary>
/// Effettua salvataggio record
/// </summary>
/// <returns></returns>
private async Task DoSave()
{
if (editRecord != null)
{
errorMsg = "";
// faccio upsert record...
await JSService.UpsertAsync(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>
private Task DoSelect(JobStepModel curRec)
{
selRecord = curRec;
return EC_Selected.InvokeAsync(curRec);
}
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();
}
}
private void ToggleAdd()
{
addVisible = !addVisible;
if (addVisible)
{
newRecord = new JobStepModel()
{
JobID = CurrJob.JobID,
Index = totalCount + 1,
Description = $"Fase {totalCount + 1}",
PhaseID = 0,
ResourceID = 0
};
}
}
#endregion Private Methods
}
}