780c2f42eb
Template: fix display righe cancellabili/non cancellabili
208 lines
6.4 KiB
C#
208 lines
6.4 KiB
C#
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Compo.Item
|
|
{
|
|
public partial class ItemMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<ItemModel?> EC_EditReq { get; set; }
|
|
|
|
[Parameter]
|
|
public List<ItemGroupModel> ListItemGroup { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public FiltSelect SelFilt { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (!SelFilt.Equals(actFilt) || true)
|
|
{
|
|
actFilt = SelFilt;
|
|
currPage = 1;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private FiltSelect actFilt = new FiltSelect();
|
|
private List<ItemModel> AllRecords = new List<ItemModel>();
|
|
private int currPage = 1;
|
|
private ItemModel? editRecord = null;
|
|
private bool isLoading = false;
|
|
private List<ItemModel> ListRecords = new List<ItemModel>();
|
|
|
|
private string mMessage = "";
|
|
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
|
|
private BootstrapModal Modal = new();
|
|
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
private string mTitle = "";
|
|
private int numRecord = 10;
|
|
|
|
private ItemModel? selRecord = null;
|
|
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IItemService IService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private string cloneBtnCss(ItemModel item)
|
|
{
|
|
return item.ItemType == Enums.ItemClassType.Bom ? "btn-warning" : "btn-success";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona articolo
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private Task DoClone(ItemModel curRec)
|
|
{
|
|
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
|
|
};
|
|
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
private async Task DoDelete(ItemModel selRec)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Sicuro di voler eliminare il record?\n" +
|
|
$"Dettagli: {selRec.ItemID} | {selRec.CodGroup} | {selRec.ItemType} | {selRec.ExtItemCode}";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
//// esegue eliminazione del record...
|
|
//await CDService.ItemDeleteAsync(selRec);
|
|
|
|
editRecord = null;
|
|
selRecord = null;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private Task DoEdit(ItemModel curRec)
|
|
{
|
|
editRecord = curRec;
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
private Task DoReset()
|
|
{
|
|
editRecord = null;
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private void DoSelect(ItemModel curRec)
|
|
{
|
|
selRecord = curRec;
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await IService.GetFiltAsync(actFilt.SelCodGroup, actFilt.SelType);
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (!string.IsNullOrEmpty(actFilt.SearchVal))
|
|
{
|
|
AllRecords = AllRecords
|
|
.Where(x =>
|
|
x.Description.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.ExtItemCode.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.SupplCode.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
totalCount = AllRecords.Count;
|
|
}
|
|
|
|
private async Task ResetEdit()
|
|
{
|
|
// reset edit
|
|
editRecord = null;
|
|
await ReloadDataAsync();
|
|
await EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
private void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
private void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |