285 lines
7.9 KiB
C#
285 lines
7.9 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Data.DbModel.Utils;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace Lux.UI.Components.Compo
|
|
{
|
|
public partial class GenValMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<GenClassModel> ListGenClass { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public FiltSelect SelFilt { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Classes
|
|
|
|
/// <summary>
|
|
/// Filtro selezione items
|
|
/// </summary>
|
|
public class FiltSelect
|
|
{
|
|
#region Public Properties
|
|
|
|
public string SearchVal { get; set; } = "";
|
|
public string SelCodGroup { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj == null)
|
|
return false;
|
|
if (!(obj is FiltSelect item))
|
|
return false;
|
|
|
|
if (SelCodGroup != item.SelCodGroup)
|
|
return false;
|
|
|
|
if (SearchVal != item.SearchVal)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
|
|
#endregion Public Classes
|
|
|
|
#region Protected Fields
|
|
|
|
protected List<GenValueModel> AllRecords = new List<GenValueModel>();
|
|
protected List<GenValueModel> ListRecords = new List<GenValueModel>();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Clona record
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoClone(GenValueModel curRec)
|
|
{
|
|
#if false
|
|
editRecord = new ItemModel()
|
|
{
|
|
ItemIDParent = curRec.ItemType == Enums.ItemClassType.Bom ? curRec.ItemID : curRec.ItemIDParent,
|
|
CodGroup = curRec.CodGroup,
|
|
ItemType = curRec.ItemType == Enums.ItemClassType.Bom ? Enums.ItemClassType.BomAlt : curRec.ItemType,
|
|
IsService = curRec.IsService,
|
|
ItemCode = curRec.ItemCode,
|
|
ExtItemCode = $"{curRec.ExtItemCode} - COPY",
|
|
SupplCode = curRec.ItemType == Enums.ItemClassType.Bom ? $"{curRec.SupplCode} ALT" : curRec.SupplCode,
|
|
Description = $"{curRec.Description} - COPY",
|
|
Cost = curRec.Cost,
|
|
Margin = curRec.Margin,
|
|
QtyMin = curRec.QtyMin,
|
|
QtyMax = curRec.QtyMax,
|
|
UM = curRec.UM
|
|
};
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
protected async Task DoDelete(GenValueModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.ClassCod} | {selRec.ValString}"))
|
|
return;
|
|
|
|
// esegue eliminazione del record...
|
|
await DLService.GenValDeleteAsync(selRec);
|
|
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
#if false
|
|
// segnalo update x reload
|
|
await EC_Updated.InvokeAsync(true);
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoEdit(GenValueModel curRec)
|
|
{
|
|
EditRecord = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
protected void DoReset()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoSelect(GenValueModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (!SelFilt.Equals(actFilt) || true)
|
|
{
|
|
actFilt = SelFilt;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
protected void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private FiltSelect actFilt = new FiltSelect();
|
|
|
|
private int currPage = 1;
|
|
|
|
private GenValueModel? EditRecord = null;
|
|
|
|
private bool isLoading = false;
|
|
|
|
private int numRecord = 10;
|
|
|
|
private GenValueModel? SelRecord = null;
|
|
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private async Task DoAdd()
|
|
{
|
|
// aggiungo un nuovo record in coda...
|
|
EditRecord = new GenValueModel()
|
|
{
|
|
ClassCod = actFilt.SelCodGroup,
|
|
ValString = $"Nuovo-{DateTime.Now:yy.MM.ss HH.mm.ss}",
|
|
Index = totalCount + 1
|
|
};
|
|
await DoSave(EditRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue spostamento
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
/// <param name="moveUp"></param>
|
|
/// <returns></returns>
|
|
private async Task MoveRec(GenValueModel curRec, bool moveUp)
|
|
{
|
|
await DLService.GenValMoveAsync(curRec, moveUp);
|
|
await DoCancel();
|
|
}
|
|
|
|
private async Task DoCancel()
|
|
{
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
}
|
|
|
|
private async Task DoSave(GenValueModel currRec)
|
|
{
|
|
// salvo
|
|
await DLService.GenValUpsertAsync(currRec);
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await DLService.GenValGetFiltAsync(actFilt.SelCodGroup);
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (string.IsNullOrEmpty(actFilt.SearchVal))
|
|
{
|
|
AllRecords = AllRecords
|
|
.OrderBy(x => x.Index)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
AllRecords = AllRecords
|
|
.Where(x =>
|
|
x.ClassCod.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.ValString.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.OrderBy(x => x.Index)
|
|
.ToList();
|
|
}
|
|
totalCount = AllRecords.Count;
|
|
}
|
|
|
|
private async Task ResetEdit()
|
|
{
|
|
// reset edit
|
|
EditRecord = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |