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;
using iSTP_Embedded;

namespace iSTP_DataProcessing
{
    public partial class iSTP_CompensatoryModWnd : Form
    {
        private bool Alltrue = true;

        public bool GetResult { get { return this.Alltrue; } }

        public iSTP_CompensatoryModWnd(bool[] packetVerified, ISTPConfiguration conf)
        {
            InitializeComponent();
            SensorVerification(packetVerified, conf);
            this.FormClosing += iSTP_CompensatoryModWnd_FormClosing;
        }

        void iSTP_CompensatoryModWnd_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!Alltrue)
            {
                DialogResult _res = MessageBox.Show("Do you wish stop test?",
                                                    "Compensatory mod Question",
                                                    MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Question,
                                                    MessageBoxDefaultButton.Button1);
                if (_res == System.Windows.Forms.DialogResult.No)
                {
                    this.Alltrue = true;
                }
            }
            
        }

        public void SensorVerification(bool[] packetVerified, ISTPConfiguration conf)
        {
            checkedListBox1.Items.Clear();
            checkedListBox1.SelectionMode = SelectionMode.None;

            for (int i = 0; i < conf.Size; i++)
            {
                if (i < packetVerified.Length)
                {
                    checkedListBox1.Items.Add(conf.Sensors[i].LongName);
                    if (packetVerified[i])
                    {
                        checkedListBox1.SetItemChecked(i, true);
                    }
                    else
                    {
                        checkedListBox1.SetItemChecked(i, false);
                        Alltrue = false;
                    }
                }
            }

            if (!Alltrue)
            {
                MessageBox.Show("Some sensors positions are not equal with BatchX sensorList.csv",
                                "Compesatory mod Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
