using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Runtime.InteropServices;

namespace INT89DB_26
{
    public class DataStore
    {
        #region Enum
        public enum EquipmentStatus
        {
            Stop = 0,
            Start = 1,
        };

        public enum FeedbackBoardDataTransfer
        {
            None,
            Step1_6203,
            Step2_6208,
        }

        public enum FeedbackStatus
        {
            None,
            Positive,
            Negative,
        };

        public enum E_FormStore
        {
            FormNone = 0,
            FormMainDisplay,
            FormMenu,
            FormCommunication,
            FormCalibration,
            FormSystemSetting,
            FormIOTest,
            FormEquipmentSetting,
            FormDataBackup,
            FormConfiguration,
            FormTimeSetting,
            FormInformation,
            FormFactory,
            FormProgramUpdate,
            FormEquipmentTest,
            FormUserSetting,
            FormOptionSetting,
        };

        public enum E_LanguageID
        {
            Korean = 0,
            English,
            Chinese,
            Czech,
            German,
            Russian,
            Japanese,
        };

        public enum MessageBoxIcon
        {
            None,
            Hand,
            Question,
            Exclamation,
            Asterisk,
        }

        public enum UserGroup
        {
            None = 0,
            Level1Operator,
            Level2Engineer,
            Level3Manager,
            Level4Developer,
            LogOff,
        };

        public enum JudgmentStatus
        {
            Empty,
            Under,
            Pass,
            Over,
            Double,
            SensorError,
            EXNg,
        };

        public enum WeightStatus
        {
            Empty,
            WeightChange,
            WeightZero,
            CalNomal,
            CalBalans,
            CalStandby,
            CalFinish,
            CalError,
        };

        public enum ResponseData
        {
            NAK = 0,
            ACK = 1,
        };

        public enum UserPassword
        {
            f0_Level1 = 0,
            f1_Level2 = 1,
            f2_Level3 = 2,
        }

        public enum CommunicationMode
        {
            f0_None = 0,
            f1_STD1 = 1,
            f2_STD2 = 2,
            f98_FB_Board = 98,
            f99_Modbus = 99,
        }
        #endregion
    }

    #region CommunicationCommand
    public class CommunicationCommand
    {
        // 중량조정모드
        public static readonly string ModeCalibration = "Csc00";
        // 노멀모드
        public static readonly string ModeNormal = "Csn00";
        // 판정설정모드
        public static readonly string ModeJudgment = "Csg00";
        // IO 테스트모드
        public static readonly string ModeIOTest = "Cst00";
        // 바이패스
        public static readonly string ModeBypass = "Csb00";
        // 장비 테스트모드
        public static readonly string ModeEquipmentTest = "Csy00";
        // 메뉴모드
        public static readonly string ModeMenu = "Csm00";

        // 중량조정 - 분동
        public static readonly string CalibrationBalance = "Ccb00";
        // 중량조정 - 시작
        public static readonly string CalibrationStart = "Ccs00";
        // 중량조정 - 취소
        public static readonly string CalibrationCancel = "Ccx00";
        // 중량보정 - 한자리올림
        public static readonly string CalibrationUp = "Ccu00";
        // 중량보정 - 한자리내림
        public static readonly string CalibrationDown = "Ccd00";

        // 파라미터 쓰기
        public static readonly string Write = "Pw000";
        // 파라미터 읽기
        public static readonly string Read = "Pr000";
        // Bypass To Motor
        public static readonly string BypassToMotor = "Pb000";
        // IO테스트 - OUT
        public static readonly string IOTest = "Pt000";

        // 임펠러 모터 - 정회전
        public static readonly string ImpellerMotorForward = "Cmc00";
        // 임펠러 모터 - 역회전
        public static readonly string ImpellerMotorReverse = "Cmr00";
        // 모터 - 다운
        public static readonly string MotorDown = "Cmd00";
        // 모터 - 업
        public static readonly string MotorUp = "Cmu00";

        // Cut 신호
        public static readonly string CutInpupt = "Cbc00";
        // 공장초기화
        public static readonly string Initialization = "Cbi00";
        // 운전
        public static readonly string Start = "Cbs00";
        // 정지
        public static readonly string Stop = "Cbt00";
        // 영점
        public static readonly string Zero = "Cbz00";

        // 판정 - bypass 1회
        public static readonly string BypassOnce = "Cjb00";
        // 판정 - byNG 1회
        public static readonly string ByNGOnce = "Cjc00";
        // 판정 - bypass 연속 OFF
        public static readonly string BypassOFF = "Cjd00";
        // 판정 - bypass 연속 ON
        public static readonly string BypassON = "Cjd01";
        // 판정 - byNG 연속 OFF
        public static readonly string ByNGOFF = "Cje00";
        // 판정 - byNG 연속 ON
        public static readonly string ByNGON = "Cje01";
    }
    public class CommunicationID
    {
        public static readonly string MainBoard = "0";
        public static readonly string SubBoard1 = "A";
        public static readonly string SubBoard2 = "B";
        public static readonly string SubBoard3 = "C";
        public static readonly string SubBoard4 = "D";
        public static readonly string SubBoard5 = "E";
        public static readonly string SubBoard6 = "F";
        public static readonly string SubBoard7 = "G";
        public static readonly string SubBoard8 = "H";
        public static readonly string SubBoard9 = "I";
        public static readonly string SubBoard10 = "J";
        public static readonly string SubBoard11 = "K";
        public static readonly string SubBoard12 = "L";
        public static readonly string SubBoardAll = "Z";
    }

    public class CommunicationAddress
    {
        // Address None
        public static readonly string None = "0000";        

        // 임펠러 모터 - 회전각도
        public static readonly string ImpellerMotorAngle = "1101";        
        // 임펠러 모터 - 통신속도
        public static readonly string ImpellerMotorBaudrate = "1102";        
        // 임펠러 모터 - 회전방향
        public static readonly string ImpellerMotorDirection = "1103";
        // 바이패스
        public static readonly string Bypass = "1201";
        // 보드 버전 모두 읽기
        public static readonly string ProgramVersion = "1500";

        // 품목설정 - 품번
        public static readonly string ProductNumber = "2001";
        // 품목설정 - 하한 설정값
        public static readonly string UnderRange = "2002";
        // 품목설정 - 기준 설정값
        public static readonly string PassRange = "2003";
        // 품목설정 - 상한 설정값
        public static readonly string OverRange = "2004";
        // 품목설정 - 용기 설정값
        public static readonly string TareRange = "2005";

        // 중량조정 - 최대중량 설정값
        public static readonly string MaxWeight = "3001";
        // 중량조정 - 분동중량 설정값
        public static readonly string BalanceWeight = "3002";
        // 중량조정 - 한눈의 값
        public static readonly string Digit = "3003";
        // 중량조정 - 파라미터 읽기
        public static readonly string ParameterRead3901 = "3901";

