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

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

namespace INT_PT002.Forms
{
    public partial class FormMain : Form
    {
        #region Field
        public bool IsSmartFileIOOpen;
        public bool IsCommunicationLogOpen;
        private int CommunicationCheckCount;
        public int FlagAutomaticLogoutWarningTime;

        // 로그온 색상
        public Color ColorLogOff;
        public Color ColorLogOn;

        // 파일 위치
        private string m_PathLaunchFolder;
        private string m_PathSystemFileFolder;
        private string m_PathDataBackupFolder;
        private string m_PathProgramSaveFolder;
        private string m_PathDataStatisticsFolder;
        private string m_PathDataFolder;
        private string m_PathDataHistoryFolder;
        private string m_PathDataInspectionFolder;
        private string m_PathDataAlarmFolder;
        private static string m_PathBinFolder;

        // UserGroup
        public UserGroup CurrentUserGroup;
        // 업데이트 메인보드
        public UpdateForMainBoard UpdateForMain;
        // 현재 장비 상태
        public SystemStatus CurrentSystemStatus;

        // SystemConfiguration
        public SystemConfiguration SystemConfig;

        // Current Recipe
        public Recipe CurrentRecipe;

        // Leak Data
        private LeakData CurrentLeakData;

        // Dll User_Name List
        public List<string> ListDllUserName;

        // IO Test - input data
        private Collection<string> CollectionIOTest_InputData;

        // 장비 구동 상태
        private Define.E_EquipmentStatus m_EquipmentStatus;

        // 알람
        private AlarmList CurrentAlarmList;

        // Form
        public FormMainDisplay2 ChildFormMainDisplay;
        public FormMenu ChildFormMenu;
        #endregion

        #region Constructor
        public FormMain()
        {
            InitializeComponent();
        } 
        #endregion

        #region Property
        public string PathLaunchFolder
        {
            get { return this.m_PathLaunchFolder; }
            set { this.m_PathLaunchFolder = value; }
        }
        public string PathSystemFileFolder
        {
            get { return this.m_PathSystemFileFolder; }
            set { this.m_PathSystemFileFolder = value; }
        }
        public string PathDataBackupFolder
        {
            get { return this.m_PathDataBackupFolder; }
            set { this.m_PathDataBackupFolder = value; }
        }
        public string PathProgramSaveFolder
        {
            get { return this.m_PathProgramSaveFolder; }
            set { this.m_PathProgramSaveFolder = value; }
        }
        public string PathDataStatisticsFolder
        {
            get { return this.m_PathDataStatisticsFolder; }
            private set { this.m_PathDataStatisticsFolder = value; }
        }
        public string PathDataFolder
        {
            get { return this.m_PathDataFolder; }
            private set { this.m_PathDataFolder = value; }
        }
        public string PathDataHistoryFolder
        {
            get { return this.m_PathDataHistoryFolder; }
            private set { this.m_PathDataHistoryFolder = value; }
        }
        public string PathDataInspectionFolder
        {
            get { return this.m_PathDataInspectionFolder; }
            private set { this.m_PathDataInspectionFolder = value; }
        }
        public string PathDataAlarmFolder
        {
            get { return this.m_PathDataAlarmFolder; }
            private set { this.m_PathDataAlarmFolder = value; }
        }

        public Define.E_EquipmentStatus EquipmentStatus
        {
            get { return this.m_EquipmentStatus; }
            private set { this.m_EquipmentStatus = value; }
        }
        #endregion

        #region Method
        public static void Exception(Exception ex)
        {
            try
            {
                string fileName = "SD Card\\DataBackup\\" + string.Format("{0:yyyyMMdd_HHmmss}_Exception.txt", DateTime.Now);
                FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                sw.Write(ex.ToString());

                sw.Close();
                fs.Close();
            }
            catch
            {
                string fileName = "Flash Disk\\" + string.Format("{0:yyyyMMdd_HHmmss}_Exception.txt", DateTime.Now);
                FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(fs);

                sw.Write(ex.ToString());

                sw.Close();
                fs.Close();
            }
        }

