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

namespace INT63DC_2C
{
    public class DataStore
    {
        public delegate void EventHandlerAlarmStateChange(DataStore.TrackingAlarm alarm, string status);

        #region Enum
        public enum EquipmentStatus
        {
            Stop = 0,
            Start = 1,
        };

        public enum FormStore
        {
            FormNone = 0,
            FormMainDisplay,
            FormMenu,
            FormSystemSetting,
            FormEquipmentSetting,
            FormConfiguration,
            FormCalibration,
            FormEquipmentTest,
            FormIOTest,
            FormTimeSetting,
            FormInformation,
            FormFactory,
            FormProgramUpdate,
            FormDataStatistics,
            FormOptionSetting,
            FormMotorSetting,
            FormCommunication,
            FormUserEditor,
            FormUserGroupEditor,
            FormDataViewer,
            FormDataBackup,
        };

        public enum FormMainDisplayStore
        {
            FormMainDisplayBarGraph,
            FormMainDisplayDotGraph,
            FormMainDisplayTable,
        };

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

        public enum E_UpdateCheck
        {
            Fail,
            Success,
            NotUsbMomery,
            NotUpdateFolder,
            NotFile,
            TooManyFiles,
        };

        public enum UserGroup
        {
            None = 0,
            Level1 = 1,
            Level2 = 2,
            Level3 = 3,
            Admin = 4,
            Developer = 5,
            NotLogin = 6,
            LogOut = 7,
        };

        public enum E_CommMode
        {
            f0_None = 0,
            f1_STD1 = 1,
            f2_STD2 = 2,
            f3_STD3 = 3,
            f99_Modbus = 99,
        };

        public enum JudgmentStatus
        {
            None,
            Under,
            Pass,
            Over,
            Double,
            SensorError,
            ExNG,
            Empty,
            UnderLimit,
            OverLimit,
        };

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

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

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

        public enum EnumFileUserGroup
        {
            f0_Level1 = 0,
            f1_Level2 = 1,
            f2_Level3 = 2,
            f3_NotLogin = 3,
        }

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

        public enum E_UserGroup_FileIndex
        {
            f0_Level1 = 0,
            f1_Level2 = 1,
            f2_Level3 = 2,
            f3_NotLogin = 3,
        }

        public enum E_FileHeaderItem
        {
            LoginId,
            SerialNumber,
            EquipmentColumns,
            TimeStamp,
            EquipmentType,
        }

        public enum E_DataType
        {
            None,
            History,
            Inspection,
            Others,
        }

        public enum E_Step3
        {
            Step1,
            Step2,
            Step3,
        };

        public enum E_TrackingOperation
        {
            None,
            PowerOn,
            BootingComplete,
            EquipmentStart,
            EquipmentStop,
            Login,
            Logout,
            Calibration,
            Zero,
            Clear,
            UserEditor,
            Update,
            FunctionUpdate,
            DataBackup,
            GroupEditor,
            Initialization,

            BP_PassOnce,
            BP_NgOnce,
            BP_PassON,
            BP_PassOFF,
            BP_NgON,
            BP_NgOFF,

            SP_Once,
            SP_ON,
            SP_OFF,

            MainCut,
            ProductCopy,
            ProductPaste,
            ProductAllPaste,

            Motor_EEPROM,
            Motor_AlarmReset,
            Motor_Origin,
            Motor_OneStep,
            Motor_JOGCW,
            Motor_JOGCCW,

            TryEthernetStart,
            TryEthernetStop,
            EthernetConnect,
            EthernetDisconnect,

            // Modbus Clear
            MB_Clear,
            MB_EquipmentStart,
            MB_EquipmentStop,
        }
        public enum TrackingParameter
        {
            ProductNumber,
            WeightOverRange,
            WeightPassRange,
            WeightUnderRange,
            WeightTareRange,
            WeightOverRangeLimit,
            WeightUnderRangeLimit,
            WeightLimitEnable,

            BP_Individual,
            BP_All,
            BP_Direction,
            BP_Mode,

            SP_Mode,
            SP_Time,
            SP_Count,

            LK_Mode,
            LK_Time,

            ChangeTime,
            ChangeName,
            ChangeLOT,

            JudgmentFilter,
            JudgmentDelayTime,
            JudgmentTurnDelayTime,
            JudgmentCount,
            JudgmentSpeed,

            Sorter1DelayTime,
            Sorter1RunTime,
            Sorter2DelayTime,
            Sorter2RunTime,
            Sorter3DelayTime,
            Sorter3RunTime,
            Sorter4DelayTime,
            Sorter4RunTime,
            EntryGateDelayTime,
            EntryGateRunTime,
            DischargeStopperDelayTime,
            DischargeStopperRunTime,
            Stopper2DelayTime,
            Stopper2RunTime,
            ForcedZeroDelayTime,
            DynamicCorrection1,
            DynamicCorrection2,
            DynamicCorrection3,
            DynamicCorrection4,
            DynamicCorrection5,
            DynamicCorrection6,
            DynamicCorrection7,
            DynamicCorrection8,
            DynamicCorrection9,
            DynamicCorrection10,
            DynamicCorrection11,
            DynamicCorrection12,
            DynamicCorrection13,
            DynamicCorrection14,
            DynamicCorrection15,
            DynamicCorrection16,

            AutoZeroTime,
            AutoZeroRange,
            AutoZeroVariance,
            AutoZeroMode,

            Com3Baudrate,
            Com3Mode,
            TCPOpMode,
            TCPComMode,
            TCPLocalPort,
            TCPLocalIPConfig,
            TCPLocalIPAddress,
            TCPLocalSubnetMask,
            TCPLocalGateway,
            TCPServerIPAddress,
            TCPServerPort,
            Mod_StartAddr,

            CalMaxWeight,
            CalBalWeight,
            CalDigit,

            EtcEmptyWeight,
            EtcTurnDelay,
            EtcTurnOperation,
            EtcChattering,
            EtcBuzzerRunTime,
            EtcRelayRunTime,
            EtcDecimalpoint,

            MotorOriginOffset,
            MotorOriginSpeed,
            MotorSpeed,
            MotorAcceleration,
            MotorDeceleration,
            MotorPosition1,

            Level1Name,
            Level2Name,
            Level3Name,
            AutoLogout,

            DataStoragePeriod,

            // Modbus
            MB_WeightOverRange,
            MB_WeightPassRange,
            MB_WeightUnderRange,
            MB_WeightTareRange,
            MB_ProductNumber,
            MB_WeightOverRangeLimit,
            MB_WeightUnderRangeLimit,
        }
        public enum TrackingAlarm
        {
            None,
            a1_EntrySensorError,
            a2_LoadcellError,
            a3_PressureError,
            a4_,
            
            a5_,
            a6_,
            a7_Sorter2Error,
            a8_EmergencyStop,

            a9_,
            a10_ServoAlarm,
            a11_,
            a12_ServoTorqueAlarm,
            
            a13_,
            a14_Sorter1Error,
            a15_ProductDischargeError,
            a16_ProductJamError,
        }
        #endregion
    }

    public class OptionPassword
    {
        // 기본 
        public static readonly string Default = "0810";

        // 1. 데이터
        // 데이터집계
        public static readonly string DataStatistics = "1000";
        // CFR Part11
        public static readonly string Part11 = "1001";

        // 2. 통신
        // 피드백보드
        public static readonly string FeedbackBoard = "2000";
    }

    #region CommunicationCommand
    public class CommunicationCommand
    {
        // 운전데이터 Respone
        public static readonly string StartDataCMD = "Sr0";

        // 중량조정모드
        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 MotorAlarmReset = "Cma00";
        // 임펠러 모터 - 정회전
        public static readonly string ImpellerMotorForward = "Cmc00";
        // 임펠러 모터 - 역회전
        public static readonly string ImpellerMotorReverse = "Cmr00";
        // 모터 - 다운
        public static readonly string MotorDown = "Cmd00";
        // 모터 - Step
        public static readonly string MotorStep = "Cms00";
        // 모터 - Position 0 
        public static readonly string MotorPosition0 = "Cm000";
        // 모터 - Position 1 
        public static readonly string MotorPosition1 = "Cm100";
        // 모터 - Position 2 
        public static readonly string MotorPosition2 = "Cm200";
        // 모터 - Origin
        public static readonly string MotorOrigin = "Cmo00";
        // 모터 - JOG CW OFF
        public static readonly string MotorJogCwOff = "Cmg00";
        // 모터 - JOG CW ON
        public static readonly string MotorJogCwOn = "Cmg01";
        // 모터 - JOG CCW OFF
        public static readonly string MotorJogCcwOff = "Cmh00";
        // 모터 - JOG CCW ON
        public static readonly string MotorJogCcwOn = "Cmh01";

        // 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 Clear = "Cbe00";
        // 영점
        public static readonly string Zero = "Cbz00";
        // NG Signal
        public static readonly string NgSignal = "Cbn00";
        // Pass Signal
        public static readonly string PassSignal = "Cbm00";
        // Sampling Signal
        public static readonly string SamplingSignal = "Cba00";
        // Leak Signal
        public static readonly string LeakSamplingSignal = "Cbg00";
        // Buzzer ON
        public static readonly string BuzzerOn = "Cae00";
        // Buzzer Off
        public static readonly string BuzzerOff = "CAE00";

        // 판정 - 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 static readonly string AlarmReset = "Car00";
    }
    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 SubBoard13 = "M";
        public static readonly string SubBoard14 = "N";
        public static readonly string SubBoard15 = "O";
        public static readonly string SubBoard16 = "P";
        public static readonly string SubBoardAll = "Z";
    }
    public class CommunicationAddress
    {
        // Address None
        public static readonly string None = "0000";

        // ACK
        public static readonly string ACK = "1";
        // NAK
        public static readonly string NAK = "0";

        // Empty 중량 설정
        public static readonly string _1021_EmptyWeight = "1021";
        // Weight Limit 사용유무
        public static readonly string _1023_WeightLimitEnable = "1023";
        // Weight Limit 무시 수량
        public static readonly string _1025_WeightLimitIgnoreCount = "1025";
        // 바이패스
        public static readonly string _1201_Bypass = "1201";
        // 보드 버전 모두 읽기
        public static readonly string _1500_ProgramVersion = "1500";

        // 품목설정 - 품번
        public static readonly string _2001_ProductNumber = "2001";
        // 품목설정 - 하한 설정값
        public static readonly string _2002_UnderRange = "2002";
        // 품목설정 - 기준 설정값
        public static readonly string _2003_PassRange = "2003";
        // 품목설정 - 상한 설정값
        public static readonly string _2004_OverRange = "2004";
        // 품목설정 - 용기 설정값
        public static readonly string _2005_TareRange = "2005";
        // 품목설정 - 하한 Limit 설정값
        public static readonly string _2201_UnderLimitRange = "2201";
        // 품목설정 - 상한 Limit 설정값
        public static readonly string _2202_OverLimitRange = "2202";

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

        // 자동영점 - 시간
        public static readonly string _4001_ZeroTime = "4001";
        // 자동영점 - 범위
        public static readonly string _4002_ZeroRange = "4002";
        // 자동영점 - 변량
        public static readonly string _4003_ZeroVariate = "4003";
        // 자동영점 - 모드
        public static readonly string _4004_ZeroMode = "4004";
        // 강제영점 지연시간
        public static readonly string _4501_ForcedZeroDelayTime = "4501";
        // 자동영점 - 파라미터 읽기
        public static readonly string _4901_ParameterRead4901 = "4901";

        // 판정설정 - 필터
        public static readonly string _5001_Filter = "5001";
        // 판정설정 - 판정지연
        public static readonly string _5002_JudgmentDelayTime = "5002";
        // 판정설정 - 이중지연
        public static readonly string _5003_DoubleDelayTime = "5003";
        // 판정설정 - 판정개수
        public static readonly string _5004_JudgmentCount = "5004";
        // 판정설정 - 이송속도
        public static readonly string _5005_FeedSpeed = "5005";
        // 판정설정 - 동보정
        public static readonly string _5006_DynamicCorrection = "5006";
        // 판정설정 - 턴지연시간
        public static readonly string _5017_TurnDelayTime = "5017";
        // 판정설정 - 원점옵셋
        public static readonly string _5018_OriginOffset = "5018";
        // 판정설정 - 원점속도
        public static readonly string _5019_OriginSpeed = "5019";
        // 판정설정 - 인버터토크
        public static readonly string _5020_InverterTorque = "5020";
        // 판정설정 - 진입게이트 지연시간
        public static readonly string _5032_EntryGateDelayTime = "5032";
        // 판정설정 - 진입게이트 동작시간
        public static readonly string _5033_EntryGateRunTime = "5033";
        // 판정설정 - 배출스토퍼 지연시간
        public static readonly string _5034_DischargeStopperDelayTime = "5034";
        // 판정설정 - 배출스토퍼 동작시간
        public static readonly string _5034_DischargeStopperRunTime = "5035";
        // 판정설정 - 스토퍼2 지연시간
        public static readonly string _5036_Stopper2DelayTime = "5036";
        // 판정설정 - 스토퍼2 동작시간
        public static readonly string _5037_Stopper2RunTime = "5037";
        // 판정설정 - 선별기 모드 값
        public static readonly string _5101_Sorter1Mode = "5101";
        // 판정설정 - 선별기1 지연시간
        public static readonly string _5102_Sorter1DelayTime = "5102";
        // 판정설정 - 선별기1 동작시간
        public static readonly string _5103_Sorter1RunTime = "5103";
        // 판정설정 - 선별기2 지연시간
        public static readonly string _5105_Sorter2DelayTime = "5105";
        // 판정설정 - 선별기2 동작시간
        public static readonly string _5106_Sorter2RunTime = "5106";
        // 판정설정 - 선별기3 지연시간
        public static readonly string _5108_Sorter3DelayTime = "5108";
        // 판정설정 - 선별기3 동작시간
        public static readonly string _5109_Sorter3RunTime = "5109";
        // 판정설정 - 선별기4 지연시간
        public static readonly string _5111_Sorter4DelayTime = "5111";
        // 판정설정 - 선별기4 동작시간
        public static readonly string _5112_Sorter4RunTime = "5112";
        // 판정설정 - 외부출력1 지연시간 (외부 신호 출력 턴지연시간)
        public static readonly string _5202_EXT1DelayTime = "5202";
        // 판정설정 - 외부출력1 동작시간 (외부 신호 출력 턴동작시간)
        public static readonly string _5203_EXT1RunTime = "5203";

        // 옵션 - 부저 ON시간
        public static readonly string _6001_BuzzerOnTime = "6001";
        // 옵션 - 릴레이 동작시간
        public static readonly string _6002_RelayOperatingTime = "6002";
        // 옵션 - 이중진입사용여부
        public static readonly string _6005_DoubleEnter = "6005";
        // 옵션 - 채터링감지 설정
        public static readonly string _6006_Chattering = "6006";
        // 옵션 - 파라미터 읽기
        public static readonly string _6901_ParameterRead6901 = "6901";

        // 통신,IO설정 - INPUT ALL
        public static readonly string _7500_InputAll = "7500";
        // 통신,IO설정 = OUTPUT1
        public static readonly string _7701_Output1 = "7701";
        // 통신,IO설정 = OUTPUT2
        public static readonly string _7702_Output2 = "7702";
        // 통신,IO설정 = OUTPUT3
        public static readonly string _7703_Output3 = "7703";
        // 통신,IO설정 = OUTPUT4
        public static readonly string _7704_Output4 = "7704";
        // 통신,IO설정 = OUTPUT5
        public static readonly string _7705_Output5 = "7705";
        // 통신,IO설정 = OUTPUT6
        public static readonly string _7706_Output6 = "7706";
        // 통신,IO설정 = OUTPUT7
        public static readonly string _7707_Output7 = "7707";
        // 통신,IO설정 = OUTPUT8
        public static readonly string _7708_Output8 = "7708";
        // 통신,IO설정 = OUTPUT9
        public static readonly string _7709_Output9 = "7709";
        // 통신,IO설정 = OUTPUT10
        public static readonly string _7710_Output10 = "7710";
        // 통신,IO설정 = OUTPUT11
        public static readonly string _7711_Output11 = "7711";
        // 통신,IO설정 = OUTPUT12
        public static readonly string _7712_Output12 = "7712";
        // 통신,IO설정 = OUTPUT13
        public static readonly string _7713_Output13 = "7713";
        // 통신,IO설정 = OUTPUT14
        public static readonly string _7714_Output14 = "7714";
        // 통신,IO설정 = OUTPUT15
        public static readonly string _7715_Output15 = "7715";
        // 통신,IO설정 = OUTPUT16
        public static readonly string _7716_Output16 = "7716";

        // 중량 설정값 쓰기
        public static readonly string _9003_ParameterWeightRange = "9003";
        // 시스템 설정 모두 쓰기
        public static readonly string _9029_ParameterSystem = "9029";
        // 품목 설정 모두 쓰기1 
        public static readonly string _9030_ParameterProduct1 = "9030";
        // 개별 동보정값 쓰기
        public static readonly string _9034_ParameterDynamicCorrection = "9034";
        // 품목 설정 모두 쓰기2
        public static readonly string _9040_ParameterProduct2 = "9040";
    }
    #endregion

    #region ServoMotor(Panasonic)
    public class ServoMotorParameterAddress
    {
        // SaveAllParameters - 0x1020
        public static readonly int SaveAllParameters = 4128;
        // EEPROM - 0x6173h
        public static readonly int EEPROM = 24947;
        // Speed 0 - 0x4600     
        public static readonly int Speed0 = 17920;
        // Speed 1 - 0x4601     
        public static readonly int Speed1 = 17921;
        // Acceleration1 - 0x4611
        public static readonly int Acceleration1 = 17937;
        // Deceleration1 - 0x4621
        public static readonly int Deceleration1 = 17953;
        // CMD 0 - 0x4802
        public static readonly int CMD0 = 18434;
        // CMD 1 - 0x4806
        public static readonly int CMD1 = 18438;
        // CMD 2 - 0x480A
        public static readonly int CMD2 = 18442;
        // CMD 5 - 0x4816
        public static readonly int CMD5 = 18454;
        // CMD 6 - 0x481A
        public static readonly int CMD6 = 18458;
        // CMD 7 - 0x481E 
        public static readonly int CMD7 = 18462;
        // CMD 8 - 0x4822
        public static readonly int CMD8 = 18466;
        // CMD 10 - 0x482A
        public static readonly int CMD10 = 18474;
        // CMD 11 - 0x482E
        public static readonly int CMD11 = 18478;
        // CMD 16 - 0x4842       
        public static readonly int CMD16 = 18498;
        // CMD 17 - 0x4846       
        public static readonly int CMD17 = 18502;
    }
    #endregion

    #region CommunicationRespone
    public class CommunicationRespone
    {
        #region Field
        private bool m_IsFirst;

        private string m_TransactionID;
        private string m_TransferCount;
        #endregion

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

        #region Property
        public bool IsFirst
        {
            get { return this.m_IsFirst; }
            set { this.m_IsFirst = value; }
        }

        /// <summary>
        /// Data ID (0~9)
        /// </summary>
        public string TransactionID
        {
            get { return this.m_TransactionID; }
            set { this.m_TransactionID = value; }
        }
        /// <summary>
        /// 재전송 CNT (0~9)
        /// </summary>
        public string TransferCount
        {
            get { return this.m_TransferCount; }
            set { this.m_TransferCount = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.IsFirst = false;

            this.TransactionID = "a";
            this.TransferCount = "a";
        }
        #endregion
    }
    #endregion

    #region UserGroup
    public class UserPasswordType
    {
        #region Field
        private string m_Level1Password;
        private string m_Level2Password;
        private string m_Level3Password;
        private string m_Level4Password;
        private string m_DefinedPassword;
      
        private DataStore.UserGroup m_Group;
        #endregion
        
        #region Constructor
        public UserPasswordType()
        {
            this.Initialization();
        } 
        #endregion

        #region Property
        public string Level1Password
        {
            get { return this.m_Level1Password; }
            private set { this.m_Level1Password = value; }
        }
        public string Level2Password
        {
            get { return this.m_Level2Password; }
            private set { this.m_Level2Password = value; }
        }
        public string Level3Password
        {
            get { return this.m_Level3Password; }
            private set { this.m_Level3Password = value; }
        }
        public string Level4Password
        {
            get { return this.m_Level4Password; }
            private set { this.m_Level4Password = value; }
        }
        public string DefinedPassword
        {
            get { return this.m_DefinedPassword; }
            private set { this.m_DefinedPassword = value; }
        }

        public DataStore.UserGroup Group
        {
            get { return this.m_Group; }
            set { this.m_Group = value; }
        } 
        #endregion

        #region Method
        public void Initialization()
        {
            this.Level1Password = "1000";
            this.Level2Password = "2000";
            this.Level3Password = "3000";
            this.Level4Password = "0714";
            this.SetDefinedPassword("0810");

            this.Group = DataStore.UserGroup.LogOut;
        }

        public void SetDefinedPassword(string pass)
        {
            this.DefinedPassword = string.Format("{0:MMdd}{1}", DateTime.Now, pass);
        }
        #endregion
    }
    #endregion

    #region SystemConfiguration
    public class SystemConfigurationItem
    {
        #region Field
        private bool m_IsDataBackup;
        private bool m_IsEachNG;
        private bool m_IsWeightViewForward;
        private bool m_IsBypassMode;
        private bool m_IsLogin;
        private bool m_IsBypassDirectionPass;
        private bool m_IsBypassOnce;
        private bool m_IsOptDataStatistics;
        private bool m_IsCutView;
        private bool m_IsSamplingOnce;
        private bool m_IsSamplingRun;
        private bool m_IsWeightLimitEnable;
        private bool m_IsLeakSamplingRun;
        private bool m_IsLeakSamplingOnce;
        private bool m_IsPart11;
        private bool m_IsSorterCheckEnable;
        private bool m_IsModbus;
        private bool m_IsDeleteAfterBackup;

        private int m_NumberOfLoginFailures;
        private int m_DecimalPlaces;
        private int m_EquipmentColumns;
        private int m_ProductNumber;
        private int m_Serial3BaudRate;
        private int m_Serial3Mode;
        private int m_UsbID;
        private int m_InverterTorque;
        private int m_EXT1_DelayTime;
        private int m_EXT1_RunTime;
        private int m_Sorter1Location;
        private int m_Sorter2Location;
        private int m_Sorter3Location;
        private int m_Sorter4Location;
        private int m_MotorSelect;
        private int m_SamplingTime;
        private int m_SamplingCount;
        private int m_SamplingCurrentCount;
        private int m_WeightLimitIgnoreCount;
        private int m_ComRetryCNT;
        private int m_LeakSamplingTime;
        private int m_StoragePeriod;
        private int m_AutomaticLogout;

        private string m_Unit;
        private string m_SerialNumber;
        private string m_EmptyWeight;
        private string m_ComPort;
        private string m_User_Level1_Name;
        private string m_User_Level2_Name;
        private string m_User_Level3_Name;

        private DataStore.E_LanguageID m_Language;
        private DataStore.FormStore m_CurrentForm;
        private UserItem m_CurrentUser;

        private int m_EthernetServerPort;
        private int m_EthernetMode;
        private int m_EthernetOperationMode;
        private int m_EthernetLocalPort;
        private int m_ModbusTcpAddress1;
        private int m_ModbusTcpAddress2;
        private int m_ModbusTcpStartAddress;
        private string m_EthernetServerAddress;
        #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 IsEachNG
        {
            get { return this.m_IsEachNG; }
            set { this.m_IsEachNG = value; }
        }
        public bool IsWeightViewForward
        {
            get { return this.m_IsWeightViewForward; }
            set { this.m_IsWeightViewForward = value; }
        }
        public bool IsBypassMode
        {
            get { return this.m_IsBypassMode; }
            set { this.m_IsBypassMode = 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 bool IsOptDataStatistics
        {
            get { return this.m_IsOptDataStatistics; }
            set { this.m_IsOptDataStatistics = value; }
        }
        public bool IsCutView
        {
            get { return this.m_IsCutView; }
            set { this.m_IsCutView = value; }
        }
        public bool IsSamplingOnce
        {
            get { return this.m_IsSamplingOnce; }
            set { this.m_IsSamplingOnce = value; }
        }
        public bool IsSamplingRun
        {
            get { return this.m_IsSamplingRun; }
            set { this.m_IsSamplingRun = value; }
        }
        public bool IsWeightLimitEnable
        {
            get { return this.m_IsWeightLimitEnable; }
            set { this.m_IsWeightLimitEnable = value; }
        }
        public bool IsLeakSamplingRun
        {
            get { return this.m_IsLeakSamplingRun; }
            set { this.m_IsLeakSamplingRun = value; }
        }
        public bool IsLeakSamplingOnce
        {
            get { return this.m_IsLeakSamplingOnce; }
            set { this.m_IsLeakSamplingOnce = value; }
        }
        public bool IsPart11
        {
            get { return this.m_IsPart11; }
            set { this.m_IsPart11 = value; }
        }
        public bool IsSorterCheckEnable
        {
            get { return this.m_IsSorterCheckEnable; }
            set { this.m_IsSorterCheckEnable = value; }
        }
        public bool IsModbus
        {
            get { return this.m_IsModbus; }
            set { this.m_IsModbus = value; }
        }
        public bool IsDeleteAfterBackup
        {
            get { return this.m_IsDeleteAfterBackup; }
            set { this.m_IsDeleteAfterBackup = value; }
        }

        public int NumberOfLoginFailures
        {
            get { return this.m_NumberOfLoginFailures; }
            set { this.m_NumberOfLoginFailures = 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 ProductNumber
        {
            get { return this.m_ProductNumber; }
            set { this.m_ProductNumber = 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 UsbID
        {
            get { return this.m_UsbID; }
            set { this.m_UsbID = value; }
        }
        public int InverterTorque
        {
            get { return this.m_InverterTorque; }
            set { this.m_InverterTorque = value; }
        }
        public int EXT1_DelayTime
        {
            get { return this.m_EXT1_DelayTime; }
            set { this.m_EXT1_DelayTime = value; }
        }
        public int EXT1_RunTime
        {
            get { return this.m_EXT1_RunTime; }
            set { this.m_EXT1_RunTime = value; }
        }
        public int Sorter1Location
        {
            get { return this.m_Sorter1Location; }
            set { this.m_Sorter1Location = value; }
        }
        public int Sorter2Location
        {
            get { return this.m_Sorter2Location; }
            set { this.m_Sorter2Location = value; }
        }
        public int Sorter3Location
        {
            get { return this.m_Sorter3Location; }
            set { this.m_Sorter3Location = value; }
        }
        public int Sorter4Location
        {
            get { return this.m_Sorter4Location; }
            set { this.m_Sorter4Location = value; }
        }
        public int MotorSelect
        {
            get { return this.m_MotorSelect; }
            set { this.m_MotorSelect = value; }
        }
        public int SamplingTime
        {
            get { return this.m_SamplingTime; }
            set { this.m_SamplingTime = value; }
        }
        public int SamplingCount
        {
            get { return this.m_SamplingCount; }
            set { this.m_SamplingCount = value; }
        }
        public int SamplingCurrentCount
        {
            get { return this.m_SamplingCurrentCount; }
            set { this.m_SamplingCurrentCount = value; }
        }
        public int WeightLimitIgnoreCount
        {
            get { return this.m_WeightLimitIgnoreCount; }
            set { this.m_WeightLimitIgnoreCount = value; }
        }
        public int ComRetryCNT
        {
            get { return this.m_ComRetryCNT; }
            set { this.m_ComRetryCNT = value; }
        }
        public int LeakSamplingTime
        {
            get { return this.m_LeakSamplingTime; }
            set { this.m_LeakSamplingTime = value; }
        }
        public int StoragePeriod
        {
            get { return this.m_StoragePeriod; }
            set { this.m_StoragePeriod = value; }
        }
        public int AutomaticLogout
        {
            get { return this.m_AutomaticLogout; }
            set { this.m_AutomaticLogout = 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 string EmptyWeight
        {
            get { return this.m_EmptyWeight; }
            set { this.m_EmptyWeight = value; }
        }
        public string ComPort
        {
            get { return this.m_ComPort; }
            set { this.m_ComPort = value; }
        }
        public string User_Level1_Name
        {
            get { return this.m_User_Level1_Name; }
            set { this.m_User_Level1_Name = value; }
        }
        public string User_Level2_Name
        {
            get { return this.m_User_Level2_Name; }
            set { this.m_User_Level2_Name = value; }
        }
        public string User_Level3_Name
        {
            get { return this.m_User_Level3_Name; }
            set { this.m_User_Level3_Name = value; }
        }

        public DataStore.E_LanguageID Language
        {
            get { return this.m_Language; }
            set { this.m_Language = value; }
        }
        public DataStore.FormStore CurrentForm
        {
            get { return this.m_CurrentForm; }
            set { this.m_CurrentForm = value; }
        }
        public UserItem 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 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 EthernetLocalPort
        {
            get { return this.m_EthernetLocalPort; }
            set { this.m_EthernetLocalPort = value; }
        }
        public int ModbusTcpAddress1
        {
            get { return this.m_ModbusTcpAddress1; }
            set { this.m_ModbusTcpAddress1 = value; }
        }
        public int ModbusTcpAddress2
        {
            get { return this.m_ModbusTcpAddress2; }
            set { this.m_ModbusTcpAddress2 = 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; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.IsDataBackup = false;
            this.IsEachNG = true;
            this.IsWeightViewForward = true;
            this.IsBypassMode = false;
            this.IsLogin = false;
            this.IsBypassDirectionPass = true;
            this.IsBypassOnce = true;
            this.IsOptDataStatistics = false;
            this.IsCutView = false;
            this.IsSamplingOnce = true;
            this.IsSamplingRun = false;
            this.IsWeightLimitEnable = true;
            this.IsLeakSamplingRun = false;
            this.IsLeakSamplingOnce = true;
            this.IsPart11 = false;
            this.IsSorterCheckEnable = false;
            this.IsModbus = false;
            this.IsDeleteAfterBackup = false;

            this.NumberOfLoginFailures = 5;
            this.DecimalPlaces = 1;
            this.EquipmentColumns = 10;
            this.ProductNumber = 1;
            this.Serial3BaudRate = 0;
            this.Serial3Mode = 0;
            this.UsbID = 1;
            this.InverterTorque = 100;
            this.EXT1_DelayTime = 0;
            this.EXT1_RunTime = 1000;
            this.Sorter1Location = 6;
            this.Sorter2Location = 7;
            this.Sorter3Location = 3;
            this.Sorter4Location = 0;
            this.MotorSelect = 1;
            this.SamplingTime = 1;
            this.SamplingCount = 1;
            this.SamplingCurrentCount = 0;
            this.WeightLimitIgnoreCount = 3;
            this.ComRetryCNT = 0;
            this.LeakSamplingTime = 10;
            this.StoragePeriod = 36;
            this.AutomaticLogout = 30;

            this.Unit = "g";
            this.SerialNumber = "26A0000";
            this.EmptyWeight = "0";
            this.ComPort = "COM2";
            this.User_Level1_Name = "Level 1";
            this.User_Level2_Name = "Level 2";
            this.User_Level3_Name = "Level 3";

            this.Language = DataStore.E_LanguageID.Korean;
            this.CurrentForm = DataStore.FormStore.FormMainDisplay;
            this.CurrentUser = new UserItem();
            this.CurrentUser.Group = DataStore.UserGroup.LogOut;

            this.EthernetServerPort = 5002;
            this.EthernetMode = 0;
            this.EthernetOperationMode = 0;
            this.EthernetLocalPort = 5001;
            this.ModbusTcpAddress1 = 1000;
            this.ModbusTcpAddress2 = 1100;
            this.ModbusTcpStartAddress = 1010;
            this.EthernetServerAddress = "0.0.0.0";
        }
        #endregion
    }
    #endregion
    #region Struct SystemConfiguration1
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem1
    {
        public bool IsDataBackup;
        public bool IsEachNG;
        public bool IsLogin;
        public bool IsWeightViewForward;
        public bool IsOptDataStatistics;
        public bool IsSorterCheckEnable;
        public bool IsDeleteAfterBackup;
        public bool DummyBool7;

        public int DecimalPlaces;
        public int EquipmentColumns;
        public int ProductNumber;
        public int Serial3BaudRate;
        public int Serial3Mode;
        public int UsbID;
        public int WeightLimitIgnoreCount;
        public int MotorSelect;

        [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 bool DummyBool8;

        public int Sorter1Location;
        public int Sorter2Location;
        public int EXT1_DelayTime;
        public int EXT1_RunTime;
        public int InverterTorque;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string EmptyWeight;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string ComPort;
        [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 double DummyDouble11;
        public double DummyDouble12;
        public double DummyDouble13;
        public double DummyDouble14;
        public double DummyDouble15;
        public double DummyDouble16;
        public double DummyDouble17;
        public double DummyDouble18;
        public double DummyDouble19;
        public double DummyDouble20;
        public double DummyDouble21;
        public double DummyDouble22;

        public bool DummyBool1;
        public bool DummyBool2;
        public bool DummyBool3;
        public bool DummyBool4;
        public bool DummyBool5;
        public bool DummyBool6;
        public bool DummyBool7;
        public bool IsPart11;
        public bool IsLeakSamplingOnce;
        public bool IsSamplingOnce;

        public int DummyInt1;
        public int NumberOfLoginFailures;
        public int AutomaticLogout;
        public int StoragePeriod;
        public int LeakSamplingTime;
        public int Sorter4Location;
        public int ComRetryCNT;
        public int SamplingCount;
        public int SamplingTime;
        public int Sorter3Location;

        public double DummyDouble1;
        public double DummyDouble2;
        public double DummyDouble3;
        public double DummyDouble4;
        public double DummyDouble5;
        public double DummyDouble6;
        public double DummyDouble7;
        public double DummyDouble8;
        public double DummyDouble9;
        public double DummyDouble10;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        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 User_Level1_Name;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string User_Level2_Name;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string User_Level3_Name;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString11;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString12;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString13;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString14;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
        public string DummyString15;
    }
    #endregion
    #region Struct SystemConfiguration3
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem3
    {
        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 IsModbus;

        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;
        public int DummyInt11;
        public int DummyInt12;
        public int DummyInt13;
        public int EthernetServerPort;
        public int EthernetMode;
        public int EthernetOperationMode;
        public int EthernetLocalPort;
        public int ModbusTcpAddress1;
        public int ModbusTcpAddress2;
        public int ModbusTcpStartAddress;
        
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        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 = 40)]
        public string DummyString9;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string EthernetServerAddress;
    }
    #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 string m_UnderRangeLimit;
        private string m_OverRangeLimit;

        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 string UnderRangeLimit
        {
            get { return this.m_UnderRangeLimit; }
            set { this.m_UnderRangeLimit = value; }
        }
        public string OverRangeLimit
        {
            get { return this.m_OverRangeLimit; }
            set { this.m_OverRangeLimit = 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";
            this.UnderRangeLimit = "0";
            this.OverRangeLimit = "99999";
        }

        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 OverRangeLimit;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string UnderRangeLimit;
        [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 bool m_IsADCError;
        private bool m_IsBypassMode;

        private bool m_IsOPT1;

        private bool m_IsSamplingData;

        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; }
        }

        /// <summary>
        /// 소수점 포함된 중량값
        /// </summary>
        public double Weight
        {
            get { return this.m_Weight; }
            set { this.m_Weight = value; }
        }

        public string ADCValue
        {
            get { return this.m_ADCValue; }
            set
            {
                int temp = 0;

                this.m_ADCValue = value;

                try
                {
                    temp = int.Parse(value);
                }
                catch
                {
                    temp = 0;
                }

                if (temp < 500 || temp > 60000)
                {
                    if (this.IsADCError != true)
                        this.IsADCError = true;
                }
                else
                {
                    if (this.IsADCError != false)
                        this.IsADCError = false;
                }
            }
        }

        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 (value == DataStore.JudgmentStatus.Double || value == DataStore.JudgmentStatus.ExNG)
                {
                    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; }
        }

        /// <summary>
        /// 소수점 없는 중량값
        /// </summary>
        public string WeightString
        {
            get { return this.m_WeightString; }
            set { this.m_WeightString = value; }
        }

        public bool IsADCError
        {
            get { return this.m_IsADCError; }
            private set { this.m_IsADCError = value; }
        }
        public bool IsBypassMode
        {
            get { return m_IsBypassMode; }
            set { m_IsBypassMode = value; }
        }

        /// <summary>
        /// 스틱2모드에서 데이터 전송이 되었으면 true, 안되었으면 false
        /// </summary>
        public bool IsOPT1
        {
            get { return this.m_IsOPT1; }
            set { this.m_IsOPT1 = value; }
        }

        /// <summary>
        /// 샘플링 기능 설정 후 판정데이터가 샘플링 데이터이면 true
        /// </summary>
        public bool IsSamplingData
        {
            get { return this.m_IsSamplingData; }
            set { this.m_IsSamplingData = 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.None;
            this.ProductionSpeed = 0;
            this.WeightString = "0";
            this.IsADCError = false;
            this.IsBypassMode = false;
            this.IsOPT1 = false;
            this.IsSamplingData = false;
            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 Counter1
    [StructLayout(LayoutKind.Sequential)]
    public struct StructCounter1
    {
        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 OverCount7;
        public int PassCount7;
        public int UnderCount7;
        public int ExNGCount7;

        public int OverCount8;
        public int PassCount8;
        public int UnderCount8;
        public int ExNGCount8;

        public int OverCount9;
        public int PassCount9;
        public int UnderCount9;
        public int ExNGCount9;

        public int OverCount10;
        public int PassCount10;
        public int UnderCount10;
        public int ExNGCount10;

        public int OverCount11;
        public int PassCount11;
        public int UnderCount11;
        public int ExNGCount11;

        public int OverCount12;
        public int PassCount12;
        public int UnderCount12;
        public int ExNGCount12;

        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 Struct Counter2
    [StructLayout(LayoutKind.Sequential)]
    public struct StructCounter2
    {
        public int OverCount13;
        public int PassCount13;
        public int UnderCount13;
        public int ExNGCount13;

        public int OverCount14;
        public int PassCount14;
        public int UnderCount14;
        public int ExNGCount14;

        public int OverCount15;
        public int PassCount15;
        public int UnderCount15;
        public int ExNGCount15;

        public int OverCount16;
        public int PassCount16;
        public int UnderCount16;
        public int ExNGCount16;

        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;

        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;
        
        public int DummyInt21;
        public int DummyInt22;
        public int DummyInt23;
        public int DummyInt24;
        public int DummyInt25;
        public int DummyInt26;
        public int DummyInt27;
        public int DummyInt28;
        public int DummyInt29;
        public int DummyInt30;
        
        public int DummyInt31;
        public int DummyInt32;
        public int DummyInt33;
        public int DummyInt34;
        public int DummyInt35;
        public int DummyInt36;
        public int DummyInt37;
        public int DummyInt38;
        public int DummyInt39;
        public int DummyInt40;
        
        public int DummyInt41;
        public int DummyInt42;
    }
    #endregion

    #region JudgmentSetItem
    public class JudgmentSetItem
    {
        #region Field
        private int m_Filter;
        private int m_JudgmentDelayTime;
        private int m_JudgmentCount;
        private int m_FeedSpeed;
        private int m_TurnDelayTime;
        private int m_Sorter1DelayTime;
        private int m_Sorter1RunTime;
        private int m_Sorter2DelayTime;
        private int m_Sorter2RunTime;
        private int m_ForcedZeroDelayTime;
        private int m_OriginOffset;
        private int m_EntryGateDelayTime;
        private int m_EntryGateRunTime;
        private int m_DischargeStopperDelayTime;
        private int m_DischargeStopperRunTime;
        private int m_Stopper2DelayTime;
        private int m_Stopper2RunTime;
       
        private string m_Sorter3DelayTime;
        private string m_Sorter3RunTime;
        private string m_Sorter4DelayTime;
        private string m_Sorter4RunTime;

        private double m_DynamicCorrection;
        private double m_DynamicCorrection1;
        private double m_DynamicCorrection2;
        private double m_DynamicCorrection3;
        private double m_DynamicCorrection4;
        private double m_DynamicCorrection5;
        private double m_DynamicCorrection6;
        private double m_DynamicCorrection7;
        private double m_DynamicCorrection8;
        private double m_DynamicCorrection9;
        private double m_DynamicCorrection10;
        private double m_DynamicCorrection11;
        private double m_DynamicCorrection12;
        private double m_DynamicCorrection13;
        private double m_DynamicCorrection14;
        private double m_DynamicCorrection15;
        private double m_DynamicCorrection16;        
        #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 JudgmentCount
        {
            get { return this.m_JudgmentCount; }
            set { this.m_JudgmentCount = value; }
        }
        public int FeedSpeed
        {
            get { return this.m_FeedSpeed; }
            set { this.m_FeedSpeed = value; }
        }
        public int TurnDelayTime
        {
            get { return this.m_TurnDelayTime; }
            set { this.m_TurnDelayTime = 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 Sorter2DelayTime
        {
            get { return this.m_Sorter2DelayTime; }
            set { this.m_Sorter2DelayTime = value; }
        }
        public int Sorter2RunTime
        {
            get { return this.m_Sorter2RunTime; }
            set { this.m_Sorter2RunTime = value; }
        }
        public int ForcedZeroDelayTime
        {
            get { return this.m_ForcedZeroDelayTime; }
            set { this.m_ForcedZeroDelayTime = value; }
        }
        public int OriginOffset
        {
            get { return this.m_OriginOffset; }
            set { this.m_OriginOffset = value; }
        }
        public int EntryGateDelayTime
        {
            get { return this.m_EntryGateDelayTime; }
            set { this.m_EntryGateDelayTime = value; }
        }
        public int EntryGateRunTime
        {
            get { return this.m_EntryGateRunTime; }
            set { this.m_EntryGateRunTime = value; }
        }
        public int DischargeStopperDelayTime
        {
            get { return this.m_DischargeStopperDelayTime; }
            set { this.m_DischargeStopperDelayTime = value; }
        }
        public int DischargeStopperRunTime
        {
            get { return this.m_DischargeStopperRunTime; }
            set { this.m_DischargeStopperRunTime = value; }
        }
        public int Stopper2DelayTime
        {
            get { return this.m_Stopper2DelayTime; }
            set { this.m_Stopper2DelayTime = value; }
        }
        public int Stopper2RunTime
        {
            get { return this.m_Stopper2RunTime; }
            set { this.m_Stopper2RunTime = value; }
        }

        public string Sorter3DelayTime
        {
            get { return this.m_Sorter3DelayTime; }
            set { this.m_Sorter3DelayTime = value; }
        }
        public string Sorter3RunTime
        {
            get { return this.m_Sorter3RunTime; }
            set { this.m_Sorter3RunTime = value; }
        }
        public string Sorter4DelayTime
        {
            get { return this.m_Sorter4DelayTime; }
            set { this.m_Sorter4DelayTime = value; }
        }
        public string Sorter4RunTime
        {
            get { return this.m_Sorter4RunTime; }
            set { this.m_Sorter4RunTime = value; }
        }

        public double DynamicCorrection
        {
            get { return this.m_DynamicCorrection; }
            set { this.m_DynamicCorrection = value; }
        }
        public double DynamicCorrection1
        {
            get { return this.m_DynamicCorrection1; }
            set { this.m_DynamicCorrection1 = value; }
        }
        public double DynamicCorrection2
        {
            get { return this.m_DynamicCorrection2; }
            set { this.m_DynamicCorrection2 = value; }
        }
        public double DynamicCorrection3
        {
            get { return this.m_DynamicCorrection3; }
            set { this.m_DynamicCorrection3 = value; }
        }
        public double DynamicCorrection4
        {
            get { return this.m_DynamicCorrection4; }
            set { this.m_DynamicCorrection4 = value; }
        }
        public double DynamicCorrection5
        {
            get { return this.m_DynamicCorrection5; }
            set { this.m_DynamicCorrection5 = value; }
        }
        public double DynamicCorrection6
        {
            get { return this.m_DynamicCorrection6; }
            set { this.m_DynamicCorrection6 = value; }
        }
        public double DynamicCorrection7
        {
            get { return this.m_DynamicCorrection7; }
            set { this.m_DynamicCorrection7 = value; }
        }
        public double DynamicCorrection8
        {
            get { return this.m_DynamicCorrection8; }
            set { this.m_DynamicCorrection8 = value; }
        }
        public double DynamicCorrection9
        {
            get { return this.m_DynamicCorrection9; }
            set { this.m_DynamicCorrection9 = value; }
        }
        public double DynamicCorrection10
        {
            get { return this.m_DynamicCorrection10; }
            set { this.m_DynamicCorrection10 = value; }
        }
        public double DynamicCorrection11
        {
            get { return this.m_DynamicCorrection11; }
            set { this.m_DynamicCorrection11 = value; }
        }
        public double DynamicCorrection12
        {
            get { return this.m_DynamicCorrection12; }
            set { this.m_DynamicCorrection12 = value; }
        }
        public double DynamicCorrection13
        {
            get { return this.m_DynamicCorrection13; }
            set { this.m_DynamicCorrection13 = value; }
        }
        public double DynamicCorrection14
        {
            get { return this.m_DynamicCorrection14; }
            set { this.m_DynamicCorrection14 = value; }
        }
        public double DynamicCorrection15
        {
            get { return this.m_DynamicCorrection15; }
            set { this.m_DynamicCorrection15 = value; }
        }
        public double DynamicCorrection16
        {
            get { return this.m_DynamicCorrection16; }
            set { this.m_DynamicCorrection16 = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.Filter = 8;
            this.JudgmentDelayTime = 650;
            this.JudgmentCount = 5;
            this.FeedSpeed = 2100;
            this.TurnDelayTime = 400;
            this.Sorter1DelayTime = 300;
            this.Sorter1RunTime = 400;
            this.Sorter2DelayTime = 300;
            this.Sorter2RunTime = 400;
            this.ForcedZeroDelayTime = 0;
            this.OriginOffset = 0;
            this.EntryGateDelayTime = 330;
            this.EntryGateRunTime = 340;
            this.DischargeStopperDelayTime = 250;
            this.DischargeStopperRunTime = 500;
            this.Stopper2DelayTime = 500;
            this.Stopper2RunTime = 1000;

            this.Sorter3DelayTime = "300";
            this.Sorter3RunTime = "400";
            this.Sorter4DelayTime = "1";
            this.Sorter4RunTime = "600";

            this.DynamicCorrection = 1.000000;
            this.DynamicCorrection1 = 1.000000;
            this.DynamicCorrection2 = 1.000000;
            this.DynamicCorrection3 = 1.000000;
            this.DynamicCorrection4 = 1.000000;
            this.DynamicCorrection5 = 1.000000;
            this.DynamicCorrection6 = 1.000000;
            this.DynamicCorrection7 = 1.000000;
            this.DynamicCorrection8 = 1.000000;
            this.DynamicCorrection9 = 1.000000;
            this.DynamicCorrection10 = 1.000000;
            this.DynamicCorrection11 = 1.000000;
            this.DynamicCorrection12 = 1.000000;
            this.DynamicCorrection13 = 1.000000;
            this.DynamicCorrection14 = 1.000000;
            this.DynamicCorrection15 = 1.000000;
            this.DynamicCorrection16 = 1.000000;
        }
        #endregion
    }
    #endregion
    #region Struct JudgmentSetItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructJudgmentSetItem
    {
        public int Filter;
        public int JudgmentDelayTime;
        public int JudgmentCount;
        public int FeedSpeed;
        public int TurnDelayTime;
        public int Sorter1RunTime;

        public double DynamicCorrection;

        public int OriginOffset;
        public int ForcedZeroDelayTime;
        public int Sorter1DelayTime;
        public int Sorter2DelayTime;
        public int Sorter2RunTime;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Sorter4DelayTime;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Sorter4RunTime;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Sorter3DelayTime;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Sorter3RunTime;
    }
    #endregion
    #region StructDynamicCorrectionItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructDynamicCorrectionItem
    {
        public double DynamicCorrection1;
        public double DynamicCorrection2;
        public double DynamicCorrection3;
        public double DynamicCorrection4;
        public double DynamicCorrection5;
        public double DynamicCorrection6;
        public double DynamicCorrection7;
        public double DynamicCorrection8;
        public double DynamicCorrection9;
        public double DynamicCorrection10;
        public double DynamicCorrection11;
        public double DynamicCorrection12;

        public double DummyDouble1;
        public double DummyDouble2;
        public double DummyDouble3;
        public double DummyDouble4;
        public double DummyDouble5;
        public double DummyDouble6;
        public double DynamicCorrection13;
        public double DynamicCorrection14;
        public double DynamicCorrection15;
        public double DynamicCorrection16;

        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;
        public int DummyInt4;
        public int Stopper2DelayTime;
        public int Stopper2RunTime;
        public int EntryGateDelayTime;
        public int EntryGateRunTime;
        public int DischargeStopperDelayTime;
        public int DischargeStopperRunTime;
    } 
    #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;
        private string m_Constant7;
        private string m_Constant8;
        private string m_Constant9;
        private string m_Constant10;
        private string m_Constant11;
        private string m_Constant12;
        private string m_Constant13;
        private string m_Constant14;
        private string m_Constant15;
        private string m_Constant16;
        #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";
            this.Constant7 = "1.000000";
            this.Constant8 = "1.000000";
            this.Constant9 = "1.000000";
            this.Constant10 = "1.000000";
            this.Constant11 = "1.000000";
            this.Constant12 = "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; }
        }
        public string Constant7
        {
            get { return this.m_Constant7; }
            set { this.m_Constant7 = value; }
        }
        public string Constant8
        {
            get { return this.m_Constant8; }
            set { this.m_Constant8 = value; }
        }
        public string Constant9
        {
            get { return this.m_Constant9; }
            set { this.m_Constant9 = value; }
        }
        public string Constant10
        {
            get { return this.m_Constant10; }
            set { this.m_Constant10 = value; }
        }
        public string Constant11
        {
            get { return this.m_Constant11; }
            set { this.m_Constant11 = value; }
        }
        public string Constant12
        {
            get { return this.m_Constant12; }
            set { this.m_Constant12 = value; }
        }
        public string Constant13
        {
            get { return this.m_Constant13; }
            set { this.m_Constant13 = value; }
        }
        public string Constant14
        {
            get { return this.m_Constant14; }
            set { this.m_Constant14 = value; }
        }
        public string Constant15
        {
            get { return this.m_Constant15; }
            set { this.m_Constant15 = value; }
        }
        public string Constant16
        {
            get { return this.m_Constant16; }
            set { this.m_Constant16 = 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_PassAlarm;
        private string m_PassAlarmCount;
        #endregion

        #region Constructor
        public OptionParameterItem()
        {
            this.BuzzerOnTime = "1000";
            this.RelayOnTime = "500";
            this.Chattering = "100";
            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 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 CommunicationStatus
    public class CommunicationStatusItem
    {
        #region Field
        private bool m_IsReceivedData;
        private bool m_IsErrorReceivedData;
        private bool m_IsErrorSettingStatus;
        private bool m_IsErrorID;
        #endregion

        #region Constructor
        public CommunicationStatusItem()
        {
            this.IsReceivedData = false;
            this.IsErrorReceivedData = false;
            this.IsErrorSettingStatus = false;
            this.IsErrorID = false;
        }
        #endregion

        #region Property
        public bool IsReceivedData
        {
            get { return this.m_IsReceivedData; }
            set { this.m_IsReceivedData = value; }
        }
        public bool IsErrorReceivedData
        {
            get { return this.m_IsErrorReceivedData; }
            set { this.m_IsErrorReceivedData = value; }
        }
        public bool IsErrorSettingStatus
        {
            get { return this.m_IsErrorSettingStatus; }
            set { this.m_IsErrorSettingStatus = value; }
        }
        public bool IsErrorID
        {
            get { return this.m_IsErrorID; }
            set { this.m_IsErrorID = 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_IsEmergencyStop;
        private bool m_IsServoAlarm;
        private bool m_IsServoAlarmTorque;
        private bool m_IsServoOff;
        private bool m_IsProductDischargeError;
        private bool m_IsSorter1Error;
        private bool m_IsSorter2Error;
      
        private bool m_IsBuzzerStatus;

        public event DataStore.EventHandlerAlarmStateChange EventAlarmStateChange;
        #endregion

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

        #region Property
        public bool IsEntrySensorError
        {
            get { return this.m_IsEntrySensorError; }
            set { this.m_IsEntrySensorError = value; }
        }
        public bool IsLoadcellError
        {
            get { return this.m_IsLoadcellError; }
            set { this.m_IsLoadcellError = value; }
        }
        public bool IsPressureError
        {
            get { return this.m_IsPressureError; }
            set { this.m_IsPressureError = value; }
        }
        public bool IsEmergencyStop
        {
            get { return this.m_IsEmergencyStop; }
            set { this.m_IsEmergencyStop = value; }
        }
        public bool IsServoAlarm
        {
            get { return this.m_IsServoAlarm; }
            set { this.m_IsServoAlarm = value; }
        }
        public bool IsServoAlarmTorque
        {
            get { return this.m_IsServoAlarmTorque; }
            set { this.m_IsServoAlarmTorque = value; }
        }
        public bool IsServoOff
        {
            get { return this.m_IsServoOff; }
            set { this.m_IsServoOff = value; }
        }
        public bool IsProductDischargeError
        {
            get { return this.m_IsProductDischargeError; }
            set { this.m_IsProductDischargeError = value; }
        }
        public bool IsSorter1Error
        {
            get { return this.m_IsSorter1Error; }
            set { this.m_IsSorter1Error = value; }
        }
        public bool IsSorter2Error
        {
            get { return this.m_IsSorter2Error; }
            set { this.m_IsSorter2Error = value; }
        }

        public bool IsBuzzerStatus
        {
            get { return this.m_IsBuzzerStatus; }
            set { this.m_IsBuzzerStatus = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsEntrySensorError = false;
            this.IsLoadcellError = false;
            this.IsPressureError = false;
            this.IsEmergencyStop = false;
            this.IsServoAlarm = false;
            this.IsServoAlarmTorque = false;
            this.IsServoOff = false;
            this.IsProductDischargeError = false;
            this.IsSorter1Error = false;
            this.IsSorter2Error = false;

            this.IsBuzzerStatus = 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');

            #region 알람 16-
            if (sValue4[0] == '0')
            { }
            else
            { }
            #endregion
            #region 알람 15-배출 에러(정렬기)
            if (sValue4[1] == '0')
            {
                if (this.IsProductDischargeError != false)
                {
                    this.IsProductDischargeError = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a15_ProductDischargeError, "OFF");
                }
            }
            else
            {
                if (this.IsProductDischargeError != true)
                {
                    this.IsProductDischargeError = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a15_ProductDischargeError, "ON");
                }
            }
            #endregion
            #region 알람 14-선별기1 에러
            if (sValue4[2] == '0')
            {
                if (this.IsSorter1Error != false)
                {
                    this.IsSorter1Error = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a14_Sorter1Error, "OFF");
                }
            }
            else
            {
                if (this.IsSorter1Error != true)
                {
                    this.IsSorter1Error = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a14_Sorter1Error, "ON");
                }
            }
            #endregion
            #region 알람 13-
            if (sValue4[3] == '0')
            { }
            else
            { } 
            #endregion

            #region 알람 12-서보알람토크
            if (sValue3[0] == '0')
            {
                if (this.IsServoAlarmTorque != false)
                {
                    this.IsServoAlarmTorque = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a12_ServoTorqueAlarm, "OFF");
                }
            }
            else
            {
                if (this.IsServoAlarmTorque != true)
                {
                    this.IsServoAlarmTorque = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a12_ServoTorqueAlarm, "ON");
                }
            }
            #endregion
            #region 알람 11-
            if (sValue3[1] == '0')
            { }
            else
            { } 
            #endregion
            #region 알람 10-서보알람
            if (sValue3[2] == '0')
            {
                if (this.IsServoAlarm != false)
                {
                    this.IsServoAlarm = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a10_ServoAlarm, "OFF");
                }
            }
            else
            {
                if (this.IsServoAlarm != true)
                {
                    this.IsServoAlarm = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a10_ServoAlarm, "ON");
                }
            }
            #endregion
            #region 알람 9-
            if (sValue3[3] == '0')
            { }
            else
            { }
            #endregion

            #region 알람 8-비상정지
            if (sValue2[0] == '0')
            {
                if (this.IsEmergencyStop != false)
                {
                    this.IsEmergencyStop = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a8_EmergencyStop, "OFF");
                }
            }
            else
            {
                if (this.IsEmergencyStop != true)
                {
                    this.IsEmergencyStop = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a8_EmergencyStop, "ON");
                }
            }
            #endregion
            #region 알람 7-선별기2 에러
            if (sValue2[1] == '0')
            {
                if (this.IsSorter2Error != false)
                {
                    this.IsSorter2Error = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a7_Sorter2Error, "OFF");
                }
            }
            else
            {
                if (this.IsSorter2Error != true)
                {
                    this.IsSorter2Error = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a7_Sorter2Error, "ON");
                }
            }
            #endregion
            #region 알람 6-
            if (sValue2[2] == '0')
            { }
            else
            { }
            #endregion
            #region 알람 5-
            if (sValue2[3] == '0')
            { }
            else
            { }
            #endregion

            #region 알람 4-
            if (sValue1[0] == '0')
            { }
            else
            { }
            #endregion
            #region 알람 3-공압에러
            if (sValue1[1] == '0')
            {
                if (this.IsPressureError != false)
                {
                    this.IsPressureError = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a3_PressureError, "OFF");
                }
            }
            else
            {
                if (this.IsPressureError != true)
                {
                    this.IsPressureError = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a3_PressureError, "ON");
                }
            }
            #endregion
            #region 알람 2-셀 에러
            if (sValue1[2] == '0')
            {
                if (this.IsLoadcellError != false)
                {
                    this.IsLoadcellError = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a2_LoadcellError, "OFF");
                }
            }
            else
            {
                if (this.IsLoadcellError != true)
                {
                    this.IsLoadcellError = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a2_LoadcellError, "ON");
                }
            }
            #endregion
            #region 알람 1-입력센서 에러
            if (sValue1[3] == '0')
            {
                if (this.IsEntrySensorError != false)
                {
                    this.IsEntrySensorError = false;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a1_EntrySensorError, "OFF");
                }
            }
            else
            {
                if (this.IsEntrySensorError != true)
                {
                    this.IsEntrySensorError = true;
                    this.EventAlarmStateChange(DataStore.TrackingAlarm.a1_EntrySensorError, "ON");
                }
            }
            #endregion
        }
        #endregion
    }
    #endregion

    #region StorageItem
    public class StorageItem
    {
        #region Field
        private double m_Weight;

        private bool m_IsSamplingData;
        private bool m_IsEmptyData;

        private DataStore.JudgmentStatus m_JudgmentStatus;
        #endregion

        #region Constructor
        public StorageItem(double weight, bool sampling, bool empty, DataStore.JudgmentStatus stats)
        {
            this.Weight = weight;
            this.IsSamplingData = sampling;
            this.IsEmptyData = empty;
            this.JudgmentStatus = stats;
        }
        #endregion

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

        public bool IsSamplingData
        {
            get { return this.m_IsSamplingData; }
            set { this.m_IsSamplingData = value; }
        }
        public bool IsEmptyData
        {
            get { return this.m_IsEmptyData; }
            set { this.m_IsEmptyData = value; }
        }

        public DataStore.JudgmentStatus JudgmentStatus
        {
            get { return this.m_JudgmentStatus; }

            set { this.m_JudgmentStatus = value; }
        }
        #endregion

        #region Method
        #endregion
    }
    #endregion
    #region WeightStorageItem
    public class WeightStorageItem
    {
        #region Field
        private int m_TotalCount;
        private double m_TotalSum;

        private Queue<StorageItem> Q_Weights;

        private Collection<StorageItem> m_C_StorageItem;
        #endregion

        #region Constructor
        public WeightStorageItem()
        {
            this.TotalCount = 0;
            this.TotalSum = 0.0;

            this.Q_Weights = new Queue<StorageItem>();

            this.C_StorageItem = new Collection<StorageItem>();
            for (int i = 0; i < 10; i++)
                this.C_StorageItem.Add(new StorageItem(0.0, false, false, DataStore.JudgmentStatus.None));
        }
        #endregion

        #region Property
        public int TotalCount
        {
            get { return this.m_TotalCount; }
            private set { this.m_TotalCount = value; }
        }

        public double TotalSum
        {
            get { return this.m_TotalSum; }
            private set { this.m_TotalSum = value; }
        }

        public Collection<StorageItem> C_StorageItem
        {
            get { return this.m_C_StorageItem; }
            private set { this.m_C_StorageItem = value; }
        }
        #endregion

        #region Method
        public double WeightTenSum()
        {
            double sumValue = 0.0;

            foreach (StorageItem item in this.Q_Weights)
            {
                if (item.IsEmptyData == false)
                    sumValue = sumValue + item.Weight;
            }

            return sumValue;
        }
        public double WeightTenAverage()
        {
            int cnt = 0;
            double sumValue = 0.0;

            if (this.Q_Weights.Count < 10)
                return 0.0;

            foreach (StorageItem item in this.Q_Weights)
            {
                if (item.IsEmptyData == false)
                {
                    sumValue = sumValue + item.Weight;
                    cnt++;
                }
            }

            if (cnt == 0)
                return 0.0;
            else
                return sumValue / cnt;
        }

        public void SetQueueData()
        {
            int cnt = 0;
            StorageItem[] items = new StorageItem[this.Q_Weights.Count];

            cnt = this.Q_Weights.Count;

            this.Q_Weights.CopyTo(items, 0);

            for (int i = 0; i < items.Length; i++)
            {
                this.C_StorageItem[i].Weight = items[(items.Length - i) - 1].Weight;
                this.C_StorageItem[i].IsSamplingData = items[(items.Length - i) - 1].IsSamplingData;
                this.C_StorageItem[i].IsEmptyData = items[(items.Length - i) - 1].IsEmptyData;
                this.C_StorageItem[i].JudgmentStatus = items[(items.Length - i) - 1].JudgmentStatus;
            }

            for (int i = items.Length; i < 10 - items.Length; i++)
            {
                this.C_StorageItem[i].Weight = 0.0;
                this.C_StorageItem[i].IsSamplingData = false;
                this.C_StorageItem[i].IsEmptyData = false;
                this.C_StorageItem[i].JudgmentStatus = DataStore.JudgmentStatus.None;
            }
        }

        public double WeightTotalAverage()
        {
            if (this.TotalCount == 0)
                return 0.0;

            return this.TotalSum / this.TotalCount;
        }

        public void SetValue(double value, bool sampling, bool empty, DataStore.JudgmentStatus status)
        {
            this.Q_Weights.Enqueue(new StorageItem(value, sampling, empty, status));

            if (this.Q_Weights.Count > 10)
                this.Q_Weights.Dequeue();

            if (empty == false)
            {
                this.TotalCount++;
                this.TotalSum = this.TotalSum + value;
            }
        }
        public void SetValue(WeightData data)
        {
            bool empty = false;

            if (data.JudgmentStatus == DataStore.JudgmentStatus.Empty)
                empty = true;

            this.Q_Weights.Enqueue(new StorageItem(data.Weight, data.IsSamplingData, empty, data.JudgmentStatus));

            if (this.Q_Weights.Count > 10)
                this.Q_Weights.Dequeue();

            if (empty == false)
            {
                this.TotalCount++;
                this.TotalSum = this.TotalSum + data.Weight;
            }
        }

        public void AllClear()
        {
            this.TotalSum = 0.0;
            this.TotalCount = 0;

            this.Q_Weights.Clear();

            for (int i = 0; i < 10; i++)
            {
                this.C_StorageItem[i].Weight = 0.0;
                this.C_StorageItem[i].IsSamplingData = false;
                this.C_StorageItem[i].IsEmptyData = false;
                this.C_StorageItem[i].JudgmentStatus = DataStore.JudgmentStatus.None;
            }
        }
        #endregion
    }
    #endregion

    #region DataCollector
    public class DataCollector
    {
        #region Field
        private Collection<double> m_PassWeightData;
        private Collection<double> m_OverWeightData;
        private Collection<double> m_UnderWeightData;
        private Collection<double> m_ExNgWeightData;

        private double m_PassAverage;
        private double m_PassVariance;

        #endregion

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

        #region Porperty
        public Collection<double> PassWeightData
        {
            get { return this.m_PassWeightData; }
            private set { this.m_PassWeightData = value; }
        }
        public Collection<double> OverWeightData
        {
            get { return this.m_OverWeightData; }
            private set { this.m_OverWeightData = value; }
        }
        public Collection<double> UnderWeightData
        {
            get { return this.m_UnderWeightData; }
            private set { this.m_UnderWeightData = value; }
        }
        public Collection<double> ExNgWeightData
        {
            get { return this.m_ExNgWeightData; }
            private set { this.m_ExNgWeightData = value; }
        }

        public int TotalCount
        {
            get { return this.PassTotalCount + this.OverTotalCount + this.UnderTotalCount + this.ExNgTotalCount; }
        }
        public int TotalNGCount
        {
            get { return this.OverTotalCount + this.UnderTotalCount + this.ExNgTotalCount; }
        }

        public int PassTotalCount
        {
            get { return this.PassWeightData.Count; }
        }
        public double PassAverage
        {
            get { return this.m_PassAverage; }
            private set { this.m_PassAverage = value; }
        }
        public double PassPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.PassTotalCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    //sValue = string.Format("{0:0.000}", ((double)this.PassTotalCount / (double)this.TotalCount) * 100.000);
                    //ret = double.Parse(sValue);

                    ret = 100 - (this.OverPercentage + this.UnderPercentage + this.ExNgPercentage);
                }

                return ret;
            }
        }
        public double PassVariance
        {
            get { return this.m_PassVariance; }
            private set { this.m_PassVariance = value; }
        }
        public double PassStandardDeviation
        {
            get
            {
                return Math.Sqrt(this.PassVariance);
            }
        }
        public double PassSumWeight
        {
            get
            {
                double ret = 0.0;

                for (int i = 0; i < this.PassWeightData.Count; i++)
                    ret += this.PassWeightData[i];

                return ret;
            }
        }
        public double PassMinWeight
        {
            get
            {
                bool isFirstData = false;
                double ret = 0.0;

                if (this.PassTotalCount == 0)
                    ret = 0.0;
                else
                {
                    for (int i = 0; i < this.PassTotalCount; i++)
                    {
                        if (isFirstData == false)
                        {
                            isFirstData = true;
                            ret = this.PassWeightData[i];
                        }
                        else
                        {
                            if (ret > this.PassWeightData[i])
                                ret = this.PassWeightData[i];
                        }
                    }
                }

                return ret;
            }
        }
        public double PassMaxWeight
        {
            get
            {
                double ret = 0.0;

                if (this.PassTotalCount == 0)
                    ret = 0.0;
                else
                {
                    for (int i = 0; i < this.PassTotalCount; i++)
                    {
                        if (ret < this.PassWeightData[i])
                            ret = this.PassWeightData[i];
                    }
                }

                return ret;
            }
        }

        public int OverTotalCount
        {
            get { return this.OverWeightData.Count; }
        }
        public double OverSumWeight
        {
            get
            {
                double ret = 0.0;

                for (int i = 0; i < this.OverWeightData.Count; i++)
                    ret += this.OverWeightData[i];

                return ret;
            }
        }
        public double OverAverage
        {
            get
            {
                double ret = 0.0;

                if (this.OverWeightData.Count == 0)
                    ret = 0.0;
                else
                    ret = this.OverSumWeight / this.OverWeightData.Count;

                return ret;
            }
        }
        public double OverPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.OverTotalCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    sValue = string.Format("{0:0.00}", ((double)this.OverTotalCount / (double)this.TotalCount) * 100.00);
                    ret = double.Parse(sValue);
                }

                return ret;
            }
        }

        public int UnderTotalCount
        {
            get { return this.UnderWeightData.Count; }
        }
        public double UnderSumWeight
        {
            get
            {
                double ret = 0.0;

                for (int i = 0; i < this.UnderWeightData.Count; i++)
                    ret += this.UnderWeightData[i];

                return ret;
            }
        }
        public double UnderAverage
        {
            get
            {
                double ret = 0.0;

                if (this.UnderWeightData.Count == 0)
                    ret = 0.0;
                else
                    ret = this.UnderSumWeight / this.UnderWeightData.Count;

                return ret;
            }
        }
        public double UnderPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.UnderTotalCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    sValue = string.Format("{0:0.00}", ((double)this.UnderTotalCount / (double)this.TotalCount) * 100.00);
                    ret = double.Parse(sValue);
                }

                return ret;
            }
        }

        public int ExNgTotalCount
        {
            get { return this.ExNgWeightData.Count; }
        }
        public double ExNgPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.ExNgTotalCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    sValue = string.Format("{0:0.00}", ((double)this.ExNgTotalCount / (double)this.TotalCount) * 100.00);
                    ret = double.Parse(sValue);
                }

                return ret;
            }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.PassWeightData = new Collection<double>();
            this.OverWeightData = new Collection<double>();
            this.UnderWeightData = new Collection<double>();
            this.ExNgWeightData = new Collection<double>();

            this.ClearDatas();
        }

        public void ClearDatas()
        {
            this.PassWeightData.Clear();
            this.OverWeightData.Clear();
            this.UnderWeightData.Clear();
            this.ExNgWeightData.Clear();

            this.PassAverage = 0;
            this.PassVariance = 0;
        }

        public void AddPassWeight(double data)
        {
            this.PassWeightData.Add(data);
        }
        public void AddOverWeight(double data)
        {
            this.OverWeightData.Add(data);
        }
        public void AddUnderWeight(double data)
        {
            if (data < 0)
                this.UnderWeightData.Add(0);
            else
                this.UnderWeightData.Add(data);
        }
        public void AddExNgWeight(double data)
        {
            if (data < 0)
                this.ExNgWeightData.Add(0);
            else
                this.ExNgWeightData.Add(data);
        }

        public void StatisticalAnalysis()
        {
            double value1 = 0.0, value2 = 0.0;

            if (this.PassWeightData.Count == 0)
                return;

            #region Pass Average
            for (int i = 0; i < this.PassWeightData.Count; i++)
            {
                value1 += this.PassWeightData[i];
            }

            value1 = value1 / this.PassWeightData.Count;

            this.PassAverage = value1;
            #endregion

            #region PassVariance
            for (int i = 0; i < this.PassTotalCount; i++)
            {
                value1 = this.PassAverage - this.PassWeightData[i];
                value2 += value1 * value1;
            }

            this.PassVariance = value2 / this.PassTotalCount;
            #endregion
        }
        #endregion
    }
    #endregion
    #region DataCommonList
    public class DataCommonList
    {
        #region Field
        private string m_ProductName;
        private string m_Lot;
        private string m_StartTime;
        private string m_EndTime;
        private string m_OverRange;
        private string m_PassRange;
        private string m_UnderRange;
        private string m_TareRange;

        private int m_TotalPassCount;
        private double m_TotalPassSumWeight;
        private double m_TotalPassAverageWeight;
        private double m_TotalPassVariance;

        private int m_TotalOverCount;
        private double m_TotalOverSumWeight;

        private int m_TotalUnderCount;
        private double m_TotalUnderSumWeight;

        private int m_TotalExNgCount;
        #endregion

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

        #region Property
        public string ProductName
        {
            get { return this.m_ProductName; }
            set { this.m_ProductName = value; }
        }
        public string Lot
        {
            get { return this.m_Lot; }
            set { this.m_Lot = value; }
        }
        public string StartTime
        {
            get { return this.m_StartTime; }
            set { this.m_StartTime = value; }
        }
        public string EndTime
        {
            get { return this.m_EndTime; }
            set { this.m_EndTime = value; }
        }
        public string OverRange
        {
            get { return this.m_OverRange; }
            set { this.m_OverRange = value; }
        }
        public string PassRange
        {
            get { return this.m_PassRange; }
            set { this.m_PassRange = value; }
        }
        public string UnderRange
        {
            get { return this.m_UnderRange; }
            set { this.m_UnderRange = value; }
        }
        public string TareRange
        {
            get { return this.m_TareRange; }
            set { this.m_TareRange = value; }
        }

        public int TotalPassCount
        {
            get { return this.m_TotalPassCount; }
            set { this.m_TotalPassCount = value; }
        }
        public double TotalPassSumWeight
        {
            get { return this.m_TotalPassSumWeight; }
            set { this.m_TotalPassSumWeight = value; }
        }
        public double TotalPassAverageWeight
        {
            get { return this.m_TotalPassAverageWeight; }
            set { this.m_TotalPassAverageWeight = value; }
        }
        public double TotalPassVariance
        {
            get { return this.m_TotalPassVariance; }
            set { this.m_TotalPassVariance = value; }
        }
        public double TotalPassStandardDeviation
        {
            get
            {
                return Math.Sqrt(this.TotalPassVariance);
            }
        }
        public double TotalPassPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.TotalPassCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    //sValue = string.Format("{0:0.00}", ((double)this.TotalPassCount / (double)this.TotalCount) * 100.0);
                    //ret = double.Parse(sValue);

                    ret = 100 - (this.TotalUnderPercentage + this.TotalOverPercentage + this.TotalExNgPercentage);
                }

                return ret;
            }
        }

        public int TotalOverCount
        {
            get { return this.m_TotalOverCount; }
            set { this.m_TotalOverCount = value; }
        }
        public double TotalOverSumWeight
        {
            get { return this.m_TotalOverSumWeight; }
            set { this.m_TotalOverSumWeight = value; }
        }
        public double TotalOverPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.TotalOverCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    sValue = string.Format("{0:0.00}", ((double)this.TotalOverCount / (double)this.TotalCount) * 100.00);
                    ret = double.Parse(sValue);
                }

                return ret;
            }
        }

        public int TotalUnderCount
        {
            get { return this.m_TotalUnderCount; }
            set { this.m_TotalUnderCount = value; }
        }
        public double TotalUnderSumWeight
        {
            get { return this.m_TotalUnderSumWeight; }
            set { this.m_TotalUnderSumWeight = value; }
        }
        public double TotalUnderPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.TotalUnderCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    sValue = string.Format("{0:0.00}", ((double)this.TotalUnderCount / (double)this.TotalCount) * 100.00);
                    ret = double.Parse(sValue);
                }

                return ret;
            }
        }

        public int TotalExNgCount
        {
            get { return this.m_TotalExNgCount; }
            set { this.m_TotalExNgCount = value; }
        }
        public double TotalExNgPercentage
        {
            get
            {
                double ret = 0.0;
                string sValue = "";

                if (this.TotalExNgCount == 0 || this.TotalCount == 0)
                    ret = 0.0;
                else
                {
                    sValue = string.Format("{0:0.00}", ((double)this.TotalExNgCount / (double)this.TotalCount) * 100.00);
                    ret = double.Parse(sValue);
                }

                return ret;
            }
        }

        public int TotalCount
        {
            get
            {
                return this.TotalPassCount + this.TotalOverCount + this.TotalUnderCount + this.TotalExNgCount;
            }
        }
        public int TotalNGCount
        {
            get
            {
                return this.TotalOverCount + this.TotalUnderCount + this.TotalExNgCount;
            }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.ProductName = "-";
            this.Lot = "-";
            this.StartTime = "-";
            this.EndTime = "-";
            this.OverRange = "-";
            this.PassRange = "-";
            this.UnderRange = "-";
            this.TareRange = "-";
            this.TotalPassCount = 0;
            this.TotalOverCount = 0;
            this.TotalUnderCount = 0;
            this.TotalExNgCount = 0;
            this.TotalPassSumWeight = 0.0;
            this.TotalOverSumWeight = 0.0;
            this.TotalUnderSumWeight = 0.0;
        }

        public void Clear()
        {
            this.Initialize();
        }
        #endregion
    }
    #endregion

    #region DataViewerFilter
    public class DataViewerFilter
    {
        #region Field
        private bool m_TpyeAlarm;
        private bool m_TypeOperation;
        private bool m_TypeParameter;
        #endregion

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

        #region Property
        public bool TypeAlarm
        {
            get { return this.m_TpyeAlarm; }
            set { this.m_TpyeAlarm = value; }
        }
        public bool TypeOperation
        {
            get { return this.m_TypeOperation; }
            set { this.m_TypeOperation = value; }
        }
        public bool TypeParameter
        {
            get { return this.m_TypeParameter; }
            set { this.m_TypeParameter = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.TypeAlarm = true;
            this.TypeOperation = true;
            this.TypeParameter = true;
        }
        #endregion
    }
    #endregion

    #region HistoryData
    public class HistoryData
    {
        #region Field
        private string m_Type;
        private DateTime m_Time;
        private string m_LoginID;
        private Object m_Event;
        private string m_Detail;
        private string m_BeforeData;
        private string m_AfterData;
        #endregion

        #region Constructor
        public HistoryData()
        {
        }
        #endregion

        #region Property
        public string Type
        {
            get { return this.m_Type; }
            set { this.m_Type = value; }
        }
        public DateTime Time
        {
            get { return this.m_Time; }
            set { this.m_Time = value; }
        }
        public string LoginID
        {
            get { return this.m_LoginID; }
            set { this.m_LoginID = value; }
        }
        public Object Event
        {
            get { return this.m_Event; }
            set { this.m_Event = value; }
        }
        public string Detail
        {
            get { return this.m_Detail; }
            set { this.m_Detail = value; }
        }
        public string BeforeData
        {
            get { return this.m_BeforeData; }
            set { this.m_BeforeData = value; }
        }
        public string AfterData
        {
            get { return this.m_AfterData; }
            set { this.m_AfterData = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Type = "";
            this.Time = new DateTime();
            this.LoginID = "-";
            this.Event = new object();
            this.Detail = "";
            this.AfterData = "";
            this.BeforeData = "";
        }
        #endregion
    }
    #endregion

    #region DataBackupYear
    public class DataBackupYear
    {
        #region Field
        private string m_Year;

        public List<DataBackupMonth> Months;
        #endregion

        #region Constructor
        public DataBackupYear(string year)
        {
            this.Initialize();

            this.Year = year;
        }
        #endregion

        #region Property
        public string Year
        {
            get { return this.m_Year; }
            private set { this.m_Year = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Year = "";
            this.Months = new List<DataBackupMonth>();
        }
        #endregion
    }
    #endregion
    #region DataBackupMonth
    public class DataBackupMonth
    {
        #region Field
        private string m_Month;

        public List<string> Days;
        #endregion

        #region Constructor
        public DataBackupMonth(string month)
        {
            this.Initialize();

            this.Month = month;
        }
        #endregion

        #region Property
        public string Month
        {
            get { return this.m_Month; }
            private set { this.m_Month = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Month = "";
            this.Days = new List<string>();
        }
        #endregion
    }
    #endregion

    #region FileHeaderItem
    public class FileHeaderItem
    {
        #region Field
        private int m_EquipmentColumns;
        private int m_EquipmentType;

        private string m_LoginId;
        private string m_SerialNumber;

        private DateTime m_TimeStamp;
        #endregion

        #region Constructor
        public FileHeaderItem()
        {
        }
        #endregion

        #region Property
        public int EquipmentColumns
        {
            get { return this.m_EquipmentColumns; }
            set { this.m_EquipmentColumns = value; }
        }
        public int EquipmentType
        {
            get { return this.m_EquipmentType; }
            set { this.m_EquipmentType = value; }
        }

        public string LoginId
        {
            get { return this.m_LoginId; }
            set { this.m_LoginId = value; }
        }
        public string SerialNumber
        {
            get { return this.m_SerialNumber; }
            set { this.m_SerialNumber = value; }
        }

        public DateTime TimeStamp
        {
            get { return this.m_TimeStamp; }
            set { this.m_TimeStamp = value; }
        }
        #endregion

        #region Method
        #endregion
    }
    #endregion

    #region CalibrationStatus
    public class CalibrationStatus
    {
        #region Field
        private bool m_IsFinish;
        private bool m_IsError;
        private bool m_IsCancel;
        #endregion

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

        #region Property
        public bool IsFinish
        {
            get { return this.m_IsFinish; }
            set { this.m_IsFinish = value; }
        }
        public bool IsError
        {
            get { return this.m_IsError; }
            set { this.m_IsError = value; }
        }
        public bool IsCancel
        {
            get { return this.m_IsCancel; }
            set { this.m_IsCancel = value; }
        }
        #endregion

        #region Method
        public void Initialize()
        {
            this.IsFinish = false;
            this.IsError = false;
            this.IsCancel = false;
        }
        #endregion
    }
    #endregion

    #region DatabackupFileInfo1
    public class DatabackupFileInfo1
    {
        #region Field
        private int m_Index;
        private string m_Name; 
        #endregion

        #region Constructor
        public DatabackupFileInfo1(int index, string name)
        {
            this.Index = index;
            this.Name = name;
        } 
        #endregion

        #region Property
        public int Index
        {
            get { return this.m_Index; }
            set { this.m_Index = value; }
        }
        public string Name
        {
            get { return this.m_Name; }
            set { this.m_Name = value; }
        } 
        #endregion
    } 
    #endregion
    #region DatabackupFileInfo2
    public class DatabackupFileInfo2
    {
        #region Field
        private Collection<DatabackupFileInfo1> m_Files; 
        #endregion

        #region Constructor
        public DatabackupFileInfo2()
        {
            this.Files = new Collection<DatabackupFileInfo1>();
        } 
        #endregion

        #region Property
        public Collection<DatabackupFileInfo1> Files
        {
            get { return this.m_Files; }
            set { this.m_Files = value; }
        } 
        #endregion

        #region Method
        public void Add(int index, string name)
        {
            this.Files.Add(new DatabackupFileInfo1(index, name));
        }
        public void Clear()
        {
            this.Files.Clear();
        }
        public int GetIndex(string name)
        {
            int index = -1;
            for (int i = 0; i < this.Files.Count; i++)
            {
                if (this.Files[i].Name == name)
                    index = this.Files[i].Index;
            }

            return index;
        }
        public void RemoveAt(string name)
        {
            int index = -1;
            for (int i = 0; i < this.Files.Count; i++)
            {
                if (this.Files[i].Name == name)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
                this.Files.RemoveAt(index);
        } 
        #endregion
    } 
    #endregion
}
