Files
mapo-core/MP.SPEC/Pages/PODL.razor.cs
T
2022-09-13 17:35:55 +02:00

288 lines
7.8 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.Data.DatabaseModels;
using MP.SPEC.Components;
using MP.SPEC.Data;
namespace MP.SPEC.Pages
{
public partial class PODL
{
#region Protected Fields
protected DataPager pagerODL;
protected bool reqNew = false;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected IJSRuntime JSRuntime { get; set; }
[Inject]
protected MpDataService MDService { get; set; }
[Inject]
protected MessageService MsgService { get; set; }
[Inject]
protected NavigationManager NavManager { get; set; }
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Crea nuovo record e va in editing...
/// </summary>
/// <returns></returns>
protected async Task addNew()
{
currRecord = new PODLModel()
{
CodArticolo = $"_NEW_{DateTime.Now:yyyyMMdd.HHmmss}"
};
await Task.Delay(1);
}
protected async Task cancel()
{
currRecord = null;
await reloadData();
await Task.Delay(1);
}
protected void ForceReload(int newNum)
{
numRecord = newNum;
}
protected void ForceReloadPage(int newNum)
{
currPage = newNum;
}
protected override async Task OnInitializedAsync()
{
// abilito ricerca...
MsgService.ShowSearch = true;
// resetto search
MsgService.SearchVal = "";
ListAziende = await MDService.ElencoAziende();
ListGruppiFase = await MDService.ElencoGruppiFase();
ListMacchine = await MDService.MacchineGetAll();
ListStati = await MDService.AnagStatiComm();
// preselezione valori
configData = await MDService.ConfigGetAll();
var currRec = configData.FirstOrDefault(x => x.Chiave == "AZIENDA");
if (currRec != null)
{
currAzienda = currRec.Valore;
}
// carico dati
await reloadData();
}
protected async Task pgResetReq(bool doReset)
{
if (doReset)
{
await pagerODL.resetCurrPage();
}
}
/// <summary>
/// Crea nuovo record e va in editing...
/// </summary>
/// <returns></returns>
protected async Task reqNewPODL()
{
// aggiungo record articolo
currArticolo = "";
if (ListArticoli != null && ListArticoli.Count > 0)
{
var firstArt = ListArticoli.FirstOrDefault();
currArticolo = firstArt != null ? firstArt.CodArticolo : "";
}
string codExt = $"{selStato}";
string codGruppo = "";
if (ListGruppiFase != null && ListGruppiFase.Count > 0)
{
var firstFase = ListGruppiFase.FirstOrDefault(x => x.CodGruppo.StartsWith(_currAzienda));
if (firstFase != null)
{
codGruppo = firstFase.CodGruppo;
}
}
string codMacc = "";
if (ListMacchine != null && ListMacchine.Count > 0)
{
var firstMacc = ListMacchine.FirstOrDefault(x => x.Nome.Contains(currAzienda));
if (firstMacc != null)
{
codMacc = firstMacc.IdxMacchina;
}
}
currRecord = new PODLModel()
{
CodArticolo = currArticolo,
KeyBCode = codExt,
KeyRichiesta = codExt,
CodGruppo = codGruppo,
IdxMacchina = codMacc,
NumPezzi = 1,
DueDate = DateTime.Now.AddDays(30)
};
await Task.Delay(1);
}
protected async Task selRecord(PODLModel selRec)
{
currRecord = selRec;
await Task.Delay(1);
}
protected async Task update(PODLModel selRec)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler salvare le modifiche?"))
return;
await Task.Delay(1);
var done = await MDService.POdlUpdateRecord(selRec);
currRecord = null;
await reloadData();
await Task.Delay(1);
}
#endregion Protected Methods
#region Private Fields
private PODLModel? _currRecord = null;
private List<AnagArticoli>? ListArticoli;
private List<AnagGruppi>? ListAziende;
private List<AnagGruppi>? ListGruppiFase;
private List<Macchine>? ListMacchine;
private List<ListValues>? ListStati;
#endregion Private Fields
#region Private Properties
private string _artSearch { get; set; } = "";
private string _currAzienda { get; set; } = "*";
private bool addEnabled
{
get => selStato != "*";
}
private string artSearch
{
get => _artSearch;
set
{
if (!_artSearch.Equals(value))
{
_artSearch = value;
var pUpd = Task.Run(async () =>
{
await reloadData();
});
pUpd.Wait();
}
}
}
private string btnNewText
{
get => currArticolo == "" ? "Sel Articolo" : "Nuovo PODL";
}
private List<ConfigModel>? configData { get; set; } = null;
private string currArticolo { get; set; } = "";
private string currAzienda
{
get => _currAzienda;
set
{
if (!_currAzienda.Equals(value))
{
_currAzienda = value;
var pUpd = Task.Run(async () =>
{
await reloadData();
//await Task.Delay(1);
//await InvokeAsync(() => StateHasChanged());
});
pUpd.Wait();
}
}
}
private int currPage
{
get => MsgService.currPage;
set => MsgService.currPage = value;
}
private PODLModel? currRecord
{
get => _currRecord;
set
{
_currRecord = value;
artSearch = value == null ? "" : value.CodArticolo;
}
}
private bool isLoading { get; set; } = false;
private int numRecord
{
get => MsgService.numRecord;
set => MsgService.numRecord = value;
}
private string selStato
{
get => MsgService.StateSel;
set => MsgService.StateSel = value;
}
private int totalCount
{
get => MsgService.totalCount;
set => MsgService.totalCount = value;
}
#endregion Private Properties
#region Private Methods
private async Task navToODL()
{
await Task.Delay(1);
NavManager.NavigateTo("/ODL");
}
private async Task reloadData()
{
isLoading = true;
await Task.Delay(1);
if (currAzienda != "*")
{
ListArticoli = await MDService.ArticoliGetSearch(100, currAzienda, artSearch);
}
else
{
ListArticoli = new List<AnagArticoli>();
}
isLoading = false;
}
#endregion Private Methods
}
}