343 lines
9.6 KiB
C#
343 lines
9.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.SPEC.Components;
|
|
using MP.SPEC.Data;
|
|
using MP.SPEC.Services;
|
|
using NLog;
|
|
|
|
namespace MP.SPEC.Pages
|
|
{
|
|
public partial class PODL
|
|
{
|
|
#region Protected Fields
|
|
|
|
protected DataPager pagerODL = null!;
|
|
|
|
protected bool reqNew = false;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IOApiService MpIoApiCall { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
#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()
|
|
{
|
|
ListAziende = await MDService.ElencoAziende();
|
|
ListGruppiFase = await MDService.ElencoGruppiFase();
|
|
ListMacchine = await MDService.MacchineGetAll();
|
|
ListStati = await MDService.AnagStatiComm();
|
|
SearchRecords = await MDService.ListPODLFilt("*", "*");
|
|
// 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 Task.Delay(1);
|
|
pagerODL.resetCurrPage();
|
|
}
|
|
}
|
|
private List<PODLModel>? SearchRecords;
|
|
|
|
/// <summary>
|
|
/// Crea nuovo record e va in editing...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task reqNewPODL()
|
|
{
|
|
// aggiungo record articolo
|
|
if (SearchRecords != null)
|
|
{
|
|
currRecordControlli = SearchRecords.FirstOrDefault();
|
|
}
|
|
|
|
//currArticolo = "";
|
|
if (ListArticoli != null && ListArticoli.Count > 0)
|
|
{
|
|
var firstArt = ListArticoli.FirstOrDefault();
|
|
currArticolo = firstArt != null ? firstArt.CodArticolo : "";
|
|
}
|
|
string codExt = $"{currFase}";
|
|
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);
|
|
await callSyncDb(selRec);
|
|
currRecord = null;
|
|
await reloadData();
|
|
// forzo update parametri
|
|
await Task.Delay(1);
|
|
currFase = "*";
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected void UpdateTotCount(int newTotCount)
|
|
{
|
|
totalCount = newTotCount;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private PODLModel? _currRecord = null;
|
|
private PODLModel? _currRecordControlli = 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 => currFase != "*";
|
|
}
|
|
|
|
private string artSearch
|
|
{
|
|
get => _artSearch;
|
|
set
|
|
{
|
|
if (!_artSearch.Equals(value))
|
|
{
|
|
_artSearch = value;
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await reloadData();
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool selectFirst(string idxMacchina)
|
|
{
|
|
string firstMacchina = "";
|
|
bool answ = false;
|
|
if (ListMacchine != null)
|
|
{
|
|
var rawData = ListMacchine.Select(x => x.IdxMacchina).FirstOrDefault();
|
|
firstMacchina = rawData != null ? rawData : "";
|
|
}
|
|
if (firstMacchina == idxMacchina)
|
|
{
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
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();
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string currFase
|
|
{
|
|
get => currFilter.CodFase;
|
|
set
|
|
{
|
|
if (!currFilter.CodFase.Equals(value))
|
|
{
|
|
currFilter.CodFase = value;
|
|
currPage = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
private SelectPOdlParams currFilter { get; set; } = new SelectPOdlParams();
|
|
|
|
private int currPage
|
|
{
|
|
get => currFilter.CurrPage;
|
|
set => currFilter.CurrPage = value;
|
|
}
|
|
|
|
private PODLModel? currRecord
|
|
{
|
|
get => _currRecord;
|
|
set
|
|
{
|
|
_currRecord = value;
|
|
artSearch = value == null ? "" : value.CodArticolo;
|
|
}
|
|
}
|
|
private PODLModel currRecordControlli = new PODLModel();
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get => currFilter.NumRec;
|
|
set => currFilter.NumRec = value;
|
|
}
|
|
|
|
private int totalCount
|
|
{
|
|
get => currFilter.TotCount;
|
|
set => currFilter.TotCount = value;
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Chiama metodo x chiedere sync DB
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
private async Task callSyncDb(PODLModel selRec)
|
|
{
|
|
// chiamo aggiunta task SyncDb...
|
|
string idxMacc = selRec.IdxMacchina;
|
|
string restUrl = $"IOB/addTask2Exe/{idxMacc}?taskName=syncDbData&taskVal=";
|
|
try
|
|
{
|
|
var response = await MpIoApiCall.callMpIoUrlGet(restUrl);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore durante chiamata: {Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
} |