using DevExpress.XtraBars.Docking;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SystemX.Product.ALIS.Interface;
using static SystemX.Product.ALIS.UI.View.ViewCfg;

namespace SystemX.Product.ALIS.UI.Subs
{
    public partial class SelectTestListForm : DevExpress.XtraEditors.XtraForm
    {
        private eSelectType SelectOpenType;

        private IDataController ctrlDB;

        private int nSelectedItem;

        private string strSelectedItem;

        public string strNo;
        public string strProdNo;
        public string strName;
        public string strTestType;
        public string strVersion;
        public string strProdCode;
        public string strFileName;

        public int nSelectedIndex { get { return nSelectedItem; } private set { nSelectedItem = value; } }

        public string nSelectedVersion { get { return strSelectedItem; } private set { strSelectedItem = value; } }

        public SelectTestListForm(eSelectType eSelect, IDataController ctrlDB, int nMaxStepVersion, bool bLimitRelease = false)
        {
            InitializeComponent();

            SelectOpenType = eSelect;

            this.ctrlDB = ctrlDB;

            this.BringToFront();

            this.Focus();

            comboBoxEditVersionList.Properties.Items.Add("Select Version ...");

            if (bLimitRelease == false)
            {
                for (int i = nMaxStepVersion; i >= nMaxStepVersion - 10 && i >= 0; i--)
                    comboBoxEditVersionList.Properties.Items.Add(i.ToString());
            }
            else
            {
                comboBoxEditVersionList.Properties.Items.Add("View VRFY Release");

                for (int i = nMaxStepVersion; i >= 0; i--)
                    comboBoxEditVersionList.Properties.Items.Add(i.ToString());
            }

            comboBoxEditVersionList.SelectedIndex = 0;

            DialogResult = DialogResult.None;

            this.KeyPreview = true;
        }

        private void simpleButtonOK_Click(object sender, EventArgs e)
        {
            if (comboBoxEditVersionList.SelectedIndex > 0)
            {
                nSelectedIndex = comboBoxEditVersionList.SelectedIndex;

                nSelectedVersion = comboBoxEditVersionList.SelectedItem.ToString();

                DialogResult = DialogResult.OK;
            }
        }

        private void ConnectForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.None)
                DialogResult = DialogResult.Abort;
        }

        private void SelectTestListForm_Shown(object sender, EventArgs e)
        {
            labelControlInfo1.Text = "No : " + strNo;

            if (SelectOpenType == eSelectType.TestListFile)
            {
                //labelControl1.Text = "Select Test-List Version [" + strName + "]";
                labelControl1.Text = "Select Test-List Version [" + strFileName + "]";

                labelControlInfo2.Text = "File Name : " + strFileName;
            }
            else if (SelectOpenType == eSelectType.TestListVariant)
                labelControlInfo2.Text = "P_ProdNo : " + strProdNo;

            labelControlInfo3.Text = "Test Type : " + strTestType;
            labelControlInfo4.Text = "Version : " + strVersion;
            labelControlInfo5.Text = "Production Code : " + strProdCode;
        }

        private void SelectTestListForm_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Escape)
                DialogResult = DialogResult.Abort;
        }
    }
}