468 lines
14 KiB
C#
468 lines
14 KiB
C#
using EgwCoreLib.Razor;
|
|
using MagMan.Core.Services;
|
|
using MagMan.Data.Tenant.DbModels;
|
|
using MagMan.Data.Tenant.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Build.Framework;
|
|
using Microsoft.CodeAnalysis.Differencing;
|
|
using Microsoft.JSInterop;
|
|
using System.Security;
|
|
|
|
namespace MagMan.UI.Components
|
|
{
|
|
public partial class ItemMan : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public int CustomerId { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public EventCallback<RawItemModel> E_RawItemSel { get; set; }
|
|
|
|
[Parameter]
|
|
public int KeyNum { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public MaterialModel MaterialSel
|
|
{
|
|
get => materialSel;
|
|
set
|
|
{
|
|
if (materialSel != value)
|
|
{
|
|
materialSel = value;
|
|
CurrItem = null;
|
|
RawItemId = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected string actMessage
|
|
{
|
|
get => onlyActive ? "Solo Attivi" : "Mostra Eliminati";
|
|
}
|
|
|
|
[Inject]
|
|
protected MessageService AppMService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IConfiguration Configuration { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected bool OnlyActive
|
|
{
|
|
get => onlyActive;
|
|
set
|
|
{
|
|
if (onlyActive != value)
|
|
{
|
|
onlyActive = value;
|
|
DoSelect(null);
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await ForceReload(true);
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string remnMessage
|
|
{
|
|
get => "Mostra Spezzoni";// showRemn ? "Mostra Spezzoni" : "Solo Acquisto";
|
|
}
|
|
|
|
protected bool ShowRemn
|
|
{
|
|
get => showRemn;
|
|
set
|
|
{
|
|
if (showRemn != value)
|
|
{
|
|
showRemn = value;
|
|
DoSelect(null);
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await ForceReload(true);
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected int totalCount { get; set; } = 0;
|
|
|
|
[Inject]
|
|
protected TenantService TService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CheckSel(RawItemModel curItem)
|
|
{
|
|
string answ = "";
|
|
if (CurrItem != null)
|
|
{
|
|
answ = curItem.RawItemId == CurrItem.RawItemId ? "table-info" : "";
|
|
}
|
|
else
|
|
{
|
|
answ = curItem.RawItemId == RawItemId ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task CreateNew()
|
|
{
|
|
string matNote = $"{MaterialSel.MatCode.Replace("_", " ")}";
|
|
if (MaterialSel.IsBeam)
|
|
{
|
|
if (hasDecimal(MaterialSel.WMm) || hasDecimal(MaterialSel.HMm))
|
|
{
|
|
matNote += $" {MaterialSel.WMm:N2}x{MaterialSel.HMm:N2}";
|
|
}
|
|
else
|
|
{
|
|
matNote += $" {MaterialSel.WMm:N0}x{MaterialSel.HMm:N0}";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (hasDecimal(MaterialSel.HMm))
|
|
{
|
|
matNote += $" {MaterialSel.HMm:N2}";
|
|
}
|
|
else
|
|
{
|
|
matNote += $" {MaterialSel.HMm:N0}";
|
|
}
|
|
}
|
|
CurrItem = new RawItemModel()
|
|
{
|
|
MatId = MaterialSel.MatId,
|
|
Location = "nd",
|
|
Note = matNote,
|
|
QtyAvail = 0,
|
|
IsDeleted = false,
|
|
IsRemn = false,
|
|
MaterialNav = MaterialSel,
|
|
HMm = MaterialSel.HMm,
|
|
//LMm = MaterialSel.LMm,
|
|
//WMm = MaterialSel.WMm
|
|
LMm = 100,
|
|
WMm = MaterialSel.IsBeam ? MaterialSel.WMm : 100
|
|
};
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async Task DeleteRecord(RawItemModel selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
await TService.ItemDelete(KeyNum, selItem);
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void DoEdit(RawItemModel? selItem)
|
|
{
|
|
CurrItem = selItem;
|
|
if (selItem == null)
|
|
{
|
|
DoSelect(null);
|
|
}
|
|
}
|
|
|
|
protected void DoSelect(RawItemModel? selItem)
|
|
{
|
|
if (selItem != null)
|
|
{
|
|
RawItemId = selItem.RawItemId;
|
|
}
|
|
else
|
|
{
|
|
RawItemId = 0;
|
|
}
|
|
E_RawItemSel.InvokeAsync(selItem);
|
|
}
|
|
|
|
protected async Task ForceReload(bool force)
|
|
{
|
|
CurrItem = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
currSearch = "";
|
|
AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated;
|
|
numRecord = await AppMService.NumRowGridGet(gridKey);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
CurrItem = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task ReactivRecord(RawItemModel selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler riattivare il record?"))
|
|
return;
|
|
await TService.ItemReactiv(KeyNum, selItem);
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await AppMService.NumRowGridSet(gridKey, newNum);
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SortRequested(Sorter.SortCallBack e)
|
|
{
|
|
sortField = e.ParamName;
|
|
sortAsc = e.IsAscending;
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private RawItemModel? CurrItem = null;
|
|
|
|
private string currSearch = "";
|
|
|
|
private int filtType = 0;
|
|
|
|
private string gridKey = "ItemMan";
|
|
|
|
private List<RawItemModel>? ListRecords = null;
|
|
|
|
private bool onlyActive = true;
|
|
private int RawItemId = 0;
|
|
private List<RawItemModel>? SearchRecords = null;
|
|
private bool showRemn = false;
|
|
private bool sortAsc = true;
|
|
|
|
private string sortField = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
|
|
private int FiltType
|
|
{
|
|
get => filtType;
|
|
set
|
|
{
|
|
if (filtType != value)
|
|
{
|
|
filtType = value;
|
|
InvokeAsync(ReloadData);
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private MaterialModel materialSel { get; set; } = new MaterialModel();
|
|
|
|
private int numRecord { get; set; } = 10;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void AppMService_EA_SearchUpdated()
|
|
{
|
|
currSearch = AppMService.SearchVal;
|
|
await ReloadData();
|
|
}
|
|
|
|
private bool hasDecimal(decimal num)
|
|
{
|
|
return (num - Math.Round(num) != 0);
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
SearchRecords = await TService.ItemGetByMat(KeyNum, MaterialSel.MatId, OnlyActive);
|
|
// se non rischiesto nascondo i remnant...
|
|
if (!showRemn)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => !x.IsRemn).ToList();
|
|
}
|
|
// verifico filtro per ricerca
|
|
if (!string.IsNullOrEmpty(currSearch))
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => x.Note.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList();
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
SortTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void SortTable()
|
|
{
|
|
if (SearchRecords != null)
|
|
{
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "MovId":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.RawItemId).ThenBy(x => x.Note).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.RawItemId).ThenByDescending(x => x.Note).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Location":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Location).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Location).ToList();
|
|
}
|
|
break;
|
|
|
|
case "QtyAvail":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.QtyAvail).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.QtyAvail).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Note":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Note).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Note).ToList();
|
|
}
|
|
break;
|
|
|
|
case "IsDeleted":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.IsDeleted).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.IsDeleted).ToList();
|
|
}
|
|
break;
|
|
|
|
case "IsRemn":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.IsRemn).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.IsRemn).ToList();
|
|
}
|
|
break;
|
|
|
|
case "W":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.WMm).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.WMm).ToList();
|
|
}
|
|
break;
|
|
|
|
case "H":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.HMm).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.HMm).ToList();
|
|
}
|
|
break;
|
|
|
|
case "L":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.LMm).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.LMm).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// filtro x display
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<RawItemModel>();
|
|
}
|
|
}
|
|
|
|
private string textCss(bool isActive)
|
|
{
|
|
return isActive ? "text-dark" : "text-secondary text-decoration-line-through";
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |