using EgwCoreLib.Razor; using Microsoft.AspNetCore.Components; using Newtonsoft.Json.Linq; using System; using WebWindowComplex.Models; using static WebWindowComplex.Json.WindowConst; namespace WebWindowComplex.Compo { public partial class AreaSash { /// /// Sash group corrente /// [CascadingParameter(Name = "CurrSashGroup")] public Sash CurrSashGroup { get; set; } = null!; /// /// Sash dimension corrente /// [Parameter] public SashDimension CurrSashDim { get; set; } = null!; /// /// Lista di ante che si stanno editando /// [Parameter] public List SashDimEditList { get; set; } = null!; /// /// Lista delle sash /// [CascadingParameter(Name = "SashList")] public List SashList { get; set; } = null!; /// /// Livello di accesso (utente base) /// [CascadingParameter(Name = "User")] public bool User { get; set; } = false!; /// /// Indice della sash corrente /// [Parameter] public int IndexSash { get; set; } = 0; /// /// Evento per aggiornare sash dimension /// [Parameter] public EventCallback EC_UpdateSashDim { get; set; } /// /// Evento per aggiornare sash /// [Parameter] public EventCallback EC_UpdateSash { get; set; } /// /// Evento per cambiare modalità di visualizzazione /// [Parameter] public EventCallback EC_EditView { get; set; } /// /// Evento per richiedere reset dizionari /// [Parameter] public EventCallback EC_ReqResetDict { get; set; } /// /// Anta corrente /// public Area CurrAnta { get { if (CurrSashGroup.AreaList[IndexSash] is Splitted) { return CurrSashGroup.AreaList[IndexSash]; } else { return CurrSashGroup; } } set { CurrAnta = value; } } /// /// Metodo per avere il numero di decimali da usare nella form-input /// /// public int CssDecimals() { switch (CurrSashDim.MeasureType) { case Json.WindowConst.MeasureTypes.ABSOLUTE: { return 2; } case Json.WindowConst.MeasureTypes.PROPORTIONAL: { return 0; } case Json.WindowConst.MeasureTypes.PERCENTAGE: { return 1; } } return 0; } ///// ///// Metodo per avere il lo step da usare nella form-input ///// ///// //public double CssStepNumber() //{ // switch (CurrSashDim.MeasureType) // { // case Json.WindowConst.MeasureTypes.ABSOLUTE: // { // return 0.5; // } // case Json.WindowConst.MeasureTypes.PROPORTIONAL: // { // return 1; // } // case Json.WindowConst.MeasureTypes.PERCENTAGE: // { // return 0.5; // } // } // return 0; //} /// /// Selezione tipo di apertura anta /// protected int OpeningTypeIndex { get => CurrSashDim.SelOpeningTypeIndex; set { if (CurrSashDim.SelOpeningTypeIndex != value) { _ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetHwOpt }); CurrSashDim.SelOpeningTypeIndex = value; _ = EC_UpdateSashDim.InvokeAsync(CurrSashDim); } } } /// /// Selezione tipo di misura della dimensione dell'anta /// protected int MeasureTypeIndex { get => CurrSashDim.SelMeasureTypeIndex; set { if (CurrSashDim.SelMeasureTypeIndex != value) { CurrSashDim.SelMeasureTypeIndex = value; _ = EC_UpdateSashDim.InvokeAsync(CurrSashDim); } } } /// /// Inserimento dimensione anta /// protected double Dimension { get => CurrSashDim.dDimension; set { if (CurrSashDim.dDimension != value) { CurrSashDim.dDimension = (double)Math.Round((decimal)value, CssDecimals()); _ = EC_UpdateSashDim.InvokeAsync(CurrSashDim); } } } /// /// Sollevo evento richiesta per cambiare tutti i Joint /// /// Tipo di giunto che si vuole /// private Task ChangeAllJoints(Json.WindowConst.Joints JointType) { foreach (var item in CurrSashDim.JointList) item.SetSelJointType(JointType); return EC_UpdateSashDim.InvokeAsync(CurrSashDim); } /// /// Aggiornamento joint /// /// Tipo di giunto che si vuole /// private async Task UpdateJoint(Joint updRec) { // cerco il record var currRec = CurrSashDim.JointList.FirstOrDefault(x => x.ParentArea == updRec.ParentArea && x.nIndex == updRec.nIndex); // lo aggiorno if (updRec != null) { currRec = updRec; await EC_UpdateSashDim.InvokeAsync(CurrSashDim); } } /// /// Aggiornamento element /// /// Tipo di giunto che si vuole /// private async Task UpdateElement(ElementDimension updRec) { // cerco il record var currRec = CurrSashDim.ElementDimensionList.FirstOrDefault(x => x.ParentArea == updRec.ParentArea && x.nIndex == updRec.nIndex); // lo aggiorno if (updRec != null) { currRec = updRec; await EC_UpdateSashDim.InvokeAsync(CurrSashDim); } } /// /// Metodo per cambiare l'anta su cui è presente la maniglia /// /// private Task ChangeHandle() { // Cerco la Sash che si sta considerando nella lista Sash var s = SashList.Where(x => x.GroupId == CurrSashGroup.GroupId).FirstOrDefault(); if (s != null) { // Setto la presenza o meno della maniglia per ogni anta foreach (SashDimension item in s.SashList) { if (item.Equals(CurrSashDim)) { item.bHasHandle = true; } else { if (item.bHasHandle) { switch (item.SelOpeningType) { case Openings.TILTTURN_LEFT: { item.SetOpeningType(Openings.TURNONLY_LEFT); break; } case Openings.TILTTURN_RIGHT: { item.SetOpeningType(Openings.TURNONLY_RIGHT); break; } default: { break; } } } item.bHasHandle = false; } } } CurrSashGroup.RefreshHardwareList(); CurrSashGroup.SetFirstHardware(); DataUpdateProfile args = new DataUpdateProfile() { sash = CurrSashGroup, reqProfile = true }; return EC_UpdateSash.InvokeAsync(args); } /// /// Copio contenuto anta da indexCopy a IndexModify /// /// Indice dell'ante di cui voglio copiare contenuto /// Indice dell'ante di cui voglio modificare contenuto /// private Task CopyContentSash(int IndexCopy, int IndexModify) { isOpen = !isOpen; // Anta selezionata Area sashSplitted = CurrSashGroup.AreaList[IndexModify]; // Rimuovo riempimento da anta selezionata sashSplitted.AreaList.RemoveAt(0); // Creo la copia dell'anta scelta Area a; if (CurrSashGroup.AreaList[IndexCopy].AreaList.FirstOrDefault() != null) { a = CurrSashGroup.AreaList[IndexCopy].AreaList.FirstOrDefault()!.Copy(sashSplitted); // Aggiungo copia all'anta selezionata CurrSashGroup.AreaList[IndexModify].AreaList.Add(a); } DataUpdateProfile args = new DataUpdateProfile() { sash = CurrSashGroup, reqProfile = true }; return EC_UpdateSash.InvokeAsync(args); } /// /// Metodo per aggiungere lo split nella singola anta /// /// private Task AddSplitToSash() { CurrAnta.AddSplit(); DataUpdateProfile args = new DataUpdateProfile() { sash = CurrSashGroup, reqProfile = true }; return EC_UpdateSash.InvokeAsync(args); } /// /// Metodo per aggiungere l'inglesina nella singola anta /// /// private Task AddInglesinaToSash() { CurrAnta.AddInglesina(); DataUpdateProfile args = new DataUpdateProfile() { sash = CurrSashGroup, reqProfile = true }; return EC_UpdateSash.InvokeAsync(args); } private bool isOpen = false; private void ToggleDropdown() { isOpen = !isOpen; } /// /// Metodo per determinare la visualizzazione dei pulsanti dei joint /// /// /// private string ButtonJointCss(Json.WindowConst.Joints type) { foreach (var item in CurrSashDim.JointList) { if (!item.SelJointType.Equals(type)) return "btn btn-outline-secondary btn-sm"; } return "btn btn-secondary btn-sm"; } private enum ModeView { NULL = 0, View = 1, Edit = 2 } protected override void OnParametersSet() { //if (EditMode) // mode = ModeView.Edit; //else // mode = ModeView.View; } private ModeView mode { get; set; } = ModeView.View; private void doEdit(int index) { var args = new DataChangeMode { //Edit = true, IndexSashEdit = index, IndexSashClose = -1 }; _ = EC_EditView.InvokeAsync(args); } protected void ClosePopup(int index) { var args = new DataChangeMode { //Edit = false, IndexSashEdit = -1, IndexSashClose = index }; _ = EC_EditView.InvokeAsync(args); } } public class DataChangeMode { public bool Edit { get; set; } public int IndexSashEdit { get; set; } public int IndexSashClose { get; set; } } public class DataUpdateProfile { public Sash sash { get; set; } public bool reqProfile { get; set; } = false; } }