211 lines
7.1 KiB
C#
211 lines
7.1 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using MP.Data.DbModels;
|
|
using MP.SPEC.Data;
|
|
|
|
namespace MP.SPEC.Components.ProdKit
|
|
{
|
|
public partial class Manager
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public SelectXdlParams ActFilt { get; set; } = new SelectXdlParams();
|
|
|
|
[Parameter]
|
|
public bool DoAddNew { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public EventCallback<SelectXdlParams> EC_FiltUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_IsComposing { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected AuthenticationStateProvider AuthStateProv { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
isLoading = false;
|
|
if (string.IsNullOrEmpty(padCodXdl))
|
|
{
|
|
padCodXdl = await MDService.ConfigTryGetAsync("padCodXdl");
|
|
}
|
|
currPodlRec = null;
|
|
// recupero user...
|
|
var authState = await AuthStateProv.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
if (user.Identity != null && user.Identity.IsAuthenticated)
|
|
{
|
|
userNameFull = $"{user.Identity.Name}";
|
|
if (!string.IsNullOrEmpty(userNameFull))
|
|
{
|
|
var splitName = userNameFull.Split(@"\");
|
|
if (splitName.Length > 1)
|
|
{
|
|
domainName = splitName[0];
|
|
userName = splitName[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Verifico chiave Kit o la rigenero
|
|
if (string.IsNullOrEmpty(keyFilt))
|
|
{
|
|
calcKitCode();
|
|
}
|
|
DateTime oggi = DateTime.Today;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadDataAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salvataggio su Tab WIP dei dati del PODL ricevuto...
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
protected async Task SavePodl(PODLExpModel selRec)
|
|
{
|
|
if (currPodlRec == null || currPodlRec.IdxPromessa != selRec.IdxPromessa)
|
|
{
|
|
if (selRec != null)
|
|
{
|
|
// chiamo tentativo update!
|
|
WipSetupKitModel newRec = new WipSetupKitModel()
|
|
{
|
|
KeyFilt = keyFilt,
|
|
CodArt = selRec.CodArticolo,
|
|
CodOrd = selRec.KeyRichiesta,
|
|
IdxPODL = selRec.IdxPromessa,
|
|
DescArt = selRec.DescArticolo,
|
|
Qta = selRec.NumPezzi,
|
|
DataIns = DateTime.Now
|
|
};
|
|
bool fatto = await MDService.WipKitUpsertAsync(newRec);
|
|
// se non già impostato riporto impostazione filtro con macchina e gruppo ricevuto...
|
|
ActFilt.IdxMacchina = selRec.IdxMacchina;
|
|
ActFilt.CodReparto = selRec.CodGruppo;
|
|
await EC_FiltUpdated.InvokeAsync(ActFilt);
|
|
}
|
|
currPodlRec = selRec;
|
|
isComposing = true;
|
|
await EC_IsComposing.InvokeAsync(isComposing);
|
|
|
|
// rileggo
|
|
await ReloadDataAsync();
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string codArtKit = "";
|
|
|
|
/// <summary>
|
|
/// Record PODL corrente da inserire
|
|
/// </summary>
|
|
private PODLExpModel? currPodlRec = null;
|
|
|
|
private string domainName = "";
|
|
private bool isComposing;
|
|
private bool isLoading = false;
|
|
private string keyFilt = "";
|
|
private List<IstanzeKitModel> listIKP = new List<IstanzeKitModel>();
|
|
private List<PODLExpModel> listPOdlAct = new List<PODLExpModel>();
|
|
private List<PODLExpModel> listPOdlCheck = new List<PODLExpModel>();
|
|
private List<TksScoreModel> listTSM = new List<TksScoreModel>();
|
|
private List<WipSetupKitModel> listWSM = new List<WipSetupKitModel>();
|
|
private List<PODLExpModel> listPOdl2Kit = new List<PODLExpModel>();
|
|
private string padCodXdl = "00000";
|
|
private string userName = "";
|
|
private string userNameFull = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string KPColClass
|
|
{
|
|
get => DoAddNew ? "col-6" : "col-12";
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void calcKitCode()
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
keyFilt = $"KIT_{userName}_{adesso:yyMMdd}_{adesso:HHmmss}";
|
|
}
|
|
|
|
private async Task ForceReloadData(bool doReload)
|
|
{
|
|
isLoading = true;
|
|
listWSM = new List<WipSetupKitModel>();
|
|
// se richiesto resetto KIT...
|
|
if (doReload)
|
|
{
|
|
calcKitCode();
|
|
}
|
|
await ReloadDataAsync();
|
|
isComposing = false;
|
|
await EC_IsComposing.InvokeAsync(isComposing);
|
|
}
|
|
|
|
private async Task SetHasOdl(bool setHasOdl)
|
|
{
|
|
ActFilt.HasOdl = setHasOdl;
|
|
await EC_FiltUpdated.InvokeAsync(ActFilt);
|
|
await ReloadDataAsync();
|
|
}
|
|
|
|
private async Task ForceReset()
|
|
{
|
|
// svuoto filtro
|
|
ActFilt.CodReparto = "*";
|
|
ActFilt.IdxMacchina = "*";
|
|
// forzo rlettura
|
|
await ForceReloadData(true);
|
|
await EC_FiltUpdated.InvokeAsync(ActFilt);
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
listPOdlCheck = new List<PODLExpModel>();
|
|
listPOdlAct = await MDService.POdlListGetFiltAsync(ActFilt.HasOdl, ActFilt.CodFase, ActFilt.IdxMacchina, ActFilt.CodReparto, ActFilt.DtStart, ActFilt.DtEnd);
|
|
listPOdl2Kit = await MDService.POdlToKitListGetFiltAsync(ActFilt.HasOdl, ActFilt.CodFase, ActFilt.IdxMacchina, ActFilt.CodReparto, ActFilt.DtStart, ActFilt.DtEnd);
|
|
listWSM = await MDService.WipKitFiltAsync(keyFilt);
|
|
listTSM = await MDService.TksScoreAsync(keyFilt, 1000, true);
|
|
listIKP = await MDService.IstKitFiltAsync("", "");
|
|
// verifico se ho score 100%...
|
|
var recMaxScore = listTSM
|
|
.Where(x => x.TotalScore == 1)
|
|
.OrderByDescending(x => x.TotalScore)
|
|
.FirstOrDefault();
|
|
codArtKit = recMaxScore != null ? recMaxScore.CodArtParent : "";
|
|
// continuo con PODL
|
|
if (!string.IsNullOrEmpty(codArtKit))
|
|
{
|
|
listPOdlCheck = await MDService.ListPODL_ByCodArtAsync(codArtKit, true);
|
|
}
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |