266 lines
7.7 KiB
C#
266 lines
7.7 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using Newtonsoft.Json;
|
|
using WebDoorCreator.Data.DbModels;
|
|
using WebDoorCreator.UI.Data;
|
|
|
|
namespace WebDoorCreator.UI.Components.Hardware
|
|
{
|
|
public partial class HwSingleInstance
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DoorOpModel DoorOpInst { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string HwCode { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public int instanceN { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public string Lingua { get; set; } = "EN";
|
|
|
|
[CascadingParameter]
|
|
public string userId { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void setupCurrValues()
|
|
{
|
|
//currVal = new Dictionary<string, string>();
|
|
if (!string.IsNullOrEmpty(DoorOpInst.JsoncActVal))
|
|
{
|
|
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, string>>(DoorOpInst.JsoncActVal!);
|
|
var deserializedToComp = JsonConvert.DeserializeObject<Dictionary<string, string>>(DoorOpInst.JsoncActVal!);
|
|
if (deserialized != null)
|
|
{
|
|
currVal = deserialized;
|
|
currValToCompare = deserializedToComp;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setupGraphicParams()
|
|
{
|
|
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(DoorOpInst.JsoncConfigVal!);
|
|
if (deserialized != null)
|
|
{
|
|
graphicParams = deserialized;
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected string _folderName
|
|
{
|
|
get => currVal != null ? currVal["Folder"] : "";
|
|
set => currVal["Folder"] = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Array dati
|
|
/// </summary>
|
|
protected Dictionary<string, string> currVal { get; set; } = null!;
|
|
|
|
protected Dictionary<string, string>? currValToCompare { get; set; }
|
|
|
|
protected string folderName
|
|
{
|
|
get => _folderName;
|
|
set
|
|
{
|
|
if (_folderName != value)
|
|
{
|
|
_folderName = value;
|
|
var pUpd = Task.Run(async () => await ReloadData(false));
|
|
}
|
|
}
|
|
}
|
|
|
|
protected Dictionary<string, List<string>> graphicParams { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected List<ListValuesModel>? listValuesFiles { get; set; } = null!;
|
|
|
|
protected List<ListValuesModel>? listValuesFname { get; set; } = null!;
|
|
|
|
protected string templateName
|
|
{
|
|
get => currVal != null ? currVal["Template"] : "";
|
|
set
|
|
{
|
|
currVal["Template"] = value;
|
|
DoorOpInst.userConfirm = "";
|
|
DoorOpInst.DtConfirm = null;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected WebDoorCreatorService WDCService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected WDCVocabularyService WDVService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected WDCCurrDataService CamDataServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected List<string> comboSet(string pKey)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
if (graphicParams.ContainsKey(pKey))
|
|
{
|
|
answ = graphicParams[pKey].ToList();
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task doCancel()
|
|
{
|
|
await FullReloadData(true);
|
|
}
|
|
|
|
protected bool doCheckVal()
|
|
{
|
|
bool answ = false;
|
|
if (currValToCompare != null)
|
|
{
|
|
foreach (var k in currVal)
|
|
{
|
|
if (currValToCompare != null)
|
|
{
|
|
if (k.Value != currValToCompare[k.Key])
|
|
{
|
|
answ = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task doClone()
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
DoorOpModel doorOpToAdd = new DoorOpModel()
|
|
{
|
|
DateIns = adesso,
|
|
DateMod = adesso,
|
|
UserIdIns = userId,
|
|
UserIdMod = userId,
|
|
ObjectId = DoorOpInst.ObjectId,
|
|
DoorId = DoorOpInst.DoorId,
|
|
JsoncConfigVal = DoorOpInst.JsoncConfigVal,
|
|
JsoncActVal = DoorOpInst.JsoncActVal,
|
|
userConfirm = DoorOpInst.userConfirm,
|
|
DtConfirm = DoorOpInst.DtConfirm
|
|
};
|
|
|
|
List<DoorOpModel> doorOpAddList = new List<DoorOpModel>() { doorOpToAdd };
|
|
// salvo!
|
|
await WDCService.DoorOpInsert(DoorOpInst.DoorId, doorOpAddList);
|
|
await FullReloadData(true);
|
|
}
|
|
|
|
protected async Task doConfirm()
|
|
{
|
|
DoorOpInst.userConfirm = userId;
|
|
DoorOpInst.DtConfirm = DateTime.Now;
|
|
// salvo!
|
|
await WDCService.DoorOpUpdate(DoorOpInst);
|
|
}
|
|
|
|
protected async Task doDeleteInst()
|
|
{
|
|
var done = await JSRuntime.InvokeAsync<bool>("confirm", "Delete PERMANENTLY the current record?");
|
|
|
|
if (done)
|
|
{
|
|
await WDCService.DoorOpDelete(DoorOpInst);
|
|
await FullReloadData(true);
|
|
}
|
|
}
|
|
|
|
protected async Task doSave()
|
|
{
|
|
// ri-serializzo i graphics parameters...
|
|
string serVal = JsonConvert.SerializeObject(currVal);
|
|
DoorOpInst.JsoncActVal = serVal;
|
|
// salvo!
|
|
await WDCService.DoorOpUpdate(DoorOpInst);
|
|
await CamDataServ.sendCalcReq($"ORD{DoorOpInst.DoorId:00000}");
|
|
// rileggo
|
|
await FullReloadData(true);
|
|
}
|
|
|
|
protected bool isCombo(string pKey)
|
|
{
|
|
bool answ = false;
|
|
if (graphicParams.ContainsKey(pKey))
|
|
{
|
|
answ = graphicParams[pKey].Count > 1;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await FullReloadData(true);
|
|
}
|
|
|
|
protected string translate(string lemma)
|
|
{
|
|
string answ = "";
|
|
|
|
answ = WDVService.Traduci(Lingua, lemma);
|
|
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
private async Task FullReloadData(bool isFirst)
|
|
{
|
|
setupCurrValues();
|
|
setupGraphicParams();
|
|
await ReloadData(isFirst);
|
|
}
|
|
|
|
private async Task ReloadData(bool isFirst)
|
|
{
|
|
var tempListVal = await WDCService.ListValuesGetAll(HwCode, "Folder");
|
|
if (tempListVal != null)
|
|
{
|
|
listValuesFname = tempListVal;
|
|
if (listValuesFname != null)
|
|
{
|
|
if (isFirst)
|
|
{
|
|
folderName = listValuesFname.FirstOrDefault()?.Label!;
|
|
}
|
|
var tempListFiles = await WDCService.ListValuesGetAll(HwCode, "Template");
|
|
|
|
if (tempListFiles != null)
|
|
{
|
|
listValuesFiles = tempListFiles.Where(x => x.Value.Contains(folderName)).ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |