194 lines
5.7 KiB
C#
194 lines
5.7 KiB
C#
using EgwCoreLib.Utils;
|
|
using Microsoft.AspNetCore.Components;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
using System.Linq;
|
|
using Core.Models;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace LiMan.UI.Components
|
|
{
|
|
public partial class TargetSetup
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string TargetListRaw { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public EventCallback<string> EC_SaveConfig { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
protected bool RemoteCallActive { get; set; } = false;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
private string CodTipoApp = "";
|
|
|
|
protected void DoReset()
|
|
{
|
|
ReloadData(true);
|
|
}
|
|
|
|
protected async Task DoSave()
|
|
{
|
|
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler inviare la configurazione corrente al Device? L'operazione verrà messa in coda alle richieste per EgwAppControlCenter ed eseguita appena possibile."))
|
|
return;
|
|
|
|
// preparo versioen serializzata dei dati
|
|
string newData = JsonConvert.SerializeObject(SearchRecords);
|
|
// sollevo evento x chiusura
|
|
await EC_SaveConfig.InvokeAsync(newData);
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData(true);
|
|
}
|
|
|
|
protected void SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
ReloadData(false);
|
|
}
|
|
|
|
protected void SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
ReloadData(false);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool remoteCalling = false;
|
|
private bool ReqSetup = true;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string CodImpiego { get; set; } = "";
|
|
private int currPage { get; set; } = 1;
|
|
private bool isLoading { get; set; } = false;
|
|
private List<ControlTarget> ListRecords { get; set; } = new List<ControlTarget>();
|
|
private int numRecord { get; set; } = 10;
|
|
private List<ControlTarget> SearchRecords { get; set; } = new List<ControlTarget>();
|
|
private string SetupPwd { get; set; } = "";
|
|
|
|
private void DeleteRec(ControlTarget rec2del)
|
|
{
|
|
if (rec2del != null)
|
|
{
|
|
SearchRecords.Remove(rec2del);
|
|
// ricalcolo ID record...
|
|
var newList = new List<ControlTarget>();
|
|
int idx = 1;
|
|
foreach (ControlTarget rec in SearchRecords)
|
|
{
|
|
rec.Idx= idx++;
|
|
newList.Add(rec);
|
|
}
|
|
SearchRecords = newList;
|
|
|
|
// aggiorno display
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
private void MoveDown(ControlTarget rec2move)
|
|
{
|
|
if (rec2move != null)
|
|
{
|
|
var otherRec = SearchRecords.FirstOrDefault(x => x.Idx == rec2move.Idx + 1);
|
|
otherRec.Idx--;
|
|
rec2move.Idx++;
|
|
// aggiorno display
|
|
UpdateTable();
|
|
}
|
|
}
|
|
private void MoveUp(ControlTarget rec2move)
|
|
{
|
|
if (rec2move != null)
|
|
{
|
|
var otherRec = SearchRecords.FirstOrDefault(x => x.Idx == rec2move.Idx - 1);
|
|
otherRec.Idx++;
|
|
rec2move.Idx--;
|
|
// aggiorno display
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
private SubLicManager SLicManager { get; set; } = new SubLicManager();
|
|
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void ReloadData(bool forceReload)
|
|
{
|
|
// deserializzo ed assegno...
|
|
if (!string.IsNullOrEmpty(TargetListRaw))
|
|
{
|
|
if (SearchRecords.Count == 0 || forceReload)
|
|
{
|
|
SearchRecords = JsonConvert.DeserializeObject<List<ControlTarget>>(TargetListRaw);
|
|
}
|
|
}
|
|
UpdateTable();
|
|
}
|
|
|
|
private void UpdateTable()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = new List<ControlTarget>();
|
|
totalCount = SearchRecords.Count;
|
|
ListRecords = SearchRecords
|
|
.OrderBy(x => x.Idx)
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void AddNewTarget()
|
|
{
|
|
//await Task.Delay(1);
|
|
//isLoading = true;
|
|
//await InvokeAsync(StateHasChanged);
|
|
// aggiungo un record popolato secondo tipo con il primo codice libero...
|
|
ControlTarget newRec = new ControlTarget()
|
|
{
|
|
Idx = totalCount + 1,
|
|
ApplicationType = CodTipoApp,
|
|
BasePath = "C:\\ProgramData\\",
|
|
IsEnabled = CodTipoApp == "LicenceApp" || CodTipoApp == "Machine" || CodTipoApp == "WinApp",
|
|
UpdateEnabled = CodTipoApp == "WinApp"
|
|
};
|
|
// aggiungo..
|
|
SearchRecords.Add(newRec);
|
|
// torno a pag 1...
|
|
currPage = 1;
|
|
UpdateTable();
|
|
|
|
//isLoading = false;
|
|
//await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |