using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.ComboBox;

using SystemX.Product.ALIS.Interface;
using SystemX.Common.Archive;

using CpApplication;
using CpApplication.Manager;
using CpCommon;
using CpTesterPlatform.CpLogUtil;
using static PsCommon.PsCommon;

using PsKGaudi;
using PsKGaudi.Parser.PsCCSArea;
using PsKGaudi.Parser.PsCCSSTDFn;
using PsKGaudi.Parser.MacroModuleSkel;
using PsKGaudi.Parser.PsCCSSTDFn.Parameters;
using static PsKGaudi.Parser.PsCCS;

using static CpCommon.ExceptionHandler;

using static SystemX.Product.ALIS.UI.View.InfoList.UcTestListView;
using SystemX.Common;

namespace SystemX.Product.ALIS.UI.View.InfoList
{
    public partial class TestListFileInfoEdit : Form
    {
        private enum eTestListLoadType
        {
            Load = 0,
            Select
        }

        public eSelectMode CurrentWizardMode { internal set; get; }

        private CTestListFileInformation SelTestListFileInfo;

        private PsCCSGaudiFile GetTestListGaudiData;

        private byte[] ucTestListByte;

        private IDataController ctrlDB;

        private static object objInfoControlNextLock = new object();

        private string strGetModifyName;
        private string strGetModifyTestType;
        private string strGetModifyFileVersion;
        private string strGetModifyFileName;

        public enum eSelectMode
        {
            Insert = 0,
            Modify
        }

        private psGaudiImformation m_psGaudiInfo = new psGaudiImformation();

        public psGaudiImformation psGaudiInfo
        {
            get { return m_psGaudiInfo; }
            set { m_psGaudiInfo = value; }
        }

        private string strTitle = "PROD TestList-File";
        private string strWizardControl = "PROD TestList-File";
        private string strWelcomeWizard = "Welcome to the PROD TestList-File wizard!";
        private string strWizardPage = "PROD TestList Information";

        private bool bModifyFirstLoad;
        private string strTempTestListFilePos;

        public void WizardCancelEvent(object sender, EventArgs e)
        {
            if (((bool)sender) == false)
                this.DialogResult = DialogResult.Cancel;
        }

