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

using SmartX;
using INT_PT002.Controls;
using INT_PT002.DataStore;
using INT_PT002.DialogForms;
using INT_PT002.Part11_UserManager;

namespace INT_PT002.Forms
{
    public partial class FormMenu : Form
    {
        #region Field
        private FormMain m_ParentForm;

        // Recipe
        private ControlMenuRecipeSetting Child_Recipe_Setting;
        // User
        private ControlMenuUserUserEditor Child_User_UserEditor;
        private ControlMenuUserGroupEditor Child_User_GroupEditor;
        // Manual
        private ControlMenuManualIoTest Child_Manual_IoTest;
        // Log
        private ControlMenuLogHistory Child_Log_History;
        private ControlMenuLogInspection Child_Log_Inspection;
        private ControlMenuLogAlarm Child_Log_Alarm;
        // System
        private ControlMenuSystemInformation Child_System_Information;
        private ControlMenuSystemStatus Child_System_Status;

        public Define.E_TopMenuStore SelectedTopMenu;
        public Define.E_MenuRecipeStore SelectedMenuRecipe;
        public Define.E_MenuUserStore SelectedMenuUser;
        public Define.E_MenuManualStore SelectedMenuManual;
        public Define.E_MenuLogStore SelectedMenuLog;
        public Define.E_MenuSystemStore SelectedMenuSystem;

        private Queue<string> Q_FileList = new Queue<string>();
        #endregion

        #region Constructor
        public FormMenu(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;
            this.Initialize();
            this.CreateChildControls();
        } 
        #endregion

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

        #region Method
        private void Initialize()
        {
            this.SelectedTopMenu = Define.E_TopMenuStore.Recipe;
            this.SelectedMenuRecipe = Define.E_MenuRecipeStore._0_None;
            this.SelectedMenuUser = Define.E_MenuUserStore._0_None;
            this.SelectedMenuManual = Define.E_MenuManualStore._0_None;
            this.SelectedMenuLog = Define.E_MenuLogStore._0_None;
            this.SelectedMenuSystem = Define.E_MenuSystemStore._0_None;
        }
        private void CreateChildControls()
        {
            this.Child_Recipe_Setting = new ControlMenuRecipeSetting(this);
            this.Child_User_UserEditor = new ControlMenuUserUserEditor(this);
            this.Child_User_GroupEditor = new ControlMenuUserGroupEditor(this);
            this.Child_Manual_IoTest = new ControlMenuManualIoTest(this);
            this.Child_Log_History = new ControlMenuLogHistory(this);
            this.Child_Log_Inspection = new ControlMenuLogInspection(this);
            this.Child_Log_Alarm = new ControlMenuLogAlarm(this);
            this.Child_System_Information = new ControlMenuSystemInformation(this);
            this.Child_System_Status = new ControlMenuSystemStatus(this);

            this.Controls.Add(this.Child_Recipe_Setting);
            this.Controls.Add(this.Child_User_UserEditor);
            this.Controls.Add(this.Child_User_GroupEditor);
            this.Controls.Add(this.Child_Manual_IoTest);
            this.Controls.Add(this.Child_Log_Alarm);
            this.Controls.Add(this.Child_Log_History);
            this.Controls.Add(this.Child_Log_Inspection);
            this.Controls.Add(this.Child_System_Information);
            this.Controls.Add(this.Child_System_Status);

            this.Child_Recipe_Setting.Location = new Point(0, 39);
            this.Child_User_UserEditor.Location = new Point(0, 39);
            this.Child_User_GroupEditor.Location = new Point(0, 39);
            this.Child_Manual_IoTest.Location = new Point(0, 39);
            this.Child_Log_Alarm.Location = new Point(0, 39);
            this.Child_Log_History.Location = new Point(0, 39);
            this.Child_Log_Inspection.Location = new Point(0, 39);
            this.Child_System_Information.Location = new Point(0, 39);
            this.Child_System_Status.Location = new Point(0, 39);
        }

