Files
webdoorcreator/WebDoorCreator.UI/Components/Hardware/HardwareNewPanel.razor.cs
T
zaccaria.majid 56349c02a5 Fix gestione hw
2023-04-06 18:03:23 +02:00

113 lines
3.7 KiB
C#

using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using WebDoorCreator.Data;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.UI.Data;
namespace WebDoorCreator.UI.Components.Hardware
{
public partial class HardwareNewPanel
{
//[Parameter]
//public int DoorTypeTypeId { get; set; } = 0;
[Parameter]
public string HwCode { get; set; } = "";
[Parameter]
public int DoorId { get; set; } = 0;
[Parameter]
public bool HwAdded { get; set; } = false;
[Parameter]
public string Lingua { get; set; } = "EN";
[Inject]
protected WebDoorCreatorService WDCService { get; set; } = null!;
[Inject]
protected WDCVocabularyService WDVService { get; set; } = null!;
protected List<DoorOpModel>? ListRecord { get; set; } = null!;
protected List<DoorOpModel>? DoorOp { get; set; } = null!;
//protected DoorOpModel? DoorOp { get; set; } = null!;
//protected List<GraphicParamsModel> graphicParams { get; set; } = null!;
protected Dictionary<string, Dictionary<int, string>> graphicParams { get; set; } = null!;
protected List<ListValuesModel> listValuesGP { get; set; } = null!;
protected List<ListValuesModel>? listValues { get; set; } = null!;
protected List<ListValuesModel>? listValuesFname { get; set; } = null!;
protected override async Task OnParametersSetAsync()
{
await ReloadData(true);
}
private async Task ReloadData(bool isFirst)
{
ListRecord = await WDCService.DoorOpGetByDoorId(DoorId);
var tempListVal = await WDCService.ListValuesGetAll(HwCode, "Compo");
if (ListRecord != null)
{
DoorOp = ListRecord.Where(x => (x.DoorId == DoorId) && (x.ObjectId == HwCode)).ToList();
}
if (tempListVal != null)
{
listValuesFname = tempListVal.Where(x => (x.TableName == HwCode) && (x.Ordinal == 1)).ToList();
if (listValuesFname != null)
{
if (isFirst)
{
folderName = listValuesFname.FirstOrDefault()?.Value.Split(@"\")[0]!;
}
listValues = tempListVal.Where(x => (x.TableName == HwCode) && (x.Value.Contains(folderName))).ToList();
}
}
//listValues = await WDCService.ListValuesGetAll(HwCode, "*");
}
protected string _folderName { get; set; } = "";
protected string folderName
{
get => _folderName;
set
{
if (_folderName != value)
{
_folderName = value;
var pUpd = Task.Run(async () => await ReloadData(false));
}
}
}
public Dictionary<string, Dictionary<int, string>> getGraphicParams()
{
if (DoorOp != null && listValues != null)
{
var param = DoorOp.Where(x => x.ObjectId == HwCode).FirstOrDefault();
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<int, string>>>(param?.JsoncConfigVal!);
if (deserialized != null)
{
graphicParams = deserialized;
}
//listValuesGP = listValues.Where(x => x.FieldName == "Graphic Parameters1").ToList();
}
return graphicParams;
}
protected string translate(string lemma)
{
string answ = "";
answ = WDVService.Traduci(Lingua, lemma);
return answ;
}
}
}