b0804c78e7
- fix calcolo qta - fix display - fix stored ricerca
161 lines
5.3 KiB
C#
161 lines
5.3 KiB
C#
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this
|
|
// file to you under the MIT license.
|
|
using MagMan.Data.Admin.DbModels;
|
|
using MagMan.Data.Admin.Services;
|
|
using MagMan.Data.Tenant.DbModels;
|
|
using MagMan.Data.Tenant.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace MagMan.UI.Components
|
|
{
|
|
public partial class MaterialEdit
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public MaterialModel? CurrRecord { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_update { get; set; }
|
|
|
|
[Parameter]
|
|
public bool IsBeamRec { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool IsEditRec { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public int KeyNum { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public int MatType { get; set; } = 0;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TenantService TService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task DoCancel()
|
|
{
|
|
await EC_update.InvokeAsync(true);
|
|
}
|
|
|
|
protected async Task DoSave()
|
|
{
|
|
bool fatto = false;
|
|
await Task.Delay(1);
|
|
// se NON fosse editing PRIMA controllo...
|
|
if (!IsEditRec)
|
|
{
|
|
// verifico SE esista già un materiale uguale x dimensioni / tipo...
|
|
var matList = await TService.MaterialDtoGetAll(KeyNum, false, false);
|
|
if (CurrRecord != null)
|
|
{
|
|
var sameRec = matList
|
|
.Where(x => x.MatCode == CurrRecord.MatCode
|
|
&& x.WMm == CurrRecord.WMm && x.HMm == CurrRecord.HMm)
|
|
.FirstOrDefault();
|
|
if (sameRec != null)
|
|
{
|
|
// imposto fatto e mostro errore!
|
|
fatto = true;
|
|
await JSRuntime.InvokeVoidAsync("alert", "Esiste già un record equivalente: modificare dimensioni o materiale per salvare.");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (await execValidation(CurrRecord))
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
CurrRecord.MatDesc = $"{CurrRecord.MatCode} ";
|
|
if (CurrRecord.IsBeam)
|
|
{
|
|
if (TenantService.hasDecimal(CurrRecord.WMm))
|
|
{
|
|
CurrRecord.MatDesc += $"{CurrRecord.WMm:N2}x";
|
|
}
|
|
else
|
|
{
|
|
CurrRecord.MatDesc += $"{CurrRecord.WMm:N0}x";
|
|
}
|
|
}
|
|
if (TenantService.hasDecimal(CurrRecord.HMm))
|
|
{
|
|
CurrRecord.MatDesc += $"{CurrRecord.HMm:N2}";
|
|
}
|
|
else
|
|
{
|
|
CurrRecord.MatDesc += $"{CurrRecord.HMm:N0}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (CurrRecord != null && !fatto)
|
|
{
|
|
fatto = await TService.MaterialUpdate(KeyNum, CurrRecord);
|
|
}
|
|
if (fatto)
|
|
{
|
|
await EC_update.InvokeAsync(true);
|
|
}
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
AliasListAll = await TService.AliasGetFilt(KeyNum, "MatCode");
|
|
// seleziono i distinct valias value
|
|
AliasList = AliasListAll
|
|
.Where(x => x.IsActive)
|
|
.Select(x => x.ValueAlias)
|
|
.Distinct()
|
|
.ToList();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
private List<string> AliasList { get; set; } = new List<string>();
|
|
|
|
private List<AliasModel>? AliasListAll { get; set; } = null;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task<bool> execValidation(MaterialModel thisRec)
|
|
{
|
|
bool fatto = false;
|
|
bool measOk = thisRec.HMm > 0;
|
|
// verifico misure siano coerenti...
|
|
if (IsBeamRec)
|
|
{
|
|
measOk = measOk && thisRec.WMm > 0;
|
|
}
|
|
if (!measOk)
|
|
{
|
|
// imposto fatto e mostro errore!
|
|
fatto = true;
|
|
await JSRuntime.InvokeVoidAsync("alert", "Attenzione: le misure richieste devono essere > 0: aggiornare per salvare.");
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |