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

namespace AIOBOX_Debug
{
    public partial class FrmIO : Form
    {
        public FrmIO()
        {
            InitializeComponent();
        }

        private void FrmIO_Load(object sender, EventArgs e)
        {
            numericUpDown1.Value = Asa.Common.inputCount;
            numericUpDown2.Value = Asa.Common.outputCount;
            numericUpDown3.Value = Asa.Common.inputSleep;
            numericUpDown4.Value = Asa.Common.outputSleep;
            checkBox1.Checked = Asa.Common.autoUpload;
            checkBox2.Checked = Asa.Common.autoRead;
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            int n;

            n = Convert.ToInt32(numericUpDown1.Value);
            Asa.Common.box.SetInput(Asa.IOModule.Box_Type.DI, n);
            Asa.Common.inputCount = n;

            n = Convert.ToInt32(numericUpDown2.Value);
            Asa.Common.box.SetOutput(Asa.IOModule.Box_Type.DO, n);
            Asa.Common.outputCount = n;

            n = Convert.ToInt32(numericUpDown3.Value);
            Asa.Common.inputSleep = n;
            if (checkBox1.Checked)
                Asa.Common.box.AutoReadInput(true);
            else
                Asa.Common.box.AutoReadInput(true, n);

            n = Convert.ToInt32(numericUpDown4.Value);
            Asa.Common.box.AutoReadOutput(checkBox2.Checked, n);
            Asa.Common.outputSleep = n;

            Asa.Common.autoUpload = checkBox1.Checked;
            Asa.Common.autoRead = checkBox2.Checked;
            DialogResult = DialogResult.OK;
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}