        // 자동영점 - 시간
        public static readonly string ZeroTime = "4001";
        // 자동영점 - 범위
        public static readonly string ZeroRange = "4002";
        // 자동영점 - 변량
        public static readonly string ZeroVariate = "4003";
        // 자동영점 - 모드
        public static readonly string ZeroMode = "4004";
        // 자동영점 - 파라미터 읽기
        public static readonly string ParameterRead4901 = "4901";

        // 판정설정 - 필터
        public static readonly string Filter = "5001";
        // 판정설정 - 판정지연
        public static readonly string JudgmentDelayTime = "5002";
        // 판정설정 - 이중지연
        public static readonly string DoubleDelayTime = "5003";
        // 판정설정 - 판정개수
        public static readonly string JudgmentCount = "5004";
        // 판정설정 - 동보정
        public static readonly string DynamicCorrection = "5006";
        // 판정설정 - Feeding 컨베어 지연시간
        public static readonly string FeedingConveyorDelayTime = "5007";
        // 판정설정 - Feeding 컨베어 동작시간
        public static readonly string FeedingConveyorRunTime = "5008";
        // 판정설정 - 배출 컨베어 지연시간
        public static readonly string DischargeConveyorDelayTime = "5009";
        // 판정설정 - 배출 컨베어 동작시간
        public static readonly string DischargeConveyorRunTime = "5010";
        // 판정설정 - 상승지연시간
        public static readonly string UpDelayTime = "5011";
        // 판정설정 - 하강지연시간
        public static readonly string DownDelayTime = "5012";
        // 판정설정 - 인버터1 속도
        public static readonly string InverterSpeed1 = "5051";
        // 판정설정 - 인버터2 속도
        public static readonly string InverterSpeed2 = "5052";
        // 판정설정 - 인버터3 속도
        public static readonly string InverterSpeed3 = "5053";
        // 판정설정 - 인버터4 속도
        public static readonly string InverterSpeed4 = "5054";

        // 판정설정 - 선별기 모드 값
        public static readonly string Sorter1Mode = "5101";
        // 판정설정 - 선별기 지연시간
        public static readonly string Sorter1DelayTime = "5102";
        // 판정설정 - 선별기 동작시간
        public static readonly string Sorter1RunTime = "5103";

        // 옵션 - 부저 ON시간
        public static readonly string BuzzerOnTime = "6001";
        // 옵션 - 릴레이 동작시간
        public static readonly string RelayRunTime = "6002";
        // 옵션 - 이중진입사용여부
        public static readonly string DoubleEnter = "6005";
        // 옵션 - 채터링감지 설정
        public static readonly string Chattering = "6006";
        // 옵션 - OPT1 펄스폭
        public static readonly string _6203_FeedbackPulseWidth = "6203";
        // 옵션 - OPT1 Collection Rate
        public static readonly string _6208_FeedbackCollectionRate = "6208";
        // 옵션 - 파라미터 읽기
        public static readonly string ParameterRead6901 = "6901";

        // 통신,IO설정 - INPUT ALL
        public static readonly string InputAll = "7500";
        // 통신,IO설정 = OUTPUT1
        public static readonly string Output1 = "7701";
        // 통신,IO설정 = OUTPUT2
        public static readonly string Output2 = "7702";
        // 통신,IO설정 = OUTPUT3
        public static readonly string Output3 = "7703";
        // 통신,IO설정 = OUTPUT4
        public static readonly string Output4 = "7704";
        // 통신,IO설정 = OUTPUT5
        public static readonly string Output5 = "7705";
        // 통신,IO설정 = OUTPUT6
        public static readonly string Output6 = "7706";
        // 통신,IO설정 = OUTPUT7
        public static readonly string Output7 = "7707";
        // 통신,IO설정 = OUTPUT8
        public static readonly string Output8 = "7708";
        // 통신,IO설정 = OUTPUT9
        public static readonly string Output9 = "7709";
        // 통신,IO설정 = OUTPUT10
        public static readonly string Output10 = "7710";
        // 통신,IO설정 = OUTPUT11
        public static readonly string Output11 = "7711";
        // 통신,IO설정 = OUTPUT12
        public static readonly string Output12 = "7712";
        // 통신,IO설정 = OUTPUT13
        public static readonly string Output13 = "7713";
        // 통신,IO설정 = OUTPUT14
        public static readonly string Output14 = "7714";
        // 통신,IO설정 = OUTPUT15
        public static readonly string Output15 = "7715";
        // 통신,IO설정 = OUTPUT16
        public static readonly string Output16 = "7716";

        // 시스템 설정 모두 쓰기
        public static readonly string _9047_ParameterSystem = "9047";
        // 품목 설정 모두 쓰기 
        public static readonly string _9048_ParameterProduct = "9048";
    } 
    #endregion

    #region SystemConfiguration
    public class SystemConfigurationItem
    {
        #region Field
        private bool m_IsDataBackup;
        private bool m_IsBypassMode;
        private bool m_IsWeightViewForward;
        private bool m_IsLogin;
        private bool m_IsBypassDirectionPass;
        private bool m_IsBypassOnce;
        
        private int m_DecimalPlaces;
        private int m_EquipmentColumns;
        private int m_EquipmentID;
        private int m_EquipmentMode;
        private int m_ProductNumber;
        private int m_UsbID;
        private int m_Serial3BaudRate;
        private int m_Serial3Mode;
        private int m_InverterQTY;
        
        private string m_Unit;
        private string m_SerialNumber;    

        private DataStore.E_LanguageID m_Language;
        private DataStore.E_FormStore m_CurrentForm;
        private User m_CurrentUser;
     
        private int m_EthernetLocalPort;
        private int m_EthernetServerPort;
        private int m_EthernetMode;
        private int m_EthernetOperationMode;
        private int m_ModbusTcpStartAddress;
        private string m_EthernetServerAddress;

        private bool m_IsFeedback;
        private bool m_IsFeedbackBoard;
        private int m_FeedbackSampleCount;
        private int m_FeedbackIgnorePackages;
        private int m_FeedbackPulseWidth;
        private int m_FeedbackCorrectionRate;
        #endregion

        #region Constructor
        public SystemConfigurationItem()
        {
            this.Initialization();
        }
        #endregion

        #region Property
        public bool IsDataBackup
        {
            get { return this.m_IsDataBackup; }
            set { this.m_IsDataBackup = value; }
        }
        public bool IsBypassMode
        {
            get { return this.m_IsBypassMode; }
            set { this.m_IsBypassMode = value; }
        }
        public bool IsWeightViewForward
        {
            get { return this.m_IsWeightViewForward; }
            set { this.m_IsWeightViewForward = value; }
        }
        public bool IsLogin
        {
            get { return this.m_IsLogin; }
            set { this.m_IsLogin = value; }
        }
        public bool IsBypassDirectionPass
        {
            get { return this.m_IsBypassDirectionPass; }
            set { this.m_IsBypassDirectionPass = value; }
        }
        public bool IsBypassOnce
        {
            get { return this.m_IsBypassOnce; }
            set { this.m_IsBypassOnce = value; }
        }

