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

using SmartX;
using ITC81DB_2.DialogForms;

namespace ITC81DB_2.Forms
{
    public partial class FormMain : Form
    {
        #region Field
        private SmartSplash SmartSplashProgramLoad;
        public bool IsCommunicationLogOpen;
        private int CommunicationCheckCount;
        public bool IsBootingComplete;
        public int BufferSmartUart;
        public bool IsJudgmentNow1;
        public bool IsJudgmentNow2;

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

        // 파일 위치
        private string m_PathLaunchFolder;              // 프로그램 실행 폴더
        private string m_PathDataBackupFolder;          // 데이터 백업 폴더
        private string m_PathSystemFileFolder1;         // 시스템 파일 폴더1
        private string m_PathSystemFileFolder2;         // 시스템 파일 폴더2
        private string m_PathSystemFileBackupFolder;        // 시스템 파일 백업 폴더

        // 시스템 상태
        private SystemStatus m_CurrentSystemStatus;

        // System Configuration
        public SystemConfigurationItem SystemConfig;
        // #1 현재 선택 된 품목
        public ProductItem CurrentProductItem1;
        // #2 현재 선택 된 품목
        public ProductItem CurrentProductItem2;
        // #1 JudgmentSet
        public JudgmentSetItem CurrentJudgmentSetItem1;
        // #2 JudgmentSet
        public JudgmentSetItem CurrentJudgmentSetItem2;
        // 중량 조정 설정값
        public CalibrationItem CurrentCalibrationItem;
        // #1 중량 데이터
        public WeightData CurrentWeightData1;
        // #2 중량 데이터
        public WeightData CurrentWeightData2;
        // 시스템파라미터 - 9507
        public SystemParameter9507 CurrentSystemParameter9507;
        // 시스템파라미터 - 9508
        public SystemParameter9508 CurrentSystemParameter9508;
        // 시스템파라미터 - 9509
        public SystemParameter9509 CurrentSystemParameter9509;
        // 시스템파라미터 - 9510
        public SystemParameter9510 CurrentSystemParameter9510;
        // 시스템파라미터 - 9511
        public SystemParameter9511 CurrentSystemParameter9511;

        // Form
        public FormMainDisplay ChildFormMainDisplay;
        public FormMenu ChildFormMenu;

        // IO Test Input 데이터 취합
        private Collection<string> CollectionIOTest_InputData;
        // 판정설정 그래프 데이터
        private Collection<int> CollectionGraphData;      
        
        // User
        public User CurrentUser;
        // UserGroup
        public UserGroup CurrentUserGroup;
        #endregion

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

            // 프로그램 로딩 이미지
            this.SmartSplashProgramLoad = new SmartX.SmartSplash();
            this.SmartSplashProgramLoad.CenterPosition = true;
            this.SmartSplashProgramLoad.AnimationInterval = 100;
            this.SmartSplashProgramLoad.LoadingImagePathname = "SmartLoading3";
            this.SmartSplashProgramLoad.Start();
        } 
        #endregion

        #region Property
        public string PathLaunchFolder
        {
            get { return this.m_PathLaunchFolder; }
            set { this.m_PathLaunchFolder = value; }
        }
        public string PathDataBackupFolder
        {
            get { return this.m_PathDataBackupFolder; }
            set { this.m_PathDataBackupFolder = value; }
        }
        public string PathSystemFileFolder1
        {
            get { return this.m_PathSystemFileFolder1; }
            set { this.m_PathSystemFileFolder1 = value; }
        }
        public string PathSystemFileFolder2
        {
            get { return this.m_PathSystemFileFolder2; }
            set { this.m_PathSystemFileFolder2 = value; }
        }
        public string PathSystemFileBackupFolder
        {
            get { return m_PathSystemFileBackupFolder; }
            set { m_PathSystemFileBackupFolder = value; }
        } 

        public SystemStatus CurrentSystemStatus
        {
            get { return this.m_CurrentSystemStatus; }
            private set { this.m_CurrentSystemStatus = value; }
        } 
        #endregion

        #region Method
        private void DefaultSetting()
        {
            this.IsCommunicationLogOpen = false;
            this.CommunicationCheckCount = 0;
            this.IsBootingComplete = false;
            this.BufferSmartUart = 1000000;
            this.IsJudgmentNow1 = false;
            this.IsJudgmentNow2 = false;

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

            this.PathLaunchFolder = "SD Card\\";
            this.PathSystemFileFolder1 = this.PathLaunchFolder + "SystemFile1\\";
            this.PathSystemFileFolder2 = this.PathLaunchFolder + "SystemFile2\\";
            this.PathDataBackupFolder = this.PathLaunchFolder + "DataBackup\\";
            this.PathSystemFileBackupFolder = this.PathLaunchFolder + "SystemFileBackup\\";

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

            this.CollectionGraphData = new Collection<int>();
            this.CollectionGraphData.Clear();
            for (int i = 0; i < 300; i++)
                this.CollectionGraphData.Add(0);

            this.SystemConfig = new SystemConfigurationItem();
            this.CurrentProductItem1 = new ProductItem();
            this.CurrentProductItem2 = new ProductItem();
            this.CurrentJudgmentSetItem1 = new JudgmentSetItem();
            this.CurrentJudgmentSetItem2 = new JudgmentSetItem();
            this.CurrentCalibrationItem = new CalibrationItem();
            this.CurrentWeightData1 = new WeightData();
            this.CurrentWeightData2 = new WeightData();
            this.CurrentSystemStatus = new SystemStatus();
            this.CurrentSystemParameter9507 = new SystemParameter9507();
            this.CurrentSystemParameter9508 = new SystemParameter9508();
            this.CurrentSystemParameter9509 = new SystemParameter9509();
            this.CurrentSystemParameter9510 = new SystemParameter9510();
            this.CurrentSystemParameter9511 = new SystemParameter9511();
            this.CurrentUser = new User();
            this.CurrentUserGroup = new UserGroup();

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

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

            // DataBackup 폴더 생성
            if (Directory.Exists(this.PathDataBackupFolder) == false)
                Directory.CreateDirectory(this.PathDataBackupFolder);
        }

        private void CreateForm()
        {
            this.ChildFormMainDisplay = new FormMainDisplay(this);
            this.ChildFormMenu = new FormMenu(this);

            this.smartForm.MainForm = this;

            this.smartForm.AddChildForm(this.ChildFormMainDisplay);
            this.smartForm.AddChildForm(this.ChildFormMenu);
        }