        private void UpdateDisplayUser(UserItem user)
        {
            string id = "", group = "";

            switch (user.Status)
            {
                case Define.E_UserStatus.Level1:
                    id = user.ID;
                    group = "Level1";

                    this.buttonRecipe.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsRecipeEnable;
                    this.buttonUser.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsUserEnable;
                    this.buttonManual.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsManualEnable;
                    this.buttonLog.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsLogEnable;
                    this.buttonSystem.Enabled = this.ParentForm.CurrentUserGroup.Level1.IsSystemEnable;
                    break;
                case Define.E_UserStatus.Level2:
                    id = user.ID;
                    group = "Level2";

                    this.buttonRecipe.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsRecipeEnable;
                    this.buttonUser.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsUserEnable;
                    this.buttonManual.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsManualEnable;
                    this.buttonLog.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsLogEnable;
                    this.buttonSystem.Enabled = this.ParentForm.CurrentUserGroup.Level2.IsSystemEnable;
                    break;
                case Define.E_UserStatus.Level3:
                    id = user.ID;
                    group = "Level3";

                    this.buttonRecipe.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsRecipeEnable;
                    this.buttonUser.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsUserEnable;
                    this.buttonManual.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsManualEnable;
                    this.buttonLog.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsLogEnable;
                    this.buttonSystem.Enabled = this.ParentForm.CurrentUserGroup.Level3.IsSystemEnable;
                    break;
                case Define.E_UserStatus.Developer:
                    id = user.ID;
                    group = "Level4";

                    this.buttonRecipe.Enabled = true;
                    this.buttonUser.Enabled = true;
                    this.buttonManual.Enabled = true;
                    this.buttonLog.Enabled = true;
                    this.buttonSystem.Enabled = true;

                    //this.buttonHiddenMenu.Enabled = true;
                    break;
                default:
                    id = "";
                    group = "Off";

                    this.buttonRecipe.Enabled = false;
                    this.buttonUser.Enabled = false;
                    this.buttonManual.Enabled = false;
                    this.buttonLog.Enabled = false;
                    this.buttonSystem.Enabled = false;
                    break;
            }

            if (this.labelUserLevel.Text != group)
                this.labelUserLevel.Text = group;
            if (this.labelUserID.Text != id)
                this.labelUserID.Text = id;
        }