        public int DecimalPlaces
        {
            get { return this.m_DecimalPlaces; }
            set { this.m_DecimalPlaces = value; }
        }
        public int EquipmentColumns
        {
            get { return this.m_EquipmentColumns; }
            set { this.m_EquipmentColumns = value; }
        }
        public int EquipmentID
        {
            get { return this.m_EquipmentID; }
            set { this.m_EquipmentID = value; }
        } 
        public int EquipmentMode
        {
            get { return this.m_EquipmentMode; }
            set { this.m_EquipmentMode = value; }
        } 
        public int ProductNumber
        {
            get { return this.m_ProductNumber; }
            set { this.m_ProductNumber = value; }
        }
        public int UsbID
        {
            get { return this.m_UsbID; }
            set { this.m_UsbID = value; }
        }
        public int Serial3BaudRate
        {
            get { return this.m_Serial3BaudRate; }
            set { this.m_Serial3BaudRate = value; }
        }
        public int Serial3Mode
        {
            get { return this.m_Serial3Mode; }
            set { this.m_Serial3Mode = value; }
        }
        public int InverterQTY
        {
            get { return this.m_InverterQTY; }
            set { this.m_InverterQTY = value; }
        }

        public string Unit
        {
            get { return this.m_Unit; }
            set { this.m_Unit = value; }
        }
        public string SerialNumber
        {
            get { return this.m_SerialNumber; }
            set { this.m_SerialNumber = value; }
        }

        public DataStore.E_LanguageID Language
        {
            get { return this.m_Language; }
            set { this.m_Language = value; }
        }
        public DataStore.E_FormStore CurrentForm
        {
            get { return this.m_CurrentForm; }
            set { this.m_CurrentForm = value; }
        }
        public User CurrentUser
        {
            get { return this.m_CurrentUser; }
            set { this.m_CurrentUser = value; }
        }

        public bool IsEthernetEnable
        {
            get
            {
                if (this.EthernetOperationMode == 0)
                    return false;
                else
                    return true;
            }
        }
        public int EthernetLocalPort
        {
            get { return this.m_EthernetLocalPort; }
            set { this.m_EthernetLocalPort = value; }
        }
        public int EthernetServerPort
        {
            get { return this.m_EthernetServerPort; }
            set { this.m_EthernetServerPort = value; }
        }
        public int EthernetMode
        {
            get { return this.m_EthernetMode; }
            set { this.m_EthernetMode = value; }
        }
        public int EthernetOperationMode
        {
            get { return this.m_EthernetOperationMode; }
            set { this.m_EthernetOperationMode = value; }
        }
        public int ModbusTcpStartAddress
        {
            get { return this.m_ModbusTcpStartAddress; }
            set { this.m_ModbusTcpStartAddress = value; }
        }
        public string EthernetServerAddress
        {
            get { return this.m_EthernetServerAddress; }
            set { this.m_EthernetServerAddress = value; }
        }

        public bool IsFeedback
        {
            get { return this.m_IsFeedback; }
            set { this.m_IsFeedback = value; }
        }
        public bool IsFeedbackBoard
        {
            get { return this.m_IsFeedbackBoard; }
            set { this.m_IsFeedbackBoard = value; }
        }
        public int FeedbackSampleCount
        {
            get { return this.m_FeedbackSampleCount; }
            set { this.m_FeedbackSampleCount = value; }
        }
        public int FeedbackIgnorePackages
        {
            get { return this.m_FeedbackIgnorePackages; }
            set { this.m_FeedbackIgnorePackages = value; }
        }
        public int FeedbackPulseWidth
        {
            get { return this.m_FeedbackPulseWidth; }
            set { this.m_FeedbackPulseWidth = value; }
        }
        public int FeedbackCorrectionRate
        {
            get { return this.m_FeedbackCorrectionRate; }
            set { this.m_FeedbackCorrectionRate = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.IsDataBackup = false;
            this.IsBypassMode = false;
            this.IsWeightViewForward = true;
            this.IsLogin = false;
            this.IsBypassDirectionPass = true;
            this.IsBypassOnce = true;

            this.DecimalPlaces = 1;
            this.EquipmentColumns = 5;
            this.EquipmentID = 1;
            this.EquipmentMode = 0;
            this.ProductNumber = 1;
            this.UsbID = 1;
            this.Serial3BaudRate = 9600;
            this.Serial3Mode = 0;
            this.InverterQTY = 2;

            this.Unit = "g";
            this.SerialNumber = "26A0000";

            this.Language = DataStore.E_LanguageID.Korean;
            this.CurrentForm = DataStore.E_FormStore.FormMainDisplay;
            this.CurrentUser = new User();
            this.CurrentUser.Group = DataStore.UserGroup.LogOff;

            this.EthernetLocalPort = 5001;
            this.EthernetServerPort = 5002;
            this.EthernetMode = 0;
            this.EthernetOperationMode = 0;
            this.ModbusTcpStartAddress = 1010;
            this.EthernetServerAddress = "0.0.0.0";

            this.IsFeedback = false;
            this.IsFeedbackBoard = false;
            this.FeedbackSampleCount = 10;
            this.FeedbackIgnorePackages = 5;
            this.FeedbackPulseWidth = 50;
            this.FeedbackCorrectionRate = 1;
        }
        #endregion
    } 
    #endregion
    #region Struct SystemConfiguration1
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem1
    {
        public bool IsDataBackup;
        public bool DummyBool5;
        public bool DummyBool6;
        public bool DummyBool7;
        public bool IsFeedbackBoard;
        public bool IsFeedback;
        public bool IsLogin;
        public bool IsWeightViewForward;

        public int DecimalPlaces;
        public int InverterQTY;
        public int EquipmentColumns;
        public int EquipmentID;
        public int EquipmentMode;
        public int ProductNumber;
        public int EthernetLocalPort;
        public int EthernetServerPort;
        public int UsbID;
        public int EthernetMode;
        public int EthernetOperationMode;
        public int Serial3BaudRate;
        public int Serial3Mode;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
        public string DummyString6;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string Unit;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)]
        public string SerialNumber;

        public DataStore.E_LanguageID Language;

        public bool DummyBool1;
        public bool DummyBool2;
        public bool DummyBool3;
        public bool DummyBool4;