        public TestListFileInfoEdit(IDataController ctrlDB, eSelectMode setMode, CTestListFileInformation getSelTestListFileInfo)
        {
            InitializeComponent();

            this.Text = strTitle;
            wizardControl.Text = strWizardControl;
            welcomeWizardPage.Text = strWelcomeWizard;
            wizardPage.Text = strWizardPage;
            //
            CurrentWizardMode = setMode;

            SelTestListFileInfo = getSelTestListFileInfo;
            SelTestListFileInfo.TestListFileSelectRawData = null;

            this.ctrlDB = ctrlDB;

            switch (CurrentWizardMode)
            {
                case eSelectMode.Insert:
                    welcomeWizardPage.IntroductionText = "This is the procedure to insert new information into the " + strTitle + " table.";
                    wizardControl.Text = strTitle + " - Insert";
                    this.Text = strTitle + " - Insert";

                    textBoxItem6_Picker.Value = SelTestListFileInfo.RegDT;
                    textBoxItem7.Text = SelTestListFileInfo.RegUser;
                    textBoxItem8_Picker.Value = SelTestListFileInfo.UpdateDT;
                    textBoxItem9.Text = SelTestListFileInfo.UpdateUser;
                    break;
                case eSelectMode.Modify:
                    welcomeWizardPage.IntroductionText = "This is the procedure to modify new information in the " + strTitle + " table.";
                    wizardControl.Text = strTitle + " - Modify";
                    this.Text = strTitle + " - Modify";

                    string strGetCurrentDir = Directory.GetCurrentDirectory();
                    Guid uguid = Guid.NewGuid();
                    strTempTestListFilePos = @strGetCurrentDir + @"\TempTestList\";

                    if (Directory.Exists(strTempTestListFilePos) == false)
                        Directory.CreateDirectory(strTempTestListFilePos);

                    strTempTestListFilePos += uguid.ToString("B") + ".CpXv" + SelTestListFileInfo.Version + SelTestListFileInfo.ProdCode;
                    SelTestListFileInfo.TestListFileLoadRawData = XDataArchive.DecompressGZipByteToByte(SelTestListFileInfo.TestListFileLoadRawData);
                    File.WriteAllBytes(strTempTestListFilePos, (byte[])SelTestListFileInfo.TestListFileLoadRawData);

                    bModifyFirstLoad = false;

                    //textBoxItem1.Text = SelTestListFileInfo.Name;
                    textBoxItem2.Text = SelTestListFileInfo.TestType;
                    textBoxItem3.Text = SelTestListFileInfo.Version;
                    textBoxItem4.Text = SelTestListFileInfo.ProdCode;
                    textBoxItem5.Text = SelTestListFileInfo.FileName;

                    textBoxItem6_Picker.Value = SelTestListFileInfo.RegDT;
                    textBoxItem7.Text = SelTestListFileInfo.RegUser;
                    textBoxItem8_Picker.Value = SelTestListFileInfo.UpdateDT;
                    textBoxItem9.Text = SelTestListFileInfo.UpdateUser;

                    //strGetModifyName = SelTestListFileInfo.Name;
                    strGetModifyTestType = SelTestListFileInfo.TestType;
                    strGetModifyFileVersion = SelTestListFileInfo.Version;
                    strGetModifyFileName = SelTestListFileInfo.FileName;

                    textBoxItem11.Text = SelTestListFileInfo.Comment;
                    textBoxItem12.Text = SelTestListFileInfo.Description;

                    //View Modify SHow
                    //textBoxModify1.Text = SelTestListFileInfo.Name;
                    textBoxModify2.Text = SelTestListFileInfo.TestType;
                    textBoxModify3.Text = SelTestListFileInfo.Version;
                    textBoxModify4.Text = SelTestListFileInfo.ProdCode;
                    textBoxModify5.Text = SelTestListFileInfo.FileName;
                    textBoxModify8.Text = SelTestListFileInfo.Comment;
                    textBoxModify9.Text = SelTestListFileInfo.Description;

                    panelModify.Visible = true;

                    break;
            }
        }

