Files
2026-01-19 10:29:50 +01:00

276 lines
8.0 KiB
C#

using EgwCoreLib.Razor;
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json.Linq;
using System;
using WebWindowTest.Models;
using static WebWindowTest.Json.WindowConst;
namespace WebWindowTest.Compo
{
public partial class AreaSash
{
/// <summary>
/// Sash group corrente
/// </summary>
[CascadingParameter(Name = "CurrSashGroup")]
public Sash CurrSashGroup { get; set; } = null!;
/// <summary>
/// Sash dimension corrente
/// </summary>
[Parameter]
public SashDimension CurrSashDim { get; set; } = null!;
/// <summary>
/// Lista delle sash
/// </summary>
[CascadingParameter(Name = "SashList")]
public List<Sash> SashList { get; set; } = null!;
/// <summary>
/// Modalità di visualizzazione (view /edit)
/// </summary>
[Parameter]
public bool EditMode { get; set; } = false;
/// <summary>
/// Indice della sash corrente
/// </summary>
[Parameter]
public int IndexSash { get; set; } = 0;
/// <summary>
/// Evento per aggiornare sash dimension
/// </summary>
[Parameter]
public EventCallback<SashDimension> EC_UpdateSashDim { get; set; }
/// <summary>
/// Evento per aggiornare sash
/// </summary>
[Parameter]
public EventCallback<Sash> EC_UpdateSash { get; set; }
/// <summary>
/// Evento per cambiare modalità di visualizzazione
/// </summary>
[Parameter]
public EventCallback<DataChangeMode> EC_EditView { get; set; }
/// <summary>
/// Anta corrente
/// </summary>
public Area CurrAnta
{
get
{
if (CurrSashGroup.AreaList[IndexSash] is Splitted)
{
return CurrSashGroup.AreaList[IndexSash];
}
else
{
return CurrSashGroup;
}
}
set
{
CurrAnta = value;
}
}
/// <summary>
/// Metodo per avere il numero di decimali da usare nella form-input
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Metodo per avere il lo step da usare nella form-input
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Selezione tipo di apertura anta
/// </summary>
protected int OpeningTypeIndex
{
get => CurrSashDim.SelOpeningTypeIndex;
set
{
if (CurrSashDim.SelOpeningTypeIndex != value)
{
CurrSashDim.SelOpeningTypeIndex = value;
_ = EC_UpdateSashDim.InvokeAsync(CurrSashDim);
}
}
}
/// <summary>
/// Selezione tipo di misura della dimensione dell'anta
/// </summary>
protected int MeasureTypeIndex
{
get => CurrSashDim.SelMeasureTypeIndex;
set
{
if (CurrSashDim.SelMeasureTypeIndex != value)
{
CurrSashDim.SelMeasureTypeIndex = value;
_ = EC_UpdateSashDim.InvokeAsync(CurrSashDim);
}
}
}
/// <summary>
/// Inserimento dimensione anta
/// </summary>
protected double Dimension
{
get => CurrSashDim.dDimension;
set
{
if (CurrSashDim.dDimension != value)
{
CurrSashDim.dDimension = (double)Math.Round((decimal)value, CssDecimals());
_ = EC_UpdateSashDim.InvokeAsync(CurrSashDim);
}
}
}
/// <summary>
/// Metodo per cambiare l'anta su cui è presente la maniglia
/// </summary>
/// <returns></returns>
private async 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();
await EC_UpdateSash.InvokeAsync(CurrSashGroup);
}
private bool isOpen = false;
private void ToggleDropdown()
{
isOpen = !isOpen;
}
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; }
}
}