using System;

namespace NKC_WF.WebUserControls
{
    public partial class cmp_slider : BaseUserControl
    {
        /// <summary>
        /// Valore min ammesso
        /// </summary>
        public int minVal
        {
            set
            {
                lblMin.Text = value.ToString();
                txtSlider.Attributes.Remove("min");
                txtSlider.Attributes.Add("min", value.ToString());
            }
            get
            {
                int answ = 1;
                int.TryParse(lblMin.Text, out answ);
                return answ;
            }
        }
        /// <summary>
        /// Valore MAX ammesso
        /// </summary>
        public int maxVal
        {
            set
            {
                lblMax.Text = value.ToString();
                txtSlider.Attributes.Remove("max");
                txtSlider.Attributes.Add("max", value.ToString());
            }
            get
            {
                int answ = 100;
                int.TryParse(lblMax.Text, out answ);
                return answ;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void txtSlider_TextChanged(object sender, EventArgs e)
        {
            // segnala evento registrazione valore
            txtSelVal.Text = txtSlider.Text;
            raiseEvent();
        }
        /// <summary>
        /// valore selezionato
        /// </summary>
        public int selValue
        {
            get
            {
                int answ = 0;
                int.TryParse(txtSlider.Text, out answ);
                return answ;
            }
            set
            {
                // lo imposto sapendo che HO LIMITE...
                value = value > maxVal ? maxVal : value;
                value = value < minVal ? minVal : value;
                txtSlider.Text = value.ToString();
                txtSelVal.Text = txtSlider.Text;
            }
        }

        protected void lbtRem_Click(object sender, EventArgs e)
        {
            selValue--;
            raiseEvent();
        }

        protected void lbtAdd_Click(object sender, EventArgs e)
        {
            selValue++;
            raiseEvent();
        }

        protected void txtSelVal_TextChanged(object sender, EventArgs e)
        {
            // salvo valore!
            int newVal = selValue;
            int.TryParse(txtSelVal.Text, out newVal);
            selValue = newVal;
            raiseEvent();
        }
    }
}