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

using SmartX;
using INT99DC_7C.Forms;

namespace INT99DC_7C.Controls
{
    public partial class ControlIOTest : UserControl
    {
        #region Field
        private FormIOTest m_ParentForm;
        private Collection<SmartButton> CollectionOutputButton;      
        #endregion

        #region Constructor
        public ControlIOTest(FormIOTest parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.DefaultSetting();
            this.InitializeControl();
        } 
        #endregion

        #region Property
        public FormIOTest ParentForm
        {
            get { return this.m_ParentForm; }
            set { this.m_ParentForm = value; }
        } 
        #endregion

        #region Method
        private void InitializeDesign()
        {
        }
        private void InitializeControl()
        {
            foreach (SmartButton button in this.CollectionOutputButton)
                button.ButtonUp();
        }
        private void DefaultSetting()
        {
            this.CollectionOutputButton = new Collection<SmartButton>();
            this.CollectionOutputButton.Clear();
            this.CollectionOutputButton.Add(this.buttonOutput17);
            this.CollectionOutputButton.Add(this.buttonOutput18);
            this.CollectionOutputButton.Add(this.buttonOutput19);
            this.CollectionOutputButton.Add(this.buttonOutput20);
            this.CollectionOutputButton.Add(this.buttonOutput21);
            this.CollectionOutputButton.Add(this.buttonOutput22);
            this.CollectionOutputButton.Add(this.buttonOutput23);
            this.CollectionOutputButton.Add(this.buttonOutput24);
            this.CollectionOutputButton.Add(this.buttonOutput25);
            this.CollectionOutputButton.Add(this.buttonOutput26);
            this.CollectionOutputButton.Add(this.buttonOutput27);
            this.CollectionOutputButton.Add(this.buttonOutput28);
            this.CollectionOutputButton.Add(this.buttonOutput29);
            this.CollectionOutputButton.Add(this.buttonOutput30);
            this.CollectionOutputButton.Add(this.buttonOutput31);
            this.CollectionOutputButton.Add(this.buttonOutput32);
        }

        public void DisplayRefresh()
        {
            this.InitializeControl();
        }
        #endregion

        #region Event Handler
        private void buttonOutput_Click(object sender, EventArgs e)
        {
            SmartButton button = sender as SmartButton;

            if (button == null)
                return;

            if (button.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, Helper.StringZeroFillDigits4(button.Tag.ToString()),
                    Helper.StringZeroFillDigits4("1"));
            }
            else
            {
                this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.IOTest, CommunicationID.MainBoard, Helper.StringZeroFillDigits4(button.Tag.ToString()),
                    Helper.StringZeroFillDigits4("0"));
            }
        } 
        #endregion
    }
}
