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; 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? searchrecords; protected AnagUdcModel? udc; protected AnagUdcModel? currUdc; protected override async Task OnParametersSetAsync() { await MIService.ConfigResetCache(); var result = await MIService.tryGetConfig("MAG_SmartUdcEdit"); if (result != null) { canMod = result; } await Task.Delay(1); searchrecords = MIService.ElencoUDC(); udc = searchrecords.Where(x => x.UDC == lastScan).FirstOrDefault(); if (udc != null) { currUdc = udc; if (udc.UDC.Contains("MFI")) { tipo = "FINITO"; } } } protected bool isForced = false; protected async void insertScan() { var alert = await JSRuntime.InvokeAsync("confirm", $"Confermi di voler salvare la seguente scansione per la sessione {sessID}?"); if (currUdc != null) { if (alert) { 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 { NavManager.NavigateTo(NavManager.Uri, true); } } protected string reqArtMod = "disabilita"; protected string reqQtaMod = "disabilita"; protected void cssDisableArt() { reqArtMod = ""; } protected void cssDisableQta() { reqQtaMod = ""; } //private void saveSel(AnagUdcModel udcToSend) //{ // Task.FromResult(udcSend.InvokeAsync(udcToSend)); //} } }