        public int FeedbackSampleCount;
        public int FeedbackIgnorePackages;
        public int ModbusTcpStartAddress;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string EthernetServerAddress;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString5;
    }
    #endregion
    #region Struct SystemConfiguration2
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem2
    {
        public bool DummyBool1;
        public bool DummyBool2;
        public bool DummyBool3;
        public bool DummyBool4;
        public bool DummyBool5;
        public bool DummyBool6;
        public bool DummyBool7;
        public bool DummyBool8;
        public bool DummyBool9;
        public bool DummyBool10;
        public bool DummyBool11;
        public bool DummyBool12;
        public bool DummyBool13;
        public bool DummyBool14;
        public bool DummyBool15;
        public bool DummyBool16;
        public bool DummyBool17;
        public bool DummyBool18;
        public bool DummyBool19;
        public bool DummyBool20;

        public int FeedbackCorrectionRate;
        public int FeedbackPulseWidth;
        public int DummyInt3;
        public int DummyInt4;
        public int DummyInt5;
        public int DummyInt6;
        public int DummyInt7;
        public int DummyInt8;
        public int DummyInt9;
        public int DummyInt10;
        public int DummyInt11;
        public int DummyInt12;
        public int DummyInt13;
        public int DummyInt14;
        public int DummyInt15;
        public int DummyInt16;
        public int DummyInt17;
        public int DummyInt18;
        public int DummyInt19;
        public int DummyInt20;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string DummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string DummyString5;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString6;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString7;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString8;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString9;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString10;
    }
    #endregion

    #region ProductItem
    public class ProductItem
    {
        #region Field
        private int m_Number;

        private string m_Name;
        private string m_LotNo;
        private string m_UnderRange;
        private string m_PassRange;
        private string m_OverRange;
        private string m_TareRange;

        private int m_ProgressBarMaximum;
        private int m_ProgressBarMinimum;
        #endregion

        #region Constructor
        public ProductItem()
        {
            this.Initialization();
        }
        #endregion

        #region Property
        public int Number
        {
            get { return this.m_Number; }
            set { this.m_Number = value; }
        }

        public string Name
        {
            get { return this.m_Name; }
            set { this.m_Name = value; }
        }
        public string LotNo
        {
            get { return this.m_LotNo; }
            set { this.m_LotNo = value; }
        }
        public string UnderRange
        {
            get { return this.m_UnderRange; }
            set 
            { 
                this.m_UnderRange = value;

                this.ProgressBarLevelRescale();
            }
        }
        public string PassRange
        {
            get { return this.m_PassRange; }
            set { this.m_PassRange = value; }
        }
        public string OverRange
        {
            get { return this.m_OverRange; }
            set
            { 
                this.m_OverRange = value;

                this.ProgressBarLevelRescale();
            }
        } 
        public string TareRange
        {
            get { return this.m_TareRange; }
            set { this.m_TareRange = value; }
        }

        public int ProgressBarMaximum
        {
            get { return this.m_ProgressBarMaximum; }
            private set { this.m_ProgressBarMaximum = value; }
        }
        public int ProgressBarMinimum
        {
            get { return this.m_ProgressBarMinimum; }
            private set { this.m_ProgressBarMinimum = value; }
        } 
        #endregion

        #region Method
        public void Initialization()
        {
            this.Number = 1;
            this.Name = "ProductName 1";
            this.LotNo = "Lot 1";
            this.UnderRange = "1000";
            this.PassRange = "2000";
            this.OverRange = "3000";
            this.TareRange = "0";
        }

        private void ProgressBarLevelRescale()
        {
            int minBar, maxBar, gap;
            int OverRange, UnderRange;

            if (this.OverRange == null || this.UnderRange == null)
                return;

            OverRange = int.Parse(this.OverRange);
            UnderRange = int.Parse(this.UnderRange);

            gap = OverRange - UnderRange;

            minBar = UnderRange - gap;
            maxBar = OverRange + gap;

            this.ProgressBarMaximum = maxBar;
            this.ProgressBarMinimum = minBar;
        }
        #endregion
    } 
    #endregion
    #region StructProductItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructProductItem
    {
        public int Number;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string Name;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string LotNo;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string OverRange;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string UnderRange;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string PassRange;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string TareRange;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString5;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString6;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString7;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString8;
    }
    #endregion

    #region WeightData
    public class WeightData
    {
        #region Field
        private int m_UnderCount;
        private int m_PassCount;
        private int m_OverCount;
        private int m_ExNGCount;
        private double m_Weight;
        private DataStore.JudgmentStatus m_JudgmentStatus;
        private DataStore.WeightStatus m_Status;

        private string m_ADCValue;
        private int m_ProductionSpeed;

        private int PreviousTimeTickCount;
        private bool m_IsStart;

        private string m_WeightString;

        private ushort m_UpdateCount;
        #endregion

        #region Constructor
        public WeightData()
        {
            this.Initialization();
        }
        #endregion

        #region Property
        public int UnderCount
        {
            get { return this.m_UnderCount; }
            set { this.m_UnderCount = value; }
        }
        public string UnderRatio
        {
            get
            {
                string ret = "";

                if (this.UnderCount == 0 || this.TotalCount == 0)
                    ret = "0.00";
                else
                    ret = string.Format("{0:##0.00}", (float.Parse(this.UnderCount.ToString()) * 100.0F) / this.TotalCount);

                return ret;
            }
        }

        public int PassCount
        {
            get { return this.m_PassCount; }
            set { this.m_PassCount = value; }
        }
        public string PassRatio
        {
            get
            {
                string ret = "";

                if (this.PassCount == 0 || this.TotalCount == 0)
                    ret = "0.00";
                else
                    ret = string.Format("{0:##0.00}", (float.Parse(this.PassCount.ToString()) * 100.0F) / this.TotalCount);

                return ret;
            }
        }

        public int OverCount
        {
            get { return this.m_OverCount; }
            set { this.m_OverCount = value; }
        }
        public string OverRatio
        {
            get
            {
                string ret = "";

                if (this.OverCount == 0 || this.TotalCount == 0)
                    ret = "0.00";
                else
                    ret = string.Format("{0:##0.00}", (float.Parse(this.OverCount.ToString()) * 100.0F) / this.TotalCount);

                return ret;
            }
        }

        public int ExNGCount
        {
            get { return this.m_ExNGCount; }
            set { this.m_ExNGCount = value; }
        }

        public int TotalNGCount
        {
            get { return this.UnderCount + this.OverCount + this.ExNGCount; }
        }

        public int TotalCount
        {
            get { return this.UnderCount + this.PassCount + this.OverCount + this.ExNGCount; }
        }

        public double Weight
        {
            get { return this.m_Weight; }
            set { this.m_Weight = value; }
        }

        public string ADCValue
        {
            get { return this.m_ADCValue; }
            set { this.m_ADCValue = value; }
        }

        public DataStore.JudgmentStatus JudgmentStatus
        {
            get { return this.m_JudgmentStatus; }
            set
            {
                this.m_JudgmentStatus = value;

                this.ProductionSpeedCalculation();

                if (value == DataStore.JudgmentStatus.Under)
                {
                    if (this.UnderCount < 10000000)
                        this.UnderCount++;
                    else
                        this.UnderCount = 0;
                }
                else if (value == DataStore.JudgmentStatus.Pass)
                {
                    if (this.PassCount < 10000000)
                        this.PassCount++;
                    else
                        this.PassCount = 0;
                }
                else if (value == DataStore.JudgmentStatus.Over)
                {
                    if (this.OverCount < 10000000)
                        this.OverCount++;
                    else
                        this.OverCount = 0;
                }
                else
                {
                    if (this.ExNGCount < 10000000)
                        this.ExNGCount++;
                    else
                        this.ExNGCount = 0;
                }
            }
        }

        public DataStore.WeightStatus Status
        {
            get { return this.m_Status; }
            set { this.m_Status = value; }
        }

        public int ProductionSpeed
        {
            get { return this.m_ProductionSpeed; }
            set { this.m_ProductionSpeed = value; }
        }
        public bool IsStart
        {
            get { return this.m_IsStart; }
            set { this.m_IsStart = value; }
        }

        public string WeightString
        {
            get { return this.m_WeightString; }
            set { this.m_WeightString = value; }
        }

        public ushort UpdateCount
        {
            get { return this.m_UpdateCount; }
            set { this.m_UpdateCount = value; }
        }
        #endregion

        #region Mehtod
        public void ClearCount()
        {
            this.UnderCount = 0;
            this.PassCount = 0;
            this.OverCount = 0;
            this.ExNGCount = 0;
            this.UpdateCount = 0;
        }

        public void Initialization()
        {
            this.UnderCount = 0;
            this.PassCount = 0;
            this.OverCount = 0;
            this.ExNGCount = 0;
            this.Weight = 0.0;
            this.ADCValue = "12345";
            this.JudgmentStatus = DataStore.JudgmentStatus.Empty;
            this.ProductionSpeed = 0;
            this.WeightString = "0";
            this.UpdateCount = 0;
        }

        private void ProductionSpeedCalculation()
        {
            int currentTimeTickCount = 0, gap = 0;
            double millisecond = 0.0, speed = 0.0;

            if (this.IsStart == false)
            {
                this.PreviousTimeTickCount = Environment.TickCount & Int32.MaxValue;
                this.IsStart = true;
            }
            else
            {
                currentTimeTickCount = Environment.TickCount & Int32.MaxValue;
                gap = Math.Abs(currentTimeTickCount - this.PreviousTimeTickCount);
                millisecond = gap / 1000.0;
                speed = 60 / millisecond;
                this.ProductionSpeed = int.Parse(string.Format("{0:f0}", speed));

                this.PreviousTimeTickCount = Environment.TickCount;
            }
        } 
        #endregion
    }
    #endregion
    #region Struct Counter
    [StructLayout(LayoutKind.Sequential)]
    public struct StructCounter
    {
        public int OverCount1;
        public int PassCount1;
        public int UnderCount1;
        public int ExNGCount1;

        public int OverCount2;
        public int PassCount2;
        public int UnderCount2;
        public int ExNGCount2;

        public int OverCount3;
        public int PassCount3;
        public int UnderCount3;
        public int ExNGCount3;

        public int OverCount4;
        public int PassCount4;
        public int UnderCount4;
        public int ExNGCount4;

        public int OverCount5;
        public int PassCount5;
        public int UnderCount5;
        public int ExNGCount5;

        public int OverCount6;
        public int PassCount6;
        public int UnderCount6;
        public int ExNGCount6;

        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;
        public int DummyInt4;
        public int DummyInt5;
        public int DummyInt6;
        public int DummyInt7;
        public int DummyInt8;
        public int DummyInt9;
        public int DummyInt10;
    }
    #endregion

    #region JudgmentSetItem
    public class JudgmentSetItem
    {
        #region Field
        private int m_Filter;
        private int m_JudgmentDelayTime;
        private int m_DoubleDelayTime;
        private int m_JudgmentCount;
        private double m_DynamicCorrection;
        
        private int m_Sorter1Mode;
        private int m_Sorter1DelayTime;
        private int m_Sorter1RunTime;

        private int m_ConveyorSpeed1;
        private int m_ConveyorSpeed2;
        private int m_ConveyorSpeed3;
        private int m_ConveyorSpeed4;
        #endregion

        #region Constructor
        public JudgmentSetItem()
        {
            this.Initialization();
        }
        #endregion

        #region Property
        public int Filter
        {
            get { return this.m_Filter; }
            set { this.m_Filter = value; }
        }
        public int JudgmentDelayTime
        {
            get { return this.m_JudgmentDelayTime; }
            set { this.m_JudgmentDelayTime = value; }
        }
        public int DoubleDelayTime
        {
            get { return this.m_DoubleDelayTime; }
            set { this.m_DoubleDelayTime = value; }
        }
        public int JudgmentCount
        {
            get { return this.m_JudgmentCount; }
            set { this.m_JudgmentCount = value; }
        }
        public double DynamicCorrection
        {
            get { return this.m_DynamicCorrection; }
            set { this.m_DynamicCorrection = value; }
        }

        public int Sorter1Mode
        {
            get { return this.m_Sorter1Mode; }
            set { this.m_Sorter1Mode = value; }
        }
        public int Sorter1DelayTime
        {
            get { return this.m_Sorter1DelayTime; }
            set { this.m_Sorter1DelayTime = value; }
        }
        public int Sorter1RunTime
        {
            get { return this.m_Sorter1RunTime; }
            set { this.m_Sorter1RunTime = value; }
        }

        public int ConveyorSpeed1
        {
            get { return this.m_ConveyorSpeed1; }
            set { this.m_ConveyorSpeed1 = value; }
        }
        public int ConveyorSpeed2
        {
            get { return this.m_ConveyorSpeed2; }
            set { this.m_ConveyorSpeed2 = value; }
        }
        public int ConveyorSpeed3
        {
            get { return this.m_ConveyorSpeed3; }
            set { this.m_ConveyorSpeed3 = value; }
        }
        public int ConveyorSpeed4
        {
            get { return this.m_ConveyorSpeed4; }
            set { this.m_ConveyorSpeed4 = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.Filter = 8;
            this.JudgmentDelayTime = 1000;
            this.DoubleDelayTime = 900;
            this.JudgmentCount = 10;
            this.DynamicCorrection = 1.000000;

            this.Sorter1Mode = 0;
            this.Sorter1DelayTime = 1;
            this.Sorter1RunTime = 1000;

            this.ConveyorSpeed1 = 60;
            this.ConveyorSpeed2 = 60;
            this.ConveyorSpeed3 = 60;
            this.ConveyorSpeed4 = 60;
        }
        #endregion
    }
    #endregion
    #region Struct JudgmentSetItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructJudgmentSetItem
    {
        public int Filter;
        public int JudgmentDelayTime;
        public int DoubleDelayTime;
        public int JudgmentCount;
        public int ConveyorSpeed1;
        public double DynamicCorrection;
        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;
        public int DummyInt4;
        public int Sorter1Mode;
        public int Sorter1DelayTime;
        public int Sorter1OperatingTime;
        public int DummyInt5;
        public int DummyInt6;
        public int DummyInt7;
        public int DummyInt8;
        public int DummyInt9;
        public int DummyInt10;
        public int DummyInt11;
        public int DummyInt12;
        public int DummyInt13;

        public int ConveyorSpeed4;
        public int ConveyorSpeed3;
        public int ConveyorSpeed2;
        public int DummyInt14;
        public int DummyInt15;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string DummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string DummyString5;
    }
    #endregion 

    #region User
    public class CollectionUser
    {
        #region Field
        private Collection<User> m_Level1Users;
        private Collection<User> m_Level2Users;
        private Collection<User> m_Level3Users;

        private User m_DeveloperUser;
        #endregion

        #region Constructor
        public CollectionUser()
        {
            this.Initialize();
        }
        #endregion

        #region Property
        public Collection<User> Level1Users
        {
            get { return this.m_Level1Users; }
            set { this.m_Level1Users = value; }
        }
        public Collection<User> Level2Users
        {
            get { return this.m_Level2Users; }
            set { this.m_Level2Users = value; }
        }
        public Collection<User> Level3Users
        {
            get { return this.m_Level3Users; }
            set { this.m_Level3Users = value; }
        }

        public User DeveloperUser
        {
            get { return this.m_DeveloperUser; }
            private set { this.m_DeveloperUser = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Level1Users = new Collection<User>();
            this.Level2Users = new Collection<User>();
            this.Level3Users = new Collection<User>();

            this.Level1Users.Clear();
            this.Level2Users.Clear();
            this.Level3Users.Clear();

            for (int i = 0; i < 5; i++)
            {
                this.Level1Users.Add(new User());
                this.Level2Users.Add(new User());
                this.Level3Users.Add(new User());
            }

            this.DeveloperUser = new User();
            this.DeveloperUser.ID = "Intech";
            this.DeveloperUser.Password = "20090810";
            this.DeveloperUser.Group = DataStore.UserGroup.Level4Developer;
        }

        public User FindUser(string id)
        {
            User user = null;

            // 개발자 유저 검색
            if (id == this.DeveloperUser.ID)
            {
                user = new User();
                user.ID = this.DeveloperUser.ID;
                user.Password = this.DeveloperUser.Password;
                user.Group = this.DeveloperUser.Group;
                return user;
            }

            // 일반 유저 검색
            for (int i = 0; i < this.Level1Users.Count; i++)
            {
                if (this.Level1Users[i].Group != DataStore.UserGroup.None)
                {
                    if (this.Level1Users[i].ID.Trim() == id.Trim())
                    {
                        user = new User();
                        user.ID = this.Level1Users[i].ID.Trim();
                        user.Password = this.Level1Users[i].Password;
                        user.Group = this.Level1Users[i].Group;
                        return user;
                    }
                }

                if (this.Level2Users[i].Group != DataStore.UserGroup.None)
                {
                    if (this.Level2Users[i].ID.Trim() == id.Trim())
                    {
                        user = new User();
                        user.ID = this.Level2Users[i].ID.Trim();
                        user.Password = this.Level2Users[i].Password;
                        user.Group = this.Level2Users[i].Group;
                        return user;
                    }
                }

                if (this.Level3Users[i].Group != DataStore.UserGroup.None)
                {
                    if (this.Level3Users[i].ID.Trim() == id.Trim())
                    {
                        user = new User();
                        user.ID = this.Level3Users[i].ID.Trim();
                        user.Password = this.Level3Users[i].Password;
                        user.Group = this.Level3Users[i].Group;
                        return user;
                    }
                }
            }

            return user;
        }
        public User FindDeveloperUser(string id)
        {
            User user = null;

            // 개발자 유저 검색
            if (id == this.DeveloperUser.ID)
            {
                user = new User();
                user.ID = this.DeveloperUser.ID;
                user.Password = this.DeveloperUser.Password;
                user.Group = this.DeveloperUser.Group;
                return user;
            }

            return user;
        }

        public bool SearchID(string id)
        {
            bool ret = false;

            for (int i = 0; i < this.Level1Users.Count; i++)
            {
                if (this.Level1Users[i].ID.Trim() == id.Trim())
                    return ret = true;
            }
            for (int i = 0; i < this.Level2Users.Count; i++)
            {
                if (this.Level2Users[i].ID.Trim() == id.Trim())
                    return ret = true;
            }
            for (int i = 0; i < this.Level3Users.Count; i++)
            {
                if (this.Level3Users[i].ID.Trim() == id.Trim())
                    return ret = true;
            }

            return ret;
        }
        #endregion
    }
    #endregion
    #region UserItem
    public class User
    {
        #region Field
        private string m_ID;
        private string m_Password;
        private DataStore.UserGroup m_Group;
        #endregion

        #region Constructor
        public User()
        {
            this.Initialize();
        }
        #endregion

        #region Property
        public string ID
        {
            get { return this.m_ID; }
            set { this.m_ID = value; }
        }
        public string Password
        {
            get { return this.m_Password; }
            set { this.m_Password = value; }
        }
        public DataStore.UserGroup Group
        {
            get { return this.m_Group; }
            set { this.m_Group = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.ID = "-";
            this.Password = "-";
            this.Group = DataStore.UserGroup.None;
        }
        #endregion
    }
    #endregion
    #region StructUserItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructUserItem
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string ID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Password;

        public DataStore.UserGroup Group;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Dummy1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Dummy2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Dummy3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Dummy4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Dummy5;
    }
    #endregion

    #region CalibraqtionItem
    public class CalibrationItem
    {
        #region Field
        private string m_BalanceWeight;
        private string m_MaxWeight;
        private string m_Digit;
        private string m_Constant1;
        private string m_Constant2;
        private string m_Constant3;
        private string m_Constant4;
        private string m_Constant5;
        private string m_Constant6;
        #endregion

        #region Constructor
        public CalibrationItem()
        {
            this.BalanceWeight = "5000";
            this.MaxWeight = "9999";
            this.Digit = "1";
            this.Constant1 = "1.000000";
            this.Constant2 = "1.000000";
            this.Constant3 = "1.000000";
            this.Constant4 = "1.000000";
            this.Constant5 = "1.000000";
            this.Constant6 = "1.000000";
        }
        #endregion

        #region Property
        public string BalanceWeight
        {
            get { return this.m_BalanceWeight; }
            set { this.m_BalanceWeight = value; }
        }

        public string MaxWeight
        {
            get { return this.m_MaxWeight; }
            set { this.m_MaxWeight = value; }
        }

        public string Digit
        {
            get { return this.m_Digit; }
            set { this.m_Digit = value; }
        }

        public string Constant1
        {
            get { return this.m_Constant1; }
            set { this.m_Constant1 = value; }
        }
        public string Constant2
        {
            get { return this.m_Constant2; }
            set { this.m_Constant2 = value; }
        }

        public string Constant3
        {
            get { return this.m_Constant3; }
            set { this.m_Constant3 = value; }
        }

        public string Constant4
        {
            get { return this.m_Constant4; }
            set { this.m_Constant4 = value; }
        }

        public string Constant5
        {
            get { return this.m_Constant5; }
            set { this.m_Constant5 = value; }
        }

        public string Constant6
        {
            get { return this.m_Constant6; }
            set { this.m_Constant6 = value; }
        }
        #endregion
    }
    #endregion
    #region ZeroParameterItem
    public class ZeroParameterItem
    {
        #region Field
        private string m_Range;
        private string m_Time;
        private string m_Variate;
        private string m_Mode;
        #endregion

        #region Constructor
        public ZeroParameterItem()
        {
            this.Range = "20";
            this.Time = "100";
            this.Variate = "2";
            this.Mode = "0";
        }
        #endregion

        #region Property
        public string Range
        {
            get { return this.m_Range; }
            set { this.m_Range = value; }
        }

        public string Time
        {
            get { return this.m_Time; }
            set { this.m_Time = value; }
        }

        public string Variate
        {
            get { return this.m_Variate; }
            set { this.m_Variate = value; }
        }

        public string Mode
        {
            get { return this.m_Mode; }
            set { this.m_Mode = value; }
        }
        #endregion
    }
    #endregion
    #region OptionParameterItem
    public class OptionParameterItem
    {
        #region Field
        private string m_BuzzerOnTime;
        private string m_RelayOnTime;
        private string m_Chattering;
        private string m_DoubleEnter;
        private string m_PassAlarm;
        private string m_PassAlarmCount;
        #endregion

        #region Constructor
        public OptionParameterItem()
        {
            this.BuzzerOnTime = "1000";
            this.RelayOnTime = "500";
            this.Chattering = "100";
            this.DoubleEnter = "0";
            this.PassAlarm = "0";
            this.PassAlarmCount = "0";
        }
        #endregion

        #region Property
        public string BuzzerOnTime
        {
            get { return this.m_BuzzerOnTime; }
            set { this.m_BuzzerOnTime = value; }
        }
        public string RelayOnTime
        {
            get { return this.m_RelayOnTime; }
            set { this.m_RelayOnTime = value; }
        }
        public string Chattering
        {
            get { return this.m_Chattering; }
            set { this.m_Chattering = value; }
        }
        public string DoubleEnter
        {
            get { return this.m_DoubleEnter; }
            set { this.m_DoubleEnter = value; }
        }
        public string PassAlarm
        {
            get { return this.m_PassAlarm; }
            set { this.m_PassAlarm = value; }
        }
        public string PassAlarmCount
        {
            get { return this.m_PassAlarmCount; }
            set { this.m_PassAlarmCount = value; }
        } 
        #endregion
    }
    #endregion
    #region AlarmList
    public class AlarmList
    {
        #region Field
        private bool m_IsEntrySensorError;
        private bool m_IsLoadcellError;
        private bool m_IsPressureError;
        private bool m_ISDoorAlarm;

        private bool m_IsEntrySensor2Error;
        private bool m_IsFullSensorError;
        private bool m_IsRejectAlarm;
        private bool m_IsEmergencyStop;

        private bool m_IsInverterAlarm;
        private bool m_IsServoAlarm;
        private bool m_IsCommunicationError;
        private bool m_IsServoTorqueAlarm;
        #endregion

        #region Constructor
        public AlarmList()
        {
            this.Initialize();
        }
        #endregion

        #region Property
        public bool IsEntrySensorError
        {
            get { return this.m_IsEntrySensorError; }
            private set { this.m_IsEntrySensorError = value; }
        }
        public bool IsLoadcellError
        {
            get { return this.m_IsLoadcellError; }
            private set { this.m_IsLoadcellError = value; }
        }
        public bool IsPressureError
        {
            get { return this.m_IsPressureError; }
            private set { this.m_IsPressureError = value; }
        }
        public bool IsDoorAlarm
        {
            get { return this.m_ISDoorAlarm; }
            private set { this.m_ISDoorAlarm = value; }
        }

        public bool IsEntrySensor2Error
        {
            get { return this.m_IsEntrySensor2Error; }
            private set { this.m_IsEntrySensor2Error = value; }
        }
        public bool IsFullSensorError
        {
            get { return this.m_IsFullSensorError; }
            private set { this.m_IsFullSensorError = value; }
        }
        public bool IsRejectAlarm
        {
            get { return this.m_IsRejectAlarm; }
            private set { this.m_IsRejectAlarm = value; }
        }
        public bool IsEmergencyStop
        {
            get { return this.m_IsEmergencyStop; }
            private set { this.m_IsEmergencyStop = value; }
        }

        public bool IsInverterAlarm
        {
            get { return this.m_IsInverterAlarm; }
            private set { this.m_IsInverterAlarm = value; }
        }
        public bool IsServoAlarm
        {
            get { return this.m_IsServoAlarm; }
            private set { this.m_IsServoAlarm = value; }
        }
        public bool IsCommunicationError
        {
            get { return this.m_IsCommunicationError; }
            private set { this.m_IsCommunicationError = value; }
        }
        public bool IsServoTorqueAlarm
        {
            get { return this.m_IsServoTorqueAlarm; }
            private set { this.m_IsServoTorqueAlarm = value; }
        }

        /// <summary>
        /// 현재 알람이 있는지 없는지 리턴해줌
        /// true : 알람있음, false
        /// </summary>
        public bool IsCurrentAlarm
        {
            get
            {
                bool ret = false;

                if (this.IsLoadcellError == true || this.IsPressureError == true || this.IsDoorAlarm == true ||
                    this.IsRejectAlarm == true || this.IsEmergencyStop == true || this.IsInverterAlarm == true ||
                    this.IsServoAlarm == true || this.IsCommunicationError == true || this.IsServoTorqueAlarm == true)
                {
                    ret = true;
                }

                return ret;
            }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsEntrySensorError = false;
            this.IsLoadcellError = false;
            this.IsPressureError = false;
            this.IsDoorAlarm = false;
            this.IsEntrySensor2Error = false;
            this.IsFullSensorError = false;
            this.IsRejectAlarm = false;
            this.IsEmergencyStop = false;
            this.IsInverterAlarm = false;
            this.IsServoAlarm = false;
            this.IsCommunicationError = false;
            this.IsServoTorqueAlarm = false;
        }

        public void SetAlarm(string alarm)
        {
            string sValue1 = "", sValue2 = "", sValue3 = "", sValue4 = "", sValue5 = "", sValue6 = "", sValue7 = "", sValue8 = "";

            if (alarm.Length != 8)
                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');
            sValue4 = Convert.ToString(Convert.ToInt16(alarm.Substring(3, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue5 = Convert.ToString(Convert.ToInt16(alarm.Substring(4, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue6 = Convert.ToString(Convert.ToInt16(alarm.Substring(5, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue7 = Convert.ToString(Convert.ToInt16(alarm.Substring(6, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');
            sValue8 = Convert.ToString(Convert.ToInt16(alarm.Substring(7, 1), 16), 2).PadLeft((4 <= 1) ? 1 : 4, '0');

            // 알람 12-서보토크알람
            if (sValue3[0] == '0')
                this.IsServoTorqueAlarm = false;
            else
                this.IsServoTorqueAlarm = true;
            // 알람 11-통신에러
            if (sValue3[1] == '0')
                this.IsCommunicationError = false;
            else
                this.IsCommunicationError = true;
            // 알람 10-서보알람
            if (sValue3[2] == '0')
                this.IsServoAlarm = false;
            else
                this.IsServoAlarm = true;
            // 알람 9-인버터알람
            if (sValue3[3] == '0')
                this.IsInverterAlarm = false;
            else
                this.IsInverterAlarm = true;

            // 알람 8-비상정지
            if (sValue2[0] == '0')
                this.IsEmergencyStop = false;
            else
                this.IsEmergencyStop = true;
            // 알람 7-리젝터 알람
            if (sValue2[1] == '0')
                this.IsRejectAlarm = false;
            else
                this.IsRejectAlarm = true;
            // 알람 6-적체센서 에러
            if (sValue2[2] == '0')
                this.IsFullSensorError = false;
            else
                this.IsFullSensorError = true;
            // 알람 5-입력센서2 에러(병넘어짐)
            if (sValue2[3] == '0')
                this.IsEntrySensor2Error = false;
            else
                this.IsEntrySensor2Error = true;

            // 알람 4-도어알람
            if (sValue1[0] == '0')
                this.IsDoorAlarm = false;
            else
                this.IsDoorAlarm = true;
            // 알람 3-공압에러
            if (sValue1[1] == '0')
                this.IsPressureError = false;
            else
                this.IsPressureError = true;
            // 알람 2-셀 에러
            if (sValue1[2] == '0')
                this.IsLoadcellError = false;
            else
                this.IsLoadcellError = true;
            // 알람 1-입력센서 에러
            if (sValue1[3] == '0')
                this.IsEntrySensorError = false;
            else
                this.IsEntrySensorError = true;
        }
        #endregion
    }
    #endregion

    #region FeedBackStatus
    public class FeedBackSystem
    {
        #region Field
        private bool m_IsFbCalComplete;

        private int m_IgnoreCount;

        private double m_FeedbackWeight;

        private DataStore.FeedbackStatus m_Status;

        private Collection<int> m_WeightList;

        private int m_UpdateFeedbackData;
        #endregion

        #region Constructor
        public FeedBackSystem()
        {
            this.DefaultSetting();
        }
        #endregion

        #region Property
        /// <summary>
        /// Feedback calculation complete
        /// </summary>
        public bool IsFbCalComplete
        {
            get { return this.m_IsFbCalComplete; }
            set { this.m_IsFbCalComplete = value; }
        }

        public int IgnoreCount
        {
            get { return this.m_IgnoreCount; }
            set { this.m_IgnoreCount = value; }
        }
        public int SumWeight
        {
            get
            {
                int sum = 0;

                foreach (int weignt in this.WeightList)
                    sum += weignt;

                return sum;
            }
        }

        public double FeedbackWeight
        {
            get { return this.m_FeedbackWeight; }
            set { this.m_FeedbackWeight = value; }
        }

        public DataStore.FeedbackStatus Status
        {
            get { return this.m_Status; }
            private set { this.m_Status = value; }
        }

        public Collection<int> WeightList
        {
            get { return this.m_WeightList; }
            private set { this.m_WeightList = value; }
        }
        public int UpdateFeedbackData
        {
            get { return this.m_UpdateFeedbackData; }
            set { this.m_UpdateFeedbackData = value; }
        }
        #endregion

        #region Method
        private void DefaultSetting()
        {
            this.WeightList = new Collection<int>();
            this.WeightList.Clear();

            this.IsFbCalComplete = false;
            this.IgnoreCount = 0;
            this.FeedbackWeight = 0.0;
            this.Status = DataStore.FeedbackStatus.None;
            this.UpdateFeedbackData = 0;
        }

        public void SetWeight(int weight, DataStore.FeedbackStatus status)
        {
            if (status != this.Status)
                this.WeightList.Clear();

            this.WeightList.Add(weight);
            this.Status = status;
        }

        public void ClearDataList()
        {
            this.WeightList.Clear();
        }
        public void ClearData()
        {
            this.ClearDataList();
            this.IgnoreCount = 0;
            this.IsFbCalComplete = false;
            this.Status = DataStore.FeedbackStatus.None;
        }
        public void ClearDataAll()
        {
            this.ClearData();

            this.UpdateFeedbackData = 0;
            this.FeedbackWeight = 0.0;
        }
        #endregion
    }
    #endregion
    #region FeedbackItem
    public class FeedbackConfiguration
    {
        #region Field
        private bool m_IsBootingComplete;
        private int m_RetryCount;

        private DataStore.FeedbackBoardDataTransfer m_DataTransfer;

        private string m_HighLimit;
        private string m_LowLimit;
        private string m_DeadZone;
        #endregion

        #region Constructor
        public FeedbackConfiguration()
        {
            this.Initialization();
            this.DefaultSetting();
        }
        #endregion

        #region Property
        public bool IsBootingComplete
        {
            get { return this.m_IsBootingComplete; }
            set { this.m_IsBootingComplete = value; }
        }
        public int RetryCount
        {
            get { return this.m_RetryCount; }
            set { this.m_RetryCount = value; }
        }
        public DataStore.FeedbackBoardDataTransfer DataTransfer
        {
            get { return this.m_DataTransfer; }
            set { this.m_DataTransfer = value; }
        }

        public string HighLimit
        {
            get { return this.m_HighLimit; }
            set { this.m_HighLimit = value; }
        }
        public string LowLimit
        {
            get { return this.m_LowLimit; }
            set { this.m_LowLimit = value; }
        }
        public string DeadZone
        {
            get { return this.m_DeadZone; }
            set { this.m_DeadZone = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.HighLimit = "3000";
            this.LowLimit = "1000";
            this.DeadZone = "0";
        }
        private void DefaultSetting()
        {
            this.IsBootingComplete = false;
            this.RetryCount = 0;
            this.DataTransfer = DataStore.FeedbackBoardDataTransfer.None;
        }
        #endregion
    }
    #endregion
    #region Struct FeedbackItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructFeedbackConfiguration
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string HightLimit;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string LowLimit;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DeadZone;

        public bool DummyBool1;
        public bool DummyBool2;
        public bool DummyBool3;

        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString3;
    }
    #endregion
}