        public void TransferProductParameter1(int productNumber)
        {
            string value = "";

            StringBuilder sb = new StringBuilder();
            ProductItem pItem = new ProductItem();
            JudgmentSetItem jItem = new JudgmentSetItem();

            this.LoadProductFile1(ref pItem, productNumber - 1);
            this.LoadJudgmentSetFile1(ref jItem, productNumber - 1);

            sb.Append(Helper.StringZeroFillDigits7(pItem.UnderRange));                          // 하한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.OverRange));                           // 상한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.TareRange));                           // 용기(78)
            value = Helper.DoubleToString(jItem.DynamicCorrection, 6);
            value = value.Replace(".", "");
            sb.Append(Helper.StringZeroFillDigits7(value));                                     // 동보정(7)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Filter.ToString()));                   // 필터(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentDelayTime.ToString()));        // 판정지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DoubleDelayTime.ToString()));          // 이중지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentCount.ToString()));            // 판정개수(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed1.ToString()));               // 인버터1속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed2.ToString()));               // 인버터2속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed3.ToString()));               // 인버터3속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgmentLength.ToString()));       // 자동판정-길이(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment1.ToString()));            // 자동판정-1(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment2.ToString()));            // 자동판정-2(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment3.ToString()));            // 자동판정-3(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1Mode.ToString()));              // 선별기1모드(4)    
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1DelayTime.ToString()));         // 선별기1지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1RunTime.ToString()));           // 선별기1동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter2Mode.ToString()));              // 선별기2모드(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter2DelayTime.ToString()));         // 선별기2지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter2RunTime.ToString()));           // 선별기2동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(this.SystemConfig.EquipmentID.ToString()));  // 장비ID(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DescendDelayTime.ToString()));          // 하강지연(4)                    
            sb.Append(Helper.StringZeroFillDigits4(jItem.AscendDelayTime.ToString()));            // 상승지연(4)
            sb.Append("0000");                                                                  // Dummy4(4)
            sb.Append("0000");                                                                  // Dummy5(4)
            sb.Append(Helper.StringZeroFillDigits4(pItem.Number.ToString()));                   // 품번 

            this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9014_SystemParameterWrite, sb.ToString());
        }
        public void TransferProductParameter2(int productNumber)
        {
            string value = "";

            StringBuilder sb = new StringBuilder();
            ProductItem pItem = new ProductItem();
            JudgmentSetItem jItem = new JudgmentSetItem();

            this.LoadProductFile2(ref pItem, productNumber - 1);
            this.LoadJudgmentSetFile2(ref jItem, productNumber - 1);

            sb.Append(Helper.StringZeroFillDigits7(pItem.UnderRange));                          // 하한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.OverRange));                           // 상한값(7)
            sb.Append(Helper.StringZeroFillDigits7(pItem.TareRange));                           // 용기(78)
            value = Helper.DoubleToString(jItem.DynamicCorrection, 6);
            value = value.Replace(".", "");
            sb.Append(Helper.StringZeroFillDigits7(value));                                     // 동보정(7)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Filter.ToString()));                   // 필터(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentDelayTime.ToString()));        // 판정지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DoubleDelayTime.ToString()));          // 이중지연(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.JudgmentCount.ToString()));            // 판정개수(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed1.ToString()));               // 인버터1속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed2.ToString()));               // 인버터2속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.FeedSpeed3.ToString()));               // 인버터3속도(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgmentLength.ToString()));       // 자동판정-길이(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment1.ToString()));            // 자동판정-1(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment2.ToString()));            // 자동판정-2(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.AutoJudgment3.ToString()));            // 자동판정-3(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1Mode.ToString()));              // 선별기1모드(4)    
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1DelayTime.ToString()));         // 선별기1지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter1RunTime.ToString()));           // 선별기1동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter2Mode.ToString()));              // 선별기2모드(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter2DelayTime.ToString()));         // 선별기2지연시간(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.Sorter2RunTime.ToString()));           // 선별기2동작시간(4)
            sb.Append(Helper.StringZeroFillDigits4(this.SystemConfig.EquipmentID.ToString()));  // 장비ID(4)
            sb.Append(Helper.StringZeroFillDigits4(jItem.DescendDelayTime.ToString()));          // 하강지연(4)                    
            sb.Append(Helper.StringZeroFillDigits4(jItem.AscendDelayTime.ToString()));            // 상승지연(4)
            sb.Append("0000");                                                                  // Dummy4(4)
            sb.Append("0000");                                                                  // Dummy5(4)
            sb.Append(Helper.StringZeroFillDigits4(pItem.Number.ToString()));                   // 품번 

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

        private void ConverterAlarm(ref WeightData data, string alarm, int laneNum)
        {
            string sValue1 = "", sValue2 = "", sValue3 = "";

            if (alarm.Length != 3)
                return;

            sValue1 = Convert.ToString(Convert.ToInt16(alarm.Substring(0, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue2 = Convert.ToString(Convert.ToInt16(alarm.Substring(1, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue3 = Convert.ToString(Convert.ToInt16(alarm.Substring(2, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');

            // 알람 12-외부에러
            if (sValue3[0] == '0')
            { }
            else
            { }
            // 알람 11-진입센서걸림(센서에러감지시간)
            if (sValue3[1] == '0')
                data.IsEntryStucked = false;
            else
            {
                data.IsEntryStucked = true;
                if (this.CurrentSystemStatus.Equipment == DataStore.EquipmentStatus.Start)
                {
                    this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
                    this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                }
            }
            // 알람 10-
            if (sValue3[2] == '0')
            { }
            else
            { }
            // 알람 9-인버터에러
            if (sValue3[3] == '0')
            { }
            else
            { }
            // 알람 8-제품진입 미감지
            if (sValue2[0] == '0')
                data.IsEntryNotDetected = false;
            else
            {
                if (laneNum == 1)
                {
                    if (this.IsJudgmentNow1 == false)
                    {
                        data.IsEntryNotDetected = true;
                        if (this.CurrentSystemStatus.Equipment == DataStore.EquipmentStatus.Start)
                        {
                            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
                            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                        }
                    }
                }
                else
                {
                    if (this.IsJudgmentNow2 == false)
                    {
                        data.IsEntryNotDetected = true;
                        if (this.CurrentSystemStatus.Equipment == DataStore.EquipmentStatus.Start)
                        {
                            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
                            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
                        }
                    }
                }
            }
            // 알람 7-리젝터 동작 감지
            if (sValue2[1] == '0')
            { }
            else
            { }
            // 알람 6-적체센서 에러
            if (sValue2[2] == '0')
            { }
            else
            { }
            // 알람 5-공압에러
            if (sValue2[3] == '0')
            { }
            else
            { }

            // 알람 4-Emergency
            if (sValue1[0] == '0')
                data.IsEmergencyStop = false;
            else
                data.IsEmergencyStop = true;
            // 알람 3-도어인터록
            if (sValue1[1] == '0')
            { }
            else
            { }
            // 알람 2-셀 에러
            if (sValue1[2] == '0')
                data.IsLoadCellError = false;
            else
                data.IsLoadCellError = true;

            // 알람 1-입력센서 에러
            if (sValue1[3] == '0')
                data.IsEntrySensorError = false;
            else
                data.IsEntrySensorError = true;
        }

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

            switch (mode)
            {
                case DataStore.DisplayMode.Normal:
                    this.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.Menu:
                    this.TransferData(CommunicationCommand.ModeMenu, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.Calibration:
                    this.TransferData(CommunicationCommand.ModeCalibration, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.SystemSetting:
                    this.TransferData(CommunicationCommand.ModeJudgment, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.IOTest:
                    this.TransferData(CommunicationCommand.ModeIOTest, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.Bypass:
                    this.TransferData(CommunicationCommand.ModeBypass, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.EquipmentTest:
                    this.TransferData(CommunicationCommand.ModeEquipmentTest, CommunicationID.MainBoard);
                    break;
                case DataStore.DisplayMode.SorterTest:
                    this.TransferData(CommunicationCommand.ModeRejectorTest, CommunicationID.MainBoard);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// Set User
        /// </summary>
        /// <param name="user"></param>
        public void SetUser(DataStore.UserGroup user)
        {
            if (this.CurrentSystemStatus.CurrentUserPasswordType.Group != user)
                this.CurrentSystemStatus.CurrentUserPasswordType.Group = user;
        }

        public void PrintingHeadLine()
        {
            if (this.SystemConfig.SerialCOM1Mode == 3)
            {
                this.TransferSerialCOM1("\n--------------------------------");
                this.TransferSerialCOM1(" NO LANE GRADE WEIGHT    COUNT");
                this.TransferSerialCOM1("--------------------------------");
            }

            if (this.SystemConfig.SerialCOM3Mode == 3)
            {
                this.TransferSerialCOM3("\n--------------------------------");
                this.TransferSerialCOM3(" NO LANE GRADE WEIGHT    COUNT");
                this.TransferSerialCOM3("--------------------------------");
            }
        }
        public void PrintingWeight(WeightData data1, WeightData data2, ProductItem pItem1, ProductItem pItem2)
        {
            string value = "";

            if (this.SystemConfig.SerialCOM1Mode == 3)
            {
                this.TransferSerialCOM1("##############################");
                this.TransferSerialCOM1("     TOTAL  PRINT  LINE1    ");
                this.TransferSerialCOM1("##############################");
                this.TransferSerialCOM1(string.Format(" PART    = {0}", pItem1.Number));
                if (data1.StartTime.Year == 1111 || data1.StopTime.Year == 1111)
                    data1.StartTime = data1.StopTime = DateTime.Now;
                this.TransferSerialCOM1(string.Format(" START   = {0}", data1.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM1(string.Format(" END     = {0}", data1.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM1(string.Format("\n UNDER   = {0}g",
                    Helper.StringToDecimalPlaces(pItem1.UnderRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data1.UnderCount));
                this.TransferSerialCOM1(string.Format(" TOTAL.W = {0}kg", data1.UnderSumWeightKG));
                this.TransferSerialCOM1(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data1.UnderAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" RATIO   = {0}%", data1.UnderRatio));

                this.TransferSerialCOM1(string.Format("\n PASS    = {0}g",
                  Helper.StringToDecimalPlaces(pItem1.PassRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data1.PassCount));
                this.TransferSerialCOM1(string.Format(" TOTAL.W = {0}kg", data1.PassSumWeightKG));
                this.TransferSerialCOM1(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data1.PassAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" RATIO   = {0}%", data1.PassRatio));

                this.TransferSerialCOM1(string.Format("\n OVER    = {0}g",
                  Helper.StringToDecimalPlaces(pItem1.OverRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data1.OverCount));
                this.TransferSerialCOM1(string.Format(" TOTAL.W = {0}kg", data1.OverSumWeightKG));
                this.TransferSerialCOM1(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data1.OverAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" RATIO   = {0}%", data1.OverRatio));

                this.TransferSerialCOM1(string.Format("\n TARE    = {0}g",
                    Helper.StringToDecimalPlaces(pItem1.TareRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1("\n TOTAL");
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data1.TotalCount1));

                this.TransferSerialCOM1("##############################\n\n\n\n");

                this.TransferSerialCOM1("##############################");
                this.TransferSerialCOM1("     TOTAL  PRINT  LINE2    ");
                this.TransferSerialCOM1("##############################");
                this.TransferSerialCOM1(string.Format(" PART    = {0}", pItem2.Number));
                if (data2.StartTime.Year == 1111 || data2.StopTime.Year == 1111)
                    data2.StartTime = data2.StopTime = DateTime.Now;
                this.TransferSerialCOM1(string.Format(" START   = {0}", data2.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM1(string.Format(" END     = {0}", data2.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM1(string.Format("\n UNDER   = {0}g",
                    Helper.StringToDecimalPlaces(pItem2.UnderRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data2.UnderCount));
                this.TransferSerialCOM1(string.Format(" TOTAL.W = {0}kg", data2.UnderSumWeightKG));
                this.TransferSerialCOM1(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data2.UnderAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" RATIO   = {0}%", data2.UnderRatio));

                this.TransferSerialCOM1(string.Format("\n PASS    = {0}g",
                  Helper.StringToDecimalPlaces(pItem2.PassRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data2.PassCount));
                this.TransferSerialCOM1(string.Format(" TOTAL.W = {0}kg", data2.PassSumWeightKG));
                this.TransferSerialCOM1(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data2.PassAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" RATIO   = {0}%", data2.PassRatio));

                this.TransferSerialCOM1(string.Format("\n OVER    = {0}g",
                  Helper.StringToDecimalPlaces(pItem2.OverRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data2.OverCount));
                this.TransferSerialCOM1(string.Format(" TOTAL.W = {0}kg", data2.OverSumWeightKG));
                this.TransferSerialCOM1(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data2.OverAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1(string.Format(" RATIO   = {0}%", data2.OverRatio));

                this.TransferSerialCOM1(string.Format("\n TARE    = {0}g",
                    Helper.StringToDecimalPlaces(pItem2.TareRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM1("\n TOTAL");
                this.TransferSerialCOM1(string.Format(" COUNT   = {0}", data2.TotalCount1));

                this.TransferSerialCOM1("##############################\n\n\n\n");
            }

            if (this.SystemConfig.SerialCOM3Mode == 3)
            {
                this.TransferSerialCOM3("##############################");
                this.TransferSerialCOM3("     TOTAL  PRINT  LINE1    ");
                this.TransferSerialCOM3("##############################");
                this.TransferSerialCOM3(string.Format(" PART    = {0}", pItem1.Number));
                if (data1.StartTime.Year == 1111 || data1.StopTime.Year == 1111)
                    data1.StartTime = data1.StopTime = DateTime.Now;
                this.TransferSerialCOM3(string.Format(" START   = {0}", data1.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM3(string.Format(" END     = {0}", data1.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM3(string.Format("\n UNDER   = {0}g",
                    Helper.StringToDecimalPlaces(pItem1.UnderRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data1.UnderCount));
                this.TransferSerialCOM3(string.Format(" TOTAL.W = {0}kg", data1.UnderSumWeightKG));
                this.TransferSerialCOM3(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data1.UnderAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" RATIO   = {0}%", data1.UnderRatio));

                this.TransferSerialCOM3(string.Format("\n PASS    = {0}g",
                  Helper.StringToDecimalPlaces(pItem1.PassRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data1.PassCount));
                this.TransferSerialCOM3(string.Format(" TOTAL.W = {0}kg", data1.PassSumWeightKG));
                this.TransferSerialCOM3(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data1.PassAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" RATIO   = {0}%", data1.PassRatio));

                this.TransferSerialCOM3(string.Format("\n OVER    = {0}g",
                  Helper.StringToDecimalPlaces(pItem1.OverRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data1.OverCount));
                this.TransferSerialCOM3(string.Format(" TOTAL.W = {0}kg", data1.OverSumWeightKG));
                this.TransferSerialCOM3(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data1.OverAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" RATIO   = {0}%", data1.OverRatio));

                this.TransferSerialCOM3(string.Format("\n TARE    = {0}g",
                    Helper.StringToDecimalPlaces(pItem1.TareRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3("\n TOTAL");
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data1.TotalCount1));

                this.TransferSerialCOM3("##############################\n\n\n\n");

                this.TransferSerialCOM3("##############################");
                this.TransferSerialCOM3("     TOTAL  PRINT  LINE2    ");
                this.TransferSerialCOM3("##############################");
                this.TransferSerialCOM3(string.Format(" PART    = {0}", pItem2.Number));
                if (data2.StartTime.Year == 1111 || data2.StopTime.Year == 1111)
                    data2.StartTime = data2.StopTime = DateTime.Now;
                this.TransferSerialCOM3(string.Format(" START   = {0}", data2.StartTime.ToString("yyyy-MM-dd HH:mm:ss")));
                this.TransferSerialCOM3(string.Format(" END     = {0}", data2.StopTime.ToString("yyyy-MM-dd HH:mm:ss")));

                this.TransferSerialCOM3(string.Format("\n UNDER   = {0}g",
                    Helper.StringToDecimalPlaces(pItem2.UnderRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data2.UnderCount));
                this.TransferSerialCOM3(string.Format(" TOTAL.W = {0}kg", data2.UnderSumWeightKG));
                this.TransferSerialCOM3(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data2.UnderAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" RATIO   = {0}%", data2.UnderRatio));

                this.TransferSerialCOM3(string.Format("\n PASS    = {0}g",
                  Helper.StringToDecimalPlaces(pItem2.PassRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data2.PassCount));
                this.TransferSerialCOM3(string.Format(" TOTAL.W = {0}kg", data2.PassSumWeightKG));
                this.TransferSerialCOM3(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data2.PassAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" RATIO   = {0}%", data2.PassRatio));

                this.TransferSerialCOM3(string.Format("\n OVER    = {0}g",
                  Helper.StringToDecimalPlaces(pItem2.OverRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data2.OverCount));
                this.TransferSerialCOM3(string.Format(" TOTAL.W = {0}kg", data2.OverSumWeightKG));
                this.TransferSerialCOM3(string.Format(" AVG     = {0}g",
                    Helper.DoubleToString(data2.OverAverage, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3(string.Format(" RATIO   = {0}%", data2.OverRatio));

                this.TransferSerialCOM3(string.Format("\n TARE    = {0}g",
                    Helper.StringToDecimalPlaces(pItem2.TareRange, this.SystemConfig.DecimalPlaces)));
                this.TransferSerialCOM3("\n TOTAL");
                this.TransferSerialCOM3(string.Format(" COUNT   = {0}", data2.TotalCount1));

                this.TransferSerialCOM3("##############################\n\n\n\n");
            }
        }

        public void TimerSensorErrorInterval()
        {
            if (this.timerSensorError1.Enabled == true)
                this.timerSensorError1.Enabled = false;
            this.timerSensorError1.Interval = this.SystemConfig.SensorErrorDetectingTime;
            
            if (this.timerSensorError2.Enabled == true)
                this.timerSensorError2.Enabled = false;
            this.timerSensorError2.Interval = this.SystemConfig.SensorErrorDetectingTime;

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("timerSensorError Interval ({0:yyyy-MM-dd HH:mm:ss}): timer1:{1}, timer2:{2}", DateTime.Now, 
                    this.timerSensorError1.Interval, this.timerSensorError2.Interval));
        }
        public void TimerEntryNotDetectedIgnoreTimeInverval()
        {
            this.timerEntryNotDetectedIgnoreTime1.Interval = this.SystemConfig.EntryNotDetectedIgnoreTime;
            this.timerEntryNotDetectedIgnoreTime2.Interval = this.SystemConfig.EntryNotDetectedIgnoreTime;
        }

        #region Uart Communication
        public void OpenSmartUartLink()
        {
            string fullPath = "";

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

            #region Test 용 통신 로그
            fullPath = this.PathDataBackupFolder + "Communicationlog.txt";
            this.smartFileCommunicationLog.FilePathName = fullPath;
            //this.smartFileCommunicationLog.Open();
            //this.IsCommunicationLogOpen = true;
            #endregion
        }
        public void CloseSmartUartLink()
        {
            if (this.IsCommunicationLogOpen == true)
            {
                this.IsCommunicationLogOpen = false;
                this.smartFileCommunicationLog.Close();
            }
            this.smartSerialPort2.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;
        }

        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.smartSerialPort2.IsOpen == true)
                this.smartSerialPort2.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(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.StringZeroFillDigits4(data.Length.ToString()));
            sb.Append(address);
            sb.Append(data);

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

            sb.Append(chkSum);

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

            // 통신 확인 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(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.smartSerialPort2.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 = "", lane = "";

            if (this.ChksumCheck(strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(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.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));

            cmd = strTemp.Substring(0, 3);
            lane = strTemp.Substring(5, 1);

            switch (cmd)
            {
                case "CI0":
                    #region Main Board Booted
                    if (this.CurrentSystemStatus.Equipment == DataStore.EquipmentStatus.Start)
                    {
                        this.CurrentSystemStatus.Equipment = DataStore.EquipmentStatus.Stop;

                        // 생산속도 Clear
                        this.CurrentWeightData1.ProductionSpeed = 0;
                        this.CurrentWeightData2.ProductionSpeed = 0;
                        this.CurrentWeightData1.IsStart = false;
                        this.CurrentWeightData2.IsStart = false;

                        // 정지 시간 저장
                        this.CurrentWeightData1.StopTime = DateTime.Now;
                        this.CurrentWeightData2.StopTime = DateTime.Now;
                        this.SaveCounterFile1(this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                        this.SaveCounterFile2(this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);

                        this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    }
                    // Read SystemParameter1
                    this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9507_SystemParameterRead, ""); 
                    #endregion
                    break;
                case "CBI":
                    #region 공장초기화완료
                    this.ChildFormMenu.CenterEquipInitialize.UpdateDisplayMainBoardInitialization();
                    #endregion
                    break;
                case "CBS":
                    #region 운전
                    this.CurrentSystemStatus.Equipment = DataStore.EquipmentStatus.Start;

                    // 운전시 중량 0 으로 Clear
                    this.CurrentWeightData1.Weight = 0.0;
                    this.CurrentWeightData2.Weight = 0.0;

                    // 운전 시간 저장
                    if (this.CurrentWeightData1.TotalCount1 == 0 && this.CurrentWeightData2.TotalCount1 == 0)
                    {
                        this.CurrentWeightData1.StartTime = DateTime.Now;
                        this.CurrentWeightData2.StartTime = DateTime.Now;
                        this.SaveCounterFile1(this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                        this.SaveCounterFile2(this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);
                    }

                    // 운전 시, Pop up 창 자동 Close
                    this.ChildFormMainDisplay.PopUpWarningClose();

                    if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.MainDisplay)
                        this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    else
                        this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    #endregion
                    break;
                case "CBT":
                    #region 정지
                    this.CurrentSystemStatus.Equipment = DataStore.EquipmentStatus.Stop;

                    // 생산속도 Clear
                    this.CurrentWeightData1.ProductionSpeed = 0;
                    this.CurrentWeightData2.ProductionSpeed = 0;
                    this.CurrentWeightData1.IsStart = false;
                    this.CurrentWeightData2.IsStart = false;

                    // 정지 시간 저장
                    this.CurrentWeightData1.StopTime = DateTime.Now;
                    this.CurrentWeightData2.StopTime = DateTime.Now;
                    this.SaveCounterFile1(this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                    this.SaveCounterFile2(this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);

                    if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.MainDisplay)
                        this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment);
                    else
                        this.ChildFormMenu.UpdateEquipmentStatusDisplay(this.CurrentSystemStatus.Equipment); 
                    #endregion
                    break;
                case "CBE":
                    #region 소거

                    #endregion
                    break;
                case "CBZ":
                    #region 영점

                    #endregion
                    break;
                case "CSa":
                    try
                    {
                        switch (lane)
                        {
                            case "A":
                                // 센서에러 감지시간 설정 시
                                if (this.SystemConfig.SensorErrorDetectingTime > 0)
                                    this.timerSensorError1.Enabled = true;
                                break;
                            case "B":
                                // 센서에러 감지시간 설정 시
                                if (this.SystemConfig.SensorErrorDetectingTime > 0)
                                    this.timerSensorError2.Enabled = true;
                                break;
                            default:
                                break;
                        }
                    }
                    catch
                    {
                        ret = -1;
                    }                    
                    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.WriteString(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.WriteString(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.WriteString(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;
                case "PB0":
                    if ((ret = this.ReceiveCommandPB0(lane, address, receiveData)) != 0)
                        return ret = -1;
                    break;
                default:
                    break;
            }

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

            // SIZE 확인
            if (this.SizeCheck("S", strTemp) == false)
            {
                // 로그
                if (this.IsCommunicationLogOpen == true)
                    this.smartFileCommunicationLog.WriteString(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.WriteString(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.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.UtcNow, strTemp));

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

            switch (cmd)
            {
                case "SN0":
                    if ((ret = this.ReceiveCommandSN0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SR0":
                    if ((ret = this.ReceiveCommandSR0(lane, transferCount, receiveData)) != 0)
                        return ret;
                    break;
                case "SC0":
                    if ((ret = this.ReceiveCommandSC0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "ST0":
                    if ((ret = this.ReceiveCommandST0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SF0":
                    if ((ret = this.ReceiveCommandSF0(lane, receiveData)) != 0)
                        return ret;
                    break;
                case "SG0":
                    if ((ret = this.ReceiveCommandSG0(lane, receiveData)) != 0)
                        return ret;
                    break;
                default:
                    break;
            }

            // ex
            #region ex
            //if (cmd == "SG0")
            //{
            //    byte[] a = new UTF8Encoding().GetBytes(strTemp.Substring(0, strTemp.Length - 2));
            //    int j = 0, first, second;
            //    char char1, char2;
            //    string value1 = "";
            //    for (int i = 0; i < a.Length; i++)
            //    {
            //        j += a[i];
            //    }

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

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

            //    value1 = char1.ToString() + char2.ToString();
            //    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateChecksumDisplay(strTemp.Substring(strTemp.Length - 2, 2), value1);
            //}
            #endregion

            return ret;
        }

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

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

                        if (iValue != this.SystemConfig.ProductNumber)
                        {
                            this.SystemConfig.ProductNumber = iValue;
                            this.SaveSystemConfigurationFile(this.SystemConfig);
                        }

                        // 최초에 부팅이 완료 되었는지 확인
                        if (this.IsBootingComplete == false)
                            this.IsBootingComplete = true;

                        this.LoadProductFile1(ref this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
                        this.LoadProductFile2(ref this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
                        this.LoadCounterFile1(ref this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
                        this.LoadCounterFile2(ref this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);
                        this.LoadJudgmentSetFile1(ref this.CurrentJudgmentSetItem1, this.SystemConfig.ProductNumber - 1);
                        this.LoadJudgmentSetFile2(ref this.CurrentJudgmentSetItem2, this.SystemConfig.ProductNumber - 1);

                        // 생산속도 Clear
                        this.CurrentWeightData1.ProductionSpeed = 0;
                        this.CurrentWeightData2.ProductionSpeed = 0;
                        this.CurrentWeightData1.IsStart = false;
                        this.CurrentWeightData2.IsStart = false;

                        if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateCurrentProductDisplay(this.CurrentSystemStatus.Equipment,
                                this.CurrentProductItem1, this.CurrentProductItem2, this.CurrentWeightData1, this.CurrentWeightData2);
                        else if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.SystemJudgmentSetting)
                            this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateCurrentProductDisplay(this.CurrentSystemStatus.Equipment, this.CurrentProductItem1, this.CurrentProductItem2);
                        break;
                    case "3601":
                        #region Value Assign
                        this.CurrentCalibrationItem.Constant1 = receiveData.Substring(0, 7).Trim();
                        this.CurrentCalibrationItem.Constant2 = receiveData.Substring(7, 7).Trim();
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.SystemCalibration)
                            this.ChildFormMenu.CenterSystemCalibration.UpdateConstantDisplay(this.CurrentCalibrationItem);
                        else if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.SystemJudgmentSetting)
                            this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateConstantDisplay(this.CurrentSystemStatus.Equipment, this.CurrentCalibrationItem);
                        break;
                    case "3901":
                        #region Value Assign
                        this.CurrentCalibrationItem.MaxWeight = receiveData.Substring(0, 7).Trim();
                        this.CurrentCalibrationItem.BalanceWeight = receiveData.Substring(7, 7).Trim();
                        this.CurrentCalibrationItem.Digit = receiveData.Substring(14, 7).Trim();
                        this.CurrentCalibrationItem.Constant1 = receiveData.Substring(21, 7).Trim();
                        this.CurrentCalibrationItem.Constant2 = receiveData.Substring(28, 7).Trim();
                        #endregion
                        this.ChildFormMenu.CenterSystemCalibration.UpdateCalibrationItemDisplay(this.CurrentSystemStatus.Equipment, this.CurrentCalibrationItem);
                        break;
                    case "4901":
                        #region Value Assign
                        this.CurrentSystemParameter9510.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Mode = receiveData.Substring(12, 4).Trim();
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.SystemAutoZero)
                            this.ChildFormMenu.CenterSystemAutoZero.UpdateZero1ParameterDisplay(this.CurrentSystemParameter9510);
                        else if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.MainDisplayMenu.UpdateZero1ParameterDisplay(this.CurrentSystemParameter9510);
                        break;
                    case "4902":
                        #region Value Assign
                        this.CurrentSystemParameter9510.AutoZero2Mode = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Time = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Range = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Variate = receiveData.Substring(12, 4).Trim();
                        #endregion
                        this.ChildFormMenu.CenterSystemAutoZero.UpdateZero2ParameterDisplay(this.CurrentSystemParameter9510);
                        break;
                    case "4903":
                        #region Value Assign
                        this.CurrentSystemParameter9511.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Mode = receiveData.Substring(12, 4).Trim();
                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.SystemAutoZero)
                            this.ChildFormMenu.CenterSystemAutoZero.UpdateZero3ParameterDisplay(this.CurrentSystemParameter9511);
                        else if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.MainDisplayMenu.UpdateZero2ParameterDisplay(this.CurrentSystemParameter9511);
                        break;
                    case "4904":
                        #region Value Assign
                        this.CurrentSystemParameter9511.AutoZero2Mode = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Time = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Range = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Variate = receiveData.Substring(12, 4).Trim();
                        #endregion
                        this.ChildFormMenu.CenterSystemAutoZero.UpdateZero4ParameterDisplay(this.CurrentSystemParameter9511);
                        break;
                    case "5302":
                        #region Value Assign
                        #endregion
                        break;
                    case "6901":
                        #region Value Assign
                        #endregion
                        break;
                    case "9507":
                        #region Value Assign
                        this.CurrentSystemParameter9507.BuzzerOnTime = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9507.RelayOnTime = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9507.SorterDoubleEntry = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9507.Chattering = receiveData.Substring(12, 4).Trim();
                        this.CurrentSystemParameter9507.EntryNotDetectedWeight = receiveData.Substring(16, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy1 = receiveData.Substring(23, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy2 = receiveData.Substring(30, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy3 = receiveData.Substring(37, 7).Trim();
                        this.CurrentSystemParameter9507.Dummy4 = receiveData.Substring(44, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy5 = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy6 = receiveData.Substring(52, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy7 = receiveData.Substring(56, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy8 = receiveData.Substring(60, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy9 = receiveData.Substring(64, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy10 = receiveData.Substring(68, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy11 = receiveData.Substring(72, 4).Trim();
                        this.CurrentSystemParameter9507.Dummy12 = receiveData.Substring(76, 4).Trim();
                        #endregion
                        // Read SystemParameter9508
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9508_SystemParameterRead, "");
                        break;
                    case "9508":
                        #region Value Assign
                        this.CurrentSystemParameter9508.OPT1SamplingCount = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1DelayCount = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1PulseWidth = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1IsWeightSetting = receiveData.Substring(12, 4).Trim();
                        this.CurrentSystemParameter9508.OPT1OverRange = receiveData.Substring(16, 7).Trim();
                        this.CurrentSystemParameter9508.OPT1UnderRange = receiveData.Substring(23, 7).Trim();
                        this.CurrentSystemParameter9508.OPT1Port = receiveData.Substring(30, 4).Trim();
                        this.CurrentSystemParameter9508.OPT2Port = receiveData.Substring(34, 4).Trim();
                        this.CurrentSystemParameter9508.OPT2DelayTime1 = receiveData.Substring(38, 4).Trim();
                        this.CurrentSystemParameter9508.OPt2DelayTime2 = receiveData.Substring(42, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy1 = receiveData.Substring(46, 7).Trim();
                        this.CurrentSystemParameter9508.Dummy2 = receiveData.Substring(53, 7).Trim();
                        this.CurrentSystemParameter9508.Dummy3 = receiveData.Substring(60, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy4 = receiveData.Substring(64, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy5 = receiveData.Substring(68, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy6 = receiveData.Substring(72, 4).Trim();
                        this.CurrentSystemParameter9508.Dummy6 = receiveData.Substring(76, 4).Trim();
                        #endregion
                        // Read SystemParameter9509
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9509_SystemParameterRead, "");
                        break;
                    case "9509":
                        #region Value Assign
                        this.CurrentSystemParameter9509.ExternalOut1Mode = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut1DelayTime = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut1RunTime = receiveData.Substring(8, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut2Mode = receiveData.Substring(12, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut2DelayTime = receiveData.Substring(16, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut2RunTime = receiveData.Substring(20, 4).Trim();
                        
                        this.CurrentSystemParameter9509.ExternalOut3Mode = receiveData.Substring(24, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut3DelayTime = receiveData.Substring(28, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut3RunTime = receiveData.Substring(32, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut4Mode = receiveData.Substring(36, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut4DelayTime = receiveData.Substring(40, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut4RunTime = receiveData.Substring(44, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut9Mode = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut9DelayTime = receiveData.Substring(52, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut9RunTime = receiveData.Substring(56, 4).Trim();

                        this.CurrentSystemParameter9509.ExternalOut10Mode = receiveData.Substring(60, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut10DelayTime = receiveData.Substring(64, 4).Trim();
                        this.CurrentSystemParameter9509.ExternalOut10RunTime = receiveData.Substring(68, 4).Trim();

                        this.CurrentSystemParameter9509.Dummy1 = receiveData.Substring(72, 4).Trim();
                        this.CurrentSystemParameter9509.Dummy2 = receiveData.Substring(76, 4).Trim();
                        #endregion
                        // Read SystemParameter9510
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9510_SystemParameterRead, "");
                        break;
                    case "9510":
                        #region Value Assign
                        this.CurrentSystemParameter9510.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero1Mode = receiveData.Substring(12, 4).Trim();

                        this.CurrentSystemParameter9510.AutoZero2Mode = receiveData.Substring(16, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Time = receiveData.Substring(20, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Range = receiveData.Substring(24, 4).Trim();
                        this.CurrentSystemParameter9510.AutoZero2Variate = receiveData.Substring(28, 4).Trim();

                        this.CurrentSystemParameter9510.Dummy1 = receiveData.Substring(32, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy2 = receiveData.Substring(36, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy3 = receiveData.Substring(40, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy4 = receiveData.Substring(44, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy5 = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9510.Dummy6 = receiveData.Substring(52, 4).Trim();
                        #endregion
                        // Read SystemParameter9511
                        this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9511_SystemParameterRead, "");
                        break;
                    case "9511":
                        #region Value Assign
                        this.CurrentSystemParameter9511.AutoZero1Time = receiveData.Substring(0, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Range = receiveData.Substring(4, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Variate = receiveData.Substring(8, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero1Mode = receiveData.Substring(12, 4).Trim();

                        this.CurrentSystemParameter9511.AutoZero2Mode = receiveData.Substring(16, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Time = receiveData.Substring(20, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Range = receiveData.Substring(24, 4).Trim();
                        this.CurrentSystemParameter9511.AutoZero2Variate = receiveData.Substring(28, 4).Trim();

                        this.CurrentSystemParameter9511.Dummy1 = receiveData.Substring(32, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy2 = receiveData.Substring(36, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy3 = receiveData.Substring(40, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy4 = receiveData.Substring(44, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy5 = receiveData.Substring(48, 4).Trim();
                        this.CurrentSystemParameter9511.Dummy6 = receiveData.Substring(52, 4).Trim();
                        #endregion
                        this.TransferProductParameter1(this.SystemConfig.ProductNumber);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 파라미터 쓰기 응답
        private int ReceiveCommandPW0(string lane, string address, string receiveData)
        {
            int ret = 0;
            DataStore.ResponseData response = DataStore.ResponseData.NAK;

            try
            {
                if (receiveData == "0")
                    response = DataStore.ResponseData.NAK;
                else
                    response = DataStore.ResponseData.ACK;

                switch (address)
                {
                    case "4004":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4901_ParameterRead1, "");
                        break;
                    case "4005":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4902_ParameterRead2, "");
                        break;
                    case "4024":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4903_ParameterRead3, "");
                        break;
                    case "4025":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._4904_ParameterRead4, "");
                        break;
                    case "9006":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferProductParameter1(this.SystemConfig.ProductNumber);
                        break;
                    case "9007":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._2001_ProductNumber, "");
                        break;
                    case "9014":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferProductParameter2(this.SystemConfig.ProductNumber);
                        break;
                    case "9017":
                        if (response == DataStore.ResponseData.ACK)
                            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._2001_ProductNumber, "");
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // Bypass to motor
        private int ReceiveCommandPB0(string lane, string address, string receiveData)
        {
            int ret = 0;
            DataStore.ResponseData response = DataStore.ResponseData.NAK;

            try
            {
                if (receiveData == "0000")
                    response = DataStore.ResponseData.NAK;
                else
                    response = DataStore.ResponseData.ACK;

                switch (address)
                {
                    case "1101":
                        break;
                    case "1102":
                        break;
                    case "1103":
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }

        // 정지시 중량
        private int ReceiveCommandSN0(string lane, string receiveData)
        {
            int ret = 0;

            try
            {
                switch (lane)
                {
                    case "Z":
                        #region Value Assign

                        if (this.CurrentSystemStatus.Equipment == DataStore.EquipmentStatus.Stop)
                        {
                            this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                            this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                            this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                            this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                            this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(24, 5), this.SystemConfig.DecimalPlaces);
                            this.CurrentWeightData2.ADCValue = receiveData.Substring(29, 5);
                        }
                        else
                        {
                            this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);

                            this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                            this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                        }

                        #endregion
                        if (this.CurrentSystemStatus.CurrentDisplay == DataStore.DisplayStore.MainDisplay)
                            this.ChildFormMainDisplay.UpdateStopWeightDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1, this.CurrentWeightData2);
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 운전시 중량
        private int ReceiveCommandSR0(string lane, string transferCount, string receiveData)
        {
            int ret = 0;

            if (this.timerSensorError1.Enabled == true)
                this.timerSensorError1.Enabled = false;
            if (this.timerSensorError2.Enabled == true)
                this.timerSensorError2.Enabled = false;

            try
            {
                switch (lane)
                {
                    case "A":
                        #region Value Assign
                        this.CurrentWeightData1.JudgmentStatus = Helper.StringToJudgmentStatus(receiveData.Substring(0, 2));
                        this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                        this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                        this.CurrentWeightData1.WeightString = receiveData.Substring(5, 5);
                        this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);
                        this.CurrentWeightData1.ProductionSpeed = int.Parse(receiveData.Substring(15, 4).Trim());
                        
                        this.CurrentWeightData1.WeightSum(this.CurrentWeightData1.JudgmentStatus);
                        #endregion
                        // 통신 제대로 받으면 ACK
                        this.TransferData(string.Format("{0}{1}{2}", CommunicationCommand.RunWeightData, (int)DataStore.ResponseData.ACK, transferCount), CommunicationID.MainBoard);

                        this.IsJudgmentNow1 = true;
                        // 로그
                        if (this.IsCommunicationLogOpen == true)
                            this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow1 ({0:yyyy-MM-dd HH:mm:ss}): true", DateTime.Now));
                        this.timerEntryNotDetectedIgnoreTime1.Enabled = true;
                        
                        // 통신 COM1
                        if (this.SystemConfig.SerialCOM1Mode != 0)
                        {
                            switch (this.SystemConfig.SerialCOM1Mode)
                            {
                                case 1:
                                    this.TransferSerialCOM1(this.Transfer_1_STD1(this.SystemConfig, DataStore.Line.Line1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 2:
                                    this.TransferSerialCOM1(this.Transfer_2_Remote(this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 3:
                                    if (this.SystemConfig.IsPrint1Enable == true)
                                        this.TransferSerialCOM1(this.Transfer_3_Print(this.CurrentWeightData1, DataStore.Line.Line1, this.CurrentProductItem1));
                                    break;
                                case 4:
                                    this.TransferSerialCOM1(this.Transfer_4_STD2(this.SystemConfig, DataStore.Line.Line1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                default:
                                    break;
                            }
                        }
                        // 통신 COM3
                        if (this.SystemConfig.SerialCOM3Mode != 0)
                        {
                            switch (this.SystemConfig.SerialCOM3Mode)
                            {
                                case 1:
                                    this.TransferSerialCOM3(this.Transfer_1_STD1(this.SystemConfig, DataStore.Line.Line1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 2:
                                    this.TransferSerialCOM3(this.Transfer_2_Remote(this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                case 3:
                                    if (this.SystemConfig.IsPrint1Enable == true)
                                        this.TransferSerialCOM3(this.Transfer_3_Print(this.CurrentWeightData1, DataStore.Line.Line1, this.CurrentProductItem1));
                                    break;
                                case 4:
                                    this.TransferSerialCOM3(this.Transfer_4_STD2(this.SystemConfig, DataStore.Line.Line1, this.CurrentWeightData1, this.CurrentProductItem1));
                                    break;
                                default:
                                    break;
                            }
                        }

                        // CurrentDisplay
                        switch (this.CurrentSystemStatus.CurrentDisplay)
                        {
                            case DataStore.DisplayStore.MainDisplay:
                                #region MainDisplay
                                this.ChildFormMainDisplay.UpdateStartWeightDisplay1(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1);

                                if (this.CurrentWeightData1.JudgmentStatus != DataStore.JudgmentStatus.Empty)
                                    this.DataBackup1(this.CurrentWeightData1);

                                // 표준분포
                                this.CurrentWeightData1.SetNormalDistribution(this.CurrentProductItem1.CollectionNormalDistributionRange, this.CurrentWeightData1.WeightString); 
                                #endregion
                                break;
                            default:
                                break;
                        }
                        break;
                    case "B":
                        #region Value Assign
                        this.CurrentWeightData2.JudgmentStatus = Helper.StringToJudgmentStatus(receiveData.Substring(0, 2));
                        this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 2);
                        this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                        this.CurrentWeightData2.WeightString = receiveData.Substring(5, 5);
                        this.CurrentWeightData2.ADCValue = receiveData.Substring(10, 5);
                        this.CurrentWeightData2.ProductionSpeed = int.Parse(receiveData.Substring(15, 4).Trim());

                        this.CurrentWeightData2.WeightSum(this.CurrentWeightData2.JudgmentStatus);
                        #endregion
                        // 통신 제대로 받으면 ACK
                        this.TransferData(string.Format("{0}{1}{2}", CommunicationCommand.RunWeightData, (int)DataStore.ResponseData.ACK, transferCount), CommunicationID.MainBoard);

                        this.IsJudgmentNow2 = true;
                        // 로그
                        if (this.IsCommunicationLogOpen == true)
                            this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow2 ({0:yyyy-MM-dd HH:mm:ss}): true", DateTime.Now));
                        this.timerEntryNotDetectedIgnoreTime2.Enabled = true;

                        // 통신 COM1
                        if (this.SystemConfig.SerialCOM1Mode != 0)
                        {
                            switch (this.SystemConfig.SerialCOM1Mode)
                            {
                                case 1:
                                    this.TransferSerialCOM1(this.Transfer_1_STD1(this.SystemConfig, DataStore.Line.Line2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 2:
                                    this.TransferSerialCOM1(this.Transfer_2_Remote(this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 3:
                                    if (this.SystemConfig.IsPrint2Enable == true)
                                        this.TransferSerialCOM1(this.Transfer_3_Print(this.CurrentWeightData2, DataStore.Line.Line2, this.CurrentProductItem2));
                                    break;
                                case 4:
                                    this.TransferSerialCOM1(this.Transfer_4_STD2(this.SystemConfig, DataStore.Line.Line2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                default:
                                    break;
                            }
                        }
                        // 통신 COM3
                        if (this.SystemConfig.SerialCOM3Mode != 0)
                        {
                            switch (this.SystemConfig.SerialCOM3Mode)
                            {
                                case 1:
                                    this.TransferSerialCOM3(this.Transfer_1_STD1(this.SystemConfig, DataStore.Line.Line2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 2:
                                    this.TransferSerialCOM3(this.Transfer_2_Remote(this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                case 3:
                                    if(this.SystemConfig.IsPrint2Enable == true)
                                        this.TransferSerialCOM3(this.Transfer_3_Print(this.CurrentWeightData2, DataStore.Line.Line2, this.CurrentProductItem2));
                                    break;
                                case 4:
                                    this.TransferSerialCOM3(this.Transfer_4_STD2(this.SystemConfig, DataStore.Line.Line2, this.CurrentWeightData2, this.CurrentProductItem2));
                                    break;
                                default:
                                    break;
                            }
                        }
                        
                        // CurrentDisplay
                        switch (this.CurrentSystemStatus.CurrentDisplay)
                        {
                            case DataStore.DisplayStore.MainDisplay:
                                #region MainDisplay
                                this.ChildFormMainDisplay.UpdateStartWeightDisplay2(this.CurrentSystemStatus.Equipment, this.CurrentWeightData2);

                                if (this.CurrentWeightData2.JudgmentStatus != DataStore.JudgmentStatus.Empty)
                                    this.DataBackup2(this.CurrentWeightData2);

                                // 표준분포
                                this.CurrentWeightData2.SetNormalDistribution(this.CurrentProductItem2.CollectionNormalDistributionRange, this.CurrentWeightData2.WeightString);
                                #endregion
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                ret = -1;
            }

            return ret;
        }
        // 중량조정시 중량
        private int ReceiveCommandSC0(string lane, string receiveData)
        {
            int ret = 0;

            switch (lane)
            {
                case "Z":
                    #region Value Assign
                    this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                    this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                    this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                    this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(24, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData2.ADCValue = receiveData.Substring(29, 5);
                    #endregion
                    this.ChildFormMenu.CenterSystemCalibration.UpdateWeightDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1, this.CurrentWeightData2);
                    break;
                default:
                    break;
            }

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

            switch (lane)
            {
                case "0":
                    #region Value Assign
                    for (int i = 0; i < 8; i++)
                        this.CollectionIOTest_InputData[i] = receiveData.Substring(i, 1);
                    #endregion
                    if (this.CurrentSystemStatus.CurrentMode == DataStore.DisplayMode.IOTest)
                        this.ChildFormMenu.CenterSystemIOTest.UpdateInputRead(this.CollectionIOTest_InputData);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // 판정설정시 중량 - 정지
        private int ReceiveCommandSF0(string lane, string receiveData)
        {
            int ret = 0;
            
            switch (lane)
            {
                case "Z":
                    #region Value Assign
                    this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                    this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                    this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(19, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(21, 3), 2);
                    this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(24, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData2.ADCValue = receiveData.Substring(29, 5);
                    #endregion
                    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateStopWeightDisplay(this.CurrentSystemStatus.Equipment,
                        this.CurrentWeightData1, this.CurrentWeightData2);
                    break;
                default:
                    break;
            }

            return ret;
        }
        // 판정설정 그래프
        private int ReceiveCommandSG0(string lane, string receiveData)
        {
            int ret = 0, temp = 15;

            if (this.timerSensorError1.Enabled == true)
                this.timerSensorError1.Enabled = false;
            if (this.timerSensorError2.Enabled == true)
                this.timerSensorError2.Enabled = false;

            switch (lane)
            {
                case "A":
                    #region Value Assign
                    this.CurrentWeightData1.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData1, receiveData.Substring(2, 3), 1);
                    this.CurrentWeightData1.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData1.ADCValue = receiveData.Substring(10, 5);

                    for (int i = 0; i < this.CollectionGraphData.Count; i++)
                    {
                        this.CollectionGraphData[i] = int.Parse(receiveData.Substring(temp, 5));
                        temp += 5;
                    }
                    #endregion
                    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateGraphDataDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData1, this.CollectionGraphData);
                    break;
                case "B":
                    #region Value Assign
                    this.CurrentWeightData2.Status = Helper.StringToWeightStatus(receiveData.Substring(0, 2));
                    this.ConverterAlarm(ref this.CurrentWeightData2, receiveData.Substring(2, 3), 2);
                    this.CurrentWeightData2.Weight = Helper.StringToWeight(receiveData.Substring(5, 5), this.SystemConfig.DecimalPlaces);
                    this.CurrentWeightData2.ADCValue = receiveData.Substring(10, 5);

                    for (int i = 0; i < this.CollectionGraphData.Count; i++)
                    {
                        this.CollectionGraphData[i] = int.Parse(receiveData.Substring(temp, 5));
                        temp += 5;
                    }
                    #endregion
                    this.ChildFormMenu.CenterSystemJudgmentSetting.UpdateGraphDataDisplay(this.CurrentSystemStatus.Equipment, this.CurrentWeightData2, this.CollectionGraphData);
                    break;
                default:
                    break;
            }

            return ret;
        }
        #endregion

        #region Serial Communication
        #region Serial COM1
        public void OpenSerialCOM1()
        {
            if (this.SystemConfig.SerialCOM1Mode == 0)
                return;

            if (this.serialPort1.IsOpen == true)
                this.serialPort1.Close();

            switch (this.SystemConfig.SerialCOM1BaudRate)
            {
                case 0:
                    this.serialPort1.BaudRate = 9600;
                    break;
                case 1:
                    this.serialPort1.BaudRate = 19200;
                    break;
                case 2:
                    this.serialPort1.BaudRate = 38400;
                    break;
                case 3:
                    this.serialPort1.BaudRate = 115200;
                    break;
                default:
                    this.serialPort1.BaudRate = 9600;
                    break;
            }

            this.serialPort1.Open();
        }
        public void CloseSerialCOM1()
        {
            this.serialPort1.Close();
        }
        public void TransferSerialCOM1(string strTemp)
        {
            if (this.serialPort1.IsOpen == true)
                this.serialPort1.WriteLine(strTemp);
        }
        public void TransferSerialCOM1(byte[] buffer, int offset, int count)
        {
            if (this.serialPort1.IsOpen == true)
                this.serialPort1.Write(buffer, offset, count);
        }
        #endregion

        #region Serial COM3
        public void OpenSerialCOM3()
        {
            if (this.SystemConfig.SerialCOM3Mode == 0)
                return;

            if (this.serialPort3.IsOpen == true)
                this.serialPort3.Close();

            switch (this.SystemConfig.SerialCOM3BaudRate)
            {
                case 0:
                    this.serialPort3.BaudRate = 9600;
                    break;
                case 1:
                    this.serialPort3.BaudRate = 19200;
                    break;
                case 2:
                    this.serialPort3.BaudRate = 38400;
                    break;
                case 3:
                    this.serialPort3.BaudRate = 115200;
                    break;
                default:
                    this.serialPort3.BaudRate = 9600;
                    break;
            }

            this.serialPort3.Open();
        }
        public void CloseSerialCOM3()
        {
            this.serialPort3.Close();
        }
        public void TransferSerialCOM3(string strTemp)
        {
            if (this.serialPort3.IsOpen == true)
                this.serialPort3.WriteLine(strTemp);
        }
        public void TransferSerialCOM3(byte[] buffer, int offset, int count)
        {
            if (this.serialPort3.IsOpen == true)
                this.serialPort3.Write(buffer, offset, count);
        }
        #endregion

        private string Transfer_1_STD1(SystemConfigurationItem system, DataStore.Line line, WeightData weight, ProductItem product)
        {
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return "";

            sb.Append((char)0x02);
            sb.Append(string.Format("IN{0:000}", system.EquipmentID));
            sb.Append(string.Format("{0:0000}", product.Number));
            sb.Append((int)line);

            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.UnderRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.PassRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.OverRange, this.SystemConfig.DecimalPlaces)));

            switch (weight.JudgmentStatus)
            {
                case DataStore.JudgmentStatus.Empty:
                    break;
                case DataStore.JudgmentStatus.Under:
                    sb.Append("U");
                    break;
                case DataStore.JudgmentStatus.Pass:
                    sb.Append("P");
                    break;
                case DataStore.JudgmentStatus.Over:
                    sb.Append("O");
                    break;
                case DataStore.JudgmentStatus.Double:
                    sb.Append("D");
                    break;
                case DataStore.JudgmentStatus.Metal:
                    sb.Append("M");
                    break;
                case DataStore.JudgmentStatus.ExNg:
                    sb.Append("E");
                    break;
                default:
                    sb.Append("E");
                    break;
            }

            sb.Append(Helper.StringZeroFillDigits6(Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces)));
            sb.Append((char)0x03);

            return sb.ToString();
        }
        private string Transfer_2_Remote(WeightData weight, ProductItem product)
        {
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return "";

            sb.Append((char)0x02);
            sb.Append("01");

            switch (weight.JudgmentStatus)
            {
                case DataStore.JudgmentStatus.Empty:
                    break;
                case DataStore.JudgmentStatus.Under:
                    sb.Append("U");
                    break;
                case DataStore.JudgmentStatus.Pass:
                    sb.Append("P");
                    break;
                case DataStore.JudgmentStatus.Over:
                    sb.Append("O");
                    break;
                case DataStore.JudgmentStatus.Double:
                    sb.Append("D");
                    break;
                case DataStore.JudgmentStatus.Metal:
                    sb.Append("M");
                    break;
                case DataStore.JudgmentStatus.ExNg:
                    sb.Append("E");
                    break;
                default:
                    sb.Append(" ");
                    break;
            }

            sb.Append(Helper.StringZeroFillDigits6(Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces)));
            sb.Append((char)0x03);

            return sb.ToString();
        }
        private string Transfer_3_Print(WeightData weight, DataStore.Line line, ProductItem product)
        {
            string value = "";
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return "";

            sb.Append(string.Format("{0, 4}", this.SystemConfig.ProductNumber));
            sb.Append(string.Format("{0, 3}", (int)line));

            if (weight.JudgmentStatus == DataStore.JudgmentStatus.Under)
                sb.Append("    U");
            else if (weight.JudgmentStatus == DataStore.JudgmentStatus.Pass)
                sb.Append("    P");
            else if (weight.JudgmentStatus == DataStore.JudgmentStatus.Over)
                sb.Append("    O");
            else if (weight.JudgmentStatus == DataStore.JudgmentStatus.Double)
                sb.Append("    D");
            else
                sb.Append("    E");

            value = Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces);
            sb.Append(value.PadLeft(8, ' '));
            value = weight.TotalCount1.ToString();
            sb.Append(value.PadLeft(11, ' '));

            return sb.ToString();
        }
        private string Transfer_4_STD2(SystemConfigurationItem system, DataStore.Line line, WeightData weight, ProductItem product)
        {
            StringBuilder sb = new StringBuilder();

            if (weight.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                return "";

            sb.Append((char)0x02);
            sb.Append(string.Format("IN{0:000}", system.EquipmentID));
            sb.Append(string.Format("{0:0000}", product.Number));
            sb.Append((int)line);

            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.UnderRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.PassRange, this.SystemConfig.DecimalPlaces)));
            sb.Append(Helper.StringZeroFillDigits6(Helper.StringToDecimalPlaces(product.OverRange, this.SystemConfig.DecimalPlaces)));

            sb.Append(string.Format("{0:0000000}", weight.UnderCount));
            sb.Append(string.Format("{0:0000000}", weight.PassCount));
            sb.Append(string.Format("{0:0000000}", weight.OverCount));
            sb.Append(string.Format("{0:0000000}", weight.ExNGCount));
            sb.Append(string.Format("{0:000000000}", weight.TotalCount1));

            switch (weight.JudgmentStatus)
            {
                case DataStore.JudgmentStatus.Empty:
                    break;
                case DataStore.JudgmentStatus.Under:
                    sb.Append("U");
                    break;
                case DataStore.JudgmentStatus.Pass:
                    sb.Append("P");
                    break;
                case DataStore.JudgmentStatus.Over:
                    sb.Append("O");
                    break;
                case DataStore.JudgmentStatus.Double:
                    sb.Append("D");
                    break;
                case DataStore.JudgmentStatus.Metal:
                    sb.Append("M");
                    break;
                case DataStore.JudgmentStatus.ExNg:
                    sb.Append("E");
                    break;
                default:
                    sb.Append("E");
                    break;
            }

            if (weight.Weight <= 0.0)
                sb.Append("-");
            else
                sb.Append(" ");

            string temp = Helper.DoubleToString(weight.Weight, this.SystemConfig.DecimalPlaces);
            if (temp.StartsWith("-"))
                temp = temp.Substring(1, temp.Length - 1);
            sb.Append(temp.PadLeft(6, ' '));
            sb.Append((char)0x03);

            return sb.ToString();
        }
        #endregion

        #region Data Backup
        private void RemoveUsbBackupFile()
        {
            bool directoryCheck = false;

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

                DirectoryInfo dir = new DirectoryInfo(this.PathDataBackupFolder);

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

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

            }

        }
        private void DataBackup1(WeightData item)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "";
            StreamWriter sw;
            DateTime time = DateTime.Now;

            this.RemoveUsbBackupFile();

            if (this.SystemConfig.IsDataBackup == true)
            {
                fullFilePath = string.Format("{0}{1:yyyyMMdd}_{2}_{3}_Line1.csv", this.PathDataBackupFolder, DateTime.Now, this.SystemConfig.UsbID, this.CurrentProductItem1.Name);

                DirectoryInfo di = new DirectoryInfo(this.PathDataBackupFolder);
                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)
                {
                    sw.Write("Date");
                    sw.Write(",");
                    sw.Write("Time");
                    sw.Write(",");
                    sw.Write("P_No");
                    sw.Write(",");
                    sw.Write("Name");
                    sw.Write(",");
                    sw.Write("Lot");
                    sw.Write(",");
                    sw.Write("UnderRange");
                    sw.Write(",");
                    sw.Write("PassRange");
                    sw.Write(","); 
                    sw.Write("OverRange");
                    sw.Write(",");
                    sw.Write("TareRange");
                    sw.Write(",");
                    sw.Write("Weight");
                    sw.Write(",");
                    sw.Write("Grade");
                    sw.WriteLine();
                }

                sw.Write(string.Format("{0:yyyy-MM-dd}", time));
                sw.Write(",");
                sw.Write(string.Format("{0:HH:mm:ss}", time));
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Number);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Name);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.LotNo);
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.DoubleToString(item.Weight, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(item.JudgmentStatus);
                sw.WriteLine();

                sw.Close();
            }
        }
        private void DataBackup2(WeightData item)
        {
            bool fileCheck = false, directoryCheck = false;
            string fullFilePath = "";
            StreamWriter sw;
            DateTime time = DateTime.Now;

            this.RemoveUsbBackupFile();

            if (this.SystemConfig.IsDataBackup == true)
            {
                fullFilePath = string.Format("{0}{1:yyyyMMdd}_{2}_{3}_Line2.csv", this.PathDataBackupFolder, DateTime.Now, this.SystemConfig.UsbID, this.CurrentProductItem1.Name);

                DirectoryInfo di = new DirectoryInfo(this.PathDataBackupFolder);
                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)
                {
                    sw.Write("Date");
                    sw.Write(",");
                    sw.Write("Time");
                    sw.Write(",");
                    sw.Write("P_No");
                    sw.Write(",");
                    sw.Write("Name");
                    sw.Write(",");
                    sw.Write("Lot");
                    sw.Write(",");
                    sw.Write("UnderRange");
                    sw.Write(",");
                    sw.Write("PassRange");
                    sw.Write(",");
                    sw.Write("OverRange");
                    sw.Write(",");
                    sw.Write("TareRange");
                    sw.Write(",");
                    sw.Write("Weight");
                    sw.Write(",");
                    sw.Write("Grade");
                    sw.WriteLine();
                }

                sw.Write(string.Format("{0:yyyy-MM-dd}", time));
                sw.Write(",");
                sw.Write(string.Format("{0:HH:mm:ss}", time));
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Number);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.Name);
                sw.Write(",");
                sw.Write(this.CurrentProductItem1.LotNo);
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.UnderRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.PassRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.OverRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.StringToDecimalPlaces(this.CurrentProductItem1.TareRange, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(Helper.DoubleToString(item.Weight, this.SystemConfig.DecimalPlaces));
                sw.Write(",");
                sw.Write(item.JudgmentStatus);
                sw.WriteLine();

                sw.Close();
            }
        }
        #endregion

        #region SystemConfiguration File
        private void CreateSystemConfigurationFile()
        {
            StructSystemConfigurationItem structItem;

            this.SystemConfig.Initialization();

            structItem.IsDataBackup = this.SystemConfig.IsDataBackup;
            structItem.IsLogin = this.SystemConfig.IsLogin;

            structItem.EquipmentID = this.SystemConfig.EquipmentID;
            structItem.DecimalPlaces = this.SystemConfig.DecimalPlaces;
            structItem.ProductNumber = this.SystemConfig.ProductNumber;
            structItem.UsbID = this.SystemConfig.UsbID;
            structItem.SerialCOM1BaudRate = this.SystemConfig.SerialCOM1BaudRate;
            structItem.SerialCOM1Mode = this.SystemConfig.SerialCOM1Mode;
            structItem.SerialCOM3BaudRate = this.SystemConfig.SerialCOM3BaudRate;
            structItem.SerialCOM3Mode = this.SystemConfig.SerialCOM3Mode;
            structItem.SerialCOM4BaudRate = this.SystemConfig.SerialCOM4BaudRate;
            structItem.SerialCOM4Mode = this.SystemConfig.SerialCOM4Mode;

            structItem.SerialNumber = this.SystemConfig.SerialNumber;
            structItem.Language = this.SystemConfig.Language;
            structItem.Unit = this.SystemConfig.Unit;

            structItem.DummyBool1 = false;
            structItem.DummyBool2 = false;
            structItem.DummyBool3 = false;
            structItem.DummyBool4 = false;
            structItem.DummyBool5 = false;
            structItem.DummyInt1 = 1;
            structItem.DummyInt2 = 1;
            structItem.EntryNotDetectedIgnoreTime = this.SystemConfig.EntryNotDetectedIgnoreTime;
            structItem.SensorErrorDetectingTime = this.SystemConfig.SensorErrorDetectingTime;
            structItem.EquipmentType = this.SystemConfig.EquipmentType;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, 0);
        }
        public void SaveSystemConfigurationFile(SystemConfigurationItem item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem structItem;

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemConfigurationFile();
            }

            structItem.IsDataBackup = item.IsDataBackup;
            structItem.IsLogin = item.IsLogin;

            structItem.EquipmentID = item.EquipmentID;
            structItem.DecimalPlaces = item.DecimalPlaces;
            structItem.ProductNumber = item.ProductNumber;
            structItem.UsbID = item.UsbID;
            structItem.SerialCOM1BaudRate = item.SerialCOM1BaudRate;
            structItem.SerialCOM1Mode = item.SerialCOM1Mode;
            structItem.SerialCOM3BaudRate = item.SerialCOM3BaudRate;
            structItem.SerialCOM3Mode = item.SerialCOM3Mode;
            structItem.SerialCOM4BaudRate = item.SerialCOM4BaudRate;
            structItem.SerialCOM4Mode = item.SerialCOM4Mode;

            structItem.SerialNumber = item.SerialNumber;
            structItem.Language = item.Language;
            structItem.Unit = item.Unit;

            structItem.DummyBool1 = false;
            structItem.DummyBool2 = false;
            structItem.DummyBool3 = false;
            structItem.DummyBool4 = false;
            structItem.DummyBool5 = false;
            structItem.DummyInt1 = 1;
            structItem.DummyInt2 = 1;
            structItem.EntryNotDetectedIgnoreTime = item.EntryNotDetectedIgnoreTime;
            structItem.SensorErrorDetectingTime = item.SensorErrorDetectingTime;
            structItem.EquipmentType = item.EquipmentType;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, 0);
            this.smartFileIO.Close();
        }
        public void LoadSystemConfigurationFile()
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructSystemConfigurationItem structItem;

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateSystemConfigurationFile();
            }

            try
            {
                structItem = (StructSystemConfigurationItem)this.smartFileIO.ReadStructure(0, typeof(StructSystemConfigurationItem));

                this.SystemConfig.IsDataBackup = structItem.IsDataBackup;
                this.SystemConfig.IsLogin = structItem.IsLogin;

                this.SystemConfig.EquipmentID = structItem.EquipmentID;
                this.SystemConfig.DecimalPlaces = structItem.DecimalPlaces;
                this.SystemConfig.ProductNumber = structItem.ProductNumber;
                this.SystemConfig.UsbID = structItem.UsbID;
                this.SystemConfig.SerialCOM1BaudRate = structItem.SerialCOM1BaudRate;
                this.SystemConfig.SerialCOM1Mode = structItem.SerialCOM1Mode;
                this.SystemConfig.SerialCOM3BaudRate = structItem.SerialCOM3BaudRate;
                this.SystemConfig.SerialCOM3Mode = structItem.SerialCOM3Mode;
                this.SystemConfig.SerialCOM4BaudRate = structItem.SerialCOM4BaudRate;
                this.SystemConfig.SerialCOM4Mode = structItem.SerialCOM4Mode;

                this.SystemConfig.SerialNumber = structItem.SerialNumber;
                this.SystemConfig.Language = structItem.Language;
                this.SystemConfig.Unit = structItem.Unit;

                this.SystemConfig.EquipmentType = structItem.EquipmentType;
                this.SystemConfig.SensorErrorDetectingTime = structItem.SensorErrorDetectingTime;
                this.SystemConfig.EntryNotDetectedIgnoreTime = structItem.EntryNotDetectedIgnoreTime;
            }
            catch
            {
                // 초기화를 실행해 주세요
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        #endregion

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

            for (int i = 0; i < 3; i++)
            {
                #region StructItem
                structItem.IsBasic = item.IsBasic;
                structItem.IsBasicDataBackup = item.IsBasicDataBackup;
                structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
                structItem.IsBasicProduct = item.IsBasicProduct;
                structItem.IsBasicTime = item.IsBasicTime;

                structItem.IsConfiCommunication = item.IsConfiCommunication;
                structItem.IsConfiguration = item.IsConfiguration;
                structItem.IsConfiOption = item.IsConfiOption;

                structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
                structItem.IsEquipInitialize = item.IsEquipInitialize;
                structItem.IsEquipment = item.IsEquipment;
                structItem.IsEquipUpdate = item.IsEquipUpdate;
                structItem.IsEquipUser = item.IsEquipUser;

                structItem.IsInforAS = item.IsInforAS;
                structItem.IsInformation = item.IsInformation;
                structItem.IsInforSystem = item.IsInforSystem;

                structItem.IsSystem = item.IsSystem;
                structItem.IsSystemAutoZero = item.IsSystemAutoZero;
                structItem.IsSystemCalibration = item.IsSystemCalibration;
                structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
                structItem.IsSystemIOTest = item.IsSystemIOTest;
                structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
                structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

                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;
                structItem.Dummy19 = false;
                structItem.Dummy20 = false;
                #endregion

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserGroupFile(UserGroup item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserGroupItem structItem;

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level1
            structItem.IsBasic = item.Level1.IsBasic;
            structItem.IsBasicDataBackup = item.Level1.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.Level1.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.Level1.IsBasicProduct;
            structItem.IsBasicTime = item.Level1.IsBasicTime;

            structItem.IsConfiCommunication = item.Level1.IsConfiCommunication;
            structItem.IsConfiguration = item.Level1.IsConfiguration;
            structItem.IsConfiOption = item.Level1.IsConfiOption;

            structItem.IsEquipFunctionSetting = item.Level1.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.Level1.IsEquipInitialize;
            structItem.IsEquipment = item.Level1.IsEquipment;
            structItem.IsEquipUpdate = item.Level1.IsEquipUpdate;
            structItem.IsEquipUser = item.Level1.IsEquipUser;

            structItem.IsInforAS = item.Level1.IsInforAS;
            structItem.IsInformation = item.Level1.IsInformation;
            structItem.IsInforSystem = item.Level1.IsInforSystem;

            structItem.IsSystem = item.Level1.IsSystem;
            structItem.IsSystemAutoZero = item.Level1.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.Level1.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.Level1.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.Level1.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.Level1.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.Level1.IsSystemSorterSetting;

            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;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)DataStore.EnumFileUserGroup.f0_Level1);
            #endregion

            #region Level2
            structItem.IsBasic = item.Level2.IsBasic;
            structItem.IsBasicDataBackup = item.Level2.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.Level2.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.Level2.IsBasicProduct;
            structItem.IsBasicTime = item.Level2.IsBasicTime;

            structItem.IsConfiCommunication = item.Level2.IsConfiCommunication;
            structItem.IsConfiguration = item.Level2.IsConfiguration;
            structItem.IsConfiOption = item.Level2.IsConfiOption;

            structItem.IsEquipFunctionSetting = item.Level2.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.Level2.IsEquipInitialize;
            structItem.IsEquipment = item.Level2.IsEquipment;
            structItem.IsEquipUpdate = item.Level2.IsEquipUpdate;
            structItem.IsEquipUser = item.Level2.IsEquipUser;

            structItem.IsInforAS = item.Level2.IsInforAS;
            structItem.IsInformation = item.Level2.IsInformation;
            structItem.IsInforSystem = item.Level2.IsInforSystem;

            structItem.IsSystem = item.Level2.IsSystem;
            structItem.IsSystemAutoZero = item.Level2.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.Level2.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.Level2.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.Level2.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.Level2.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.Level2.IsSystemSorterSetting;

            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;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)DataStore.EnumFileUserGroup.f1_Level2);
            #endregion

            #region Level3
            structItem.IsBasic = item.Level3.IsBasic;
            structItem.IsBasicDataBackup = item.Level3.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.Level3.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.Level3.IsBasicProduct;
            structItem.IsBasicTime = item.Level3.IsBasicTime;

            structItem.IsConfiCommunication = item.Level3.IsConfiCommunication;
            structItem.IsConfiguration = item.Level3.IsConfiguration;
            structItem.IsConfiOption = item.Level3.IsConfiOption;

            structItem.IsEquipFunctionSetting = item.Level3.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.Level3.IsEquipInitialize;
            structItem.IsEquipment = item.Level3.IsEquipment;
            structItem.IsEquipUpdate = item.Level3.IsEquipUpdate;
            structItem.IsEquipUser = item.Level3.IsEquipUser;

            structItem.IsInforAS = item.Level3.IsInforAS;
            structItem.IsInformation = item.Level3.IsInformation;
            structItem.IsInforSystem = item.Level3.IsInforSystem;

            structItem.IsSystem = item.Level3.IsSystem;
            structItem.IsSystemAutoZero = item.Level3.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.Level3.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.Level3.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.Level3.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.Level3.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.Level3.IsSystemSorterSetting;

            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;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)DataStore.EnumFileUserGroup.f2_Level3);
            #endregion

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

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level1
            structItem.IsBasic = item.IsBasic;
            structItem.IsBasicDataBackup = item.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.IsBasicProduct;
            structItem.IsBasicTime = item.IsBasicTime;

            structItem.IsConfiCommunication = item.IsConfiCommunication;
            structItem.IsConfiguration = item.IsConfiguration;
            structItem.IsConfiOption = item.IsConfiOption;

            structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.IsEquipInitialize;
            structItem.IsEquipment = item.IsEquipment;
            structItem.IsEquipUpdate = item.IsEquipUpdate;
            structItem.IsEquipUser = item.IsEquipUser;

            structItem.IsInforAS = item.IsInforAS;
            structItem.IsInformation = item.IsInformation;
            structItem.IsInforSystem = item.IsInforSystem;

            structItem.IsSystem = item.IsSystem;
            structItem.IsSystemAutoZero = item.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

            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;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)DataStore.EnumFileUserGroup.f0_Level1);
            #endregion

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

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level2
            structItem.IsBasic = item.IsBasic;
            structItem.IsBasicDataBackup = item.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.IsBasicProduct;
            structItem.IsBasicTime = item.IsBasicTime;

            structItem.IsConfiCommunication = item.IsConfiCommunication;
            structItem.IsConfiguration = item.IsConfiguration;
            structItem.IsConfiOption = item.IsConfiOption;

            structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.IsEquipInitialize;
            structItem.IsEquipment = item.IsEquipment;
            structItem.IsEquipUpdate = item.IsEquipUpdate;
            structItem.IsEquipUser = item.IsEquipUser;

            structItem.IsInforAS = item.IsInforAS;
            structItem.IsInformation = item.IsInformation;
            structItem.IsInforSystem = item.IsInforSystem;

            structItem.IsSystem = item.IsSystem;
            structItem.IsSystemAutoZero = item.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

            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;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)DataStore.EnumFileUserGroup.f1_Level2);
            #endregion

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

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            #region Level3
            structItem.IsBasic = item.IsBasic;
            structItem.IsBasicDataBackup = item.IsBasicDataBackup;
            structItem.IsBasicDataStatistics = item.IsBasicDataStatistics;
            structItem.IsBasicProduct = item.IsBasicProduct;
            structItem.IsBasicTime = item.IsBasicTime;

            structItem.IsConfiCommunication = item.IsConfiCommunication;
            structItem.IsConfiguration = item.IsConfiguration;
            structItem.IsConfiOption = item.IsConfiOption;

            structItem.IsEquipFunctionSetting = item.IsEquipFunctionSetting;
            structItem.IsEquipInitialize = item.IsEquipInitialize;
            structItem.IsEquipment = item.IsEquipment;
            structItem.IsEquipUpdate = item.IsEquipUpdate;
            structItem.IsEquipUser = item.IsEquipUser;

            structItem.IsInforAS = item.IsInforAS;
            structItem.IsInformation = item.IsInformation;
            structItem.IsInforSystem = item.IsInforSystem;

            structItem.IsSystem = item.IsSystem;
            structItem.IsSystemAutoZero = item.IsSystemAutoZero;
            structItem.IsSystemCalibration = item.IsSystemCalibration;
            structItem.IsSystemExternalOutput = item.IsSystemExternalOutput;
            structItem.IsSystemIOTest = item.IsSystemIOTest;
            structItem.IsSystemJudgmentSetting = item.IsSystemJudgmentSetting;
            structItem.IsSystemSorterSetting = item.IsSystemSorterSetting;

            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;
            structItem.Dummy19 = false;
            structItem.Dummy20 = false;

            this.smartFileIO.WriteStructure(structItem, (int)DataStore.EnumFileUserGroup.f2_Level3);
            #endregion

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

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

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupFile();
            }

            try
            {
                #region Level1
                structItem = (StructUserGroupItem)this.smartFileIO.ReadStructure((int)DataStore.EnumFileUserGroup.f0_Level1, typeof(StructUserGroupItem));

                item.Level1.IsBasic = structItem.IsBasic;
                item.Level1.IsBasicDataBackup = structItem.IsBasicDataBackup;
                item.Level1.IsBasicDataStatistics = structItem.IsBasicDataStatistics;
                item.Level1.IsBasicProduct = structItem.IsBasicProduct;
                item.Level1.IsBasicTime = structItem.IsBasicTime;

                item.Level1.IsConfiCommunication = structItem.IsConfiCommunication;
                item.Level1.IsConfiguration = structItem.IsConfiguration;
                item.Level1.IsConfiOption = structItem.IsConfiOption;

                item.Level1.IsEquipFunctionSetting = structItem.IsEquipFunctionSetting;
                item.Level1.IsEquipInitialize = structItem.IsEquipInitialize;
                item.Level1.IsEquipment = structItem.IsEquipment;
                item.Level1.IsEquipUpdate = structItem.IsEquipUpdate;
                item.Level1.IsEquipUser = structItem.IsEquipUser;

                item.Level1.IsInforAS = structItem.IsInforAS;
                item.Level1.IsInformation = structItem.IsInformation;
                item.Level1.IsInforSystem = structItem.IsInforSystem;

                item.Level1.IsSystem = structItem.IsSystem;
                item.Level1.IsSystemAutoZero = structItem.IsSystemAutoZero;
                item.Level1.IsSystemCalibration = structItem.IsSystemCalibration;
                item.Level1.IsSystemExternalOutput = structItem.IsSystemExternalOutput;
                item.Level1.IsSystemIOTest = structItem.IsSystemIOTest;
                item.Level1.IsSystemJudgmentSetting = structItem.IsSystemJudgmentSetting;
                item.Level1.IsSystemSorterSetting = structItem.IsSystemSorterSetting;
                #endregion

                #region Level2
                structItem = (StructUserGroupItem)this.smartFileIO.ReadStructure((int)DataStore.EnumFileUserGroup.f1_Level2, typeof(StructUserGroupItem));

                item.Level2.IsBasic = structItem.IsBasic;
                item.Level2.IsBasicDataBackup = structItem.IsBasicDataBackup;
                item.Level2.IsBasicDataStatistics = structItem.IsBasicDataStatistics;
                item.Level2.IsBasicProduct = structItem.IsBasicProduct;
                item.Level2.IsBasicTime = structItem.IsBasicTime;

                item.Level2.IsConfiCommunication = structItem.IsConfiCommunication;
                item.Level2.IsConfiguration = structItem.IsConfiguration;
                item.Level2.IsConfiOption = structItem.IsConfiOption;

                item.Level2.IsEquipFunctionSetting = structItem.IsEquipFunctionSetting;
                item.Level2.IsEquipInitialize = structItem.IsEquipInitialize;
                item.Level2.IsEquipment = structItem.IsEquipment;
                item.Level2.IsEquipUpdate = structItem.IsEquipUpdate;
                item.Level2.IsEquipUser = structItem.IsEquipUser;

                item.Level2.IsInforAS = structItem.IsInforAS;
                item.Level2.IsInformation = structItem.IsInformation;
                item.Level2.IsInforSystem = structItem.IsInforSystem;

                item.Level2.IsSystem = structItem.IsSystem;
                item.Level2.IsSystemAutoZero = structItem.IsSystemAutoZero;
                item.Level2.IsSystemCalibration = structItem.IsSystemCalibration;
                item.Level2.IsSystemExternalOutput = structItem.IsSystemExternalOutput;
                item.Level2.IsSystemIOTest = structItem.IsSystemIOTest;
                item.Level2.IsSystemJudgmentSetting = structItem.IsSystemJudgmentSetting;
                item.Level2.IsSystemSorterSetting = structItem.IsSystemSorterSetting;
                #endregion

                #region Level3
                structItem = (StructUserGroupItem)this.smartFileIO.ReadStructure((int)DataStore.EnumFileUserGroup.f2_Level3, typeof(StructUserGroupItem));

                item.Level3.IsBasic = structItem.IsBasic;
                item.Level3.IsBasicDataBackup = structItem.IsBasicDataBackup;
                item.Level3.IsBasicDataStatistics = structItem.IsBasicDataStatistics;
                item.Level3.IsBasicProduct = structItem.IsBasicProduct;
                item.Level3.IsBasicTime = structItem.IsBasicTime;

                item.Level3.IsConfiCommunication = structItem.IsConfiCommunication;
                item.Level3.IsConfiguration = structItem.IsConfiguration;
                item.Level3.IsConfiOption = structItem.IsConfiOption;

                item.Level3.IsEquipFunctionSetting = structItem.IsEquipFunctionSetting;
                item.Level3.IsEquipInitialize = structItem.IsEquipInitialize;
                item.Level3.IsEquipment = structItem.IsEquipment;
                item.Level3.IsEquipUpdate = structItem.IsEquipUpdate;
                item.Level3.IsEquipUser = structItem.IsEquipUser;

                item.Level3.IsInforAS = structItem.IsInforAS;
                item.Level3.IsInformation = structItem.IsInformation;
                item.Level3.IsInforSystem = structItem.IsInforSystem;

                item.Level3.IsSystem = structItem.IsSystem;
                item.Level3.IsSystemAutoZero = structItem.IsSystemAutoZero;
                item.Level3.IsSystemCalibration = structItem.IsSystemCalibration;
                item.Level3.IsSystemExternalOutput = structItem.IsSystemExternalOutput;
                item.Level3.IsSystemIOTest = structItem.IsSystemIOTest;
                item.Level3.IsSystemJudgmentSetting = structItem.IsSystemJudgmentSetting;
                item.Level3.IsSystemSorterSetting = structItem.IsSystemSorterSetting;
                #endregion
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region UserGroupPassword File
        private void CreateUserGroupPasswordFile()
        {
            this.CurrentSystemStatus.CurrentUserPasswordType.Initialization();

            this.smartFileIO.WriteString(this.CurrentSystemStatus.CurrentUserPasswordType.Level1Password, (int)DataStore.EnumFileUserPassword.f0_Level1);
            this.smartFileIO.WriteString(this.CurrentSystemStatus.CurrentUserPasswordType.Level2Password, (int)DataStore.EnumFileUserPassword.f1_Level2);
            this.smartFileIO.WriteString(this.CurrentSystemStatus.CurrentUserPasswordType.Level3Password, (int)DataStore.EnumFileUserPassword.f2_Level3);
        }
        public void SaveUserGroupPasswordFile(UserPasswordType item)
        {
            string fullFilePath = "";
            bool fileCheck = false;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroupPassword.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupPasswordFile();
            }

            this.smartFileIO.WriteString(item.Level1Password, (int)DataStore.EnumFileUserPassword.f0_Level1);
            this.smartFileIO.WriteString(item.Level2Password, (int)DataStore.EnumFileUserPassword.f1_Level2);
            this.smartFileIO.WriteString(item.Level3Password, (int)DataStore.EnumFileUserPassword.f2_Level3);

            this.smartFileIO.Close();
        }
        private void LoadUserGroupPasswordFile()
        {
            string fullFilePath = "";
            bool fileCheck = false;

            fullFilePath = this.PathSystemFileFolder1 + "UserGroupPassword.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserGroupPasswordFile();
            }

            try
            {
                this.CurrentSystemStatus.CurrentUserPasswordType.Level1Password = this.smartFileIO.ReadString((int)DataStore.EnumFileUserPassword.f0_Level1);
                this.CurrentSystemStatus.CurrentUserPasswordType.Level2Password = this.smartFileIO.ReadString((int)DataStore.EnumFileUserPassword.f1_Level2);
                this.CurrentSystemStatus.CurrentUserPasswordType.Level3Password = this.smartFileIO.ReadString((int)DataStore.EnumFileUserPassword.f2_Level3);
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        #endregion
        #region UserLevel1File
        private void CreateUserLevel1File()
        {
            StructUserItem structItem;
            UserItem item = new UserItem();

            structItem.ID = "L1";
            structItem.Password = "1111";
            structItem.Group = DataStore.UserGroup.Level1Operator;

            structItem.Dummy1 = "";
            structItem.Dummy2 = "";
            structItem.Dummy3 = "";
            structItem.Dummy4 = "";
            structItem.Dummy5 = "";

            this.smartFileIO.WriteStructure_Begin(structItem, 0);

            for (int i = 1; i < 5; i++)
            {
                structItem.ID = item.ID;
                structItem.Password = item.Password;
                structItem.Group = item.Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserLevel1File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel1File();
            }

            if (item.Count == 0)
                return;

            for (int i = 0; i < item.Count; i++)
            {
                structItem.ID = item[i].ID;
                structItem.Password = item[i].Password;
                structItem.Group = item[i].Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure(structItem, i);
            }

            this.smartFileIO.Close();
        }
        public void LoadUserLevel1File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel1File();
            }

            try
            {
                for (int i = 0; i < item.Count; i++)
                {
                    structItem = (StructUserItem)this.smartFileIO.ReadStructure(i, typeof(StructUserItem));

                    item[i].ID = structItem.ID;
                    item[i].Password = structItem.Password;
                    item[i].Group = structItem.Group;
                }
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region UserLevel2File
        private void CreateUserLevel2File()
        {
            StructUserItem structItem;
            UserItem item = new UserItem();

            structItem.ID = "L2";
            structItem.Password = "2222";
            structItem.Group = DataStore.UserGroup.Level2Engineer;

            structItem.Dummy1 = "";
            structItem.Dummy2 = "";
            structItem.Dummy3 = "";
            structItem.Dummy4 = "";
            structItem.Dummy5 = "";

            this.smartFileIO.WriteStructure_Begin(structItem, 0);

            for (int i = 1; i < 5; i++)
            {
                structItem.ID = item.ID;
                structItem.Password = item.Password;
                structItem.Group = item.Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserLevel2File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel2File();
            }

            if (item.Count == 0)
                return;

            for (int i = 0; i < item.Count; i++)
            {
                structItem.ID = item[i].ID;
                structItem.Password = item[i].Password;
                structItem.Group = item[i].Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure(structItem, i);
            }

            this.smartFileIO.Close();
        }
        public void LoadUserLevel2File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel2File();
            }

            try
            {
                for (int i = 0; i < item.Count; i++)
                {
                    structItem = (StructUserItem)this.smartFileIO.ReadStructure(i, typeof(StructUserItem));

                    item[i].ID = structItem.ID;
                    item[i].Password = structItem.Password;
                    item[i].Group = structItem.Group;
                }
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region UserLevel3File
        private void CreateUserLevel3File()
        {
            StructUserItem structItem;
            UserItem item = new UserItem();

            structItem.ID = "L3";
            structItem.Password = "3333";
            structItem.Group = DataStore.UserGroup.Level3Manager;

            structItem.Dummy1 = "";
            structItem.Dummy2 = "";
            structItem.Dummy3 = "";
            structItem.Dummy4 = "";
            structItem.Dummy5 = "";

            this.smartFileIO.WriteStructure_Begin(structItem, 0);

            for (int i = 1; i < 5; i++)
            {
                structItem.ID = item.ID;
                structItem.Password = item.Password;
                structItem.Group = item.Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveUserLevel3File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel3.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel3File();
            }

            if (item.Count == 0)
                return;

            for (int i = 0; i < item.Count; i++)
            {
                structItem.ID = item[i].ID;
                structItem.Password = item[i].Password;
                structItem.Group = item[i].Group;

                structItem.Dummy1 = "";
                structItem.Dummy2 = "";
                structItem.Dummy3 = "";
                structItem.Dummy4 = "";
                structItem.Dummy5 = "";

                this.smartFileIO.WriteStructure(structItem, i);
            }

            this.smartFileIO.Close();
        }
        public void LoadUserLevel3File(Collection<UserItem> item)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructUserItem structItem;

            fullFilePath = this.PathSystemFileFolder1 + "UserLevel3.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateUserLevel3File();
            }

            try
            {
                for (int i = 0; i < item.Count; i++)
                {
                    structItem = (StructUserItem)this.smartFileIO.ReadStructure(i, typeof(StructUserItem));

                    item[i].ID = structItem.ID;
                    item[i].Password = structItem.Password;
                    item[i].Group = structItem.Group;
                }
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(23, this.SystemConfig.Language);
                myMsg.ShowDialog();

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

        #region Product File #1
        private void CreateProductFile1()
        {
            StructProductItem structItem;

            this.CurrentProductItem1.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Number = i + 1;
                structItem.Name = string.Format("Product {0}", i + 1);
                structItem.LotNo = string.Format("Lot {0}", i + 1);
                structItem.PassRange = this.CurrentProductItem1.PassRange;
                structItem.OverRange = this.CurrentProductItem1.OverRange;
                structItem.UnderRange = this.CurrentProductItem1.UnderRange;
                structItem.TareRange = this.CurrentProductItem1.TareRange;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveProductFile1(ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;
            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateProductFile1();
            }

            structItem.Number = item.Number;
            structItem.Name = item.Name;
            structItem.LotNo = item.LotNo;
            structItem.OverRange = item.OverRange;
            structItem.PassRange = item.PassRange;
            structItem.UnderRange = item.UnderRange;
            structItem.TareRange = item.TareRange;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadProductFile1(ref ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateProductFile1();
            }

            try
            {
                structItem = (StructProductItem)this.smartFileIO.ReadStructure(index, typeof(StructProductItem));

                item.Number = structItem.Number;
                item.Name = structItem.Name;
                item.LotNo = structItem.LotNo;
                item.PassRange = structItem.PassRange;
                item.OverRange = structItem.OverRange;
                item.UnderRange = structItem.UnderRange;
                item.TareRange = structItem.TareRange;
            }
            catch
            {
                // 초기화를 실행해 주세요
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        public void LoadProductName1(ref Collection<string> values)
        {
            string fullFilePath = "";
            StructProductItem structItem;

            values.Clear();

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

            this.smartFileIO.Open(this.BufferSmartUart);

            if (this.smartFileIO.ReadStructureAllBuffer() == true)
            {
                for (int i = 0; i < 1000; i++)
                {
                    structItem = (StructProductItem)this.smartFileIO.ReadStructureBuffer(typeof(StructProductItem), i);

                    values.Add(structItem.Name);
                }
            }

            this.smartFileIO.Close();
        }
        #endregion
        #region Product File #2
        private void CreateProductFile2()
        {
            StructProductItem structItem;

            this.CurrentProductItem2.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Number = i + 1;
                structItem.Name = string.Format("Product {0}", i + 1);
                structItem.LotNo = string.Format("Lot {0}", i + 1);
                structItem.PassRange = this.CurrentProductItem2.PassRange;
                structItem.OverRange = this.CurrentProductItem2.OverRange;
                structItem.UnderRange = this.CurrentProductItem2.UnderRange;
                structItem.TareRange = this.CurrentProductItem2.TareRange;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveProductFile2(ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            FileInfo fileInfo = new FileInfo(fullFilePath);
            fileCheck = fileInfo.Exists;
            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateProductFile2();
            }

            structItem.Number = item.Number;
            structItem.Name = item.Name;
            structItem.LotNo = item.LotNo;
            structItem.OverRange = item.OverRange;
            structItem.PassRange = item.PassRange;
            structItem.UnderRange = item.UnderRange;
            structItem.TareRange = item.TareRange;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadProductFile2(ref ProductItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructProductItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateProductFile2();
            }

            try
            {
                structItem = (StructProductItem)this.smartFileIO.ReadStructure(index, typeof(StructProductItem));

                item.Number = structItem.Number;
                item.Name = structItem.Name;
                item.LotNo = structItem.LotNo;
                item.PassRange = structItem.PassRange;
                item.OverRange = structItem.OverRange;
                item.UnderRange = structItem.UnderRange;
                item.TareRange = structItem.TareRange;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }

            this.smartFileIO.Close();
        }
        public void LoadProductName2(ref Collection<string> values)
        {
            string fullFilePath = "";
            StructProductItem structItem;

            values.Clear();

            fullFilePath = this.PathSystemFileFolder2 + "ProductItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

            this.smartFileIO.Open(this.BufferSmartUart);

            if (this.smartFileIO.ReadStructureAllBuffer() == true)
            {
                for (int i = 0; i < 1000; i++)
                {
                    structItem = (StructProductItem)this.smartFileIO.ReadStructureBuffer(typeof(StructProductItem), i);

                    values.Add(structItem.Name);
                }
            }

            this.smartFileIO.Close();
        }
        #endregion

        #region JudgmentSet File #1
        private void CreateJudgmentSetFile1()
        {
            StructJudgmentSetItem structItem;

            this.CurrentJudgmentSetItem1.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Filter = this.CurrentJudgmentSetItem1.Filter;
                structItem.JudgmentDelayTime = this.CurrentJudgmentSetItem1.JudgmentDelayTime;
                structItem.DoubleDelayTime = this.CurrentJudgmentSetItem1.DoubleDelayTime;
                structItem.JudgmentCount = this.CurrentJudgmentSetItem1.JudgmentCount;
                structItem.FeedSpeed1 = this.CurrentJudgmentSetItem1.FeedSpeed1;
                structItem.FeedSpeed2 = this.CurrentJudgmentSetItem1.FeedSpeed2;
                structItem.FeedSpeed3 = this.CurrentJudgmentSetItem1.FeedSpeed3;
                structItem.DynamicCorrection = this.CurrentJudgmentSetItem1.DynamicCorrection;

                structItem.Sorter1Mode = this.CurrentJudgmentSetItem1.Sorter1Mode;
                structItem.Sorter1DelayTime = this.CurrentJudgmentSetItem1.Sorter1DelayTime;
                structItem.Sorter1RunTime = this.CurrentJudgmentSetItem1.Sorter1RunTime;
                structItem.Sorter2Mode = this.CurrentJudgmentSetItem1.Sorter2Mode;
                structItem.Sorter2DelayTime = this.CurrentJudgmentSetItem1.Sorter2DelayTime;
                structItem.Sorter2RunTime = this.CurrentJudgmentSetItem1.Sorter2RunTime;

                structItem.AutoJudgmentLength = this.CurrentJudgmentSetItem1.AutoJudgmentLength;
                structItem.AutoJudgment1 = this.CurrentJudgmentSetItem1.AutoJudgment1;
                structItem.AutoJudgment2 = this.CurrentJudgmentSetItem1.AutoJudgment2;
                structItem.AutoJudgment3 = this.CurrentJudgmentSetItem1.AutoJudgment3;

                structItem.DescendDelayTime = this.CurrentJudgmentSetItem1.DescendDelayTime;
                structItem.AscendDelayTime = this.CurrentJudgmentSetItem1.AscendDelayTime;
                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";
                structItem.DummyString5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveJudgmentSetFile1(JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile1();
            }

            structItem.Filter = item.Filter;
            structItem.JudgmentDelayTime = item.JudgmentDelayTime;
            structItem.DoubleDelayTime = item.DoubleDelayTime;
            structItem.JudgmentCount = item.JudgmentCount;
            structItem.FeedSpeed1 = item.FeedSpeed1;
            structItem.FeedSpeed2 = item.FeedSpeed2;
            structItem.FeedSpeed3 = item.FeedSpeed3;
            structItem.DynamicCorrection = item.DynamicCorrection;

            structItem.Sorter1Mode = item.Sorter1Mode;
            structItem.Sorter1DelayTime = item.Sorter1DelayTime;
            structItem.Sorter1RunTime = item.Sorter1RunTime;
            structItem.Sorter2Mode = item.Sorter2Mode;
            structItem.Sorter2DelayTime = item.Sorter2DelayTime;
            structItem.Sorter2RunTime = item.Sorter2RunTime;

            structItem.AutoJudgmentLength = item.AutoJudgmentLength;
            structItem.AutoJudgment1 = item.AutoJudgment1;
            structItem.AutoJudgment2 = item.AutoJudgment2;
            structItem.AutoJudgment3 = item.AutoJudgment3;

            structItem.DescendDelayTime = item.DescendDelayTime;
            structItem.AscendDelayTime = item.AscendDelayTime;
            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadJudgmentSetFile1(ref JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile1();
            }

            try
            {
                structItem = (StructJudgmentSetItem)this.smartFileIO.ReadStructure(index, typeof(StructJudgmentSetItem));

                item.Filter = structItem.Filter;
                item.JudgmentDelayTime = structItem.JudgmentDelayTime;
                item.DoubleDelayTime = structItem.DoubleDelayTime;
                item.JudgmentCount = structItem.JudgmentCount;
                item.FeedSpeed1 = structItem.FeedSpeed1;
                item.FeedSpeed2 = structItem.FeedSpeed2;
                item.FeedSpeed3 = structItem.FeedSpeed3;
                item.DynamicCorrection = structItem.DynamicCorrection;

                item.Sorter1Mode = structItem.Sorter1Mode;
                item.Sorter1DelayTime = structItem.Sorter1DelayTime;
                item.Sorter1RunTime = structItem.Sorter1RunTime;
                item.Sorter2Mode = structItem.Sorter2Mode;
                item.Sorter2DelayTime = structItem.Sorter2DelayTime;
                item.Sorter2RunTime = structItem.Sorter2RunTime;

                item.AutoJudgmentLength = structItem.AutoJudgmentLength;
                item.AutoJudgment1 = structItem.AutoJudgment1;
                item.AutoJudgment2 = structItem.AutoJudgment2;
                item.AutoJudgment3 = structItem.AutoJudgment3;

                item.DescendDelayTime = structItem.DescendDelayTime;
                item.AscendDelayTime = structItem.AscendDelayTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region JudgmentSet File #2
        private void CreateJudgmentSetFile2()
        {
            StructJudgmentSetItem structItem;

            this.CurrentJudgmentSetItem2.Initialization();

            for (int i = 0; i < 1000; i++)
            {
                structItem.Filter = this.CurrentJudgmentSetItem2.Filter;
                structItem.JudgmentDelayTime = this.CurrentJudgmentSetItem2.JudgmentDelayTime;
                structItem.DoubleDelayTime = this.CurrentJudgmentSetItem2.DoubleDelayTime;
                structItem.JudgmentCount = this.CurrentJudgmentSetItem2.JudgmentCount;
                structItem.FeedSpeed1 = this.CurrentJudgmentSetItem2.FeedSpeed1;
                structItem.FeedSpeed2 = this.CurrentJudgmentSetItem2.FeedSpeed2;
                structItem.FeedSpeed3 = this.CurrentJudgmentSetItem2.FeedSpeed3;
                structItem.DynamicCorrection = this.CurrentJudgmentSetItem2.DynamicCorrection;

                structItem.Sorter1Mode = this.CurrentJudgmentSetItem2.Sorter1Mode;
                structItem.Sorter1DelayTime = this.CurrentJudgmentSetItem2.Sorter1DelayTime;
                structItem.Sorter1RunTime = this.CurrentJudgmentSetItem2.Sorter1RunTime;
                structItem.Sorter2Mode = this.CurrentJudgmentSetItem2.Sorter2Mode;
                structItem.Sorter2DelayTime = this.CurrentJudgmentSetItem2.Sorter2DelayTime;
                structItem.Sorter2RunTime = this.CurrentJudgmentSetItem2.Sorter2RunTime;

                structItem.AutoJudgmentLength = this.CurrentJudgmentSetItem2.AutoJudgmentLength;
                structItem.AutoJudgment1 = this.CurrentJudgmentSetItem2.AutoJudgment1;
                structItem.AutoJudgment2 = this.CurrentJudgmentSetItem2.AutoJudgment2;
                structItem.AutoJudgment3 = this.CurrentJudgmentSetItem2.AutoJudgment3;

                structItem.DescendDelayTime = this.CurrentJudgmentSetItem2.DescendDelayTime;
                structItem.AscendDelayTime = this.CurrentJudgmentSetItem2.AscendDelayTime;
                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyString1 = "";
                structItem.DummyString2 = "";
                structItem.DummyString3 = "";
                structItem.DummyString4 = "";
                structItem.DummyString5 = "";

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveJudgmentSetFile2(JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile2();
            }

            structItem.Filter = item.Filter;
            structItem.JudgmentDelayTime = item.JudgmentDelayTime;
            structItem.DoubleDelayTime = item.DoubleDelayTime;
            structItem.JudgmentCount = item.JudgmentCount;
            structItem.FeedSpeed1 = item.FeedSpeed1;
            structItem.FeedSpeed2 = item.FeedSpeed2;
            structItem.FeedSpeed3 = item.FeedSpeed3;
            structItem.DynamicCorrection = item.DynamicCorrection;

            structItem.Sorter1Mode = item.Sorter1Mode;
            structItem.Sorter1DelayTime = item.Sorter1DelayTime;
            structItem.Sorter1RunTime = item.Sorter1RunTime;
            structItem.Sorter2Mode = item.Sorter2Mode;
            structItem.Sorter2DelayTime = item.Sorter2DelayTime;
            structItem.Sorter2RunTime = item.Sorter2RunTime;

            structItem.AutoJudgmentLength = item.AutoJudgmentLength;
            structItem.AutoJudgment1 = item.AutoJudgment1;
            structItem.AutoJudgment2 = item.AutoJudgment2;
            structItem.AutoJudgment3 = item.AutoJudgment3;

            structItem.DescendDelayTime = item.DescendDelayTime;
            structItem.AscendDelayTime = item.AscendDelayTime;
            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyString1 = "";
            structItem.DummyString2 = "";
            structItem.DummyString3 = "";
            structItem.DummyString4 = "";
            structItem.DummyString5 = "";

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadJudgmentSetFile2(ref JudgmentSetItem item, int index)
        {
            bool fileCheck = false;
            string fullFilePath = "";
            StructJudgmentSetItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "JudgmentSetItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);
                this.CreateJudgmentSetFile2();
            }

            try
            {
                structItem = (StructJudgmentSetItem)this.smartFileIO.ReadStructure(index, typeof(StructJudgmentSetItem));

                item.Filter = structItem.Filter;
                item.JudgmentDelayTime = structItem.JudgmentDelayTime;
                item.DoubleDelayTime = structItem.DoubleDelayTime;
                item.JudgmentCount = structItem.JudgmentCount;
                item.FeedSpeed1 = structItem.FeedSpeed1;
                item.FeedSpeed2 = structItem.FeedSpeed2;
                item.FeedSpeed3 = structItem.FeedSpeed3;
                item.DynamicCorrection = structItem.DynamicCorrection;

                item.Sorter1Mode = structItem.Sorter1Mode;
                item.Sorter1DelayTime = structItem.Sorter1DelayTime;
                item.Sorter1RunTime = structItem.Sorter1RunTime;
                item.Sorter2Mode = structItem.Sorter2Mode;
                item.Sorter2DelayTime = structItem.Sorter2DelayTime;
                item.Sorter2RunTime = structItem.Sorter2RunTime;

                item.AutoJudgmentLength = structItem.AutoJudgmentLength;
                item.AutoJudgment1 = structItem.AutoJudgment1;
                item.AutoJudgment2 = structItem.AutoJudgment2;
                item.AutoJudgment3 = structItem.AutoJudgment3;

                item.DescendDelayTime = structItem.DescendDelayTime;
                item.AscendDelayTime = structItem.AscendDelayTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

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

        #region Counter File #1
        private void CreateCounterFile1()
        {
            StructCounterItem structItem;
            WeightData item = new WeightData();
            item.ClearCount();

            for (int i = 0; i < 1000; i++)
            {
                structItem.OverCount = item.OverCount;
                structItem.OverSumWeight = item.OverSumWeight;
                structItem.PassCount = item.PassCount;
                structItem.PassSumWeight = item.PassSumWeight;
                structItem.UnderCount = item.UnderCount;
                structItem.UnderSumWeight = item.UnderSumWeight;
                structItem.ExNGCount = item.ExNGCount;

                structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
                structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
                structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
                structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
                structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
                structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
                structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
                structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
                structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
                structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

                structItem.StartTime = item.StartTime;
                structItem.StopTime = item.StopTime;

                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyInt4 = 0;
                structItem.DummyInt5 = 0;

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveCounterFile1(WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile1();
            }

            structItem.OverCount = item.OverCount;
            structItem.OverSumWeight = item.OverSumWeight;
            structItem.PassCount = item.PassCount;
            structItem.PassSumWeight = item.PassSumWeight;
            structItem.UnderCount = item.UnderCount;
            structItem.UnderSumWeight = item.UnderSumWeight;
            structItem.ExNGCount = item.ExNGCount;

            structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
            structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
            structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
            structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
            structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
            structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
            structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
            structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
            structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
            structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

            structItem.StartTime = item.StartTime;
            structItem.StopTime = item.StopTime;

            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyInt4 = 0;
            structItem.DummyInt5 = 0;

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadCounterFile1(ref WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem1.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile1();
            }

            try
            {
                structItem = (StructCounterItem)this.smartFileIO.ReadStructure(index, typeof(StructCounterItem));

                item.UnderCount = structItem.UnderCount;
                item.UnderSumWeight = structItem.UnderSumWeight;
                item.PassCount = structItem.PassCount;
                item.PassSumWeight = structItem.PassSumWeight;
                item.OverCount = structItem.OverCount;
                item.OverSumWeight = structItem.OverSumWeight;
                item.ExNGCount = structItem.ExNGCount;

                item.CollectionNormalDistributionCount[0] = structItem.NormalDistribution1;
                item.CollectionNormalDistributionCount[1] = structItem.NormalDistribution2;
                item.CollectionNormalDistributionCount[2] = structItem.NormalDistribution3;
                item.CollectionNormalDistributionCount[3] = structItem.NormalDistribution4;
                item.CollectionNormalDistributionCount[4] = structItem.NormalDistribution5;
                item.CollectionNormalDistributionCount[5] = structItem.NormalDistribution6;
                item.CollectionNormalDistributionCount[6] = structItem.NormalDistribution7;
                item.CollectionNormalDistributionCount[7] = structItem.NormalDistribution8;
                item.CollectionNormalDistributionCount[8] = structItem.NormalDistribution9;
                item.CollectionNormalDistributionCount[9] = structItem.NormalDistribution10;

                if (structItem.StartTime.Year == 1111)
                    item.StartTime = DateTime.Now;
                else
                    item.StartTime = structItem.StartTime;

                if (structItem.StopTime.Year == 1111)
                    item.StopTime = DateTime.Now;
                else
                    item.StopTime = structItem.StopTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

                this.smartFileIO.Close();
            }
            this.smartFileIO.Close();
        }
        #endregion
        #region Counter File #2
        private void CreateCounterFile2()
        {
            StructCounterItem structItem;
            WeightData item = new WeightData();
            item.ClearCount();

            for (int i = 0; i < 1000; i++)
            {
                structItem.OverCount = item.OverCount;
                structItem.OverSumWeight = item.OverSumWeight;
                structItem.PassCount = item.PassCount;
                structItem.PassSumWeight = item.PassSumWeight;
                structItem.UnderCount = item.UnderCount;
                structItem.UnderSumWeight = item.UnderSumWeight;
                structItem.ExNGCount = item.ExNGCount;

                structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
                structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
                structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
                structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
                structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
                structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
                structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
                structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
                structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
                structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

                structItem.StartTime = item.StartTime;
                structItem.StopTime = item.StopTime;

                structItem.DummyInt1 = 0;
                structItem.DummyInt2 = 0;
                structItem.DummyInt3 = 0;
                structItem.DummyInt4 = 0;
                structItem.DummyInt5 = 0;

                this.smartFileIO.WriteStructure_Begin(structItem, i);
            }
            this.smartFileIO.WriteStructure_End();
        }
        public void SaveCounterFile2(WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile2();
            }

            structItem.OverCount = item.OverCount;
            structItem.OverSumWeight = item.OverSumWeight;
            structItem.PassCount = item.PassCount;
            structItem.PassSumWeight = item.PassSumWeight;
            structItem.UnderCount = item.UnderCount;
            structItem.UnderSumWeight = item.UnderSumWeight;
            structItem.ExNGCount = item.ExNGCount;

            structItem.NormalDistribution1 = item.CollectionNormalDistributionCount[0];
            structItem.NormalDistribution2 = item.CollectionNormalDistributionCount[1];
            structItem.NormalDistribution3 = item.CollectionNormalDistributionCount[2];
            structItem.NormalDistribution4 = item.CollectionNormalDistributionCount[3];
            structItem.NormalDistribution5 = item.CollectionNormalDistributionCount[4];
            structItem.NormalDistribution6 = item.CollectionNormalDistributionCount[5];
            structItem.NormalDistribution7 = item.CollectionNormalDistributionCount[6];
            structItem.NormalDistribution8 = item.CollectionNormalDistributionCount[7];
            structItem.NormalDistribution9 = item.CollectionNormalDistributionCount[8];
            structItem.NormalDistribution10 = item.CollectionNormalDistributionCount[9];

            structItem.StartTime = item.StartTime;
            structItem.StopTime = item.StopTime;

            structItem.DummyInt1 = 0;
            structItem.DummyInt2 = 0;
            structItem.DummyInt3 = 0;
            structItem.DummyInt4 = 0;
            structItem.DummyInt5 = 0;

            this.smartFileIO.WriteStructure(structItem, index);
            this.smartFileIO.Close();
        }
        public void LoadCounterFile2(ref WeightData item, int index)
        {
            string fullFilePath = "";
            bool fileCheck = false;
            StructCounterItem structItem;

            fullFilePath = this.PathSystemFileFolder2 + "counterItem2.int";
            this.smartFileIO.FilePathName = fullFilePath;

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

            if (fileCheck == true)
                this.smartFileIO.Open(this.BufferSmartUart);
            else
            {
                this.smartFileIO.Open(this.BufferSmartUart);

                this.CreateCounterFile2();
            }

            try
            {
                structItem = (StructCounterItem)this.smartFileIO.ReadStructure(index, typeof(StructCounterItem));

                item.UnderCount = structItem.UnderCount;
                item.UnderSumWeight = structItem.UnderSumWeight;
                item.PassCount = structItem.PassCount;
                item.PassSumWeight = structItem.PassSumWeight;
                item.OverCount = structItem.OverCount;
                item.OverSumWeight = structItem.OverSumWeight;
                item.ExNGCount = structItem.ExNGCount;

                item.CollectionNormalDistributionCount[0] = structItem.NormalDistribution1;
                item.CollectionNormalDistributionCount[1] = structItem.NormalDistribution2;
                item.CollectionNormalDistributionCount[2] = structItem.NormalDistribution3;
                item.CollectionNormalDistributionCount[3] = structItem.NormalDistribution4;
                item.CollectionNormalDistributionCount[4] = structItem.NormalDistribution5;
                item.CollectionNormalDistributionCount[5] = structItem.NormalDistribution6;
                item.CollectionNormalDistributionCount[6] = structItem.NormalDistribution7;
                item.CollectionNormalDistributionCount[7] = structItem.NormalDistribution8;
                item.CollectionNormalDistributionCount[8] = structItem.NormalDistribution9;
                item.CollectionNormalDistributionCount[9] = structItem.NormalDistribution10;

                item.StartTime = structItem.StartTime;
                item.StopTime = structItem.StopTime;
            }
            catch
            {
                DialogFormMessage myMsg = new DialogFormMessage(17, this.SystemConfig.Language);
                myMsg.ShowDialog();

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

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

            // 변수 초기 셋팅
            this.DefaultSetting();

            // SystemConfiguration 파일 읽기
            this.LoadSystemConfigurationFile();
            Thread.Sleep(50);

            // Counter 파일 읽기
            this.LoadCounterFile1(ref this.CurrentWeightData1, this.SystemConfig.ProductNumber - 1);
            this.LoadCounterFile2(ref this.CurrentWeightData2, this.SystemConfig.ProductNumber - 1);
            Thread.Sleep(50);

            // 품목 파일 읽기
            this.LoadProductFile1(ref this.CurrentProductItem1, this.SystemConfig.ProductNumber - 1);
            this.LoadProductFile2(ref this.CurrentProductItem2, this.SystemConfig.ProductNumber - 1);
            Thread.Sleep(50);

            // SystemParameter 파일 읽기
            this.LoadJudgmentSetFile1(ref this.CurrentJudgmentSetItem1, this.SystemConfig.ProductNumber - 1);
            this.LoadJudgmentSetFile2(ref this.CurrentJudgmentSetItem2, this.SystemConfig.ProductNumber - 1);
            Thread.Sleep(50);

            // UserGroupPassword 파일 읽기
            this.LoadUserGroupPasswordFile();

            // UserGroup 파일 읽기
            this.LoadUserGroupFile(ref this.CurrentUserGroup);
            // User 파일 읽기
            this.LoadUserLevel1File(this.CurrentUser.Level1Users);
            this.LoadUserLevel2File(this.CurrentUser.Level2Users);
            this.LoadUserLevel3File(this.CurrentUser.Level3Users);

            // 폼 생성
            this.CreateForm();

            this.SmartSplashProgramLoad.Finish();
            this.smartForm.Show((int)DataStore.FormStore.FormMainDisplay);
            this.ChildFormMainDisplay.CurrentBottomMenuControlEnable(DataStore.EquipmentStatus.Stop);

            this.TimerSensorErrorInterval();
            this.TimerEntryNotDetectedIgnoreTimeInverval();

            // 메인 통신 OPEN
            this.OpenSmartUartLink();
            // CH1 OPEN
            this.OpenSerialCOM1();
            // CH2 OPEN
            this.OpenSerialCOM3();
            // Read SystemParameter1
            this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._9507_SystemParameterRead, "");

            // Mouse On
            //this.smartForm.Mode = SmartForm.RUNMODE.DEVELOPER;
            //this.smartForm.MouseCursor = SmartForm.OnOff.ON;
        }
        #endregion

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

            // 통신 확인
            if (this.CommunicationCheckCount / 3 == 1)
            {
                this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = true;
                this.CommunicationCheckCount = 0;
            }
            else
            {
                this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = false;
                this.CommunicationCheckCount += 1;
            }
        }

        private void timerEntryNotDetectedIgnoreTime1_Tick(object sender, EventArgs e)
        {
            this.timerEntryNotDetectedIgnoreTime1.Enabled = false;

            if (this.IsJudgmentNow1 == true)
                this.IsJudgmentNow1 = false;

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow1 ({0:yyyy-MM-dd HH:mm:ss}): false", DateTime.Now));
        }
        private void timerEntryNotDetectedIgnoreTime2_Tick(object sender, EventArgs e)
        {
            this.timerEntryNotDetectedIgnoreTime2.Enabled = false;

            if (this.IsJudgmentNow2 == true)
                this.IsJudgmentNow2 = false;

            // 로그
            if (this.IsCommunicationLogOpen == true)
                this.smartFileCommunicationLog.WriteString(string.Format("IsJudgmentNow2 ({0:yyyy-MM-dd HH:mm:ss}): false", DateTime.Now));
        }

        private void timerSensorError1_Tick(object sender, EventArgs e)
        {
            this.timerSensorError1.Enabled = false;
            if (this.SystemConfig.Language == DataStore.LanguageID.Korean)
                this.ChildFormMainDisplay.PopUpWarning("#1 진입센서 이상");
            else
                this.ChildFormMainDisplay.PopUpWarning("#1 Entry Sensor stucked");

            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        private void timerSensorError2_Tick(object sender, EventArgs e)
        {
            this.timerSensorError2.Enabled = false;
            if (this.SystemConfig.Language == DataStore.LanguageID.Korean)
                this.ChildFormMainDisplay.PopUpWarning("#2 진입센서 이상");
            else
                this.ChildFormMainDisplay.PopUpWarning("#2 Entry Sensor stucked");

            this.TransferData(CommunicationCommand.BuzzerOnContinuousEnable, CommunicationID.MainBoard);
            this.TransferData(CommunicationCommand.Stop, CommunicationID.MainBoard);
        }
        #endregion
    }
}