Files

221 lines
7.6 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.JSInterop;
using Newtonsoft.Json;
using System.Text;
using WebDoorCreator.Data.DbModels;
using WebDoorCreator.Data.Services;
using WebDoorCreator.UI.Data;
using static Org.BouncyCastle.Math.EC.ECCurve;
namespace WebDoorCreator.UI.Pages
{
public partial class HwPdfConfirm
{
#region Protected Fields
protected int doorId = 0;
protected string objectId = "";
#endregion Protected Fields
#region Protected Properties
protected List<DoorOpModel> allDoorOps { get; set; } = new List<DoorOpModel>();
[Inject]
protected IConfiguration config { get; set; } = null!;
protected WebDoorCreator.Data.DDF.Converter currDdfConv { get; set; } = null!;
protected DoorOpModel currDoorOp { get; set; } = new DoorOpModel();
protected int doorOpId { get; set; } = 0;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
[Inject]
protected QueueDataService QDataServ { get; set; } = null!;
protected bool reqConf { get; set; } = false;
protected string userLang
{
get => WDCUService.currLanguage ?? "EN";
set => WDCUService.currLanguage = value;
}
[Inject]
protected WDCRefreshService WDCRService { get; set; } = null!;
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
[Inject]
protected WDCRefreshService WDRService { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected bool checkIfConf()
{
bool answ = false;
if (allDoorOps != null)
{
var rawObj = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(currDoorOp.JsoncActVal!);
if (rawObj != null)
{
foreach (var op in allDoorOps)
{
var opObj = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(op.JsoncActVal!);
if (opObj != null)
{
if (rawObj["template"] == opObj["template"] && op.DtConfirm != null && op.userConfirm != "")
{
answ = true;
}
}
}
}
}
return answ;
}
protected async Task doClose()
{
// ora chiudo!
await Task.Delay(50);
await JSRuntime.InvokeVoidAsync("window.close");
await Task.Delay(50);
}
protected async Task doConfirm()
{
currDoorOp.userConfirm = WDCUService.userId;
currDoorOp.DtConfirm = DateTime.Now;
var doorOps2Save = new List<DoorOpModel>() { currDoorOp };
var done = await WDService.DoorOpUpdate(doorOps2Save);
if (done)
{
// ricalcola!
await refreshSVG();
// piccola attesa..
await Task.Delay(50);
// riporto update...
WDRService.ReportDoorOpConf(doorId, doorOpId, objectId);
// ora chiudo!
await Task.Delay(50);
await JSRuntime.InvokeVoidAsync("window.close");
await Task.Delay(50);
}
}
protected override void OnInitialized()
{
base.OnInitialized();
string vers = config.GetValue<string>("ConfDDF:VersNumber");
bool remDoorOp = config.GetValue<bool>("ConfDDF:RemoveDoorOps");
var headRows = config.GetSection("ConfDDF:Header").Get<List<string>>();
var footRows = config.GetSection("ConfDDF:Footer").Get<List<string>>();
currDdfConv = new WebDoorCreator.Data.DDF.Converter(vers, remDoorOp, headRows, footRows);
}
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
QueryHelpers.ParseQuery(uri.Query).TryGetValue("objectId", out var sObjectId);
if (!string.IsNullOrEmpty(sObjectId))
{
objectId = sObjectId;
}
QueryHelpers.ParseQuery(uri.Query).TryGetValue("doorId", out var sDoorId);
if (!string.IsNullOrEmpty(sDoorId))
{
int.TryParse(sDoorId, out doorId);
}
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("reqConf", out var sReqConf))
{
reqConf = bool.Parse(sReqConf);
}
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("doorOpId", out var sDoorOpId))
{
doorOpId = int.Parse(sDoorOpId);
await ReloadData();
}
}
/// <summary>
/// Effettua generazione DDF + refresh SVG
/// </summary>
/// <returns></returns>
protected async Task refreshSVG()
{
List<DoorOpModel>? listOpAll = await WDService.DoorOpGetByDoorId(doorId);
if (listOpAll != null)
{
List<string> ordListVal = new List<string>();
List<DoorOpModel> listOp = listOpAll.Where(x => x.userConfirm != "" && x.DtConfirm != null).ToList();
if (listOp != null)
{
// chiamo metodo x avere DDF serializzato
var CurrentCompoOrder = await WDService.ListValuesGetAll("*", "Hardware");
if (CurrentCompoOrder != null)
{
foreach (var item in CurrentCompoOrder.OrderBy(x => x.Ordinal).ToList())
{
ordListVal.Add(item.TableName);
}
}
listOp = listOp.OrderBy(d => ordListVal.IndexOf(d.ObjectId)).ToList();
string currDdf = currDdfConv.GetSerialized(listOp);
// versione corrente del DDF generato
int currVers = await QDataServ.SendCalcReq(doorId, currDdf);
}
}
}
protected async Task ReloadData()
{
currDoorOp = await WDService.DoorOpGetById(doorOpId);
docUrl = "Docs/1001.pdf";
if (currDoorOp != null)
{
allDoorOps = await WDService.DoorOpGetByDoorId(currDoorOp.DoorId);
if (currDoorOp.CurrVals.ContainsKey("template"))
{
docUrl = $"docs/{objectId}/{currDoorOp.CurrVals["template"]}.pdf";
}
}
// fin finale caratteri! space Stripe: " " --> "_"
docUrl = docUrl.Replace(" ", "_").Replace(@"\", "/");
}
#endregion Protected Methods
#region Private Fields
private string docUrl = "";
#endregion Private Fields
#region Private Properties
private Dictionary<string, string> heightList { get; set; } = new Dictionary<string, string>() { { "200", "200px" }, { "400", "400px" }, { "600", "600px" }, { "800", "800px" }, { "1000", "1000px" }, { "1200", "1200px" }, { "1400", "1400px" } };
#endregion Private Properties
}
}