From 2e00ea39a7d2ab80fe71d93e571126fb5756767e Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Wed, 5 Apr 2023 17:08:14 +0200 Subject: [PATCH] inizio gestione nuova listvalues --- .../Data/WebDoorCreatorService.cs | 120 ++++++++++++++++-- WebDoorCreator.UI/Pages/SuperAdmin.razor.cs | 2 +- 2 files changed, 109 insertions(+), 13 deletions(-) diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index ca471c9..d0e4375 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NLog; using StackExchange.Redis; using System.Diagnostics; @@ -155,6 +156,8 @@ namespace WebDoorCreator.UI.Data string compoName = ""; int numHier = 1; List listGraphicParams = new List(); + List listValues = new List(); + ListValuesTempModel Values = new ListValuesTempModel(); dbController.TestTablesTruncate(); @@ -261,7 +264,13 @@ namespace WebDoorCreator.UI.Data numHead = 1; foreach (var match in lineToSearch) { - listGraphicParams = await GraphicParamsGetAll(file, match, numHead, numPar); + Values = await GraphicParamsGetAll(file, match, numHead, numPar, $"{compoNameSplit[1]}"); + + if (listValues.Where(x => x.TableName == Values.TableName && x.FieldName == Values.FieldName && x.Value == Values.Value).Count() == 0 && Values.TableName != "" && Values.FieldName != "" && Values.Value != "") + { + listValues.Add(Values); + } + numHead++; } @@ -286,7 +295,9 @@ namespace WebDoorCreator.UI.Data } } - fatto = await dbController.DoorOpTypeAddRange(ListObjDOT); + fatto = await dbController.ListValuesAdd(listValues); + //fatto = await dbController.DoorOpTypeAddRange(ListObjDOT); + return fatto; } @@ -544,7 +555,7 @@ namespace WebDoorCreator.UI.Data return dbResult; } - public async Task ListValuesInsert(string rootPath) + public async Task ListValuesLuaNgeInsert(string rootPath) { List values = new List(); string[] dirs = Directory.GetDirectories(rootPath); @@ -577,9 +588,9 @@ namespace WebDoorCreator.UI.Data { TableName = $"{compoCode}".Replace(" ", "_"), FieldName = "Compo", - value = @$"{tName[tName.Length - 1]}\{Path.GetFileName(templateFile)}".Replace(" ", "_"), - label = Path.GetFileName(templateFile).Split(".")[0], - ordinal = ordin + Value = @$"{tName[tName.Length - 1]}\{Path.GetFileName(templateFile)}".Replace(" ", "_"), + Label = Path.GetFileName(templateFile).Split(".")[0], + Ordinal = ordin }; values.Add(temp); @@ -729,6 +740,7 @@ namespace WebDoorCreator.UI.Data return answ; } +#if false /// /// Setting the graphic parameters for components /// @@ -737,15 +749,16 @@ namespace WebDoorCreator.UI.Data /// /// /// - public async Task> GraphicParamsGetAll(string file, string match, int n, int i) + public async Task> GraphicParamsGetAll(string file, string match, int n, int i, string HwCode) { await Task.Delay(1); List listGraphicParams = new List(); IniFile fIni = new IniFile(file); - //estraggo la lista di componenti che sono attive per il cliente - var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); //cerco il contenuto delle sezioni - if (int.Parse(match.Substring(match.Length - 2, 1)) == n) //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 + //cerco il contenuto delle sezioni + var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); + //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 + if (int.Parse(match.Substring(match.Length - 2, 1)) == n) { foreach (string param in graphicParamsName) { @@ -762,20 +775,103 @@ namespace WebDoorCreator.UI.Data CompoParamAlias = compoParamsSplit[1].Split("/")[1]; } + //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + + ListValuesTempModel listValObj = new ListValuesTempModel() + { + TableName = HwCode, + FieldName = match.Substring(1, match.Length - 2), + Value = param.Split("=")[1].Split(";")[1].Split("/")[0], + Label = param.Split("=")[1].Split(";")[1].Split("/")[1], + DefaultVal = param.Split("=")[1].Split(";")[2], + InputType = param.Split("=")[1].Split(";")[0] + }; + GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = CompoParamName, graphicParamAlias = CompoParamAlias, graphicParamType = compoParamsSplit[0], graphicParamDefaultVal = compoParamsSplit[2] }; - listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + listGraphicParams.Add(graphicParams); await dbController.ParamAdd(graphicParams); } else { GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = compoParams }; - listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + listGraphicParams.Add(graphicParams); await dbController.ParamAdd(graphicParams); } } } return listGraphicParams; + } +#endif + + public async Task GraphicParamsGetAll(string file, string match, int n, int i, string HwCode) + { + await Task.Delay(1); + List listValuesTemp = new List(); + ListValuesTempModel listValObj = new ListValuesTempModel(); + + IniFile fIni = new IniFile(file); + //cerco il contenuto delle sezioni + var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); + //controllo se tra numPar numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti numPar parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 + if (int.Parse(match.Substring(match.Length - 2, 1)) == n) + { + foreach (string param in graphicParamsName) + { + string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione + var compoParamsSplit = compoParams.Split(";"); + + string CompoParamName = ""; + string CompoParamAlias = ""; + if (param.Split("=")[0].StartsWith("Param")) + { + if (compoParamsSplit[1].Contains("/")) + { + CompoParamName = compoParamsSplit[1].Split("/")[0]; + CompoParamAlias = compoParamsSplit[1].Split("/")[1]; + } + else if (compoParamsSplit[1].Contains(" ")) + { + CompoParamName = compoParamsSplit[1].Split(" ")[1]; + //CompoParamAlias = compoParamsSplit[1].Split(" ")[1]; + } + + //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + + listValObj = new ListValuesTempModel() + { + TableName = $"{HwCode}_{n}", + FieldName = match.Substring(1, match.Length - 2), + Value = CompoParamName, + Label = CompoParamAlias, + Ordinal = n, + DefaultVal = param.Split("=")[1].Split(";")[2], + InputType = param.Split("=")[1].Split(";")[0] + }; + + if (listValuesTemp.Where(x => x.TableName == listValObj.TableName && x.FieldName == listValObj.FieldName && x.Value == listValObj.Value).Count() == 0 && listValObj.TableName != "" && listValObj.FieldName != "" && listValObj.Value != "") + { + listValuesTemp.Add(listValObj); + } + else + { + Log.Error($"GraphicParamsGetAll | Duplicated key: {listValObj.TableName} {listValObj.FieldName} {listValObj.Value} "); + } + + //GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = CompoParamName, graphicParamAlias = CompoParamAlias, graphicParamType = compoParamsSplit[0], graphicParamDefaultVal = compoParamsSplit[2] }; + //listGraphicParams.Add(graphicParams); + //await dbController.ParamAdd(graphicParams); + } + else + { + //GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = compoParams }; + //listGraphicParams.Add(graphicParams); + //await dbController.ParamAdd(graphicParams); + } + } + } + + return listValObj; } /// diff --git a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs index 9ccb2c3..870f590 100644 --- a/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs +++ b/WebDoorCreator.UI/Pages/SuperAdmin.razor.cs @@ -302,7 +302,7 @@ namespace WebDoorCreator.UI.Pages protected async Task refreshFiles() { await Task.Delay(1); - await WDService.ListValuesInsert(@$"{defaultPath}"); + await WDService.ListValuesLuaNgeInsert(@$"{defaultPath}"); } } } \ No newline at end of file