using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WebWindowTest.Json; namespace WebWindowTest.Models { public class SplitDimension { #region Public Constructors public SplitDimension(double dDimension, bool bIsRelative, Split Parent, bool IsVertList) { m_dDimension = dDimension; m_bIsRelative = bIsRelative; m_Parent = Parent; m_bIsVertListDim = IsVertList; } #endregion Public Constructors #region Public Properties public bool bIsRelative { get { return m_bIsRelative; } } public bool bIsVertListDim { get { return m_bIsVertListDim; } } public double dDimension { get { return m_dDimension; } set { // Controllo che il valore inserito sia compreso tra 0 e 100 if (value > 0 && value < 100) { // se sono in percentuale if (m_bIsRelative) { List RelativeDimList = new List(); if (bIsVertListDim) RelativeDimList = m_Parent.SplitVertList.Where(x => x.bIsRelative).ToList(); else RelativeDimList = m_Parent.SplitHorizList.Where(x => x.bIsRelative).ToList(); // verifico se ci sono assoluti //List RelativeDimList = m_Parent.SplitPositionList.Where(x => x.bIsRelative).ToList(); if (RelativeDimList.Count > 0) { if (m_Parent.bIsPercentage) { int nIndex = RelativeDimList.IndexOf(this); if (value < m_dDimension) { if (nIndex < RelativeDimList.Count - 1) RelativeDimList[nIndex + 1].SetDimension(RelativeDimList[nIndex + 1].dDimension + (m_dDimension - value)); else if (RelativeDimList.Count > 1) RelativeDimList[nIndex - 1].SetDimension(RelativeDimList[nIndex - 1].dDimension + (m_dDimension - value)); else { m_dDimension = 100; return; } } else { double dRes = value; if (nIndex < RelativeDimList.Count - 1) { for (var nInd = 0; nInd <= nIndex - 1; nInd++) dRes += RelativeDimList[nInd].dDimension; dRes = (100 - dRes) / (RelativeDimList.Count - nIndex - 1); if (dRes != 0) { for (var Ind = nIndex + 1; Ind <= RelativeDimList.Count - 1; Ind++) RelativeDimList[Ind].SetDimension(dRes); } else return; } else if (RelativeDimList.Count > 1) { if (RelativeDimList.Count > 2) { for (var Ind = 0; Ind <= nIndex - 2; Ind++) dRes += RelativeDimList[Ind].dDimension; } dRes = (100 - dRes); if (dRes != 0) RelativeDimList[nIndex - 1].SetDimension(dRes); else return; } else { m_dDimension = 100; return; } } } else { } } } m_dDimension = value; m_Parent.ParentWindow.OnUpdatePreview(m_Parent.ParentWindow.sSerialized()); } } } public Split Parent { get { return m_Parent; } set { m_Parent = value; } } #endregion Public Properties #region Public Methods public SplitDimension Copy() { SplitDimension newSplitDim = new SplitDimension(dDimension, bIsRelative, m_Parent, bIsVertListDim); return newSplitDim; } #endregion Public Methods #region Internal Methods internal JsonSplitDimension Serialize() { JsonSplitDimension JsonSplitDimension = new JsonSplitDimension(m_bIsRelative, m_dDimension); return JsonSplitDimension; } internal void SetDimension(double dValue) { m_dDimension = dValue; } internal void SetIsRelative(bool value) { m_bIsRelative = value; } internal void SetIsVertListDim(bool value) { m_bIsVertListDim = value; } #endregion Internal Methods #region Private Fields private bool m_bIsRelative = false; private bool m_bIsVertListDim = false; private double m_dDimension; // reference private Split m_Parent; #endregion Private Fields } }