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 CurrRecords { get; set; } = null!; [Parameter] public string CurrSearch { get; set; } = string.Empty; [Parameter] public EventCallback EC_Selected { get; set; } [Parameter] public EventCallback EC_Updated { get; set; } [Parameter] public List ListAllTags { get; set; } = new List(); [Parameter] public List ListPhases { get; set; } [Parameter] public List ListResources { get; set; } #endregion Public Properties #region Protected Fields protected List FiltRecords = new List(); protected List ListRecords = new List(); #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 modalOpt = new Dictionary(); #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!; /// /// Elenco ordinato fasi /// private List ListPhasesOrd { get => ListPhases.OrderBy(x => x.CodPhase).ThenBy(x => x.Name).ToList(); } /// /// Elenco ordinato risorse /// private List 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 /// /// Check selezione riga item /// /// /// private string checkSel(JobStepModel curRec) { string answ = ""; if (selRecord != null) { answ = curRec.JobStepID == selRecord.JobStepID ? "table-info" : ""; } return answ; } /// /// Genera nuovo record e lo salva /// 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; } } } /// /// Annullamento salvataggio /// private Task DoCancel() { editRecord = null; selRecord = null; return EC_Updated.InvokeAsync(true); } /// /// Eliminazione record /// /// 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()) return; // esegue eliminazione del record... await JSService.DeleteAsync(rec2del); // segnalo update x reload await EC_Updated.InvokeAsync(true); } /// /// Edit articolo selezionato /// /// private Task DoEdit(JobStepModel curRec) { editRecord = curRec; selRecord = curRec; return Task.Delay(1); } /// /// Reset selezione /// private Task DoReset() { editRecord = null; selRecord = null; return EC_Selected.InvokeAsync(selRecord); } /// /// Effettua salvataggio record /// /// 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; } } /// /// Selezione articolo x display info /// /// 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 } }