using Egw.Window.Data;
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 = "SashGroupList")]
public List SashGroupList { get; set; } = null!;
///
/// Lista di sash dimension in stato edit
///
[CascadingParameter(Name = "SashDimEditList")]
public List SashDimEditList { get; set; } = null!;
///
/// Frame corrente
///
[Parameter]
public Frame FrameWindow { get; set; } = null!;
///
/// Evento per salvare stato edit singole ante
///
[Parameter]
public EventCallback> EC_EditSashDim { get; set; }
#endregion Public Properties
#region Protected Properties
protected override void OnParametersSet()
{
currSashDimEdit = SashDimEditList;
}
#endregion Protected Properties
#region Private Fields
private bool editMode = false;
private List currSashDimEdit = new List();
#endregion Private Fields
#region Private Properties
///
/// Selezione quantità di ante
///
private 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
///
private int SashBottomRailQty
{
get => CurrSashGroup.SashBottomRailQty;
set
{
if (CurrSashGroup.SashBottomRailQty != value)
{
CurrSashGroup.SashBottomRailQty = value;
if (CurrSashGroup.SashBottomRailQty > 0)
CurrSashGroup.SashBottomRail = true;
else
CurrSashGroup.SashBottomRail = false;
var args = new DataUpdateSash()
{
currSash = CurrSashGroup
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
}
}
}
///
/// Selezione tipo di orientamento della sash
///
private 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
///
private 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
///
private 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);
}
}
}
private MeasureTypes MeasureType
{
get
{
MeasureTypes type = CurrSashGroup.SashList.First().SelMeasureType;
for (int i = 1; i < CurrSashGroup.SashList.Count; i++)
{
if (CurrSashGroup.SashList.ElementAt(i).SelMeasureType != type)
return MeasureTypes.NULL;
}
return type;
}
set
{
for (int i = 0; i < CurrSashGroup.SashList.Count; i++)
{
CurrSashGroup.SashList.ElementAt(i).SelMeasureTypeIndex = (int)value;
}
var args = new DataUpdateSash
{
currSash = CurrSashGroup,
noSvg = true
};
_ = EC_UpdateSashGroup.InvokeAsync(args);
}
}
private int ChangeType
{
get
{
return CurrSashGroup.bIsDimensionLight ? 1 : 0;
}
set
{
if (value == 1)
CurrSashGroup.bIsDimensionLight = true;
else
CurrSashGroup.bIsDimensionLight = false;
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);
}
}
}
}
}
#endregion Private Properties
#region Private Methods
///
/// Metodo per rimuovere area corrente
///
///
private async Task RemoveArea()
{
CurrSashGroup.Remove();
if (FrameWindow.SelThreshold.Name.Contains("Threshold") && SashGroupList.IndexOf(CurrSashGroup) == 0)
{
Threshold? updThreshold = FrameWindow.ThresholdList.FirstOrDefault(x => x.Name != "Threshold");
if (updThreshold != null)
FrameWindow.SelThresholdFromName = updThreshold.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).SelMeasureTypeIndex = (int)type;
// }
// var args = new DataUpdateSash
// {
// currSash = CurrSashGroup,
// noSvg = true
// };
// return EC_UpdateSashGroup.InvokeAsync(args);
//}
///
/// Metodo per aggiornare la sash dimension
///
///
///
private 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
///
///
///
private 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
///
///
///
private 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
///
///
///
private 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
///
///
///
private Task ResetDict(DataUpdateRes args)
{
return EC_ReqResetDict.InvokeAsync(args);
}
private void EditView(DataChangeMode args)
{
//editMode = args.Edit;
if(args.IndexSashEdit != -1)
currSashDimEdit.Add(args.IndexSashEdit);
if (args.IndexSashClose != -1)
currSashDimEdit.Remove(args.IndexSashClose);
_ = EC_EditSashDim.InvokeAsync(currSashDimEdit);
}
///
/// 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";
}
private string MeasureTypeCss(MeasureTypes type)
{
for (int i = 0; i < CurrSashGroup.SashList.Count; i++)
{
if (!CurrSashGroup.SashList.ElementAt(i).MeasureType.Equals(type))
return "dropdown-item";
}
return "dropdown-item fw-bold";
}
private string TypeDimensionCss(bool type)
{
if(CurrSashGroup.bIsDimensionLight && type)
return "dropdown-item fw-bold";
else if(!CurrSashGroup.bIsDimensionLight && !type)
return "dropdown-item fw-bold";
return "dropdown-item";
}
#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;
}
}