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!; /// /// Sash dimension corrente /// [Parameter] public bool EditMode { get; set; } = false; /// /// Indice della sash corrente /// [Parameter] public int IndexSash { get; set; } = 0; /// /// Evento per cambiare l'anta su cui � presente la maniglia /// [Parameter] public EventCallback EC_ChangeHandle { get; set; } /// /// Evento per aggiornare sash dimension /// [Parameter] public EventCallback EC_UpdateSashDim { get; set; } /// /// Evento per cambiare l'anta su cui � presente la maniglia /// [Parameter] public EventCallback EC_CopyContentSash { get; set; } /// /// Evento per cambiare modalit� di visualizzazione /// [Parameter] public EventCallback EC_EditView { get; set; } /// /// Anta corrente /// public Area CurrAnta { get { if (CurrSashGroup.AreaList[IndexSash] is Splitted) { return CurrSashGroup.AreaList[IndexSash]; } else { return CurrSashGroup; } } set { CurrAnta = value; } } public int CssDecimals() { switch (CurrSashDim.MeasureType) { case Json.WindowConst.MeasureTypes.ABSOLUT: { return 2; } case Json.WindowConst.MeasureTypes.PROPORTIONAL: { return 0; } case Json.WindowConst.MeasureTypes.PERCENTAGE: { return 1; } } return 0; } /// /// Sollevo evento richiesta per cambiare tutti i Joint /// /// private async Task ChangeAllJoints(Json.WindowConst.Joints JointType) { foreach (var item in CurrSashDim.JointList) item.SetSelJointType(JointType); await EC_UpdateSashDim.InvokeAsync(CurrSashDim); } /// /// Report aggiornamento joint /// /// /// 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); } } /// /// Sollevo evento per cambiare l'anta su cui � presente la maniglia /// /// private async Task RaiseChangeHandle(SashDimension sashDim, Sash currSash) { var Args = new DataChangeHandle { currSashDimension = sashDim, currItem = currSash, }; await EC_ChangeHandle.InvokeAsync(Args); } /// /// Sollevo evento per cambiare l'anta su cui � presente la maniglia /// /// private async Task RaiseCopyContentSash(int indexC, int indexM) { isOpen = !isOpen; var Args = new DataCopyContentSash { currItem = CurrSashGroup, indexCopy = indexC, indexModify = indexM, }; await EC_CopyContentSash.InvokeAsync(Args); } private bool isOpen = false; private void ToggleDropdown() { isOpen = !isOpen; } private string ButtonJointCss(WebWindowComplex.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 DataChangeHandle { public SashDimension currSashDimension { get; set; } = null!; public Sash currItem { get; set; } = null!; } public class DataCopyContentSash { public Sash currItem { get; set; } = null!; public int indexCopy { get; set; } = 0; public int indexModify { get; set; } = 0; } }