255 lines
7.6 KiB
C#
255 lines
7.6 KiB
C#
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Compo.Item
|
|
{
|
|
public partial class SellingItemMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<SellingItemModel?> 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 void OnInitialized()
|
|
{
|
|
ConfInit();
|
|
//base.OnInitialized();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (!SelFilt.Equals(actFilt) || true)
|
|
{
|
|
actFilt = SelFilt;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private FiltSelect actFilt = new FiltSelect();
|
|
|
|
private List<SellingItemModel> AllRecords = new List<SellingItemModel>();
|
|
|
|
/// <summary>
|
|
/// URL di base API server
|
|
/// </summary>
|
|
private string apiUrl = "";
|
|
|
|
/// <summary>
|
|
/// Base path x network share files
|
|
/// </summary>
|
|
private string basePath = "unsafe_uploads";
|
|
|
|
private int currPage = 1;
|
|
|
|
private SellingItemModel? editRecord = null;
|
|
|
|
/// <summary>
|
|
/// Path base img
|
|
/// </summary>
|
|
private string imgBasePath = "";
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<SellingItemModel> ListRecords = new List<SellingItemModel>();
|
|
|
|
private int numRecord = 10;
|
|
|
|
private SellingItemModel? selRecord = null;
|
|
|
|
private int totalCount = 0;
|
|
|
|
private BootstrapModal Modal = new();
|
|
private string mTitle = "";
|
|
private string mMessage = "";
|
|
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
|
|
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IConfiguration Config { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IImageCacheService ICService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private ISellingItemService SIService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private string checkSel(SellingItemModel curRec)
|
|
{
|
|
return (selRecord != null && curRec.SellingItemID == selRecord.SellingItemID) ? "table-info" : "";
|
|
}
|
|
|
|
private void ConfInit()
|
|
{
|
|
basePath = Config.GetValue<string>("ServerConf:FileSharePath") ?? "unsafe_uploads";
|
|
apiUrl = Config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "";
|
|
imgBasePath = Config.GetValue<string>("ServerConf:ImageBaseUrl") ?? "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clona articolo
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private void DoClone(SellingItemModel curRec)
|
|
{
|
|
editRecord = new SellingItemModel()
|
|
{
|
|
Cost = curRec.Cost,
|
|
Description = $"{curRec.Description} - CLONE",
|
|
Envir = curRec.Envir,
|
|
ExtItemCode = curRec.ExtItemCode,
|
|
IsService = curRec.IsService,
|
|
ItemCode = curRec.ItemCode,
|
|
ItemSteps = curRec.ItemSteps,
|
|
JobID = curRec.JobID,
|
|
Margin = curRec.Margin,
|
|
SerStruct = curRec.SerStruct,
|
|
SourceType = curRec.SourceType,
|
|
SupplCode = curRec.SupplCode,
|
|
UM = curRec.UM
|
|
};
|
|
}
|
|
|
|
private string doCloneCss(SellingItemModel item)
|
|
{
|
|
return item.SourceType == Enums.ItemSourceType.ND ? "btn-warning" : "btn-success";
|
|
}
|
|
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
private async Task DoDelete(SellingItemModel selRec)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Sicuro di voler eliminare il record?\n " +
|
|
$" Dettagli: {selRec.SellingItemID} | {selRec.Envir} | {selRec.ExtItemCode} | {selRec.Description}";
|
|
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.SellingItemDeleteAsync(selRec);
|
|
|
|
editRecord = null;
|
|
selRecord = null;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private Task DoEdit(SellingItemModel curRec)
|
|
{
|
|
editRecord = curRec;
|
|
selRecord = curRec;
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
private Task DoReset()
|
|
{
|
|
selRecord = null;
|
|
editRecord = null;
|
|
return EC_EditReq.InvokeAsync(editRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private async Task DoSelect(SellingItemModel curRec)
|
|
{
|
|
await DoReset();
|
|
selRecord = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcola src immagine direttamente da modello dati + base path
|
|
/// </summary>
|
|
/// <param name="imgUrl"></param>
|
|
/// <returns></returns>
|
|
private string imgSrc(string imgUrl)
|
|
{
|
|
return $"{apiUrl}/{imgBasePath}/{imgUrl}";
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await SIService.GetFiltAsync(actFilt.Envir, actFilt.SourceType);
|
|
// 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 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
|
|
}
|
|
} |