Files
mapo-mono/MP.MONO.UI/Components/MaintTaskSched.razor.cs
zaccaria.majid e1bdfe7c71 -Aggiunta link x pdf pagina maintenance
-fix layout index con allarmi visibili in caso !=0
2022-11-02 15:01:14 +01:00

311 lines
8.7 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.MONO.Data.DbModels;
namespace MP.MONO.UI.Components
{
public partial class MaintTaskSched
{
#region Public Properties
[Parameter]
public EventCallback<bool> reqChangeMode { get; set; }
#endregion Public Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task ResetData()
{
showAddNew = false;
showEdit = false;
currRec = null;
await ReloadData();
}
protected async Task UpdateActivData()
{
//int currTaskId = currRec.PMTaskId;
await ReloadData();
//currRec = ListRecords.Where(x => x.PMTaskId == currTaskId).FirstOrDefault();
showAddNew = false;
}
#endregion Protected Methods
#region Private Fields
private int _MaxRecord = 200;
private PrevMaintTaskModel? currRec = new PrevMaintTaskModel();
#if false
private bool doSetup = false;
#endif
private List<PrevMaintTaskModel>? ListRecords = null;
// FARE!!! filtro macchina
private int MachineId = 1;
private List<PrevMaintTaskModel>? SearchRecords = null;
#endregion Private Fields
#region Private Properties
private int _currPage { get; set; } = 1;
private int _numRecord { get; set; } = 10;
private string addNewMessage
{
get => showAddNew ? "Hide Add New Task " : "Show Add new Task ";
}
private int currPage
{
get => _currPage;
set
{
if (_currPage != value)
{
currPMTaskId = 0;
_currPage = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int currPMTaskId { get; set; } = 0;
private int currPMTaskIdMod { get; set; } = 0;
private bool isLoading { get; set; } = false;
private string mainCssClass
{
get => currPMTaskId == 0 ? "px-0 flex-fill" : "px-0 flex-grow-0";
}
private int MaxRecord
{
get
{
return _MaxRecord;
}
set
{
if (_MaxRecord != value)
{
_MaxRecord = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int numRecord
{
get => _numRecord;
set
{
if (_numRecord != value)
{
currPMTaskId = 0;
_numRecord = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private PrevMaintTaskModel? selRecord { get; set; } = null;
private bool showAddNew { get; set; } = false;
private bool showEdit { get; set; } = false;
private int totalCount
{
get
{
int answ = 0;
if (SearchRecords != null)
{
answ = SearchRecords.Count;
}
return answ;
}
}
#endregion Private Properties
#region Private Methods
/// <summary>
/// Solleva evento cambio modo (Pending/Scheduled)
/// </summary>
private void ChangeMode()
{
reqChangeMode.InvokeAsync(true);
}
private string cssCheckDisabled(bool isDisabled)
{
return isDisabled ? "text-decoration-line-through" : "";
}
private string cssCheckSel(int PMTaskId)
{
string ans = "";
if ((PMTaskId == currPMTaskId) || (PMTaskId == currPMTaskIdMod))
{
ans = "table-primary";
}
else
{
ans = "";
}
return ans;
}
private string cssCheckSelMod(int PMTaskId)
{
return PMTaskId == currPMTaskIdMod ? "table-primary" : "";
}
/// <summary>
/// Elimina o disabilita un record
/// </summary>
/// <param name="currRec"></param>
/// <returns></returns>
private async Task DeleteRecord(PrevMaintTaskModel currRec)
{
#if false
bool stopDelete = false;
# endif
bool forceDelete = false;
string confirmMessage = "Are you sure?";
// verifico messaggio secondo livello protezione...
if (currRec.Protected)
{
confirmMessage = "Are you sure you want to disable this Task? This is a Manufacturer defined task and cannot be deleted.";
}
else
// se no fosse protetto --> verifico se ha record associati x cui decidere delete/disable
{
if (currRec.NumTaskDone > 0)
{
confirmMessage = "Are you sure you want to disable this custom task? There are previous task execution, delete is not permitted.";
}
else
{
confirmMessage = "Are you sure you want to delete this custom task? this is a permanet decision";
forceDelete = true;
}
confirmMessage = currRec.NumTaskDone > 0 ? "Are you sure you want to disable this custom task? There are previous task execution, delete is not permitted." : "Are you sure you want to delete this custom task? this is a permanet decision";
}
if (!await JSRuntime.InvokeAsync<bool>("confirm", confirmMessage))
return;
// altrimenti elimino
await MMDataService.PMTaskDeleteRecord(currRec, forceDelete);
// update pending...
await MMDataService.SchedMaintTaskCreateMissing(currRec.MachineId);
await ReloadData();
await Task.Delay(1);
}
private async Task EditRecord(PrevMaintTaskModel cRec)
{
currRec = cRec;
currPMTaskIdMod = cRec.PMTaskId;
currPMTaskId = 0;
//showAddNew = true;
await Task.Delay(1);
showEdit = true;
}
/// <summary>
/// Riabilita un record disabilitato
/// </summary>
/// <param name="currRec"></param>
/// <returns></returns>
private async Task EnableRecord(PrevMaintTaskModel currRec)
{
string confirmMessage = "Are you sure to re-enable this Task?";
if (!await JSRuntime.InvokeAsync<bool>("confirm", confirmMessage))
return;
// altrimenti riabilito
await MMDataService.PMTaskEnableRecord(currRec);
// update pending...
await MMDataService.SchedMaintTaskCreateMissing(currRec.MachineId);
await ReloadData();
await Task.Delay(1);
}
private void ForceReload(int newNum)
{
numRecord = newNum;
}
private void ForceReloadPage(int newNum)
{
currPage = newNum;
}
private async Task ReloadData()
{
isLoading = true;
ListRecords = null;
await Task.Delay(1);
SearchRecords = await MMDataService.PrevMaintTaskGetFilt(MachineId, 0, MaxRecord);
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
await Task.Delay(1);
isLoading = false;
}
private async Task ShowDetail(PrevMaintTaskModel? currRec)
{
selRecord = currRec;
if (currRec != null)
{
currPMTaskId = currRec.PMTaskId;
currPMTaskIdMod = 0;
}
else
{
currPMTaskId = 0;
}
//await ReloadData();
await Task.Delay(1);
}
/// <summary>
/// Gestione aggiunta nuovo record intervento
/// </summary>
private void toggleAddNew()
{
showAddNew = !showAddNew;
showEdit = !showEdit;
// se mostro --> creo nuovo record...
if (showEdit)
{
currRec = new PrevMaintTaskModel();
}
}
#endregion Private Methods
}
}