        #region Log
        // Backup
        private void Backup(Define.E_DataType type, TreeView view)
        {
            string targetPath = "", sourceFilePath = "", destFilePath = "", dataFolderPath = "";
            string[] result;
            DirectoryInfo dir;
            FileInfo[] files;
            List<string> listSelectedFile = new List<string>();     // 백업할 파일 리스트 (yyyy/MM/filename.csv)
            this.Q_FileList = new Queue<string>();

            switch (type)
            {
                case Define.E_DataType.None:
                    break;
                case Define.E_DataType.History:
                    dataFolderPath = this.ParentForm.PathDataHistoryFolder;
                    break;
                case Define.E_DataType.Inspection:
                    dataFolderPath = this.ParentForm.PathDataInspectionFolder;
                    break;
                default:
                    break;
            }

            if (dataFolderPath == "")
                return;

            #region 백업 할 파일 리스트
            listSelectedFile = this.GetSeletedNodeList(view);
            #endregion

            if (listSelectedFile.Count == 0)
            {
                DialogFormMessage msg = new DialogFormMessage(4, this.ParentForm.SystemConfig.LANGUAGE);
                msg.ShowDialog();
                return;
            }

            SmartX.SmartSplash.Start(SmartSplash.BuiltInLoadingImages.PROCESSING1, 200);

            #region USB 장착 유무 체크
            // USB 장착 유무 체크
            dir = new DirectoryInfo(targetPath);
            if (dir.Exists == false)
            {
                // USB메모리가 장착되지 않았습니다
                DialogFormMessage msg = new DialogFormMessage(5, this.ParentForm.SystemConfig.LANGUAGE);
                msg.ShowDialog();
                SmartX.SmartSplash.Finish();
                return;
            }
            #endregion

            try
            {

            }
            catch
            {
                // 제조사에 문의하세요
                DialogFormMessage msg = new DialogFormMessage(6, this.ParentForm.SystemConfig.LANGUAGE);
                SmartX.SmartSplash.Finish();
                msg.ShowDialog();
                return;
            }
        }
        // FileCopy
        private void FileCopy(Define.E_DataType type)
        {
            int count = 0;
            string targetPath = "", destTargetPath = "", sourceFilePath = "", destFilePath = "";
            string[] result;
            DirectoryInfo dir;
            FileInfo[] files;

            try
            {
                #region USB 복사
                targetPath = "하드 디스크\\";

                // USB\SerialNumber\ 루트
                destTargetPath = string.Format("{0}{1}\\Data\\{2}\\{3}\\", targetPath, this.ParentForm.SystemConfig.SERIAL_NUMBER, type, DateTime.Now.ToString("yyyyMMdd_HHmmss"));

                // USB 폴더 체크 및 생성
                dir = new DirectoryInfo(destTargetPath);
                if (dir.Exists == false)
                    dir.Create();

                // 파일 복사
                dir = new DirectoryInfo(this.ParentForm.PathDataInspectionFolder);
                if (dir.Exists == false)
                    dir.Create();

                files = dir.GetFiles();
                count = files.Length;
                foreach (FileInfo file in files)
                {
                    result = file.FullName.Split('\\');
                    sourceFilePath = file.FullName;
                    destFilePath = string.Format("{0}{1}", destTargetPath, result[result.Length - 1]);

                    // 파일 중복 검사
                    if (File.Exists(destFilePath) == true)
                    {
                        DialogFormYesNo df = new DialogFormYesNo(this.ParentForm.SystemConfig.LANGUAGE, 31, Path.GetFileName(result[result.Length - 1]));
                        df.BringToFront();
                        if (df.ShowDialog() == DialogResult.Yes)
                        {
                            this.Refresh();
                            File.Delete(destFilePath);  // 존재하는 파일 삭제
                            File.Copy(sourceFilePath, destFilePath);
                        }
                        else
                        {
                            count--;
                            this.Refresh();
                        }
                    }
                    else
                    {
                        File.Copy(sourceFilePath, destFilePath);
                    }
                }

                // 복사 완료 메시지
                DialogFormMessage msg = new DialogFormMessage(count.ToString(), this.ParentForm.SystemConfig.LANGUAGE);
                msg.ShowDialog();
                #endregion
            }
            catch
            {
                // 제조사에 문의하세요
                DialogFormMessage msg = new DialogFormMessage(6, this.ParentForm.SystemConfig.LANGUAGE);
                msg.ShowDialog();
                return;
            }
        }