        private void DefaultSetting()
        {
            this.IsSmartFileIOOpen = false;
            this.IsCommunicationLogOpen = false;
            this.CommunicationCheckCount = 0;

            this.CurrentUserGroup = new UserGroup();
            this.EquipmentStatus = Define.E_EquipmentStatus.Stop;

            this.PathLaunchFolder = "SD Card\\";
            this.PathSystemFileFolder = this.PathLaunchFolder + "SystemFile\\";
            this.PathDataBackupFolder = this.PathLaunchFolder + "DataBackup\\";
            this.PathProgramSaveFolder = this.PathLaunchFolder + "Program\\";
            this.PathDataStatisticsFolder = this.PathLaunchFolder + "DataStatistics\\";
            this.PathDataFolder = this.PathLaunchFolder + "Data\\";
            this.PathDataHistoryFolder = this.PathDataFolder + "History\\";
            this.PathDataInspectionFolder = this.PathDataFolder + "Inspection\\";
            this.PathDataAlarmFolder = this.PathDataFolder + "Alarm\\";

            this.ColorLogOff = Color.Red;
            this.ColorLogOn = Color.Green;

            this.CurrentAlarmList = new AlarmList();
            this.CurrentAlarmList.EventAlarmStateChange += new Define.EventHandlerAlarmStateChange(this.CurrentAlarmList_Change);

            this.CurrentSystemStatus = new SystemStatus();
            this.SystemConfig = new SystemConfiguration();
            this.CurrentRecipe = new Recipe();
            this.UpdateForMain = new UpdateForMainBoard();

            this.ListDllUserName = new List<string>();
            this.ListDllUserName.Clear();

            //this.CollectionLeakDatas = new Collection<LeakData>();
            //for (int i = 0; i < FormMain.Lane; i++)
            //    this.CollectionLeakDatas.Add(new LeakData());

            this.CurrentLeakData = new LeakData(this.CurrentSystemStatus.EquipmentColumn);

            this.CollectionIOTest_InputData = new Collection<string>();
            for (int i = 0; i < 5; i++)
                this.CollectionIOTest_InputData.Add("0");

            // SystemFile 폴더 생성
            if (Directory.Exists(this.PathSystemFileFolder) == false)
                Directory.CreateDirectory(this.PathSystemFileFolder);

            // DataBackup 폴더 생성
            if (Directory.Exists(this.PathDataBackupFolder) == false)
                Directory.CreateDirectory(this.PathDataBackupFolder);
        }
        private void InitializeUserManager()
        {
            UserManager.UserListNewDataEvent += this.UserManager_UserListNewDataEvent;
            UserManager.UserListAddDataEvent += this.UserManager_UserListAddDataEvent;
            UserManager.UserListModifyUserDataEvent += this.UserManager_UserListModifyUserDataEvent;
            UserManager.UserListModifyInfoDataEvent += this.UserManager_UserListModifyInfoDataEvent;
            UserManager.UserListDeleteDataEvent += this.UserManager_UserListDeleteDataEvent;
            UserManager.UserListLockDataEvent += this.UserManager_UserListLockDataEvent;
            UserManager.UserListDefautSettingDataEvent += this.UserManager_UserListDefaultSettingDataEvent;
            UserManager.UserListLoginTimeoutDataEvent += this.UserManager_UserListLoginTimeoutDataEvent;
            UserManager.UserListGetListDataEvent += this.UserManager_UserListGetListDataEvent;
            UserManager.UserListLoginDataEvent += this.UserManager_UserListLoginDataEvent;
            UserManager.UserListLogoutDataEvent += this.UserManager_UserListLogoutDataEvent;
            UserManager.UserListGetListNameDataEvent += this.UserManager_UserListGetListNameDataEvent;

            UserManager.IntializeUserManager(this.PathSystemFileFolder);

            //if (this.SystemConfig.AUTOMATIC_LOGOUT == 1)
            //    this.FlagAutomaticLogoutWarningTime = 30;
            //else
            //    this.FlagAutomaticLogoutWarningTime = 60;

            //UserManager.UserManager_AutoLogoutSetTimeout(this.SystemConfig.AUTOMATIC_LOGOUT, this.FlagAutomaticLogoutWarningTime);
            UserManager.UserManager_AutoLogoutSetTimeout(0, 0);
        }
        private void CreateForm()
        {
            this.ChildFormMainDisplay = new FormMainDisplay2(this);
            this.ChildFormMenu = new FormMenu(this);

            this.smartForm1.MainForm = this;

            this.smartForm1.AddChildForm(this.ChildFormMainDisplay);
            this.smartForm1.AddChildForm(this.ChildFormMenu);
        }
        private void TransferSystemParameter9039()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.LCD_DATA_PERIOD.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.CHATTERING.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.JUDGMENT_DELAY_MSEC.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.BUZZER_OP.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DIFF_FILTER.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DATA_MODE.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DATA_PERIOD.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DIFF_MODE.ToString()));

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9039_ParameterAll, sb.ToString());
        }
        public void TransferRecipeParameter9043(int number)
        {
            StringBuilder sb = new StringBuilder();
            Recipe item = new Recipe();

            this.LoadRecipeFile(ref item, number - 1);

            sb.Append(Helper.StringBlankFillDigits4(item.NUMBER.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_RELIEF.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_HOLD1.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_HOLD2.ToString()));
            sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_BLOWOFF.ToString()));

            sb.Append(Helper.StringBlankFillDigits6(item.DISP_JUDG_STD_LEVEL));
            sb.Append(Helper.StringBlankFillDigits6(item.DISP_JUDG_MIN_LEVEL));
            sb.Append(Helper.StringBlankFillDigits6(item.DISP_JUDG_EMPTY_LEVEL));
            sb.Append(Helper.StringBlankFillDigits4(item.DISP_HOLD_DELAY_MSEC.ToString()));

            sb.Append(Helper.StringBlankFillDigits8(item.DIFF_LR_SECOND));
            sb.Append(Helper.StringBlankFillDigits8(item.DIFF_LR_TOTAL));
            sb.Append(Helper.StringBlankFillDigits8(item.DIFF_LR_MEAN));
            sb.Append(Helper.StringBlankFillDigits4(item.DIFF_HOLD_DELAY_MSEC.ToString()));

            sb.Append(Helper.StringBlankFillDigits6(item.VACUUM_GUAGE_LEVEL));

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9043_RecipeParameter, sb.ToString());
        }

        public void FormChange(int index)
        {
            this.smartForm1.Show(index);
        }
        private bool UI_Invoke(ThreadStart invoker)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    if (this.IsDisposed)
                        return true;

                    this.Invoke(invoker);
                }
                else
                {
                    invoker();
                }

                return true;

            }
            catch (Exception e)
            {
                return false;
            }

        }

        /// <summary>
        /// Set Mode
        /// </summary>
        /// <param name="mode"></param>
        public void SetDisplayMode(Define.E_EquipmentMode mode)
        {
            if (this.CurrentSystemStatus.CurrentEquipmentMode == mode)
                return;
            else
                this.CurrentSystemStatus.CurrentEquipmentMode = mode;

            switch (mode)
            {
                case Define.E_EquipmentMode.Normal:
                    this.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard);
                    break;
                case Define.E_EquipmentMode.Menu:
                    this.TransferData(CommunicationCommand.ModeMenu, CommunicationID.MainBoard);
                    break;
                case Define.E_EquipmentMode.IOTest:
                    this.TransferData(CommunicationCommand.ModeIOTest, CommunicationID.MainBoard);
                    break;
                case Define.E_EquipmentMode.EquipmentTest:
                    this.TransferData(CommunicationCommand.ModeEquipmentTest, CommunicationID.MainBoard);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// Set Time
        /// </summary>
        /// <param name="mode"></param>
        public void SetCurrentTime(DateTime time)
        {
            this.smartConfigs.ControlPanel.SetSystemDateTime(time);
        }

        #region SmartFile
        public void OpenSmartFileIO()
        {
            if (this.IsSmartFileIOOpen == true)
                this.smartFileIO.Close();

            this.smartFileIO.Open();
            this.IsSmartFileIOOpen = true;
        }
        public void CloseSmartFileIO()
        {
            if (this.IsSmartFileIOOpen == true)
            {
                this.smartFileIO.Close();
                this.IsSmartFileIOOpen = false;
            }
        }
        public void SmartFileIOStringWrite(string sValue)
        {
            this.OpenSmartFileIO();
            this.smartFileIO.StringType.Write(sValue);
        }
        public void SmartFileIOStringWrite(string sValue, int index)
        {
            this.OpenSmartFileIO();
            try
            {
                this.smartFileIO.StringType.Write(sValue, index, SmartFile.WriteMode.Overwrite);
            }
            catch
            {
                this.smartFileIO.StringType.Write(sValue, index, SmartFile.WriteMode.Append);
            }
        }
        #endregion

        #region SystemConfiguration File
        private void CreateSystemConfigurationFile()
        {
            StructSystemConfigurationItem structItem;
            
            this.SystemConfig.Initialize();

            structItem.RECIPE_NUMBER = this.SystemConfig.RECIPE_NUMBER;
            structItem.LANGUAGE = this.SystemConfig.LANGUAGE;

            structItem.CHART1_DRAW_STEP = this.SystemConfig.CHART1_DRAW_STEP;
            structItem.CHART2_DRAW_STEP = this.SystemConfig.CHART2_DRAW_STEP;
            
            structItem.LCD_DATA_PERIOD = this.SystemConfig.LCD_DATA_PERIOD;
            structItem.CHATTERING = this.SystemConfig.CHATTERING;
            structItem.JUDGMENT_DELAY_MSEC = this.SystemConfig.JUDGMENT_DELAY_MSEC;
            structItem.BUZZER_OP = this.SystemConfig.BUZZER_OP;

            structItem.SB_DIFF_FILTER = this.SystemConfig.SB_DIFF_FILTER;
            structItem.SB_DIFF_MODE = this.SystemConfig.SB_DIFF_MODE;
            structItem.SB_DATA_MODE = this.SystemConfig.SB_DATA_MODE;
            structItem.SB_DATA_PERIOD = this.SystemConfig.SB_DATA_PERIOD;

            structItem.SERIAL_NUMBER = this.SystemConfig.SERIAL_NUMBER;

            structItem.LEVEL1_NAME = this.SystemConfig.LEVEL1_NAME;
            structItem.LEVEL2_NAME = this.SystemConfig.LEVEL2_NAME;
            structItem.LEVEL3_NAME = this.SystemConfig.LEVEL3_NAME;

            this.smartFileIO.StructType.Write(structItem, 0, SmartFile.WriteMode.Overwrite);
        }
        public void SaveSystemConfigurationFile(SystemConfiguration item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem structItem;

            fullFilePath = this.PathSystemFileFolder + "system.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
            {
                this.smartFileIO.Open();
                this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));
            }
            else
            {
                this.smartFileIO.Open();
                this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));

                this.CreateSystemConfigurationFile();
            }

            structItem.RECIPE_NUMBER = item.RECIPE_NUMBER;
            structItem.LANGUAGE = item.LANGUAGE;

            structItem.CHART1_DRAW_STEP = item.CHART1_DRAW_STEP;
            structItem.CHART2_DRAW_STEP = item.CHART2_DRAW_STEP;

            structItem.LCD_DATA_PERIOD = item.LCD_DATA_PERIOD;
            structItem.CHATTERING = item.CHATTERING;
            structItem.JUDGMENT_DELAY_MSEC = item.JUDGMENT_DELAY_MSEC;
            structItem.BUZZER_OP = item.BUZZER_OP;

            structItem.SB_DIFF_FILTER = item.SB_DIFF_FILTER;
            structItem.SB_DIFF_MODE = item.SB_DIFF_MODE;
            structItem.SB_DATA_MODE = item.SB_DATA_MODE;
            structItem.SB_DATA_PERIOD = item.SB_DATA_PERIOD;

            structItem.SERIAL_NUMBER = item.SERIAL_NUMBER;

            structItem.LEVEL1_NAME = item.LEVEL1_NAME;
            structItem.LEVEL2_NAME = item.LEVEL2_NAME;
            structItem.LEVEL3_NAME = item.LEVEL3_NAME;

            this.smartFileIO.StructType.Write(structItem, 0, SmartFile.WriteMode.Overwrite);
            this.smartFileIO.Close();
        }
        public void LoadSystemConfigurationFile()
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem structItem;

            fullFilePath = this.PathSystemFileFolder + "system.cfg";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            if (fileCheck == true)
            {
                this.smartFileIO.Open();
                this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));
            }
            else
            {
                this.smartFileIO.Open();
                this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));

                this.CreateSystemConfigurationFile();
            }

            structItem = (StructSystemConfigurationItem)this.smartFileIO.StructType.Read(0);

            this.SystemConfig.RECIPE_NUMBER = structItem.RECIPE_NUMBER;
            this.SystemConfig.LANGUAGE = structItem.LANGUAGE;

            this.SystemConfig.CHART1_DRAW_STEP = structItem.CHART1_DRAW_STEP;
            this.SystemConfig.CHART2_DRAW_STEP = structItem.CHART2_DRAW_STEP;

            this.SystemConfig.LCD_DATA_PERIOD = structItem.LCD_DATA_PERIOD;
            this.SystemConfig.CHATTERING = structItem.CHATTERING;
            this.SystemConfig.JUDGMENT_DELAY_MSEC = structItem.JUDGMENT_DELAY_MSEC;
            this.SystemConfig.BUZZER_OP = structItem.BUZZER_OP;

            this.SystemConfig.SB_DIFF_FILTER = structItem.SB_DIFF_FILTER;
            this.SystemConfig.SB_DIFF_MODE = structItem.SB_DIFF_MODE;
            this.SystemConfig.SB_DATA_MODE = structItem.SB_DATA_MODE;
            this.SystemConfig.SB_DATA_PERIOD = structItem.SB_DATA_PERIOD;

            this.SystemConfig.SERIAL_NUMBER = structItem.SERIAL_NUMBER;

            this.SystemConfig.LEVEL1_NAME = structItem.LEVEL1_NAME;
            this.SystemConfig.LEVEL2_NAME = structItem.LEVEL2_NAME;
            this.SystemConfig.LEVEL3_NAME = structItem.LEVEL3_NAME;

            this.smartFileIO.Close();
        }
        #endregion

        #region Recipe File
        private void CreateRecipeFile()
        {
            StructRecipe structItem;

            this.CurrentRecipe.Initialize();

            for (int i = 0; i < 1000; i++)
            {
                structItem.NUMBER = i + 1;
                structItem.NAME = string.Format("INTECH {0}", i + 1);
                structItem.LOT = string.Format("LOT {0}", i + 1);

                structItem.DISP_JUDG_STD_LEVEL = this.CurrentRecipe.DISP_JUDG_STD_LEVEL;
                structItem.DISP_JUDG_MIN_LEVEL = this.CurrentRecipe.DISP_JUDG_MIN_LEVEL;
                structItem.DISP_JUDG_EMPTY_LEVEL = this.CurrentRecipe.DISP_JUDG_EMPTY_LEVEL;
                structItem.DISP_HOLD_DELAY_MSEC = this.CurrentRecipe.DISP_HOLD_DELAY_MSEC;

                structItem.DIFF_LR_SECOND = this.CurrentRecipe.DIFF_LR_SECOND;
                structItem.DIFF_LR_TOTAL = this.CurrentRecipe.DIFF_LR_TOTAL;
                structItem.DIFF_LR_MEAN = this.CurrentRecipe.DIFF_LR_MEAN;
                structItem.DIFF_HOLD_DELAY_MSEC = this.CurrentRecipe.DIFF_HOLD_DELAY_MSEC;

                structItem.VACUUM_RELIEF = this.CurrentRecipe.VACUUM_RELIEF;
                structItem.VACUUM_HOLD1 = this.CurrentRecipe.VACUUM_HOLD1;
                structItem.VACUUM_HOLD2 = this.CurrentRecipe.VACUUM_HOLD2;
                structItem.VACUUM_BLOWOFF = this.CurrentRecipe.VACUUM_BLOWOFF;
                structItem.VACUUM_GUAGE_LEVEL = this.CurrentRecipe.VACUUM_GUAGE_LEVEL;

                this.smartFileIO.StructType.WriteBuffer(structItem, i, SmartFile.WriteMode.Append);
            }
            this.smartFileIO.StructType.WriteBufferSave();
        }
        public void SaveRecipeFile(Recipe item)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructRecipe structItem;

            fullFilePath = this.PathSystemFileFolder + "RecipeItem.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.smartFileIO.Open();
            this.smartFileIO.StructType.SetStructType(typeof(StructRecipe));

            if (this.smartFileIO.StructType.GetCount() != 1000)
                this.CreateRecipeFile();

            structItem.NUMBER = item.NUMBER;
            structItem.NAME = item.NAME;
            structItem.LOT = item.LOT;

            structItem.DISP_JUDG_STD_LEVEL = item.DISP_JUDG_STD_LEVEL;
            structItem.DISP_JUDG_MIN_LEVEL = item.DISP_JUDG_MIN_LEVEL;
            structItem.DISP_JUDG_EMPTY_LEVEL = item.DISP_JUDG_EMPTY_LEVEL;
            structItem.DISP_HOLD_DELAY_MSEC = item.DISP_HOLD_DELAY_MSEC;

            structItem.DIFF_LR_SECOND = item.DIFF_LR_SECOND;
            structItem.DIFF_LR_TOTAL = item.DIFF_LR_TOTAL;
            structItem.DIFF_LR_MEAN = item.DIFF_LR_MEAN;
            structItem.DIFF_HOLD_DELAY_MSEC = item.DIFF_HOLD_DELAY_MSEC;

            structItem.VACUUM_RELIEF = item.VACUUM_RELIEF;
            structItem.VACUUM_HOLD1 = item.VACUUM_HOLD1;
            structItem.VACUUM_HOLD2 = item.VACUUM_HOLD2;
            structItem.VACUUM_BLOWOFF = item.VACUUM_BLOWOFF;
            structItem.VACUUM_GUAGE_LEVEL = item.VACUUM_GUAGE_LEVEL;

            this.smartFileIO.StructType.Write(structItem, item.NUMBER - 1, SmartFile.WriteMode.Overwrite);
            this.smartFileIO.Close();
        }
        public void LoadRecipeFile(ref Recipe item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructRecipe structItem;

            fullFilePath = this.PathSystemFileFolder + "RecipeItem.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.smartFileIO.Open();
            this.smartFileIO.StructType.SetStructType(typeof(StructRecipe));

            if (this.smartFileIO.StructType.GetCount() != 1000)
                this.CreateRecipeFile();

            structItem = (StructRecipe)this.smartFileIO.StructType.Read(index);

            item.NUMBER = structItem.NUMBER;
            item.NAME = structItem.NAME;
            item.LOT = structItem.LOT;

            item.DISP_JUDG_STD_LEVEL = structItem.DISP_JUDG_STD_LEVEL;
            item.DISP_JUDG_MIN_LEVEL = structItem.DISP_JUDG_MIN_LEVEL;
            item.DISP_JUDG_EMPTY_LEVEL = structItem.DISP_JUDG_EMPTY_LEVEL;
            item.DISP_HOLD_DELAY_MSEC = structItem.DISP_HOLD_DELAY_MSEC;

            item.DIFF_LR_SECOND = structItem.DIFF_LR_SECOND;
            item.DIFF_LR_TOTAL = structItem.DIFF_LR_TOTAL;
            item.DIFF_LR_MEAN = structItem.DIFF_LR_MEAN;
            item.DIFF_HOLD_DELAY_MSEC = structItem.DIFF_HOLD_DELAY_MSEC;

            item.VACUUM_RELIEF = structItem.VACUUM_RELIEF;
            item.VACUUM_HOLD1 = structItem.VACUUM_HOLD1;
            item.VACUUM_HOLD2 = structItem.VACUUM_HOLD2;
            item.VACUUM_BLOWOFF = structItem.VACUUM_BLOWOFF;
            item.VACUUM_GUAGE_LEVEL = structItem.VACUUM_GUAGE_LEVEL;

            this.smartFileIO.Close();
        }
        #endregion
        
        #region Uart Communication
        public void OpenSmartUartLink()
        {
            string fullPath = "";

            try
            {
                if (this.smartSerialPortLink.IsOpen == false)
                    this.smartSerialPortLink.Open();
            }
            catch
            {
            }

            #region Test 용 통신 로그
            fullPath = this.PathDataBackupFolder + "Communicationlog.txt";
            this.smartFileCommunicationLog.FilePathName = fullPath;
            this.smartFileCommunicationLog.Open();
            this.IsCommunicationLogOpen = true;
            #endregion
        }
        public void CloseSmartUartLink()
        {
            this.smartSerialPortLink.Close();
        }

        private bool SizeCheck(string cmd, string strTemp)
        {
            bool ret = false;
            string dataSize = "";
            int size = 0;

            if (strTemp == null || strTemp.Length == 0)
            {
                ret = false;
                return ret;
            }

            try
            {
                if (cmd == "P")
                    dataSize = strTemp.Substring(14, strTemp.Length - 16);
                else // "S"
                    dataSize = strTemp.Substring(10, strTemp.Length - 12);

                size = int.Parse(strTemp.Substring(6, 4).Trim());
            }
            catch
            {
                ret = false;
                return ret;
            }

            if (dataSize.Length == size)
                ret = true;
            else
            {
                ret = false;
            }

            return ret;
        }
        private bool ChksumCheck(string strTemp)
        {
            bool ret = false;
            string chkSum = "", dataChksum = "";

            if (strTemp == null || strTemp.Length == 0)
                ret = false;
            else
            {
                chkSum = strTemp.Substring(strTemp.Length - 2, 2);
                dataChksum = this.Checksumcalculator(strTemp.Substring(0, strTemp.Length - 2));

                if (chkSum == dataChksum)
                    ret = true;
                else
                    ret = false;
            }

            return ret;
        }
        private string Checksumcalculator(string strTemp)
        {
            string chkSum = "";
            byte[] temp;
            int value = 0, first = 0, second = 0;
            char char1, char2;

            if (strTemp == null || strTemp.Length == 0)
                chkSum = "cc";
            else
            {
                temp = new UTF8Encoding().GetBytes(strTemp);

                for (int i = 0; i < temp.Length; i++)
                    value += temp[i];

                first = (value & 0x00f0) >> 4;
                if (first > 9)
                    char1 = (char)(first + 0x37);
                else
                    char1 = (char)(first + 0x30);

                second = value & 0x000f;
                if (second > 9)
                    char2 = (char)(second + 0x37);
                else
                    char2 = (char)(second + 0x30);

                chkSum = char1.ToString() + char2.ToString();
            }

            return chkSum;
        }
        private string Checksumcalculator(byte[] strTemp)
        {
            string chkSum = "";
            byte[] temp;
            int value = 0, first = 0, second = 0;
            char char1, char2;

            if (strTemp == null || strTemp.Length == 0)
                chkSum = "cc";
            else
            {
                temp = strTemp;

                for (int i = 0; i < temp.Length; i++)
                    value += temp[i];

                first = (value & 0x00f0) >> 4;
                if (first > 9)
                    char1 = (char)(first + 0x37);
                else
                    char1 = (char)(first + 0x30);

                second = value & 0x000f;
                if (second > 9)
                    char2 = (char)(second + 0x37);
                else
                    char2 = (char)(second + 0x30);

                chkSum = char1.ToString() + char2.ToString();
            }

            return chkSum;
        }

        public int TransferData(string command, string id)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPortLink.IsOpen == true)
                this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        public int TransferDataStream(string command, string id, string address, string data)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);
            sb.Append(Helper.StringBlankFillDigits4(data.Length.ToString()));
            sb.Append(address);
            sb.Append(data);

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPortLink.IsOpen == true)
                this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        public int TransferDataStream4(string command, string id, string address, string data)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);
            sb.Append(Helper.StringBlankFillDigits4("4"));
            sb.Append(address);
            sb.Append(Helper.StringBlankFillDigits4(data));

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPortLink.IsOpen == true)
                this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        public int TransferDataStream6(string command, string id, string address, string data)
        {
            int ret = 0;
            string chkSum = "cc";
            StringBuilder sb = new StringBuilder();

            sb.Append(command);
            sb.Append(id);
            sb.Append(Helper.StringBlankFillDigits4("6"));
            sb.Append(address);
            sb.Append(Helper.StringBlankFillDigits6(data));

            chkSum = this.Checksumcalculator(sb.ToString());

            sb.Append(chkSum);

            if (this.smartSerialPortLink.IsOpen == true)
                this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));

            return ret;
        }
        private void ReceiveData()
        {
            int ret = 0;
            string strTemp = "";
            byte[] readByte;

            SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;

            try
            {
                receiveDataState = this.smartSerialPortLink.ReadQueue(out readByte);
                strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);
            }
            catch
            {
                return;
            }

            if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
            {
                return;
            }

            try
            {
                switch (strTemp[0])
                {
                    case 'C':
                        if ((ret = this.ReceiveCommandC(strTemp)) != 0)
                            return;
                        break;
                    case 'P':
                        if ((ret = this.ReceiveCommandP(strTemp)) != 0)
                            return;
                        break;
                    case 'S':
                        if ((ret = this.ReceiveCommandS(strTemp)) != 0)
                            return;
                        break;
                    default:
                        break;
                }
            }
            catch
            {
            }
        }

        private int ReceiveCommandC(string strTemp)
        {
            int ret = 0;
            string cmd = "", data = "";

            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Command Data CHKSUM Error", DateTime.Now, strTemp));
                return ret = -1;
            }

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);

            switch (cmd)
            {
                case "CI0":
                    this.CurrentSystemStatus.EquipmentStatus = Define.E_EquipmentStatus.Stop;
                    this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.EquipmentStatus);
                    this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.EquipmentStatus);

                    this.TransferSystemParameter9039();
                    break;
                case "CBS":
                    this.CurrentSystemStatus.EquipmentStatus = DataStore.Define.E_EquipmentStatus.Start;

                    this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.EquipmentStatus);
                    this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.EquipmentStatus);
                    break;
                case "CBT":
                    this.CurrentSystemStatus.EquipmentStatus = Define.E_EquipmentStatus.Stop;

                    this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.EquipmentStatus);
                    this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.EquipmentStatus);
                    break;
                default:
                    break;
            }

            return ret;
        }
        private int ReceiveCommandP(string strTemp)
        {
            int ret = 0;
            string cmd = "", address = "", lane = "", receiveData = "";

            // SIZE 확인
            if (this.SizeCheck("P", strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data SIZE Error", DateTime.Now, strTemp));
                return ret = -1;
            }
            // CHKSUM 확인
            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data CHKSUM Error", DateTime.Now, strTemp));
                return ret = -1;
            }

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);
            lane = strTemp.Substring(5, 1);
            address = strTemp.Substring(10, 4);
            receiveData = strTemp.Substring(14, strTemp.Length - 16);

            switch (cmd)
            {
                case "PR0":
                    if ((ret = this.ReceiveCommandPR0(lane, address, receiveData)) != 0)
                        return ret = -1;
                    break;
                case "PW0":
                    if ((ret = this.ReceiveCommandPW0(lane, address, receiveData)) != 0)
                        return ret = -1;
                    break;
                default:
                    break;
            }

            return ret;
        }
        private int ReceiveCommandS(string strTemp)
        {
            int ret = 0;
            string cmd = "", lane = "", receiveData = "";

            // SIZE 확인
            if (this.SizeCheck("S", strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data SIZE Error", DateTime.Now, strTemp));
                return ret = -1;
            }
            // CHKSUM 확인
            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data CHKSUM Error", DateTime.Now, strTemp));
                return ret = -1;
            }

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);
            lane = strTemp.Substring(5, 1);
            receiveData = strTemp.Substring(10, strTemp.Length - 12);

            switch (cmd)
            {
                case "SLA":
                    if ((ret = this.ReceiveCommandSLA(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SLB":
                    if ((ret = this.ReceiveCommandSLB(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SLC":
                    if ((ret = this.ReceiveCommandSLC(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SLD":
                    if ((ret = this.ReceiveCommandSLD(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SLE":
                    if ((ret = this.ReceiveCommandSLE(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "ST0":
                    if ((ret = this.ReceiveCommandST0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SA0":
                    if ((ret = this.ReceiveCommandSA0(lane, receiveData)) != 0)
                        return ret;
                    break;
                default:
                    break;
            }

            return ret;
        }

        // 파라미터 읽기 응답
        private int ReceiveCommandPR0(string lane, string address, string receiveData)
        {
            int ret = 0, iValue = 0;

            try
            {
                switch (address)
                {
                    case "1502":
                        #region Value Assign
                        this.SystemConfig.MAINBOARD_VERSION = receiveData;
                        #endregion
                        this.ChildFormMenu.UpdateMainBoardVersionDisplay(this.SystemConfig.MAINBOARD_VERSION);
                        break;
                    case "2001":
                        #region Value Assign
                        iValue = int.Parse(receiveData);
                        if (iValue <= 0 || iValue > 1000)
                            return ret = -1;

                        this.SystemConfig.RECIPE_NUMBER = iValue;
                        #endregion

                        this.LoadRecipeFile(ref this.CurrentRecipe, this.SystemConfig.RECIPE_NUMBER - 1);

                        this.ChildFormMainDisplay.UpdateDisplayRecipeData(this.CurrentRecipe);
                        this.ChildFormMenu.UpdateDisplayRecipeData(this.CurrentRecipe);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 파라미터 쓰기 응답
        private int ReceiveCommandPW0(string lane, string address, string receiveData)
        {
            int ret = 0, index = 0;
            byte[] beforeData;
            string ack = "", data = "";
            Define.E_ResponseData response = Define.E_ResponseData.NAK;

            try
            {
                if (receiveData == "0")
                    response = Define.E_ResponseData.NAK;
                else
                    response = Define.E_ResponseData.ACK;

                switch (address)
                {
                    case "9039":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferRecipeParameter9043(this.SystemConfig.RECIPE_NUMBER);
                        break;
                    case "9043":
                        if (response == Define.E_ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._2001_ProductNumber, "");
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }

        // 판정 데이터
        private int ReceiveCommandSLA(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign
                        for (int i = 0; i < this.CurrentSystemStatus.EquipmentColumn; i++)
                            this.CurrentLeakData.CollJudgment[i] = Helper.StringToJudgmentStatus(receiveData.Substring(i * 1, 1));
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateDisplayJudgmentData(this.CurrentLeakData);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                            this.ChildFormMenu.UpdateDisplayEquipmentJudgmentData(this.CurrentLeakData);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 진행상태
        private int ReceiveCommandSLB(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign
                        this.CurrentLeakData.ProcessStatus = Helper.StringToProcessStatus(receiveData.Substring(0, 1));
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateProcessStatusDisplay(this.CurrentLeakData.ProcessStatus);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                            this.ChildFormMenu.UpdateDisplayEquipmentProcessStatusDisplay(this.CurrentLeakData.ProcessStatus);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 차압 센서 데이터
        private int ReceiveCommandSLC(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign
                        for (int i = 0; i < this.CurrentSystemStatus.EquipmentColumn; i++)
                        {
                            this.CurrentLeakData.CollDiffData[i].MAdc = receiveData.Substring(i * 32, 8).Trim();
                            this.CurrentLeakData.CollDiffData[i].SecBufDiff = receiveData.Substring((i * 32) + 8, 8).Trim();
                            this.CurrentLeakData.CollDiffData[i].SecBufSum = receiveData.Substring((i * 32) + 16, 8).Trim();
                            this.CurrentLeakData.CollDiffData[i].DiffMean = receiveData.Substring((i * 32) + 24, 8).Trim();
                        }
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateDisplayDiffData(this.CurrentLeakData.CollDiffData);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.IOTest)
                            this.ChildFormMenu.UpdateDisplayIOTestDiffData(this.CurrentLeakData.CollDiffData);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                            this.ChildFormMenu.UpdateDisplayEquipmentDiffData(this.CurrentLeakData.CollDiffData);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 변위 센서 데이터
        private int ReceiveCommandSLD(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign
                        for (int i = 0; i < this.CurrentSystemStatus.EquipmentColumn; i++)
                        {
                            this.CurrentLeakData.CollDispData[i].RData = receiveData.Substring(i * 24, 6).Trim();
                            this.CurrentLeakData.CollDispData[i].MData = receiveData.Substring((i * 24) + 6, 6).Trim();
                            this.CurrentLeakData.CollDispData[i].MDataDiff = receiveData.Substring((i * 24) + 12, 6).Trim();
                            this.CurrentLeakData.CollDispData[i].STD = receiveData.Substring((i * 24) + 18, 6).Trim();
                        }
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateDisplayDispData(this.CurrentLeakData.CollDispData);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.IOTest)
                            this.ChildFormMenu.UpdateDisplayIOTestDispData(this.CurrentLeakData.CollDispData);
                        else if(this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                            this.ChildFormMenu.UpdateDisplayEquipmentDispData(this.CurrentLeakData.CollDispData);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 압력 데이터
        private int ReceiveCommandSLE(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign
                        for (int i = 0; i < this.CurrentSystemStatus.EquipmentColumn; i++)
                        {
                            this.CurrentLeakData.CollPresData[i].WorkingChamber = 
                                string.Format("{0}{1}", receiveData.Substring(i * 6, 1), receiveData.Substring((i * 6) + 1, 5).Trim());
                            this.CurrentLeakData.CollPresData[i].MasterChamber =
                                string.Format("{0}{1}", receiveData.Substring((i * 6) + 60, 1), receiveData.Substring((i * 6) + 61, 5).Trim());
                        }
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateDisplayPresData(this.CurrentLeakData.CollPresData);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.IOTest)
                            this.ChildFormMenu.UpdateDisplayIOTestPresData(this.CurrentLeakData.CollPresData);
                        else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.Equipment)
                            this.ChildFormMenu.UpdateDisplayEquipmentPresData(this.CurrentLeakData.CollPresData);
                        break;
                    default:
                        break;
                }
            }
            catch 
            {
                ret = -1;
            }

            return ret;
        }
        // IO테스트-IN
        private int ReceiveCommandST0(string lane, string receiveData)
        {
            int ret = 0;

            switch (lane)
            {
                case "Z":
                    #region Value Assign
                    for (int i = 0; i < 5; i++)
                        this.CollectionIOTest_InputData[i] = receiveData.Substring(i, 1);
                    #endregion

                    if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.IOTest)
                        this.ChildFormMenu.UpdateDisplayIOTestInputData(this.CollectionIOTest_InputData);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // 알람
        private int ReceiveCommandSA0(string lane, string receiveData)
        {
            int ret = 0;

            switch (lane)
            {
                case "Z":
                    #region Value Assign
                    this.CurrentAlarmList.SetAlarm(receiveData.Substring(0, 8));
                    #endregion

                    if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                        this.ChildFormMainDisplay.UpdateDisplayAlarmView(this.CurrentAlarmList);
                    else if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.IOTest)
                        this.ChildFormMenu.UpdateDisplayIOTestAlarmView(this.CurrentAlarmList);

                    break;
                default:
                    break;
            }

            return ret;
        }
        #endregion

        #region Backup
        public 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
        #region Tracking Inspection data
        private string GetJudgmentResult(Define.E_JudgmentStatus judg)
        {
            string value = "";

            switch (judg)
            {
                case Define.E_JudgmentStatus.None:
                    value = "-";
                    break;
                case Define.E_JudgmentStatus.Pass:
                    value = "Pass";
                    break;
                case Define.E_JudgmentStatus.Ng:
                    value = "Leak";
                    break;
                case Define.E_JudgmentStatus.Error:
                    value = "Empty";
                    break;
                default:
                    break;
            }

            return value;
        }
        private void GetTrackingInspectionFolderPath(ref string folder, ref string fileName)
        {
            DateTime time = DateTime.Now;

            folder = string.Format("{0}{1}\\{2}\\", this.PathDataInspectionFolder, time.Year, time.Month);
            fileName = string.Format("{0:yyyyMMdd}_Inspection_{1}.csv", time, this.CurrentRecipe.NUMBER);
        }
        public void TrackingInspectionData(LeakData item)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "", folderPath = "", fileName = "";
            StreamWriter sw;
            
            this.GetTrackingInspectionFolderPath(ref folderPath, ref fileName);
            fullFilePath = string.Format("{0}{1}", folderPath, fileName);

            DirectoryInfo di = new DirectoryInfo(folderPath);
            directoryCheck = di.Exists;
            // 폴더 체크
            if (directoryCheck == false)
                di.Create();

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            sw = new StreamWriter(fullFilePath, true, Encoding.UTF8);

            if (fileCheck == false)
            {
                this.RemoveInspectionDataFile();

                sw.Write("Date");
                sw.Write(",");
                sw.Write("Time");
                sw.Write(",");
                sw.Write("Name");
                sw.Write(",");
                sw.Write("Lot");
                sw.Write(",");
                sw.Write("1");
                sw.Write(",");
                sw.Write("2");
                sw.Write(",");
                sw.Write("3");
                sw.Write(",");
                sw.Write("4");
                sw.Write(",");
                sw.Write("5");
                sw.Write(",");
                sw.Write("6");
                sw.Write(",");
                sw.Write("7");
                sw.Write(",");
                sw.Write("8");
                sw.Write(",");
                sw.Write("9");
                sw.Write(",");
                sw.Write("10");

                sw.WriteLine();
            }

            sw.Write(string.Format("{0:yyyy-MM-dd}", DateTime.Now));
            sw.Write(",");
            sw.Write(string.Format("{0:HH:mm:ss}", DateTime.Now));
            sw.Write(",");
            sw.Write(this.CurrentRecipe.NAME);
            sw.Write(",");
            sw.Write(this.CurrentRecipe.LOT);
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[0]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[1]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[2]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[3]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[4]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[5]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[6]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[7]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[8]));
            sw.Write(",");
            sw.Write(this.GetJudgmentResult(item.CollJudgment[9]));
            sw.WriteLine();

            sw.Close();
        }
        private void RemoveInspectionDataFile()
        {
            bool directoryCheck = false;

            try
            {
                string dday = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(-180)) + ".csv";

                DirectoryInfo dir = new DirectoryInfo(this.PathDataInspectionFolder);

                directoryCheck = dir.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    dir.Create();

                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo subfile in files)
                {
                    if (subfile.Name.StartsWith("20"))  // 날짜 비교하여 10일 지난화일은 삭제함 
                    {
                        if (subfile.Name.CompareTo(dday) < 0)
                        {
                            subfile.Delete();
                        }
                    }
                }
            }
            catch
            {

            }
        }
        #endregion
        #region Tracking History data
        public void SetTrackingHistoryData(Define.E_TrackingOperation type, string detail)
        {
            HistoryData data = new HistoryData();

            data.Type = "Operation";
            data.Time = DateTime.Now;
            data.LoginID = this.CurrentSystemStatus.CurrentUser.ID;
            data.Event = type.ToString();
            data.Detail = detail;
            data.BeforeData = "";
            data.AfterData = "";

            this.TrackingHistoryData(data);
        }
        public void SetTrackingHistoryData(Define.E_TrackingParameter type, string detail, string before, string after)
        {
            HistoryData data = new HistoryData();

            data.Type = "Parameter";
            data.Time = DateTime.Now;
            data.LoginID = this.CurrentSystemStatus.CurrentUser.ID;
            data.Event = type.ToString();
            data.Detail = detail;
            data.BeforeData = before;
            data.AfterData = after;

            this.TrackingHistoryData(data);
        }

        private void TrackingHistoryData(HistoryData data)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "", folderPath = "", fileName = "";
            StreamWriter sw;
            DateTime time = DateTime.Now;

            folderPath = string.Format("{0}{1}\\{2}\\", this.PathDataHistoryFolder, time.Year, time.Month);
            fileName = string.Format("{0:yyyyMMdd}_History.csv", time);

            fullFilePath = string.Format("{0}{1}", folderPath, fileName);

            DirectoryInfo di = new DirectoryInfo(folderPath);
            directoryCheck = di.Exists;
            // 폴더 체크
            if (directoryCheck == false)
                di.Create();

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            sw = new StreamWriter(fullFilePath, true, Encoding.UTF8);

            try
            {
                if (fileCheck == false)
                {
                    this.RemoveHistoryDataFile();

                    sw.Write("Date");
                    sw.Write(",");
                    sw.Write("Time");
                    sw.Write(",");
                    sw.Write("LoginID");
                    sw.Write(",");
                    sw.Write("Event");
                    sw.Write(",");
                    sw.Write("Detail");
                    sw.Write(",");
                    sw.Write("Before");
                    sw.Write(",");
                    sw.Write("After");
                    sw.Write(",");
                    sw.Write("Type");

                    sw.WriteLine();
                }

                sw.Write(string.Format("{0:yyyy-MM-dd}", DateTime.Now));
                sw.Write(",");
                sw.Write(string.Format("{0:HH:mm:ss}", DateTime.Now));
                sw.Write(",");
                sw.Write(data.LoginID);
                sw.Write(",");
                sw.Write(data.Event.ToString());
                sw.Write(",");
                sw.Write(data.Detail);
                sw.Write(",");
                sw.Write(data.BeforeData);
                sw.Write(",");
                sw.Write(data.AfterData);
                sw.Write(",");
                sw.Write(data.Type);
                sw.WriteLine();

                sw.Close();
            }
            catch
            {

            }
        }
        private void RemoveHistoryDataFile()
        {
            bool directoryCheck = false;

            try
            {
                string dday = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(-180)) + ".csv";

                DirectoryInfo dir = new DirectoryInfo(this.PathDataHistoryFolder);

                directoryCheck = dir.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    dir.Create();

                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo subfile in files)
                {
                    if (subfile.Name.StartsWith("20"))  // 날짜 비교하여 10일 지난화일은 삭제함 
                    {
                        if (subfile.Name.CompareTo(dday) < 0)
                            subfile.Delete();
                    }
                }
            }
            catch
            {

            }
        }
        #endregion
        #region Tracking Alarm data
        public void SetTrackingAlarmData(Define.E_Trackingalarm type, string detail)
        {
            HistoryData data = new HistoryData();

            data.Type = "Alarm";
            data.Time = DateTime.Now;
            data.LoginID = this.CurrentSystemStatus.CurrentUser.ID;
            data.Event = type.ToString();
            data.Detail = detail;
            data.BeforeData = "";
            data.AfterData = "";

            this.TrackingAlarmData(data);
        }

        private void TrackingAlarmData(HistoryData data)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "", folderPath = "", fileName = "";
            StreamWriter sw;
            DateTime time = DateTime.Now;

            folderPath = string.Format("{0}{1}\\{2}\\", this.PathDataAlarmFolder, time.Year, time.Month);
            fileName = string.Format("{0:yyyyMMdd}_Alarm.csv", time);

            fullFilePath = string.Format("{0}{1}", folderPath, fileName);

            DirectoryInfo di = new DirectoryInfo(folderPath);
            directoryCheck = di.Exists;
            // 폴더 체크
            if (directoryCheck == false)
                di.Create();

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            sw = new StreamWriter(fullFilePath, true, Encoding.UTF8);

            try
            {
                if (fileCheck == false)
                {
                    this.RemoveAlarmDataFile();

                    sw.Write("Date");
                    sw.Write(",");
                    sw.Write("Time");
                    sw.Write(",");
                    sw.Write("LoginID");
                    sw.Write(",");
                    sw.Write("Event");
                    sw.Write(",");
                    sw.Write("Detail");

                    sw.WriteLine();
                }

                sw.Write(string.Format("{0:yyyy-MM-dd}", DateTime.Now));
                sw.Write(",");
                sw.Write(string.Format("{0:HH:mm:ss}", DateTime.Now));
                sw.Write(",");
                sw.Write(data.LoginID);
                sw.Write(",");
                sw.Write(data.Event.ToString());
                sw.Write(",");
                sw.Write(data.Detail);
                sw.WriteLine();

                sw.Close();
            }
            catch
            {

            }
        }
        private void RemoveAlarmDataFile()
        {
            bool directoryCheck = false;

            try
            {
                string dday = string.Format("{0:yyyyMMdd}", DateTime.Now.AddDays(-180)) + ".csv";

                DirectoryInfo dir = new DirectoryInfo(this.PathDataAlarmFolder);

                directoryCheck = dir.Exists;
                // 폴더 체크
                if (directoryCheck == false)
                    dir.Create();

                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo subfile in files)
                {
                    if (subfile.Name.StartsWith("20"))  // 날짜 비교하여 10일 지난화일은 삭제함 
                    {
                        if (subfile.Name.CompareTo(dday) < 0)
                            subfile.Delete();
                    }
                }
            }
            catch
            {

            }
        }
        #endregion

        #region UserGroupFile
        private void CreateUserGroupFile()
        {
            StructUserGroupItem structItem;
            UserGroupItem item = new UserGroupItem();

            for (int i = 0; i < 2; i++)
            {
                #region StructItem
                structItem.IsMainDisplayRecipeChange = item.IsMainDisplayProductChange;
                structItem.IsMainDisplayClear = item.IsMainDisplayClear;
                structItem.IsMainDispalySubMenu = item.IsMainDisplaySubMenu;

                structItem.IsMenuRecipe = item.IsMenuRecipe;
                structItem.IsMenuUserSetting = item.IsMenuUserSetting;
                structItem.IsMenuUserGroupEditor = item.IsMenuUserGroupEditor;
                structItem.IsMenuIOTest = item.IsMenuIOTest;
                structItem.IsMenuEquipmentLog = item.IsMenuHistoryLog;
                structItem.IsMenuCheckLog = item.IsMenuInspectionLog;
                structItem.IsMenuAlarmList = item.IsMenuAlarmLog;
                structItem.IsMenuInformation = item.IsMenuInformation;
                structItem.IsMenuStatus = item.IsMenuStatus;

                structItem.Dummy1 = false;
                structItem.Dummy2 = false;
                structItem.Dummy3 = false;
                structItem.Dummy4 = false;
                structItem.Dummy5 = false;
                structItem.Dummy6 = false;
                structItem.Dummy7 = false;
                structItem.Dummy8 = false;
                structItem.Dummy9 = false;
                structItem.Dummy10 = false;
                structItem.Dummy11 = false;
                structItem.Dummy12 = false;
                structItem.Dummy13 = false;
                structItem.Dummy14 = false;
                structItem.Dummy15 = false;
                structItem.Dummy16 = false;
                structItem.Dummy17 = false;
                structItem.Dummy18 = false;
                #endregion

                this.smartFileIO.StructType.Write(structItem, i, SmartFile.WriteMode.Overwrite);
            }
            for (int i = 2; i < 4; i++)
            {
                #region StructItem
                structItem.IsMainDisplayRecipeChange = true;
                structItem.IsMainDisplayClear = true;
                structItem.IsMainDispalySubMenu = true;

                structItem.IsMenuRecipe = true;
                structItem.IsMenuUserSetting = true;
                structItem.IsMenuUserGroupEditor = true;
                structItem.IsMenuIOTest = true;
                structItem.IsMenuEquipmentLog = true;
                structItem.IsMenuCheckLog = true;
                structItem.IsMenuAlarmList = true;
                structItem.IsMenuInformation = true;
                structItem.IsMenuStatus = true;

                structItem.Dummy1 = false;
                structItem.Dummy2 = false;
                structItem.Dummy3 = false;
                structItem.Dummy4 = false;
                structItem.Dummy5 = false;
                structItem.Dummy6 = false;
                structItem.Dummy7 = false;
                structItem.Dummy8 = false;
                structItem.Dummy9 = false;
                structItem.Dummy10 = false;
                structItem.Dummy11 = false;
                structItem.Dummy12 = false;
                structItem.Dummy13 = false;
                structItem.Dummy14 = false;
                structItem.Dummy15 = false;
                structItem.Dummy16 = false;
                structItem.Dummy17 = false;
                structItem.Dummy18 = false;
                #endregion

                this.smartFileIO.StructType.Write(structItem, i, SmartFile.WriteMode.Overwrite);
            }
        }
        public void SaveUserGroupFile(UserGroup item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.OpenSmartFileIO();
            this.smartFileIO.StructType.SetStructType(typeof(StructUserGroupItem));

            if (fileCheck == false)
                this.CreateUserGroupFile();

            #region Level1
            structItem.IsMainDisplayRecipeChange = item.Level1.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.Level1.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.Level1.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.Level1.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.Level1.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.Level1.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.Level1.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.Level1.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.Level1.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.Level1.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.Level1.IsMenuInformation;
            structItem.IsMenuStatus = item.Level1.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f0_Level1, SmartFile.WriteMode.Overwrite);
            #endregion

            #region Level2
            structItem.IsMainDisplayRecipeChange = item.Level2.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.Level2.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.Level2.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.Level2.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.Level2.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.Level2.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.Level2.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.Level2.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.Level2.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.Level2.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.Level2.IsMenuInformation;
            structItem.IsMenuStatus = item.Level2.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f1_Level2, SmartFile.WriteMode.Overwrite);
            #endregion

            #region Level3
            structItem.IsMainDisplayRecipeChange = item.Level3.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.Level3.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.Level3.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.Level3.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.Level3.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.Level3.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.Level3.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.Level3.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.Level3.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.Level3.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.Level3.IsMenuInformation;
            structItem.IsMenuStatus = item.Level3.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f2_Level3, SmartFile.WriteMode.Overwrite);
            #endregion

            #region Default
            structItem.IsMainDisplayRecipeChange = item.Default.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.Default.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.Default.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.Default.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.Default.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.Default.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.Default.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.Default.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.Default.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.Default.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.Default.IsMenuInformation;
            structItem.IsMenuStatus = item.Default.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f3_Default, SmartFile.WriteMode.Overwrite);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_Level1(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.OpenSmartFileIO();
            this.smartFileIO.StructType.SetStructType(typeof(StructUserGroupItem));

            if (fileCheck == false)
                this.CreateUserGroupFile();

            #region Level1
            structItem.IsMainDisplayRecipeChange = item.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.IsMenuInformation;
            structItem.IsMenuStatus = item.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f0_Level1, SmartFile.WriteMode.Overwrite);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_Level2(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.OpenSmartFileIO();
            this.smartFileIO.StructType.SetStructType(typeof(StructUserGroupItem));

            if (fileCheck == false)
                this.CreateUserGroupFile();

            #region Level2
            structItem.IsMainDisplayRecipeChange = item.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.IsMenuInformation;
            structItem.IsMenuStatus = item.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f1_Level2, SmartFile.WriteMode.Overwrite);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_Level3(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.OpenSmartFileIO();
            this.smartFileIO.StructType.SetStructType(typeof(StructUserGroupItem));

            if (fileCheck == false)
                this.CreateUserGroupFile();

            #region Level3
            structItem.IsMainDisplayRecipeChange = item.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.IsMenuInformation;
            structItem.IsMenuStatus = item.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f2_Level3, SmartFile.WriteMode.Overwrite);
            #endregion

            this.smartFileIO.Close();
        }
        public void SaveUserGroupFile_NotLogin(UserGroupItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.OpenSmartFileIO();
            this.smartFileIO.StructType.SetStructType(typeof(StructUserGroupItem));

            if (fileCheck == false)
                this.CreateUserGroupFile();

            #region Default
            structItem.IsMainDisplayRecipeChange = item.IsMainDisplayProductChange;
            structItem.IsMainDisplayClear = item.IsMainDisplayClear;
            structItem.IsMainDispalySubMenu = item.IsMainDisplaySubMenu;

            structItem.IsMenuRecipe = item.IsMenuRecipe;
            structItem.IsMenuUserSetting = item.IsMenuUserSetting;
            structItem.IsMenuUserGroupEditor = item.IsMenuUserGroupEditor;
            structItem.IsMenuIOTest = item.IsMenuIOTest;
            structItem.IsMenuEquipmentLog = item.IsMenuHistoryLog;
            structItem.IsMenuCheckLog = item.IsMenuInspectionLog;
            structItem.IsMenuAlarmList = item.IsMenuAlarmLog;
            structItem.IsMenuInformation = item.IsMenuInformation;
            structItem.IsMenuStatus = item.IsMenuStatus;

            structItem.Dummy1 = false;
            structItem.Dummy2 = false;
            structItem.Dummy3 = false;
            structItem.Dummy4 = false;
            structItem.Dummy5 = false;
            structItem.Dummy6 = false;
            structItem.Dummy7 = false;
            structItem.Dummy8 = false;
            structItem.Dummy9 = false;
            structItem.Dummy10 = false;
            structItem.Dummy11 = false;
            structItem.Dummy12 = false;
            structItem.Dummy13 = false;
            structItem.Dummy14 = false;
            structItem.Dummy15 = false;
            structItem.Dummy16 = false;
            structItem.Dummy17 = false;
            structItem.Dummy18 = false;

            this.smartFileIO.StructType.Write(structItem, (int)Define.E_UserGroup.f3_Default, SmartFile.WriteMode.Overwrite);
            #endregion

            this.smartFileIO.Close();
        }
        private void LoadUserGroupFile(ref UserGroup item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

            fullFilePath = this.PathSystemFileFolder + "UserGroup.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;

            this.OpenSmartFileIO();
            this.smartFileIO.StructType.SetStructType(typeof(StructUserGroupItem));

            if (fileCheck == false)
                this.CreateUserGroupFile();

            try
            {
                this.smartFileIO.StructType.FillBuffer();

                #region Level1
                structItem = (StructUserGroupItem)this.smartFileIO.StructType.ReadBuffer((int)Define.E_UserGroup.f0_Level1);

                item.Level1.IsMainDisplayProductChange = structItem.IsMainDisplayRecipeChange;
                item.Level1.IsMainDisplayClear = structItem.IsMainDisplayClear;
                item.Level1.IsMainDisplaySubMenu = structItem.IsMainDispalySubMenu;

                item.Level1.IsMenuRecipe = structItem.IsMenuRecipe;
                item.Level1.IsMenuUserSetting = structItem.IsMenuUserSetting;
                item.Level1.IsMenuUserGroupEditor = structItem.IsMenuUserGroupEditor;
                item.Level1.IsMenuIOTest = structItem.IsMenuIOTest;
                item.Level1.IsMenuHistoryLog = structItem.IsMenuEquipmentLog;
                item.Level1.IsMenuInspectionLog = structItem.IsMenuCheckLog;
                item.Level1.IsMenuAlarmLog = structItem.IsMenuAlarmList;
                item.Level1.IsMenuInformation = structItem.IsMenuInformation;
                item.Level1.IsMenuStatus = structItem.IsMenuStatus;
                #endregion

                #region Level2
                structItem = (StructUserGroupItem)this.smartFileIO.StructType.ReadBuffer((int)Define.E_UserGroup.f1_Level2);

                item.Level2.IsMainDisplayProductChange = structItem.IsMainDisplayRecipeChange;
                item.Level2.IsMainDisplayClear = structItem.IsMainDisplayClear;
                item.Level2.IsMainDisplaySubMenu = structItem.IsMainDispalySubMenu;

                item.Level2.IsMenuRecipe = structItem.IsMenuRecipe;
                item.Level2.IsMenuUserSetting = structItem.IsMenuUserSetting;
                item.Level2.IsMenuUserGroupEditor = structItem.IsMenuUserGroupEditor;
                item.Level2.IsMenuIOTest = structItem.IsMenuIOTest;
                item.Level2.IsMenuHistoryLog = structItem.IsMenuEquipmentLog;
                item.Level2.IsMenuInspectionLog = structItem.IsMenuCheckLog;
                item.Level2.IsMenuAlarmLog = structItem.IsMenuAlarmList;
                item.Level2.IsMenuInformation = structItem.IsMenuInformation;
                item.Level2.IsMenuStatus = structItem.IsMenuStatus;
                #endregion

                #region Level3
                structItem = (StructUserGroupItem)this.smartFileIO.StructType.ReadBuffer((int)Define.E_UserGroup.f2_Level3);

                item.Level3.IsMainDisplayProductChange = structItem.IsMainDisplayRecipeChange;
                item.Level3.IsMainDisplayClear = structItem.IsMainDisplayClear;
                item.Level3.IsMainDisplaySubMenu = structItem.IsMainDispalySubMenu;

                item.Level3.IsMenuRecipe = structItem.IsMenuRecipe;
                item.Level3.IsMenuUserSetting = structItem.IsMenuUserSetting;
                item.Level3.IsMenuUserGroupEditor = structItem.IsMenuUserGroupEditor;
                item.Level3.IsMenuIOTest = structItem.IsMenuIOTest;
                item.Level3.IsMenuHistoryLog = structItem.IsMenuEquipmentLog;
                item.Level3.IsMenuInspectionLog = structItem.IsMenuCheckLog;
                item.Level3.IsMenuAlarmLog = structItem.IsMenuAlarmList;
                item.Level3.IsMenuInformation = structItem.IsMenuInformation;
                item.Level3.IsMenuStatus = structItem.IsMenuStatus;
                #endregion

                #region Default
                structItem = (StructUserGroupItem)this.smartFileIO.StructType.ReadBuffer((int)Define.E_UserGroup.f3_Default);

                item.Default.IsMainDisplayProductChange = structItem.IsMainDisplayRecipeChange;
                item.Default.IsMainDisplayClear = structItem.IsMainDisplayClear;
                item.Default.IsMainDisplaySubMenu = structItem.IsMainDispalySubMenu;

                item.Default.IsMenuRecipe = structItem.IsMenuRecipe;
                item.Default.IsMenuUserSetting = structItem.IsMenuUserSetting;
                item.Default.IsMenuUserGroupEditor = structItem.IsMenuUserGroupEditor;
                item.Default.IsMenuIOTest = structItem.IsMenuIOTest;
                item.Default.IsMenuHistoryLog = structItem.IsMenuEquipmentLog;
                item.Default.IsMenuInspectionLog = structItem.IsMenuCheckLog;
                item.Default.IsMenuAlarmLog = structItem.IsMenuAlarmList;
                item.Default.IsMenuInformation = structItem.IsMenuInformation;
                item.Default.IsMenuStatus = structItem.IsMenuStatus;
                #endregion
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.LANGUAGE);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion

        #region Modbus
        public void ModbusOpen()
        {
            if (this.smartModbus.IsOpen == true)
                this.smartModbus.PortClose();

            this.smartModbus.PortOpen();
        }
        public void ModbusClose()
        {
            this.smartModbus.PortClose();
        }

        public string ServoMotorRead1(int slaveAddress, int parameterAddress)
        {
            int value = 0;
            byte[] readData = new byte[2];

            this.smartModbus.SlaveAddress = slaveAddress;
            this.smartModbus.ReadHoldingRegister(parameterAddress, 1, out readData);

            Array.Reverse(readData);
            value = BitConverter.ToInt16(readData, 0);

            return string.Format("{0}", value);
        }
        public string ServoMotorRead2(int slaveAddress, int parameterAddress)
        {
            int value = 0;
            byte[] readData = new byte[4];

            this.smartModbus.SlaveAddress = slaveAddress;
            this.smartModbus.ReadHoldingRegister(parameterAddress, 2, out readData);

            byte[] readData1 = new byte[4];
            readData1[0] = readData[1];
            readData1[1] = readData[0];
            readData1[2] = readData[3];
            readData1[3] = readData[2];

            value = BitConverter.ToInt32(readData1, 0);

            return string.Format("{0}", value);
        }
        public void ServoMotorWrite1(int slaveAddress, int parameterAddress, int value, SmartLabel label)
        {
            this.smartModbus.SlaveAddress = slaveAddress;
            if (this.smartModbus.WriteSingleRegister(parameterAddress, value) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
            {
                //MessageBox.Show("쓰기완료");
            }
            label.Text = this.ServoMotorRead1(slaveAddress, parameterAddress);
        }
        public void ServoMotorWrite1(int slaveAddress, int parameterAddress, int value)
        {
            this.smartModbus.SlaveAddress = slaveAddress;
            if (this.smartModbus.WriteSingleRegister(parameterAddress, value) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
            {
                //MessageBox.Show("쓰기완료");
            }
        }
        public void ServoMotorWrite2(int slaveAddress, int parameterAddress, int value, SmartLabel label)
        {
            byte[] data = BitConverter.GetBytes(value);

            byte[] readData1 = new byte[4];
            readData1[0] = data[1];
            readData1[1] = data[0];
            readData1[2] = data[3];
            readData1[3] = data[2];

            this.smartModbus.SlaveAddress = slaveAddress;
            if (this.smartModbus.WriteMultipleRegister(parameterAddress, 2, readData1) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
            {
                //MessageBox.Show("쓰기완료");
            }
            label.Text = this.ServoMotorRead2(slaveAddress, parameterAddress);
        }
        public void ServoMotorWrite2(int slaveAddress, int parameterAddress, int value)
        {
            byte[] data = BitConverter.GetBytes(value);

            byte[] readData1 = new byte[4];
            readData1[0] = data[1];
            readData1[1] = data[0];
            readData1[2] = data[3];
            readData1[3] = data[2];

            this.smartModbus.SlaveAddress = slaveAddress;
            if (this.smartModbus.WriteMultipleRegister(parameterAddress, 2, readData1) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
            {
                //MessageBox.Show("쓰기완료");
            }
        }
        #endregion

        #endregion

        #region Override Member
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // 변수 초기 셋팅
            this.DefaultSetting();
            // SystemConfiguration 파일 읽기
            this.LoadSystemConfigurationFile();
            // Recipe 파일 읽기
            this.LoadRecipeFile(ref this.CurrentRecipe, this.SystemConfig.RECIPE_NUMBER - 1);
            // UserGroup File Load
            this.LoadUserGroupFile(ref this.CurrentUserGroup);
            // UserManager 초기화
            this.InitializeUserManager();
            this.CurrentSystemStatus.CurrentUser.Status = Define.E_UserStatus.LogOff;
            //UserManager.UserManager_GetUserListName();

            // Form 생성
            this.CreateForm();

            // 통신 OPEN
            this.OpenSmartUartLink();

            this.smartForm1.Show(1);

            // 초기 파라미터 전송
            this.TransferSystemParameter9039();

            // timer1 Get user List Name 
            //UserManager.UserManager_GetUserListName();
            this.timerUserList.Enabled = true;

            this.ModbusOpen();
        }
        #endregion

        #region Event Handler
        private void smartSerialPortLink_OnReadQueueEvent()
        {
            this.ReceiveData();

            // 통신 확인
            if (this.CommunicationCheckCount / 3 == 1)
            {
                if (this.ChildFormMainDisplay != null)
                    this.ChildFormMainDisplay.labelCommunicationStatus.Visible = true;

                this.CommunicationCheckCount = 0;
            }
            else
            {
                if (this.ChildFormMainDisplay != null)
                    this.ChildFormMainDisplay.labelCommunicationStatus.Visible = false;

                this.CommunicationCheckCount += 1;
            }
        }

        private void smartButton1_Click(object sender, EventArgs e)
        {
            this.smartForm1.Show(2);
        }
        private void smartButton2_Click(object sender, EventArgs e)
        {
            this.smartForm1.Show(1);
        }

        private void CurrentAlarmList_Change(Define.E_Trackingalarm alarm, string status)
        {
            this.SetTrackingAlarmData(alarm, status);
        }

        private void timerUserList_Tick(object sender, EventArgs e)
        {
            this.timerUserList.Enabled = false;
            UserManager.UserManager_GetUserListName();
        }

        #region UserManagerEvent
        private void UserManager_UserListLogoutDataEvent(int status)
        {
            try
            {
                if (status == (int)UserManager.USERMGR_LOGOUT_STATUS_OK)
                {
                    // logout
                }
                else
                {
                    // logout fail !!!
                    //MessageBox.Show("Logout Failed !!!!");
                }
            }
            catch
            {
            }
        }
        private void UserManager_UserListLoginDataEvent(int status, object data)
        {
            try
            {
                if (status == (int)UserManager.E_user_mgr_status.USER_MGR_STATUS_OK)
                {
                    UserManager.UserMgr_user_info_t userInfo = (UserManager.UserMgr_user_info_t)data;

                    //this.ChildFormMainDisplay.updatedisplayuser

                    //String Message;
                }
                else
                {
                    this.UI_Invoke(delegate
                    {
                        // login fail !!!
                        //textBox_id.Enabled = true;
                        //textBox_pw.Enabled = true;
                        //comboBox_logout_timeout.Enabled = true;

                        //button_login.Text = "LOGIN";
                        //Activation.IsLogin = false;
                    });
                }
            }
            catch
            {
            }
        }
        private void UserManager_UserListGetListDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_list_t userList = (UserManager.UserMgr_user_list_t)data;

                if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.UserEditor)
                    this.ChildFormMenu.CallBackGetUserData(userList);
            }
            catch
            {
            }
        }
        private void UserManager_UserListLoginTimeoutDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_login_timeout_t loginTimeout = (UserManager.UserMgr_login_timeout_t)data;

                if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.MainDisplay)
                    this.ChildFormMainDisplay.CallBackUserListLoginTimeoutDataEvent(loginTimeout);
            }
            catch (Exception e)
            {
            }
        }
        private void UserManager_UserListLockDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_lock_t user = (UserManager.UserMgr_user_lock_t)data;

                if (this.CurrentSystemStatus.CurrentDisplayMode == Define.E_DisplayModeStore.UserEditor)
                    this.ChildFormMenu.CallBackUserListLockDataEvent(user);
            }
            catch
            {
            }
        }
        private void UserManager_UserListDefaultSettingDataEvent(object data)
        {
            try
            {

            }
            catch
            {
            }
        }
        private void UserManager_UserListDeleteDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_del_t user = (UserManager.UserMgr_user_del_t)data;
                this.ChildFormMenu.CallBackUserListDeleteDataEvent(user);
            }
            catch
            {
            }
        }
        private void UserManager_UserListModifyUserDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_modify_t user = (UserManager.UserMgr_user_modify_t)data;

                this.ChildFormMenu.CallBackUserModifyUserData(user);
            }
            catch
            {
            }
        }
        private void UserManager_UserListModifyInfoDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_info_t user = (UserManager.UserMgr_user_info_t)data;

                //this.ChildFormMenu.Child_User_UserEditor.CallBackUserListModifyInfoDataEvent(user);
            }
            catch
            {
            }
        }
        private void UserManager_UserListNewDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_info_t user = (UserManager.UserMgr_user_info_t)data;

                this.ChildFormMenu.CallBackUserListNewData(user);
            }
            catch (Exception e)
            {
            }
        }
        private void UserManager_UserListAddDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_add_t userAdd = (UserManager.UserMgr_user_add_t)data;

                if (userAdd.status == (int)UserManager.E_user_mgr_status.USER_MGR_STATUS_OK)
                {
                    //for (int i = 0; i < this.CollectionUser.Count; i++)
                    //{
                    //    if (this.CollectionUser[i].ID == userAdd.user_id)
                    //    {
                    //        this.FlagUserListCNT++;
                    //        this.CollectionUser[i].IsUpdate = true;
                    //        this.CollectionUser[i].IsLockAccount = userAdd.flock_status_account == 0 ? false : true;
                    //        this.CollectionUser[i].IsLockPassword = userAdd.flock_status_password == 0 ? false : true;
                    //        break;
                    //    }
                    //}
                }
                else
                {
                    //for (int i = 0; i < this.CollectionUser.Count; i++)
                    //{
                    //    if (this.CollectionUser[i].ID == userAdd.user_id)
                    //    {
                    //        this.CollectionUser.RemoveAt(i);
                    //        break;
                    //    }
                    //}

                    //this.SaveUserFile(this.CollectionUser);
                }
            }
            catch
            {
            }
        }
        private void UserManager_UserListGetListNameDataEvent(object data)
        {
            try
            {
                UserManager.UserMgr_user_list_name_t name = (UserManager.UserMgr_user_list_name_t)data;

                if (name.total_count == 0)
                    return;

                this.ListDllUserName.Add(name.user_id);
            }
            catch
            {
            }
        }
        #endregion
        #endregion
    }
}