        private void wizardControl_NextClick(object sender, DevExpress.XtraWizard.WizardCommandButtonClickEventArgs e)
        {
            lock (objInfoControlNextLock)
            {
                if (wizardControl.SelectedPageIndex == 0)
                {
                    if (CurrentWizardMode == eSelectMode.Modify && bModifyFirstLoad == false)
                    {
                        if (m_psGaudiInfo.bInfoLoading != false)
                            return;

                        LoadTestList(eTestListLoadType.Load, strTempTestListFilePos, SelTestListFileInfo.FileName, true);

                        labelDispLoadResult.Text = "Loading ...";
                        labelDispLoadResult.BackColor = Color.Yellow;

                        bModifyFirstLoad = true;
                    }
                }
                else if (wizardControl.SelectedPageIndex == 1)
                {
                    try
                    {
                        if (m_psGaudiInfo.bInfoNormalLoaded == false)
                            throw new Exception("The test list is loading or there is no information on the selected test list.");

                        string strItemName = "";
                        //if (textBoxItem1.Text.Length <= 0) { strItemName = "Name"; throw new Exception($"The value cannot be null. [" + strItemName + "]"); }
                        if (textBoxItem2.Text.Length <= 0) { strItemName = "Test Type"; throw new Exception($"The value cannot be null. [" + strItemName + "]"); }
                        if (textBoxItem3.Text.Length <= 0) { strItemName = "Version"; throw new Exception($"The value cannot be null. [" + strItemName + "]"); }
                        if (textBoxItem4.Text.Length <= 0) { strItemName = "Prod Code"; throw new Exception($"The value cannot be null. [" + strItemName + "]"); }
                        if (textBoxItem5.Text.Length <= 0) { strItemName = "File Name"; throw new Exception($"The value cannot be null. [" + strItemName + "]"); }

                        string strGetName = textBoxItem1.Text;
                        string strGetTestType = textBoxItem2.Text;
                        string strGetFileVersion = textBoxItem3.Text;
                        string strGetFileName = textBoxItem5.Text;

                        string strGetQueryText = "SELECT * FROM [STOR_TestListFile] WHERE No IN(SELECT No FROM [STOR_TestListFile] WHERE " + //[Name] = '" + strGetName + "' " +
                            //"AND [TestType] = '" + strGetTestType + "' " +
                            "[TestType] = '" + strGetTestType + "' " +
                            "AND [Version] = '" + strGetFileVersion + "' " +
                            "AND [FileName] = '" + strGetFileName + "' " +
                            ") ORDER BY No ASC;";

                        DataTable dtCheck = ctrlDB.GetTable(strGetQueryText);

                        if (XCommons.isHasRow(dtCheck))
                        {
                            bool bExistException = true;

                            if (CurrentWizardMode == eSelectMode.Modify)
                            {
                                if (//strGetName.CompareTo(strGetModifyName) == 0 &&
                                   strGetTestType.CompareTo(strGetModifyTestType) == 0 &&
                                   strGetFileVersion.CompareTo(strGetModifyFileVersion) == 0 &&
                                   strGetFileName.CompareTo(strGetModifyFileName) == 0)
                                    bExistException = false;
                            }

                            if (bExistException)
                            {
                                /*throw new Exception($"Name - TestType - FileVersion - FileName Combine Key is information that already exists. : " +
                                    $"{strGetName}" + " " + $"{strGetTestType}" + " " + $"{strGetFileVersion}" + " " + $"{strGetFileName}");*/
                                throw new Exception($"FileName - TestType - FileVersion Combine Key is information that already exists. : " +
                                    $"{strGetFileName}" + " " + $"{strGetTestType}" + " " + $"{strGetFileVersion}");
                            }
                        }
                        else
                        {
                            //테스트리스트 파일 수정일때 기존 파일명 버전 타입과 동일한 파일인지 확인
                            if (CurrentWizardMode == eSelectMode.Modify)
                            {
                                if (//strGetName.CompareTo(strGetModifyName) == 0 &&
                                   strGetTestType.CompareTo(strGetModifyTestType) != 0 ||
                                   strGetFileVersion.CompareTo(strGetModifyFileVersion) != 0 ||
                                   strGetFileName.CompareTo(strGetModifyFileName) != 0)
                                {
                                    throw new Exception($"When update the test-list file, the update is possible only when the information is the same. If the information is different, find the information or register a new one. \r\n" +
                                        $"FileName - TestType - FileVersion : \r\n" +
                                        $"Existing information > {strGetModifyFileName}" + " " + $"{strGetModifyTestType}" + " " + $"{strGetModifyFileVersion} \r\n" +
                                        $"Selection information > {strGetFileName}" + " " + $"{strGetTestType}" + " " + $"{strGetFileVersion} \r\n");
                                }
                            }
                        }

                        //if (bFindVariant == false) { strItemName = "ProdNo_P"; throw new Exception($"P_ProdNo that does not exist in the selected test list." + strItemName); }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, strTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        e.Handled = true;

                        return;
                    }

                    labelControlInfo1.Text = textBoxItem1.Text;
                    labelControlInfo2.Text = textBoxItem2.Text;
                    labelControlInfo3.Text = textBoxItem3.Text;
                    labelControlInfo4.Text = textBoxItem4.Text;
                    labelControlInfo5.Text = textBoxItem5.Text;

                    labelControlInfo6.Text = textBoxItem6_Picker.Value.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    labelControlInfo7.Text = textBoxItem7.Text;

                    labelControlInfo8.Text = textBoxItem8_Picker.Value.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    labelControlInfo8Sub.Text = ctrlDB.GetServerDateTimeString(); //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    labelControlInfo9.Text = textBoxItem9.Text;
                    labelControlInfo9Sub.Text = ctrlDB.GetLoginInfo().UserID;

                    labelControlInfo11.Text = textBoxItem11.Text;
                    labelControlInfo12.Text = textBoxItem12.Text;

                    richTextBoxDisp.Text = richTextBoxTestList.Text;


                    SelTestListFileInfo.VariantList.Clear();
                    foreach (KeyValuePair<string, string> kvp in m_psGaudiInfo.psVariantTable.GetStrVariantTable)
                        SelTestListFileInfo.VariantList.Add(kvp.Key);

                    switch (CurrentWizardMode)
                    {
                        case eSelectMode.Insert:
                            SelTestListFileInfo.UpdateDT = textBoxItem8_Picker.Value;
                            SelTestListFileInfo.UpdateUser = textBoxItem9.Text;
                            break;
                        case eSelectMode.Modify:
                            SelTestListFileInfo.UpdateDT = Convert.ToDateTime(labelControlInfo8Sub.Text);
                            SelTestListFileInfo.UpdateUser = labelControlInfo9Sub.Text;

                            //기존 해당 테스트리스트 사용 Variant 확인
                            string strGetQueryText = "SELECT No, ProdNo_P FROM [PROD_Variant] AS X WITH(NOLOCK) WHERE TestListFileNo = " + SelTestListFileInfo.SelectTestListFileNo.Value + ";";

                            DataTable dtCheck = ctrlDB.GetTable(strGetQueryText);

                            if (XCommons.isHasRow(dtCheck))
                            {
                                foreach(DataRow dr in dtCheck.Rows)
                                {
                                    int nGetVariantNo = int.Parse(dr["No"].ToString());
                                    string strGetProdP = dr["ProdNo_P"].ToString();
   
                                    string strGetResult = SelTestListFileInfo.VariantList.Find(x => x == strGetProdP);

                                    if(strGetResult == null)
                                    {
                                        MessageBox.Show("TestListFile to be updated among previously registered Variants " +
                                            "is not resolved in the Variant list of. Please check.\r\n" +
                                            "> Variant Table No:" + 
                                            nGetVariantNo + " [" + strGetProdP + "][" + 
                                            SelTestListFileInfo.TestType + "][" + 
                                            SelTestListFileInfo.FileName + "][" + 
                                            SelTestListFileInfo.Version + "][" + 
                                            SelTestListFileInfo.ProdCode + "]", strTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                        e.Handled = true;

                                        return;
                                    }
                                }
                            }
                            break;
                    }

                    //SelTestListFileInfo.Name = textBoxItem1.Text;
                    SelTestListFileInfo.TestType = textBoxItem2.Text;
                    SelTestListFileInfo.Version = textBoxItem3.Text;
                    SelTestListFileInfo.ProdCode = textBoxItem4.Text;
                    SelTestListFileInfo.FileName = textBoxItem5.Text;
                    SelTestListFileInfo.RegDT = textBoxItem6_Picker.Value;
                    SelTestListFileInfo.RegUser = textBoxItem7.Text;

                    SelTestListFileInfo.Comment = textBoxItem11.Text;
                    SelTestListFileInfo.Description = textBoxItem12.Text;

                    SelTestListFileInfo.TestListFileSelectRawData = new byte[ucTestListByte.Length];
                    ucTestListByte.CopyTo(SelTestListFileInfo.TestListFileSelectRawData, 0);

                    //SelTestListFileInfo.TestListFileSelectGaudiData = GetTestListGaudiData;
                }
            }
        }

        private async Task<bool> LoadTestList(eTestListLoadType eLoadType, string strLoadFileName, string strDBFileName = "", bool bDeleteFile = false)
        {
            m_psGaudiInfo.bInfoNormalLoaded = false;
            m_psGaudiInfo.bInfoLoading = true;

            try
            {
                if (PsCpDef.CheckCPFileExtension(strLoadFileName) == false || getCPxmlInfo(strLoadFileName) == false)
                    throw new Exception($"Not a normal CP TestList.");
                if (m_psGaudiInfo.psVariantTable.GetStrVariantTable.Count <= 0)
                    throw new Exception($"There is no TTNR information registered in the test list.");

                m_psGaudiInfo.psFileInfo = new PsCCSFileInfo(strLoadFileName);

                //TODO:Insert/Modify
                //if (CurrentWizardMode == eSelectMode.Insert)
                Invoke((MethodInvoker)delegate ()
                {
                    textBoxItem2.Text = m_psGaudiInfo.psTestListInfo.Type;
                    textBoxItem3.Text = m_psGaudiInfo.psFileInfo.FileVersion;
                    textBoxItem4.Text = m_psGaudiInfo.psFileInfo.FileType;

                    //if (CurrentWizardMode == eSelectMode.Insert)
                    if (strDBFileName.Length > 0)
                        textBoxItem5.Text = strDBFileName;
                    else
                        textBoxItem5.Text = m_psGaudiInfo.psFileInfo.FileName;

                    richTextBoxTestList.Clear();

                    richTextBoxTestList.Refresh();

                    richTextBoxTestList.AppendText("FileInfo: " + m_psGaudiInfo.psFileInfo.FileDirectory + "\r\n");
                    richTextBoxTestList.AppendText("FileName: " + m_psGaudiInfo.psFileInfo.FileName + "\r\n");
                    richTextBoxTestList.AppendText("FileExtention: " + m_psGaudiInfo.psFileInfo.FileExtention + "\r\n");
                    richTextBoxTestList.AppendText("FileNameWithPath: " + m_psGaudiInfo.psFileInfo.FileNameWithPath + "\r\n");

                    richTextBoxTestList.AppendText("FileVersion: " + m_psGaudiInfo.psFileInfo.FileVersion + "\r\n");
                    richTextBoxTestList.AppendText("FileType: " + m_psGaudiInfo.psFileInfo.FileType + "\r\n");

                    //richTextBoxTestList.AppendText("LockFileNameWithPath: " + m_psGaudiInfo.psFileInfo.LockFileNameWithPath + "\r\n");
                    richTextBoxTestList.AppendText("\r\n");
                    richTextBoxTestList.AppendText("CPEditorVer: " + m_psGaudiInfo.psTestListInfo.CPEditorVer + "\r\n");
                    richTextBoxTestList.AppendText("PartNumber: " + m_psGaudiInfo.psTestListInfo.PartNum + "\r\n");
                    richTextBoxTestList.AppendText("Type: " + m_psGaudiInfo.psTestListInfo.Type + "\r\n");
                    richTextBoxTestList.AppendText("Variant: " + m_psGaudiInfo.psTestListInfo.Variant + "\r\n");
                    richTextBoxTestList.AppendText("\r\n");

                    foreach (KeyValuePair<string, string> kvp in m_psGaudiInfo.psVariantTable.GetStrVariantTable)
                        richTextBoxTestList.AppendText("Variant to have : " + kvp.Key + "-" + kvp.Value + "\r\n");
                });

                await Task.Delay(100);

                string getTTNR = ((KeyValuePair<string, string>)m_psGaudiInfo.psVariantTable.GetStrVariantTable[0]).Key;
                GetTestListGaudiData = await LoadTestListFile(@strLoadFileName, getTTNR);

                if (GetTestListGaudiData != null)
                {
                    if(eLoadType == eTestListLoadType.Load)
                    {
                        SelTestListFileInfo.TestListFileLoadGaudiData = GetTestListGaudiData;
                    }
                    else if(eLoadType == eTestListLoadType.Select)
                    {
                        SelTestListFileInfo.TestListFileSelectGaudiData = GetTestListGaudiData;

                        /*if (textBoxItem1.Text.Length <= 0)
                            textBoxItem1.Text = getTTNR;*/
                    }

                    ucTestListByte = File.ReadAllBytes(strLoadFileName);

                    Invoke((MethodInvoker)delegate ()
                    {
                        textBoxItem12.Text = GetTestListGaudiData.ListTestStep[0].Comment;
                          
                        labelDispLoadResult.Text = "Test-list data verification completed.";
                        labelDispLoadResult.BackColor = Color.LimeGreen;
                    });

                    m_psGaudiInfo.bInfoNormalLoaded = true;
                }
                else
                    throw new Exception($"Failed to load test list file.");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, strTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                Invoke((MethodInvoker)delegate ()
                {
                    labelDispLoadResult.Text = "Failed to check test-list data.";
                    labelDispLoadResult.BackColor = Color.Red;
                });
            }

            await Task.Delay(1);

            if (bDeleteFile)
                File.Delete(strLoadFileName);

            m_psGaudiInfo.bInfoLoading = false;

            return m_psGaudiInfo.bInfoNormalLoaded;
        }

        private async Task<PsCCSGaudiFile> LoadTestListFile(string strFileName, string strTTNR)
        {
            return await Task.Run(async () =>
            {
                await Task.Delay(10);

                return PsCCSGaudiFile.PsCCSPaseDataApi(strFileName, strTTNR);
            });
        }

        private async void buttonSelectFile_Click(object sender, EventArgs e)
        {
            if (m_psGaudiInfo.bInfoLoading != false)
                return;

            if (openFileDialogTestList.ShowDialog() == DialogResult.OK)
            {
                labelDispLoadResult.Text = "";
                labelDispLoadResult.BackColor = Color.Silver;

                string strSelectFile = openFileDialogTestList.FileName;
                string strGetFileName = Path.GetFileNameWithoutExtension(strSelectFile);
                string strGetFileExtension = Path.GetExtension(strSelectFile);

                labelDispLoadResult.Text = "Loading ...";
                labelDispLoadResult.BackColor = Color.Yellow;

                await LoadTestList(eTestListLoadType.Select, strSelectFile, string.Empty);
            }

            await Task.Delay(1);
        }

        private bool getCPxmlInfo(string strfilename)
        {
            try
            {
                XDocument xDoc = XDocument.Load(strfilename);

                PsCCSAreaBasicInfo psBasicInfo = PsCCSAreaBasicInfo.LoadXmlData(xDoc.Root);
                PsCCSAreaTestListInfo psTestListInfo = PsCCSAreaTestListInfo.LoadXmlData(xDoc.Root);
                PsCCSAreaVariantTable psVariantTable = PsCCSAreaVariantTable.LoadXmlData(xDoc.Root);
                PsCCSFileInfo psFileInfo = new PsCCSFileInfo(strfilename);

                m_psGaudiInfo.psBasicInfo = psBasicInfo;
                m_psGaudiInfo.psTestListInfo = psTestListInfo;
                m_psGaudiInfo.psVariantTable = psVariantTable;
                m_psGaudiInfo.psFileInfo = psFileInfo;
            }
            catch (Exception ex)
            {
                return false;
            }

            return true;
        }

        private void FromFilebutton_Click(object sender, EventArgs e)
        {
            if (m_psGaudiInfo.bInfoNormalLoaded == false)
                return;

            int igetTag = Convert.ToInt32(((Control)sender).Tag);

            switch (igetTag)
            {
                case 0:
                    textBoxItem2.Text = m_psGaudiInfo.psTestListInfo.Type;
                    break;
                case 1:
                    textBoxItem3.Text = m_psGaudiInfo.psFileInfo.FileVersion;
                    break;
                case 2:
                    textBoxItem4.Text = m_psGaudiInfo.psFileInfo.FileType;
                    break;
                case 3:
                    if (CurrentWizardMode == eSelectMode.Insert)
                        textBoxItem5.Text = m_psGaudiInfo.psFileInfo.FileName;
                    break;
                case 4:
                    textBoxItem12.Text = GetTestListGaudiData.ListTestStep[0].Comment;
                    break;
            }
        }

        private bool CheckTestListLoad()
        {
            if (m_psGaudiInfo.bInfoLoading)
            {
                this.DialogResult = DialogResult.None;

                MessageBox.Show("You cannot close the information modification wizard while loading the test list.", strTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return false;
            }

            return true;
        }

        private void wizardControl_CancelClick(object sender, CancelEventArgs e)
        {
            if (CheckTestListLoad() == false)
                e.Cancel = true;
        }

        private void TestListInfoEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (CheckTestListLoad() == false)
                e.Cancel = true;
        }

        private void wizardControl_CustomizeCommandButtons(object sender, DevExpress.XtraWizard.CustomizeCommandButtonsEventArgs e)
        {
            if (e.Page == wizardPage)
            {
                this.ActiveControl = textBoxItem1;

                textBoxItem1.Focus();
            }
            else if (e.Page == welcomeWizardPage)
            {
                this.ActiveControl = e.NextButton.Button;

                e.NextButton.Button.Focus();
            }
        }
    }
}