        public List<string> DirectorySort(DirectoryInfo[] directorys)
        {
            List<string> listDirectory = new List<string>();
            Dictionary<string, int> dirNames = new Dictionary<string, int>();

            foreach (DirectoryInfo dir in directorys)
                dirNames.Add(dir.Name, int.Parse(dir.Name));

            // 순서데로 오름차순 정렬
            var vrList = dirNames.OrderBy(x => x.Value);
            foreach (var v in vrList)
                listDirectory.Add(v.Key);

            return listDirectory;
        }
        private List<string> GetSeletedNodeList(TreeView tree)
        {
            int yearCNT, monthCNT, dayCNT;
            List<string> listSelectedFile = new List<string>();

            yearCNT = tree.Nodes.Count;
            if (yearCNT != 0)
            {
                for (int i = 0; i < yearCNT; i++)
                {
                    monthCNT = tree.Nodes[i].Nodes.Count;
                    if (monthCNT != 0)
                    {
                        for (int j = 0; j < monthCNT; j++)
                        {
                            dayCNT = tree.Nodes[i].Nodes[j].Nodes.Count;
                            if (dayCNT != 0)
                            {
                                for (int k = 0; k < dayCNT; k++)
                                {
                                    if (tree.Nodes[i].Nodes[j].Nodes[k].Checked == true)
                                    {
                                        //listSelectedFile.Add(tree.Nodes[i].Nodes[j].Nodes[k].Text);
                                        listSelectedFile.Add(string.Format("{0}\\{1}\\{2}", tree.Nodes[i].Text, tree.Nodes[i].Nodes[j].Text, tree.Nodes[i].Nodes[j].Nodes[k].Text));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return listSelectedFile;
        }
        #endregion

        private void SetTopMenu(Define.E_TopMenuStore bottom)
        {
            switch (bottom)
            {
                case Define.E_TopMenuStore.Recipe:
                    this.buttonRecipe.ButtonDown();
                    this.buttonUser.ButtonUp();
                    this.buttonManual.ButtonUp();
                    this.buttonLog.ButtonUp();
                    this.buttonSystem.ButtonUp();

                    this.buttonBottom1.ButtonText = "Setting";

                    this.buttonBottom1.Visible = true;
                    this.buttonBottom2.Visible = false;
                    this.buttonBottom3.Visible = false;
                    this.buttonBottom4.Visible = false;

                    this.SelectedMenuRecipe = Define.E_MenuRecipeStore._1_Setting;
                    this.SetBottomMenuRecipe(this.SelectedMenuRecipe);
                    break;
                case Define.E_TopMenuStore.User:
                    this.buttonRecipe.ButtonUp();
                    this.buttonUser.ButtonDown();
                    this.buttonManual.ButtonUp();
                    this.buttonLog.ButtonUp();
                    this.buttonSystem.ButtonUp();

                    this.buttonBottom1.ButtonText = "User Edit";
                    this.buttonBottom2.ButtonText = "Group Edit";

                    this.buttonBottom1.Visible = true;
                    this.buttonBottom2.Visible = true;
                    this.buttonBottom3.Visible = false;
                    this.buttonBottom4.Visible = false;

                    this.SelectedMenuUser = Define.E_MenuUserStore._1_UserEditor;
                    this.SetBottomMenuUser(this.SelectedMenuUser);
                    break;
                case Define.E_TopMenuStore.Manual:
                    this.buttonRecipe.ButtonUp();
                    this.buttonUser.ButtonUp();
                    this.buttonManual.ButtonDown();
                    this.buttonLog.ButtonUp();
                    this.buttonSystem.ButtonUp();

                    this.buttonBottom1.ButtonText = "IO Test";

                    this.buttonBottom1.Visible = true;
                    this.buttonBottom2.Visible = false;
                    this.buttonBottom3.Visible = false;
                    this.buttonBottom4.Visible = false;

                    this.SelectedMenuManual = Define.E_MenuManualStore._1_IoTest;
                    this.SetBottomMenuManual(this.SelectedMenuManual);
                    break;
                case Define.E_TopMenuStore.Log:
                    this.buttonRecipe.ButtonUp();
                    this.buttonUser.ButtonUp();
                    this.buttonManual.ButtonUp();
                    this.buttonLog.ButtonDown();
                    this.buttonSystem.ButtonUp();

                    this.buttonBottom1.ButtonText = "Inspection";
                    this.buttonBottom2.ButtonText = "History";
                    this.buttonBottom3.ButtonText = "Alarm";

                    this.buttonBottom1.Visible = true;
                    this.buttonBottom2.Visible = true;
                    this.buttonBottom3.Visible = true;
                    this.buttonBottom4.Visible = false;

                    this.SelectedMenuLog = Define.E_MenuLogStore._1_Inspection;
                    this.SetBottomMenuLog(this.SelectedMenuLog);
                    break;
                case Define.E_TopMenuStore.System:
                    this.buttonRecipe.ButtonUp();
                    this.buttonUser.ButtonUp();
                    this.buttonManual.ButtonUp();
                    this.buttonLog.ButtonUp();
                    this.buttonSystem.ButtonDown();

                    this.buttonBottom1.ButtonText = "Information";
                    this.buttonBottom2.ButtonText = "Equipment";

                    this.buttonBottom1.Visible = true;
                    this.buttonBottom2.Visible = true;
                    this.buttonBottom3.Visible = false;
                    this.buttonBottom4.Visible = false;

                    this.SelectedMenuSystem = Define.E_MenuSystemStore._1_Information;
                    this.SetBottomMenuSystem(this.SelectedMenuSystem);
                    break;
                default:
                    this.buttonBottom1.Visible = false;
                    this.buttonBottom2.Visible = false;
                    this.buttonBottom3.Visible = false;
                    this.buttonBottom4.Visible = false;
                    break;
            }
        }
        private void SetBottomMenuRecipe(Define.E_MenuRecipeStore menu)
        {
            switch (menu)
            {
                case Define.E_MenuRecipeStore._0_None:
                    break;
                case Define.E_MenuRecipeStore._1_Setting:
                    this.Child_Recipe_Setting.DisplayRefresh();
                    this.Child_Recipe_Setting.BringToFront();

                    this.buttonBottom1.ButtonDown();
                    this.buttonBottom2.ButtonUp();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                default:
                    break;
            }
        }
        private void SetBottomMenuUser(Define.E_MenuUserStore menu)
        {
            switch (menu)
            {
                case Define.E_MenuUserStore._1_UserEditor:
                    this.Child_User_UserEditor.DisplayRefresh();
                    this.Child_User_UserEditor.BringToFront();

                    this.buttonBottom1.ButtonDown();
                    this.buttonBottom2.ButtonUp();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                case Define.E_MenuUserStore._2_GroupEditor:
                    this.Child_User_GroupEditor.DisplayRefresh();
                    this.Child_User_GroupEditor.BringToFront();

                    this.buttonBottom1.ButtonUp();
                    this.buttonBottom2.ButtonDown();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                default:
                    break;
            }
        }
        private void SetBottomMenuManual(Define.E_MenuManualStore menu)
        {
            switch (menu)
            {
                case Define.E_MenuManualStore._1_IoTest:
                    this.Child_Manual_IoTest.DisplayRefresh();
                    this.Child_Manual_IoTest.BringToFront();

                    this.buttonBottom1.ButtonDown();
                    this.buttonBottom2.ButtonUp();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                default:
                    break;
            }
        }
        private void SetBottomMenuLog(Define.E_MenuLogStore menu)
        {
            switch (menu)
            {
                case Define.E_MenuLogStore._1_Inspection:
                    this.Child_Log_Inspection.BringToFront();
                    this.Child_Log_Inspection.DisplayRefresh();

                    this.buttonBottom1.ButtonDown();
                    this.buttonBottom2.ButtonUp();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                case Define.E_MenuLogStore._2_History:
                    this.Child_Log_History.BringToFront();
                    this.Child_Log_History.DisplayRefresh();

                    this.buttonBottom1.ButtonUp();
                    this.buttonBottom2.ButtonDown();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                case Define.E_MenuLogStore._3_Alarm:
                    this.Child_Log_Alarm.BringToFront();
                    this.Child_Log_Alarm.DisplayRefresh();

                    this.buttonBottom1.ButtonUp();
                    this.buttonBottom2.ButtonUp();
                    this.buttonBottom3.ButtonDown();
                    this.buttonBottom4.ButtonUp();
                    break;
                default:
                    break;
            }
        }
        private void SetBottomMenuSystem(Define.E_MenuSystemStore menu)
        {
            switch (menu)
            {
                case Define.E_MenuSystemStore._1_Information:
                    this.Child_System_Information.DisplayRefresh();
                    this.Child_System_Information.BringToFront();

                    this.buttonBottom1.ButtonDown();
                    this.buttonBottom2.ButtonUp();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                case Define.E_MenuSystemStore._2_Status:
                    this.Child_System_Status.DisplayRefresh();
                    this.Child_System_Status.BringToFront();

                    this.buttonBottom1.ButtonUp();
                    this.buttonBottom2.ButtonDown();
                    this.buttonBottom3.ButtonUp();
                    this.buttonBottom4.ButtonUp();
                    break;
                default:
                    break;
            }
        }

        // Menu
        public void UpdateEquipmentStatusDisplay(Define.E_EquipmentStatus status)
        {
            if (status == Define.E_EquipmentStatus.Start)
            {
                #region Start
                this.labelStart.Visible = true;
                this.labelStop.Visible = false;
                #endregion
            }
            else
            {
                #region Stop
                this.labelStart.Visible = false;
                this.labelStop.Visible = true;
                #endregion
            }
        }
        public void Set_Equipment_ButtonEnable(bool data)
        {
            if (data == true)
            {
                this.buttonRecipe.Enabled = true;
                this.buttonUser.Enabled = true;
                this.buttonManual.Enabled = true;
                this.buttonLog.Enabled = true;
                this.buttonSystem.Enabled = true;

                this.buttonBottom1.Enabled = true;
                this.buttonBottom2.Enabled = true;
                this.buttonBottom3.Enabled = true;
                this.buttonBottom4.Enabled = true;

                this.buttonHome.Enabled = true;
            }
            else
            {
                this.buttonRecipe.Enabled = false;
                this.buttonUser.Enabled = false;
                this.buttonManual.Enabled = false;
                this.buttonLog.Enabled = false;
                this.buttonSystem.Enabled = false;

                this.buttonBottom1.Enabled = false;
                this.buttonBottom2.Enabled = false;
                this.buttonBottom3.Enabled = false;
                this.buttonBottom4.Enabled = false;

                this.buttonHome.Enabled = false;
            }
        }

        // Menu Recipe
        public void UpdateDisplayRecipeData(Recipe item)
        {
            this.Child_Recipe_Setting.UpdateDisplayControlData(item);
        }

        // Menu Manual
        public void UpdateDisplayIOTestInputData(Collection<string> datas)
        {
            this.Child_Manual_IoTest.UpdateDisplayInputData(datas);
        }
        public void UpdateDisplayIOTestDispData(Collection<DispData> datas)
        {
            this.Child_Manual_IoTest.UpdateDisplayDispData(datas);
        }
        public void UpdateDisplayIOTestDiffData(Collection<DiffData> datas)
        {
            this.Child_Manual_IoTest.UpdateDisplayDiffData(datas);
        }
        public void UpdateDisplayIOTestPresData(Collection<PressureData> datas)
        {
            this.Child_Manual_IoTest.UpdateDisplayPresData(datas);
        }
        public void UpdateDisplayIOTestAlarmView(AlarmList data)
        {
            this.Child_Manual_IoTest.UpdateDisplayAlarmView(data);
        }

        // Menu System
        public void UpdateMainBoardVersionDisplay(string data)
        {
            this.Child_System_Information.UpdateMainBoardVersionDisplay(data);
        }

        // Menu User
        public void UpdateLevelNameDisplay(SystemConfiguration data)
        {
            this.Child_User_UserEditor.UpdateLevelNameDisplay(data);
        }
        public void CallBackGetUserData(UserManager.UserMgr_user_list_t userList)
        {
            this.Child_User_UserEditor.CallBackGetUserData(userList);
        }
        public void CallBackUserListLockDataEvent(UserManager.UserMgr_user_lock_t user)
        {
            this.Child_User_UserEditor.CallBackUserListLockDataEvent(user);
        }
        public void CallBackUserListDeleteDataEvent(UserManager.UserMgr_user_del_t user)
        {
            this.Child_User_UserEditor.CallBackUserListDeleteDataEvent(user);
        }
        public void CallBackUserModifyUserData(UserManager.UserMgr_user_modify_t user)
        {
            this.Child_User_UserEditor.CallBackUserModifyUserData(user);
        }
        public void CallBackUserListNewData(UserManager.UserMgr_user_info_t user)
        {
            this.Child_User_UserEditor.CallBackUserListNewData(user);
        }

        // Menu System
        public void UpdateDisplayEquipmentDispData(Collection<DispData> datas)
        {
            this.Child_System_Status.UpdateDisplayDispData(datas);
        }
        public void UpdateDisplayEquipmentDiffData(Collection<DiffData> datas)
        {
            this.Child_System_Status.UpdateDisplayDiffData(datas);
        }
        public void UpdateDisplayEquipmentPresData(Collection<PressureData> datas)
        {
            this.Child_System_Status.UpdateDisplayPresData(datas);
        }
        public void UpdateDisplayEquipmentAlarmView(AlarmList data)
        {
            this.Child_System_Status.UpdateDisplayAlarmView(data);
        }
        public void UpdateDisplayEquipmentJudgmentData(LeakData datas)
        {
            this.Child_System_Status.UpdateDisplayJudgmentData(datas);
        }
        public void UpdateDisplayEquipmentProcessStatusDisplay(Define.E_ProcessStatus status)
        {
            this.Child_System_Status.UpdateProcessStatusDisplay(status);
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.SelectedTopMenu = Define.E_TopMenuStore.Recipe;
            this.SetTopMenu(this.SelectedTopMenu);

            this.UpdateDisplayUser(status.CurrentUser);
        }
        #endregion

        #region Event Handler
        private void buttonHome_Click(object sender, EventArgs e)
        {
            this.buttonRecipe.ButtonDown();
            this.buttonUser.ButtonUp();
            this.buttonManual.ButtonUp();
            this.buttonLog.ButtonUp();
            this.buttonSystem.ButtonUp();

            this.ParentForm.ChildFormMainDisplay.DisplayRefresh();
            this.ParentForm.FormChange((int)Define.E_FormStore.FormMainDisplay);
        }

        private void buttonRecipe_Click(object sender, EventArgs e)
        {
            if (this.SelectedTopMenu != Define.E_TopMenuStore.Recipe)
            {
                this.SelectedTopMenu = Define.E_TopMenuStore.Recipe;
                this.SetTopMenu(this.SelectedTopMenu);
            }
        }
        private void buttonUser_Click(object sender, EventArgs e)
        {
            if (this.SelectedTopMenu != Define.E_TopMenuStore.User)
            {
                this.SelectedTopMenu = Define.E_TopMenuStore.User;
                this.SetTopMenu(this.SelectedTopMenu);
            }
        }
        private void buttonManual_Click(object sender, EventArgs e)
        {
            if (this.SelectedTopMenu != Define.E_TopMenuStore.Manual)
            {
                this.SelectedTopMenu = Define.E_TopMenuStore.Manual;
                this.SetTopMenu(this.SelectedTopMenu);
            }
        }
        private void buttonLog_Click(object sender, EventArgs e)
        {
            if (this.SelectedTopMenu != Define.E_TopMenuStore.Log)
            {
                this.SelectedTopMenu = Define.E_TopMenuStore.Log;
                this.SetTopMenu(this.SelectedTopMenu);
            }
        }
        private void buttonSystem_Click(object sender, EventArgs e)
        {
            if (this.SelectedTopMenu != Define.E_TopMenuStore.System)
            {
                this.SelectedTopMenu = Define.E_TopMenuStore.System;
                this.SetTopMenu(this.SelectedTopMenu);
            }
        }

        private void buttonBottom1_Click(object sender, EventArgs e)
        {
            switch (this.SelectedTopMenu)
            {
                case Define.E_TopMenuStore.Recipe:
                    this.SelectedMenuRecipe = Define.E_MenuRecipeStore._1_Setting;
                    this.SetBottomMenuRecipe(this.SelectedMenuRecipe);
                    break;
                case Define.E_TopMenuStore.User:
                    this.SelectedMenuUser = Define.E_MenuUserStore._1_UserEditor;
                    this.SetBottomMenuUser(this.SelectedMenuUser);
                    break;
                case Define.E_TopMenuStore.Manual:
                    this.SelectedMenuManual = Define.E_MenuManualStore._1_IoTest;
                    this.SetBottomMenuManual(this.SelectedMenuManual);
                    break;
                case Define.E_TopMenuStore.Log:
                    this.SelectedMenuLog = Define.E_MenuLogStore._1_Inspection;
                    this.SetBottomMenuLog(this.SelectedMenuLog);
                    break;
                case Define.E_TopMenuStore.System:
                    this.SelectedMenuSystem = Define.E_MenuSystemStore._1_Information;
                    this.SetBottomMenuSystem(this.SelectedMenuSystem);
                    break;
                default:
                    break;
            }
        }
        private void buttonBottom2_Click(object sender, EventArgs e)
        {
            switch (this.SelectedTopMenu)
            {
                case Define.E_TopMenuStore.Recipe:
                    this.SelectedMenuRecipe = Define.E_MenuRecipeStore._0_None;
                    this.SetBottomMenuRecipe(this.SelectedMenuRecipe);
                    break;
                case Define.E_TopMenuStore.User:
                    this.SelectedMenuUser = Define.E_MenuUserStore._2_GroupEditor;
                    this.SetBottomMenuUser(this.SelectedMenuUser);
                    break;
                case Define.E_TopMenuStore.Manual:
                    this.SelectedMenuManual = Define.E_MenuManualStore._0_None;
                    this.SetBottomMenuManual(this.SelectedMenuManual);
                    break;
                case Define.E_TopMenuStore.Log:
                    this.SelectedMenuLog = Define.E_MenuLogStore._2_History;
                    this.SetBottomMenuLog(this.SelectedMenuLog);
                    break;
                case Define.E_TopMenuStore.System:
                    this.SelectedMenuSystem = Define.E_MenuSystemStore._2_Status;
                    this.SetBottomMenuSystem(this.SelectedMenuSystem);
                    break;
                default:
                    break;
            }
        }
        private void buttonBottom3_Click(object sender, EventArgs e)
        {
            switch (this.SelectedTopMenu)
            {
                case Define.E_TopMenuStore.Recipe:
                    this.SelectedMenuRecipe = Define.E_MenuRecipeStore._0_None;
                    this.SetBottomMenuRecipe(this.SelectedMenuRecipe);
                    break;
                case Define.E_TopMenuStore.User:
                    this.SelectedMenuUser = Define.E_MenuUserStore._0_None;
                    this.SetBottomMenuUser(this.SelectedMenuUser);
                    break;
                case Define.E_TopMenuStore.Manual:
                    this.SelectedMenuManual = Define.E_MenuManualStore._0_None;
                    this.SetBottomMenuManual(this.SelectedMenuManual);
                    break;
                case Define.E_TopMenuStore.Log:
                    this.SelectedMenuLog = Define.E_MenuLogStore._3_Alarm;
                    this.SetBottomMenuLog(this.SelectedMenuLog);
                    break;
                case Define.E_TopMenuStore.System:
                    this.SelectedMenuSystem = Define.E_MenuSystemStore._0_None;
                    this.SetBottomMenuSystem(this.SelectedMenuSystem);
                    break;
                default:
                    break;
            }
        }
        private void buttonBottom4_Click(object sender, EventArgs e)
        {
            switch (this.SelectedTopMenu)
            {
                case Define.E_TopMenuStore.Recipe:
                    this.SelectedMenuRecipe = Define.E_MenuRecipeStore._0_None;
                    this.SetBottomMenuRecipe(this.SelectedMenuRecipe);
                    break;
                case Define.E_TopMenuStore.User:
                    this.SelectedMenuUser = Define.E_MenuUserStore._0_None;
                    this.SetBottomMenuUser(this.SelectedMenuUser);
                    break;
                case Define.E_TopMenuStore.Manual:
                    this.SelectedMenuManual = Define.E_MenuManualStore._0_None;
                    this.SetBottomMenuManual(this.SelectedMenuManual);
                    break;
                case Define.E_TopMenuStore.Log:
                    this.SelectedMenuLog = Define.E_MenuLogStore._0_None;
                    this.SetBottomMenuLog(this.SelectedMenuLog);
                    break;
                case Define.E_TopMenuStore.System:
                    this.SelectedMenuSystem = Define.E_MenuSystemStore._0_None;
                    this.SetBottomMenuSystem(this.SelectedMenuSystem);
                    break;
                default:
                    break;
            }
        }

        private void labelStart_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                this.ParentForm.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        private void labelStop_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                this.ParentForm.TransferData(CommunicationCommand.Start, CommunicationID.MainBoard);
        }
        #endregion
    }
}