347 lines
9.4 KiB
C#
347 lines
9.4 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data.DbModels;
|
|
using MP.SPEC.Data;
|
|
|
|
namespace MP.SPEC.Pages
|
|
{
|
|
public partial class KIT : ComponentBase, IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public string checkSelect(TemplateKitModel currRec)
|
|
{
|
|
string answ = "";
|
|
#if false
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.CodArticolo == CodArticolo) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
currRecord = null;
|
|
ListTipoArt = null;
|
|
ListAziende = null;
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
protected string sChildCss
|
|
{
|
|
get => string.IsNullOrEmpty(sCodChild) ? "btn-secondary" : "btn-primary";
|
|
}
|
|
|
|
protected string SearchChild
|
|
{
|
|
get => sCodChild;
|
|
set
|
|
{
|
|
// salvo solo se minChar+ chars
|
|
if (value.Length >= minChar || string.IsNullOrEmpty(value))
|
|
{
|
|
if (sCodChild != value)
|
|
{
|
|
sCodChild = value;
|
|
currPage = 1;
|
|
#if false
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
ListRecords = null;
|
|
await Task.Delay(1);
|
|
await ReloadData();
|
|
});
|
|
pUpd.Wait();
|
|
#endif
|
|
ListRecords = null;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string SearchParent
|
|
{
|
|
get => sCodParent;
|
|
set
|
|
{
|
|
// salvo solo se minChar+ chars
|
|
if (value.Length >= minChar || string.IsNullOrEmpty(value))
|
|
{
|
|
if (sCodParent != value)
|
|
{
|
|
sCodParent = value;
|
|
currPage = 1;
|
|
ListRecords = null;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string sParentCss
|
|
{
|
|
get => string.IsNullOrEmpty(sCodParent) ? "btn-secondary" : "btn-primary";
|
|
}
|
|
|
|
protected int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (SearchRecords != null)
|
|
{
|
|
answ = SearchRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Crea nuovo record e va in editing...
|
|
/// </summary>
|
|
/// <param name="AutoGen">Genera codice numerico in automatico da counter</param>
|
|
/// <returns></returns>
|
|
protected async Task DoAddNew(bool AutoGen)
|
|
{
|
|
// imposto a ricerca x iniziare
|
|
string codParent = SearchParent;
|
|
// se deve essere autogenerato da counter...
|
|
if (AutoGen)
|
|
{
|
|
var cntRec = MDService.AnagCountersGetNext("NumKitArt");
|
|
if (cntRec != null)
|
|
{
|
|
codParent = $"{cntRec.CntCode}{cntRec.LastNum:000000}";
|
|
}
|
|
else
|
|
{
|
|
codParent = "";
|
|
}
|
|
}
|
|
currRecord = new TemplateKitModel()
|
|
{
|
|
CodArtParent = codParent,
|
|
CodArtChild = "",
|
|
Qty = 1
|
|
};
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected async Task DoCancel()
|
|
{
|
|
currRecord = null;
|
|
ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected async Task DoClone(TemplateKitModel selRec)
|
|
{
|
|
// creo record duplicato...
|
|
TemplateKitModel newRec = new TemplateKitModel()
|
|
{
|
|
CodArtParent = selRec.CodArtParent,
|
|
CodArtChild = "",//selRec.CodArtParent,
|
|
Qty = selRec.Qty
|
|
};
|
|
currRecord = newRec;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione record selezionato (previa conferma)
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
protected async Task DoDelete(TemplateKitModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Eliminazione riga KIT: sei sicuro di voler procedere?"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
var done = await MDService.TemplateKitDelete(selRec);
|
|
currRecord = null;
|
|
ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected async Task DoUpdate(TemplateKitModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confermi di voler salvare le modifiche?"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
var done = await MDService.TemplateKitUpsert(selRec);
|
|
currRecord = null;
|
|
ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
numRecord = 10;
|
|
string rawVal = MDService.ConfigTryGet("SPEC_nArtSearch");
|
|
if (!string.IsNullOrEmpty(rawVal))
|
|
{
|
|
int.TryParse(rawVal, out minChar);
|
|
}
|
|
rawVal = MDService.ConfigTryGet("SPEC_Kit_enabCount");
|
|
if (!string.IsNullOrEmpty(rawVal))
|
|
{
|
|
bool.TryParse(rawVal, out enabKitCount);
|
|
}
|
|
rawVal = MDService.ConfigTryGet("SPEC_Kit_enabSearch");
|
|
if (!string.IsNullOrEmpty(rawVal))
|
|
{
|
|
bool.TryParse(rawVal, out enabKitSearch);
|
|
}
|
|
ListAziende = await MDService.ElencoAziende();
|
|
ListTipoArt = await MDService.AnagTipoArtLV();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
}
|
|
|
|
protected void ResetChild()
|
|
{
|
|
SearchChild = "";
|
|
ReloadData();
|
|
}
|
|
|
|
protected void ResetData()
|
|
{
|
|
currRecord = null;
|
|
}
|
|
|
|
protected void ResetParent()
|
|
{
|
|
SearchParent = "";
|
|
ReloadData();
|
|
}
|
|
|
|
protected void ResetSel()
|
|
{
|
|
currRecord = null;
|
|
}
|
|
|
|
protected void SelRecord(TemplateKitModel selRec)
|
|
{
|
|
currRecord = selRec;
|
|
}
|
|
|
|
protected void SetNumPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected void SetNumRec(int newNum)
|
|
{
|
|
currPage = 1;
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void UpdateData()
|
|
{
|
|
currRecord = null;
|
|
ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private TemplateKitModel? currRecord = null;
|
|
private bool enabKitCount = false;
|
|
private bool enabKitSearch = false;
|
|
private List<AnagGruppi>? ListAziende;
|
|
private List<TemplateKitModel>? ListRecords;
|
|
private List<ListValues>? ListTipoArt;
|
|
private int minChar = 2;
|
|
private string sCodChild = "";
|
|
private List<TemplateKitModel>? SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
private int _numRecord { get; set; } = 10;
|
|
|
|
private int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string sCodParent { get; set; } = "";
|
|
private bool ShowCharts { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = MDService.TemplateKitFilt(SearchParent, SearchChild);
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |