using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using System.Net.Http; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; using MP.INVE; using MP.INVE.Shared; using MP.INVE.Components; using MP.INVE.Data; using MP.Data.DatabaseModels; using System.Runtime.CompilerServices; using Microsoft.EntityFrameworkCore.Infrastructure.Internal; using NLog.Targets; namespace MP.INVE.Components { public partial class ProcSuggestion { [Inject] private MiDataService MIService { get; set; } = null!; [Parameter] public string lastScan { get; set; } = null!; //[Parameter] //public EventCallback udcSend { get; set; } [Parameter] public string userScan { get; set; } = null!; [Parameter] public int sessID { get; set; } = 0; [Inject] public IJSRuntime JSRuntime { get; set; } = null!; [Inject] public NavigationManager NavManager { get; set; } = null!; private string tipo { get; set; } = ""; private string canMod = "false"; protected List? searchRecordsUDC; protected List? searchRecordsLotto; protected List? elencoScansioni; protected AnagUdcModel? udc; protected AnagLottoModel? lotto; protected ScanDataModel? alreadyScan; protected AnagUdcModel? currUdc; protected AnagLottoModel? currLotto; protected bool alertScan; protected bool isScannedLotto; protected bool firstMsg = false; protected bool isMod = true; protected override async Task OnAfterRenderAsync(bool firstRender) { await Task.Delay(1); if (firstRender) { firstMsg = true; } } protected override async Task OnParametersSetAsync() { await MIService.ConfigResetCache(); var result = await MIService.tryGetConfig("MAG_SmartUdcEdit"); elencoScansioni = MIService.ScanList(); var exists = elencoScansioni.Select(x => x.ScanValue).Contains(lastScan); var scansioneClone = elencoScansioni.Where(x => x.ScanValue == lastScan).FirstOrDefault(); if (exists) { if (scansioneClone != null) { isScannedLotto = scansioneClone.ScanValue.StartsWith("M2"); isMod = true; if (scansioneClone.IsUnique) { isMod = false; } alreadyScan = elencoScansioni.Where(x => x.ScanValue == lastScan).FirstOrDefault(); currUdc = null; currLotto = null; } } else { if (result != null) { canMod = result; } await Task.Delay(1); searchRecordsUDC = MIService.ElencoUDC(); udc = searchRecordsUDC.Where(x => x.UDC == lastScan).FirstOrDefault(); if (udc != null && !udc.UDC.Contains("MSL")) { currUdc = udc; tipo = "UDC"; lottoScan = udc.lottoNav.Lotto; articoloScan = udc.lottoNav.CodArt; quantitaScan = udc.Qta; noteScan = udc.Note; } else { searchRecordsLotto = MIService.ElencoLotti(); lotto = searchRecordsLotto.Where(x => x.Lotto == lastScan).FirstOrDefault(); if (lotto != null) { tipo = "LOTTO"; #if false var alertMod = await JSRuntime.InvokeAsync("confirm", $"L'oggetto {lastScan} risulta presente nelle nostre anagrafiche con i seguenti dati: \nTipo: {tipo}\nLotto: {lotto.Lotto}\nArticolo: {lotto.CodArt} \nSi desidera modificarlo?"); if (alertMod) { } else { insertScan(); } #endif currLotto = lotto; lottoScan = lotto.Lotto; articoloScan = lotto.CodArt; } else { currLotto = null; currUdc = null; alreadyScan = null; lottoScan = lastScan; articoloScan = ""; quantitaScan = 0; noteScan = ""; } } } } protected bool isForced = false; protected decimal qtaLotto = 0; protected async void insertScan() { var alertInsert = await JSRuntime.InvokeAsync("confirm", $"Confermi di voler salvare la seguente scansione per la sessione {sessID}?"); if (alertInsert) { if (currUdc != null) { if ((currUdc.lottoNav.CodArt != udc.lottoNav.CodArt) || (currUdc.Qta != udc.Qta)) { isForced = true; } //if() ScanDataModel newScan = new ScanDataModel() { DtScan = DateTime.Now, UserScan = userScan, ScanValue = lastScan, IsForced = isForced, CodArticolo = currUdc.lottoNav.CodArt, Lotto = currUdc.lottoNav.Lotto, RifExt = currUdc.lottoNav.RifExt, Qty = currUdc.Qta, Note = currUdc.Note, IsKnown = true, IsUnique = true, InveSessID = sessID }; await MIService.InsertNewScansione(newScan); NavManager.NavigateTo(NavManager.Uri, true); } else if (currLotto != null) { ScanDataModel newScan = new ScanDataModel() { DtScan = DateTime.Now, UserScan = userScan, ScanValue = lastScan, IsForced = true, CodArticolo = currLotto.CodArt, Lotto = currLotto.Lotto, RifExt = currLotto.RifExt, Qty = qtaLotto, Note = currLotto.Note, IsKnown = true, IsUnique = false, InveSessID = sessID }; await MIService.InsertNewScansione(newScan); NavManager.NavigateTo(NavManager.Uri, true); } else if (alreadyScan != null) { ScanDataModel newScan = new ScanDataModel() { DtScan = DateTime.Now, UserScan = userScan, ScanValue = lastScan, IsForced = true, CodArticolo = alreadyScan.CodArticolo, Lotto = alreadyScan.Lotto, RifExt = alreadyScan.RifExt, Qty = alreadyScan.Qty, Note = alreadyScan.Note, IsKnown = alreadyScan.IsKnown, IsUnique = alreadyScan.IsUnique, InveSessID = sessID }; await MIService.InsertNewScansione(newScan); NavManager.NavigateTo(NavManager.Uri, true); } } else { currLotto = null; currUdc = null; alreadyScan = null; NavManager.NavigateTo(NavManager.Uri, true); } } protected async void updateScansione(ScanDataModel modScan) { var alertUpdate = await JSRuntime.InvokeAsync("confirm", $"Confermi di voler modificare la seguente scansione {modScan.ScanValue}?"); if (alertUpdate) { if (alreadyScan != null) { modScan.CodArticolo = alreadyScan.CodArticolo; modScan.Qty = alreadyScan.Qty; modScan.Note = alreadyScan.Note; } await MIService.UpdateScan(modScan); } } public void resetAll() { NavManager.NavigateTo(NavManager.Uri, true); } protected string reqArtMod = "disabilita"; protected string reqQtaMod = "disabilita"; protected string _lotto = ""; protected string lottoScan { get => _lotto; set => _lotto = value; } protected string _articolo = ""; protected string articoloScan { get => _articolo; set => _articolo = value; } protected decimal _qta = 0; protected decimal quantitaScan { get => _qta; set => _qta = value; } protected string _note = ""; protected string noteScan { get => _note; set => _note = value; } protected void cssDisableArt() { reqArtMod = ""; } protected void cssDisableQta() { reqQtaMod = ""; } //private void saveSel(AnagUdcModel udcToSend) //{ // Task.FromResult(udcSend.InvokeAsync(udcToSend)); //} } }