// ALL RIGHTS RESERVED:
// ====================
// The contents of this file, and associated files in this directory, are 
// Copyright (C) SPT , all rights reserved, 2009.
// All software Source Code, Images, Database-Design and code, Graphics Design 
// and source files, and related content (collectively referred to as SOURCE) are 
// Copyright (c) SPT, 2009, All Rights Reserved.
// http://SerialPortTool.com

// PTZ Controller is a Registered Trademark of SerialPortTool.com.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Spt.Share.Controls
{
    public partial class ctlTimeSpanEdit : UserControl
    {
        private const int DefaultStayTime = 5;

        public ctlTimeSpanEdit()
        {
            InitializeComponent();
        }

        private void ctlTimeSpanEdit_Load(object sender, EventArgs e)
        {
            _valueSpin.Value = DefaultStayTime;
            _unitCombo.SelectedIndex = 0;
        }

        private Data.StaySpan _span = new Data.StaySpan();

        public Data.StaySpan Span
        {
            get 
            {
                _span.Value = (int)_valueSpin.Value;
                _span.Unit = (Data.SpanUnit)_unitCombo.SelectedIndex;

                return _span; 
            }
            set 
            { 
                _span = value;
            }
        }
	
        public void ApplyValue()
        {
            _valueSpin.Value = _span.Value;
            _unitCombo.SelectedIndex = (int)_span.Unit;
        }

        private void _valueSpin_ValueChanged(object sender, EventArgs e)
        {
            if (_valueSpin.Value <= 0)
            {
                MessageBox.Show("Stay time should be a positive value.");
                _valueSpin.Value = DefaultStayTime;

                Focus();
            }
        }
    }
}
