using Microsoft.AspNetCore.Components;
using WebWindowComplex.Models;
using static WebWindowComplex.Json.WindowConst;
using static WebWindowComplex.LayoutConst;
namespace WebWindowComplex.Compo
{
public partial class CardSashGroup
{
#region Public Properties
///
/// Sash corrente rispetto alla lista Sash
///
[CascadingParameter(Name = "CurrSashGroup")]
public Sash CurrSashGroup { get; set; } = null!;
///
/// Livello di accesso (utente base)
///
[CascadingParameter(Name = "User")]
public bool User { get; set; } = false!;
///
/// Evento per cambiare tutti i fill
///
[Parameter]
public EventCallback EC_UpdateFrame { get; set; }
///
/// Evento per tornare nella pagine Tree
///
[Parameter]
public EventCallback EC_ReqClose { get; set; }
///
/// Evento per richiedere reset dizionario Shape
///
[Parameter]
public EventCallback EC_ReqResetDict { get; set; }
///
/// Evento per richiedere opzioni hardware
///
[Parameter]
public EventCallback EC_ReqOptionHw { get; set; }
///
/// Evento per richiedere per la prima volta opzioni hardware
///
[Parameter]
public EventCallback EC_ReqFirstOptionHw { get; set; }
///
/// Evento per segnalare aggiornamento
///
[Parameter]
public EventCallback EC_UpdateSashGroup { get; set; }
///
/// Evento per richiesta profili degli Element
///
[Parameter]
public EventCallback EC_ReqElement { get; set; }
///
/// Lista di sash
///
[CascadingParameter(Name = "SashList")]
public List SashList { get; set; } = null!;
///
/// Frame corrente
///
[Parameter]
public Frame FrameWindow { get; set; } = null!;
#endregion Public Properties
#region Protected Properties
///
/// Selezione quantità di ante
///
protected int SashQty
{
get => CurrSashGroup.nSashQty;
set
{
if (CurrSashGroup.nSashQty != value)
{
CurrSashGroup.nSashQty = value;
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetHwOpt });
var args = new DataUpdateSash()
{
currSash = CurrSashGroup,
svgNoHw = true
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
_ = EC_ReqElement.InvokeAsync(CurrSashGroup);
if(CurrSashGroup.SelHardware.Id != "000000")
_ = EC_ReqOptionHw.InvokeAsync(CurrSashGroup);
}
}
}
///
/// Selezione quantità bottom rail
///
protected int SashBottomRailQty
{
get => CurrSashGroup.SashBottomRailQty;
set
{
if (CurrSashGroup.SashBottomRailQty != value)
{
CurrSashGroup.SashBottomRailQty = value;
if (CurrSashGroup.SashBottomRailQty > 0)
CurrSashGroup.SetSashBottomRail(true);
else
CurrSashGroup.SetSashBottomRail(false);
var args = new DataUpdateSash()
{
currSash = CurrSashGroup
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
}
}
}
///
/// Selezione tipo di orientamento della sash
///
protected int OrientationSashTypeIndex
{
get => CurrSashGroup.SelOrientationSashTypeIndex;
set
{
if (CurrSashGroup.SelOrientationSashTypeIndex != value)
{
CurrSashGroup.SelOrientationSashTypeIndex = value;
var args = new DataUpdateSash()
{
currSash = CurrSashGroup
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
}
}
}
///
/// Selezione famiglia hardware
///
protected string FamilyHardware
{
get => CurrSashGroup.SelFamilyHardware;
set
{
if (CurrSashGroup.SelFamilyHardware != value)
{
CurrSashGroup.SelFamilyHardware = value;
var args = new DataUpdateSash()
{
currSash = CurrSashGroup,
svgNoHw = true
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = DataAction.ResetHwOpt});
_ = EC_ReqOptionHw.InvokeAsync(CurrSashGroup);
}
}
}
///
/// Selezione hardware
///
protected string SelHwType
{
get => CurrSashGroup.SelHardwareFromId;
set
{
if (CurrSashGroup.SelHardwareFromId != value)
{
CurrSashGroup.SelHardwareFromId = value;
var args = new DataUpdateSash
{
currSash = CurrSashGroup
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
_ = EC_ReqOptionHw.InvokeAsync(CurrSashGroup);
}
}
}
#endregion Protected Properties
#region Protected Methods
///
/// Metodo per rimuovere area corrente
///
///
protected async Task RemoveArea()
{
CurrSashGroup.Remove();
FrameWindow.SetSelThresholdFromName(FrameWindow.ThresholdList.FirstOrDefault(x => x.Name != "Threshold")?.Name);
var args = new DataUpdateFrame()
{
currFrame = FrameWindow,
groupIdDelete = CurrSashGroup.GroupId
};
// richiesta reset dict shape
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req=DataAction.ResetDictShape});
await EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = DataAction.ResetDimElem});
await EC_UpdateFrame.InvokeAsync(args);
await EC_ReqClose.InvokeAsync(true);
}
///
/// Metodo per cambiare dimensione solo luce
///
///
private Task ChangeTypeDimension(bool type)
{
if(CurrSashGroup.bIsDimensionLight != type)
{
CurrSashGroup.bIsDimensionLight = type;
foreach (var CurrSashDim in CurrSashGroup.SashList)
{
if (CurrSashDim.SelMeasureType is MeasureTypes.ABSOLUTE)
{
if (CurrSashGroup.bIsDimensionLight)
{
CurrSashDim.SetDimensionLight(CurrSashDim.dDimension -
CurrSashDim.ElementDimensionList.ElementAt(1).dDimension -
CurrSashDim.ElementDimensionList.Last().dDimension);
}
else
{
CurrSashDim.SetDimensionLight(CurrSashDim.dDimension +
CurrSashDim.ElementDimensionList.ElementAt(1).dDimension +
CurrSashDim.ElementDimensionList.Last().dDimension);
}
}
}
}
DataUpdateSash args = new DataUpdateSash()
{
currSash = CurrSashGroup,
noSvg = false
};
return EC_UpdateSashGroup.InvokeAsync(args);
}
///
/// Metodo per scegliere tipo di misura
///
///
///
protected Task SetMeasureType(MeasureTypes type)
{
//isOpen = !isOpen;
for (int i = 0; i < CurrSashGroup.SashList.Count; i++)
{
CurrSashGroup.SashList.ElementAt(i).SetSelMeasureType(type, i);
}
var args = new DataUpdateSash { currSash = CurrSashGroup, noSvg = true };
return EC_UpdateSashGroup.InvokeAsync(args);
}
///
/// Metodo per aggiornare la sash dimension
///
///
///
protected async Task UpdateSashDimension(SashDimension updateSD)
{
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
var currRec = CurrSashGroup.SashList.First(x => x.nSashId == updateSD.nSashId);
if(currRec != null)
{
currRec = updateSD;
var args = new DataUpdateSash
{
currSash = CurrSashGroup
};
await EC_ReqElement.InvokeAsync(CurrSashGroup);
await EC_UpdateSashGroup.InvokeAsync(args);
}
}
///
/// Metodo per aggiornare sash group
///
///
///
protected async Task UpdateSash(DataUpdateProfile updateS)
{
_ = EC_ReqResetDict.InvokeAsync(new DataUpdateRes { req = LayoutConst.DataAction.ResetDimElem });
if (updateS != null)
{
CurrSashGroup = updateS.sash;
var args = new DataUpdateSash
{
currSash = CurrSashGroup
};
if (updateS.reqProfile)
await EC_ReqElement.InvokeAsync(CurrSashGroup);
await EC_UpdateSashGroup.InvokeAsync(args);
}
}
///
/// Metodo per aggiornare sash group
///
///
///
protected async Task UpdateBottomRail(DataBottomRail updRec)
{
if (updRec.sash != null)
{
CurrSashGroup = updRec.sash;
var args = new DataUpdateSash
{
currSash = CurrSashGroup
};
await EC_UpdateSashGroup.InvokeAsync(args);
}
}
///
/// Metodo per aggiornare bottom rail
///
///
///
protected async Task UpdateBottomRail(ElementDimension updRec)
{
var currRec = CurrSashGroup.BottomRailElemDimList.FirstOrDefault(x => x.ParentArea == updRec.ParentArea && x.nIndex == updRec.nIndex);
if (currRec != null)
{
currRec = updRec;
var args = new DataUpdateSash
{
currSash = CurrSashGroup
};
await EC_UpdateSashGroup.InvokeAsync(args);
}
}
///
/// Metodo per resettare dizionario richiesto
///
///
///
protected Task ResetDict(DataUpdateRes args)
{
return EC_ReqResetDict.InvokeAsync(args);
}
#endregion Protected Methods
#region Private Methods
private bool editMode = false;
private List currSashDimEdit = new List();
private void EditView(DataChangeMode args)
{
//editMode = args.Edit;
if(args.IndexSashEdit != -1)
currSashDimEdit.Add(args.IndexSashEdit);
if (args.IndexSashClose != -1)
currSashDimEdit.Remove(args.IndexSashClose);
}
///
/// Sollevo evento per tornare alla pagina Tree
///
private void ReqClose()
{
_ = EC_ReqClose.InvokeAsync(true);
}
///
/// Aggiornamento opzioni hardware
///
///
///
private async Task UpdateOpt(DataUpdateHwOption argsHw)
{
AGBOptionCombo AGBOptCombo = argsHw.AGBOptCombo;
AGBOptionText AGBOptText = argsHw.AGBOptText;
if (AGBOptCombo != null)
{
// cerco il record
var currRec = CurrSashGroup.HwOptionList.FirstOrDefault(x => x.sName == AGBOptCombo.sName && x.sDescription == AGBOptCombo.sDescription);
currRec = AGBOptCombo;
}
else if(AGBOptText != null)
{
// cerco il record
var currRec = CurrSashGroup.HwOptionList.FirstOrDefault(x => x.sName == AGBOptText.sName && x.sDescription == AGBOptText.sDescription);
currRec = AGBOptText;
}
if(AGBOptCombo != null || AGBOptText != null)
{
var args = new DataUpdateSash
{
currSash = CurrSashGroup
};
await EC_UpdateSashGroup.InvokeAsync(args);
await EC_ReqOptionHw.InvokeAsync(CurrSashGroup);
}
}
///
/// Prima chiamata hw option list
///
///
private Task FirstHwOptionList()
{
var args = new DataUpdateSash { currSash = CurrSashGroup };
return EC_ReqFirstOptionHw.InvokeAsync(CurrSashGroup);
}
//private bool isOpen = false;
//private void ToggleDropdown()
//{
// isOpen = !isOpen;
//}
private string AreaSashCss(int i)
{
if (i == 0)
return "row mt-4";
else
return "row mt-2";
}
#endregion Private Methods
}
public class DataUpdateSash
{
public Sash currSash { get; set; } = null!;
public bool svgNoHw { get; set; } = false;
public bool noSvg { get; set; } = false;
}
public class DataUpdateRes
{
public DataAction req { get; set; } = DataAction.None;
}
}