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

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

        public enum DisplayMode
        { 
            Normal,
            Menu,
            Calibration,
            SystemSetting,
            IOTest,
            Bypass,
            EquipmentTest,
            SorterTest,
        }

        public enum DisplayStore
        {
            MainDisplay,

            BasicDataBackup,
            BasicDataStatistics,
            BasicHelp,
            BasicProduct,
            BasicTime,

            ConfiCommunication,
            ConfiHelp,
            ConfiOption,

            EquipHelp,
            EquipInitialize,
            EquipUpdate,
            EquipFuctionSetting,
            EquipUser,
            EquipTest,

            InforAS,
            InforHelp,
            InforSystem,

            SystemAutoZero,
            SystemCalibration,
            SystemHelp,
            SystemIOTest,
            SystemJudgmentSetting,
            SystemExternalOutput,
            SystemSorterSetting,
            SystemServoMotor,
        }

        public enum FormStore
        {
            FormNone = 0,
            FormMainDisplay,
            FormMenu,
        }

        public enum MainDisplayStore
        {
            Statistics,
            BarGraph,
            LineGraph,
            List,
            Function1,
        }

        public enum MemuSide
        {
            Basic,
            Configuration,
            System,
            Equipment,
            Information,
        }

        public enum MenuBottomBasic
        {
            DataBackup,
            DataStatistics,
            Help,
            Product,
            Time,
        }

        public enum MenuBottomConfiguration
        {
            Communication,
            Help,
            Option,
            OptionBoard1,
            OptionBoard2,
        }

        public enum MenuBottomEquipment
        {
            FunctionSetting,
            Help,
            Initialize,
            Test,
            Update,
            User,
        }

        public enum MenuBottomSystem
        {
            AutoZero,
            Calibration,
            ExternalOutput,
            Help,
            IOTest,
            JudgmentSetting,
            SorterSetting,
            ServoMotor,
        }

        public enum MenuBottomInformation
        {
            Help,
            SystemInformation,
            AS,
        }

        public enum LanguageID
        {
            Korean,
            English,
            Chinese,
            Czech,
        }

        public enum JudgmentStatus
        {
            Empty,
            Under,
            Pass,
            Over,
            Double,
            Metal,
            ExNg,
        }

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

        public enum UserGroup
        {
            LogOff,
            Level1Operator,
            Level2Engineer,
            Level3Manager,
            Level4Developer,
        }

        public enum SeparateType
        {
            STXANDETX,
            ETXONLY,
            NONEFRAME_READTIMEOUT,
            STXONLY,
        }

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

        public enum UpdateCheck
        {
            Fail,
            Success,
            NotUsbMomery,
            NotUpdateFolder,
            NotFile,
        }

        public enum WeightInputMode
        { 
            Weight,
            Deviation,
        }

        public enum SerialCOM
        {
            COM1 = 0,
            COM3 = 1,
            COM4 = 2,
        }

        public enum Step2
        {
            Step1,
            Step2,
        }

        public enum Step3
        { 
            Step1,
            Step2,
            Step3,
        }

        public enum Step4
        {
            Step1,
            Step2,
            Step3,
            Step4,
        }

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

    #region ServoMotor
    public class ServoMotorParameterAddress
    {
        // Alarm Reset - 0x0049
        public static readonly int AlarmReset = 73;

        // Grop Speed 0 - 0x0131
        public static readonly int GropSpeed0 = 305;
        // Grop Speed 1 - 0x0132
        public static readonly int GropSpeed1 = 306;
        // Position CMD 0 - 0x01F4
        public static readonly int PositionCMD0 = 500;
        // Position CMD 1 - 0x01F5
        public static readonly int PositionCMD1 = 501;
        // Position CMD 2 - 0x01F6
        public static readonly int PositionCMD2 = 502;
        // Position CMD 3 - 0x01F7
        public static readonly int PositionCMD3 = 503;
        // Position CMD 4 - 0x01F8
        public static readonly int PositionCMD4 = 504;
        // Position CMD 5 - 0x01F9
        public static readonly int PositionCMD5 = 505;
        // Position CMD 8 - 0x01FC
        public static readonly int PositionCMD8 = 508;
        // Position CMD 9 - 0x01FD
        public static readonly int PositionCMD9 = 509;
        // ORG Speed 0 - 0x0258
        public static readonly int ORGSpeed0 = 600;
        // ORG Speed 1 - 0x0259
        public static readonly int ORGSpeed1 = 601;
        // Origin Offset - 0x025B
        public static readonly int OriginOffset = 603;
    }

    public class ServoMotorAlarmList
    {
        // AL-00
        public static readonly char AL00_NORMAL_ESTOP = (char)0x00;
        // AL-01
        public static readonly char AL01_OVER_CURNT = (char)0x01;
        // AL-02
        public static readonly char AL02_OVER_VOLT = (char)0x02;
        // AL-03
        public static readonly char AL03_OVER_LOAD = (char)0x03;
        // AL-04
        public static readonly char AL04_POWER_FAIL = (char)0x04;
        // AL-05
        public static readonly char AL05_LINE_FAIL = (char)0x05;
        // AL-06
        public static readonly char AL06_OVER_SPEED = (char)0x06;
        // AL-07
        public static readonly char AL07_FOLLOW_ERR = (char)0x07;
        // AL-08
        public static readonly char AL08_OUTPUT_NC = (char)0x08;
        // AL-09
        public static readonly char AL09_PPR_ERROR = (char)0x09;
        // AL-10
        public static readonly char AL10_ABS_DATA = (char)0x0A;
        // AL-11
        public static readonly char AL11_ABS_BATT = (char)0x0B;
        // AL-12
        public static readonly char AL12_ABS_MDER = (char)0x0C;
        // AL-13
        public static readonly char AL13_POWER_LINE = (char)0x0E;
        // AL-14
        public static readonly char AL14_ABS_LOW_BATT = (char)0x0F;
        // AL-15
        public static readonly char AL15_ERASE_FAIL = (char)0x10;
        // AL-16
        public static readonly char AL16_WRITE_FAIL = (char)0x11;
        // AL-17
        public static readonly char AL17_PARA_INIT = (char)0x12;
    } 
    #endregion

    #region CommunicationCommand
    public class CommunicationCommand
    {
        // 중량조정모드
        public static readonly string ModeCalibration = "Csc00";
        // 노멀모드
        public static readonly string ModeNormal = "Csn00";
        // 메뉴 모드
        public static readonly string ModeMenu = "Csm00";
        // 판정설정모드
        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 ModeRejectorTest = "Csr00";

        // 중량조정 - 분동
        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 MotorForward = "Cmc00";
        // 모터 - 역회전
        public static readonly string MotorReverse = "Cmr00";
        // 모터 - 다운
        public static readonly string MotorDown = "Cmd00";
        // 모터 - 업
        public static readonly string MotorUp = "Cmu00";
        // 모더 - 알람리셋
        public static readonly string MotorAlarmReset = "Cma00";
        // 모터 - 원점초기화
        public static readonly string MotorOrigin = "Cmo00";
        // 모터 - Step
        public static readonly string MotorStep = "Cms00";
        // 모터 - 업2
        public static readonly string MotorUp2 = "Cmp00";

        // 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";

        // 정량알람
        public static readonly string AlarmPass = "Cab00";

        // ACK
        public static readonly string ACK = "ACK";
        // NAK
        public static readonly string NAK = "NAK";
        // 운전중 중량
        public static readonly string RunWeightData = "Sr";

        // 알람 해지 - 통신에러
        public static readonly string AlarmClearCommunicationError = "Cra00";
    }
    public class CommunicationID
    {
        public static readonly string MainBoard = "0";
        public static readonly string SubBoard1 = "A";
        public static readonly string SubBoard2 = "B";
        public static readonly string SubBoard3 = "C";
        public static readonly string SubBoard4 = "D";
        public static readonly string SubBoard5 = "E";
        public static readonly string SubBoard6 = "F";
        public static readonly string SubBoard7 = "G";
        public static readonly string SubBoard8 = "H";
        public static readonly string SubBoard9 = "I";
        public static readonly string SubBoard10 = "J";
        public static readonly string SubBoard11 = "K";
        public static readonly string SubBoard12 = "L";
        public static readonly string SubBoardAll = "Z";
    }
    public class CommunicationAddress
    {
        // Address None
        public static readonly string None = "0000";

        // 임펠러 모터 - 회전각도
        public static readonly string ImpellerMotorAngle = "1101";
        // 임펠러 모터 - 통신속도
        public static readonly string ImpellerMotorBaudrate = "1102";
        // 임펠러 모터 - 회전방향
        public static readonly string ImpellerMotorDirection = "1103";
        // 바이패스
        public static readonly string Bypass = "1201";
        // 정지계량 사용 여부
        public static readonly string IsStopWeighing = "1401";
        // OPT(옵션보드) 사용
        public static readonly string OptionBoard = "1402";
        // 외부운전 사용 여부
        public static readonly string IsExternalOperation = "1403";
        // 초기구동 사용 여부
        public static readonly string IsInitialDrive = "1404";
        // 공기압감지 사용 여부
        public static readonly string IsPressureSensing = "1405";
        // 적체센서 사용 여부
        public static readonly string IsStackSensing = "1406";
        // 선별부 동작감지 사용 여부
        public static readonly string IsSorterDetecting = "1407";
        // 보드 버전 모두 읽기
        public static readonly string ProgramVersion = "1500";
        // 메인보드 버전 읽기
        public static readonly string MainProgramVersion1 = "1501";

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

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

        // 자동영점 - 모드1 시간
        public static readonly string Zero1Time = "4001";
        // 자동영점 - 모드1 범위
        public static readonly string Zero1Range = "4002";
        // 자동영점 - 모드1 변량
        public static readonly string Zero1Variate = "4003";
        // 자동영점 - 모드1 모드
        public static readonly string Zero1Mode = "4004";
        // 자동영점 - 모드2 모드
        public static readonly string Zero2Mode = "4005";
        // 자동영점 - 모드2 시간
        public static readonly string Zero2Time = "4006";
        // 자동영점 - 모드2 범위
        public static readonly string Zero2Range = "4007";
        // 자동영점 - 모드2 변량
        public static readonly string Zero2Variate = "4008";

        // 자동영점 - 모드1 파라미터 읽기
        public static readonly string ParameterRead4901 = "4901";
        // 자동영점 - 모드2 파라미터 읽기
        public static readonly string ParameterRead4902 = "4902";

        // 판정설정 - 필터
        public static readonly string Filter = "5001";
        // 판정설정 - 판정지연
        public static readonly string JudgmentDelayTime = "5002";
        // 판정설정 - 이중지연
        public static readonly string DoubleDelayTime = "5003";
        // 판정설정 - 판정개수
        public static readonly string JudgmentCount = "5004";
        // 판정설정 - 이송속도
        public static readonly string FeedSpeed = "5005";
        // 판정설정 - 동보정
        public static readonly string DynamicCorrection = "5006";
        // 판정설정 - Feeding 컨베어 지연시간
        public static readonly string FeedingConveyorDelayTime = "5007";
        // 판정설정 - Feeding 컨베어 동작시간
        public static readonly string FeedingConveyorRunTime = "5008";
        // 판정설정 - 배출 컨베어 지연시간
        public static readonly string DrainConveyorDelayTime = "5009";
        // 판정설정 - 배출 컨베어 동작시간
        public static readonly string DrainConveyorRunTime = "5010";
        // 판정설정 - 상승 지연시간
        public static readonly string UpDelayTime = "5011";
        // 판정설정 - 하강 지연시간
        public static readonly string DownDelayTime = "5012";
        // 판정설정 - 선별기 테스트
        public static readonly string SorterTest = "5100";
        // 판정설정 - 선별기1 모드 값
        public static readonly string Sorter1Mode = "5101";
        // 판정설정 - 선별기1 지연시간
        public static readonly string Sorter1DelayTime = "5102";
        // 판정설정 - 선별기1 동작시간
        public static readonly string Sorter1RunTime = "5103";
        // 판정설정 - 선별기2 모드 값
        public static readonly string Sorter2Mode = "5104";
        // 판정설정 - 선별기2 지연시간
        public static readonly string Sorter2DelayTime = "5105";
        // 판정설정 - 선별기2 동작시간
        public static readonly string Sorter2RunTime = "5106";
        // 판정설정 - 외부출력1 모드
        public static readonly string ExternalOut1Mode = "5201";
        // 판정설정 - 외부출력1 지연시간
        public static readonly string ExternalOut1DelayTime = "5202";
        // 판정설정 - 외부출력1 동작시간
        public static readonly string ExternalOut1RunTime = "5203";
        // 판정설정 - 외부출력2 모드
        public static readonly string ExternalOut2Mode = "5204";
        // 판정설정 - 외부출력2 지연시간
        public static readonly string ExternalOut2DelayTime = "5205";
        // 판정설정 - 외부출력2 동작시간
        public static readonly string ExternalOut2RunTime = "5206";
        // 판정설정 - 외부출력3 모드
        public static readonly string ExternalOut3Mode = "5207";
        // 판정설정 - 외부출력3 지연시간
        public static readonly string ExternalOut3DelayTime = "5208";
        // 판정설정 - 외부출력3 동작시간
        public static readonly string ExternalOut3RunTime = "5209";
        // 판정설정 - 외부출력4 모드
        public static readonly string ExternalOut4Mode = "5210";
        // 판정설정 - 외부출력4 지연시간
        public static readonly string ExternalOut4DelayTime = "5211";
        // 판정설정 - 외부출력4 동작시간
        public static readonly string ExternalOut4RunTime = "5212";
        // 판정설정 - 외부출력9 모드
        public static readonly string ExternalOut9Mode = "5225";
        // 판정설정 - 외부출력9 지연시간
        public static readonly string ExternalOut9DelayTime = "5226";
        // 판정설정 - 외부출력9 동작시간
        public static readonly string ExternalOut9RunTime = "5227";
        // 판정설정 - 외부출력10 모드
        public static readonly string ExternalOut10Mode = "5228";
        // 판정설정 - 외부출력10 지연시간
        public static readonly string ExternalOut10DelayTime = "5229";
        // 판정설정 - 외부출력10 동작시간
        public static readonly string ExternalOut10RunTime = "5230";
        // 판정설정 - 파라미터 읽기
        public static readonly string ParameterRead5901 = "5901";
        // 판정설정 - 스타휠 회전주기
        public static readonly string WheelCycleTime = "5301";
        // 판정설정 - 스타휠 슬롯개수
        public static readonly string WheelSlotCount = "5302";
        // 판정설정 - 스타휠 슬롯배출지연개수
        public static readonly string WheelSlotOutCount = "5303";
        // 판정설정 - 진입센서 지연시간
        public static readonly string EntrySensorDelayTime = "5304";
        // 판정설정 - 서보드라이버 토크제한
        public static readonly string ServoTorque = "5351";
        // 판정설정 - 서보드라이버 회전속도
        public static readonly string ServoSpeed = "5352";
        // 판정설정 - 원점옵셋
        public static readonly string ServoOffset = "5353";
        // 판정설정 - 사용자정의1(선별기1모드,지연,동작,선별기2모드,지연,동작)
        public static readonly string UserDefined1 = "5901";

        // 옵션 - 부저 ON시간
        public static readonly string BuzzerOnTime = "6001";
        // 옵션 - 릴레이 동작시간
        public static readonly string RelayRunTime = "6002";
        // 옵션 - 정량 알람 기능 카운트 설정
        public static readonly string PassAlarmCount = "6004";
        // 옵션 - 이중진입사용여부
        public static readonly string DoubleEnter = "6005";
        // 옵션 - 채터링감지 설정
        public static readonly string Chattering = "6006";
        // 옵션 - 외부 NG 입력 사용
        public static readonly string ExternalInput = "6007";
        // 옵션 - 파라미터 읽기
        public static readonly string ParameterRead6901 = "6901";

        // RS232 통신1 속도
        public static readonly string Serial1_BaudRate = "7001";
        // RS232 통신1 모드
        public static readonly string Serial1_Mode = "7002";
        // RS232 통신 1 속도, 모드
        public static readonly string Serial1 = "7003";

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

        // 중량설정값 쓰기
        public static readonly string ParameterWeightSetting = "9003";
        // 품목 설정 모두 쓰기 
        public static readonly string _9013_ParameterProduct = "9013";
        // 시스템파라미터 읽기1
        public static readonly string _9501_SystemParameterRead1 = "9501";
        // 시스템파라미터 읽기2
        public static readonly string _9502_SystemParameterRead2 = "9502";
        // 시스템파라미터 읽기3
        public static readonly string _9503_SystemParameterRead3 = "9503";
        // 시스템파라미터 읽기4
        public static readonly string _9504_SystemParameterRead4 = "9504";
    }
    #endregion

    #region SystemConfigurationItem
    public class SystemConfigurationItem
    {
        #region Field
        private bool m_IsDataBackup;

        private int m_EquipmentID;
        private int m_DecimalPlaces;
        private int m_ProductNumber;
        private int m_UsbID;
        private int m_COM3BaudRate;
        private int m_COM3Mode;
        private int m_COM4BaudRate;
        private int m_COM4Mode;
        
        private string m_SerialNumber;
        private string m_MainBoardVersion;
        private string m_Unit;

        private DataStore.LanguageID m_Language;
        #endregion

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

        #region Property
        public bool IsDataBackup
        {
            get { return this.m_IsDataBackup; }
            set { this.m_IsDataBackup = value; }
        }

        public int EquipmentID
        {
            get { return this.m_EquipmentID; }
            set { this.m_EquipmentID = value; }
        } 
        public int DecimalPlaces
        {
            get { return this.m_DecimalPlaces; }
            set { this.m_DecimalPlaces = value; }
        }
        public int ProductNumber
        {
            get { return this.m_ProductNumber; }
            set { this.m_ProductNumber = value; }
        }
        public int UsbID
        {
            get { return this.m_UsbID; }
            set { this.m_UsbID = value; }
        }
        public int COM3BaudRate
        {
            get { return this.m_COM3BaudRate; }
            set { this.m_COM3BaudRate = value; }
        }
        public int COM3Mode
        {
            get { return this.m_COM3Mode; }
            set { this.m_COM3Mode = value; }
        }
        public int COM4BaudRate
        {
            get { return this.m_COM4BaudRate; }
            set { this.m_COM4BaudRate = value; }
        }
        public int COM4Mode
        {
            get { return this.m_COM4Mode; }
            set { this.m_COM4Mode = value; }
        }

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

        public DataStore.LanguageID Language
        {
            get { return this.m_Language; }
            set { this.m_Language = value; }
        }
        #endregion

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

            this.EquipmentID = 1;
            this.DecimalPlaces = 1;
            this.ProductNumber = 1;
            this.UsbID = 1;
            this.COM3BaudRate = 0;
            this.COM3Mode = 0;
            this.COM4BaudRate = 0;
            this.COM4Mode = 0;

            this.SerialNumber = "23K0000";
            this.MainBoardVersion = "000";
            this.Unit = "g";

            this.Language = DataStore.LanguageID.Korean;
        }
        #endregion
    }
    #endregion
    #region StructSystemConfigurationItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem
    {
        public bool IsDataBackup;

        public int EquipmentID;
        public int DecimalPlaces;
        public int ProductNumber;
        public int UsbID;
        public int COM3BaudRate;
        public int COM3Mode;
        public int COM4BaudRate;
        public int COM4Mode;

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

        public DataStore.LanguageID Language;
        
        public bool DummyBool1;
        public bool DummyBool2;
        public bool DummyBool3;
        public bool DummyBool4;
        public bool DummyBool5;

        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;
        public int DummyInt4;
        public int DummyInt5;

        [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 = 100)]
        public string DummyString5;
    }
    #endregion

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

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

        private int m_OverRangeDeviation;
        private int m_UnderRangeDeviation;        

        private int m_ProgressBarMaximum;
        private int m_ProgressBarMinimum;

        private Collection<int> m_CollectionNormalDistributionRange;
        private Collection<int> m_CollectionNormalDistributionViewRange;
        #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.m_UnderRangeDeviation = this.UnderRangeInt - this.PassRangeInt;

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

                this.NormalDistributionRangeCalculation();
            }
        }
        public string OverRange
        {
            get { return this.m_OverRange; }
            set
            {
                this.m_OverRange = value;
                this.m_OverRangeDeviation = this.OverRangeInt - this.PassRangeInt;

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

        public int OverRangeDeviation
        {
            get { return this.m_OverRangeDeviation; }
            //set
            //{
            //    int iValue = 0;
                
            //    iValue = this.OverRangeInt - Math.Abs(value);
                
            //    this.m_OverRange = iValue.ToString();
            //    this.m_OverRangeDeviation = value;
            //}
        }
        public int UnderRangDeviation
        {
            get { return this.m_UnderRangeDeviation; }
            //set
            //{
            //    int iValue = 0;

            //    iValue = this.UnderRangeInt - Math.Abs(value);

            //    this.m_UnderRange = iValue.ToString();
            //    this.m_UnderRangeDeviation = value; 
            //}
        } 

        public int UnderRangeInt
        {
            get
            {
                if (this.UnderRange == null)
                    return -1;
                else
                    return int.Parse(this.UnderRange);
            }
        }
        public int PassRangeInt
        {
            get
            {
                if (this.PassRange == null)
                    return -1;
                else
                    return int.Parse(this.PassRange);
            }
        }
        public int OverRangeInt
        {
            get
            {
                if (this.OverRange == null)
                    return -1;
                else
                    return int.Parse(this.OverRange);
            }
        }
        public int TareRangeInt
        {
            get { return int.Parse(this.TareRange); }
        }

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

        public Collection<int> CollectionNormalDistributionRange
        {
            get { return this.m_CollectionNormalDistributionRange; }
            private set { this.m_CollectionNormalDistributionRange = value; }
        }
        public Collection<int> CollectionNormalDistributionViewRange
        {
            get { return this.m_CollectionNormalDistributionViewRange; }
            private set { this.m_CollectionNormalDistributionViewRange = value; }
        } 
        #endregion

        #region Method
        public void Initialization()
        {
            this.CollectionNormalDistributionRange = new Collection<int>();
            this.CollectionNormalDistributionRange.Clear();
            for (int i = 0; i < 8; i++)
                this.CollectionNormalDistributionRange.Add(0);

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

            this.Number = 1;
            this.Name = "ProductName 1";
            this.LotNo = "Lot 1";
            this.PassRange = "2000";
            this.UnderRange = "1000";
            this.OverRange = "3000";
            this.TareRange = "0";

            this.ProgressBarMinimum = 0;
            this.ProgressBarMaximum = 5000;
        }

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

        private void NormalDistributionRangeCalculation()
        {
            int overGap = 0, underGap = 0, gap = 0, gap1 = 0;

            if (this.OverRangeInt == -1 || this.PassRangeInt == -1 || this.UnderRangeInt == -1)
                return;

            overGap = this.OverRangeInt - this.PassRangeInt;
            underGap = this.PassRangeInt - this.UnderRangeInt;

            if (overGap > underGap)
                gap = overGap;
            else
                gap = underGap;

            gap1 = gap / 5;

            if (gap1 == 0)
                gap1 = gap;

            this.CollectionNormalDistributionViewRange[0] = gap1 * 12;
            this.CollectionNormalDistributionViewRange[1] = gap1 * 9;
            this.CollectionNormalDistributionViewRange[2] = gap1 * 6;
            this.CollectionNormalDistributionViewRange[3] = gap1 * 3;
            this.CollectionNormalDistributionViewRange[4] = 0;
            this.CollectionNormalDistributionViewRange[5] = gap1 * 3;
            this.CollectionNormalDistributionViewRange[6] = gap1 * 6;
            this.CollectionNormalDistributionViewRange[7] = gap1 * 9;
            this.CollectionNormalDistributionViewRange[8] = gap1 * 12;

            this.CollectionNormalDistributionRange[0] = this.PassRangeInt + (gap1 * 9) + 1;
            this.CollectionNormalDistributionRange[1] = this.PassRangeInt + (gap1 * 6) + 1;
            this.CollectionNormalDistributionRange[2] = this.PassRangeInt + (gap1 * 3) + 1;
            this.CollectionNormalDistributionRange[3] = this.PassRangeInt + gap1 + 1;
            this.CollectionNormalDistributionRange[4] = this.PassRangeInt - gap1 + 1;
            this.CollectionNormalDistributionRange[5] = this.PassRangeInt - (gap1 * 3) + 1;
            this.CollectionNormalDistributionRange[6] = this.PassRangeInt - (gap1 * 6) + 1;
            this.CollectionNormalDistributionRange[7] = this.PassRangeInt - (gap1 * 9) + 1;
        }
        #endregion
    }
    #endregion
    #region StructProductItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructProductItem
    {
        public int Number;

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

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

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

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
        public string DummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string DummyString4;
    }
    #endregion
    
    #region WeightData
    public class WeightData
    {
        #region Field
        private bool m_IsServoOff;
        private bool m_IsServoAlarm;
        private bool m_IsLoadCellError;
        private bool m_IsEntrySensorError;
        private bool m_IsInverterError;
        private bool m_IsEntrySensor1Error;
        private bool m_IsDrainSensorError;
        private bool m_IsEntrySensor2Error;
        private bool m_IsServoTorqueError;
        private bool m_IsPressureSensingError;
        private bool m_IsMetalError;

        private DateTime m_StartTime;
        private DateTime m_StopTime;

        private int m_UnderCount;
        private double m_UnderSumWeight;
        
        private int m_PassCount;
        private double m_PassSumWeight;
        
        private int m_OverCount;
        private double m_OverSumWeight;
        
        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 Collection<int> m_CollectionNormalDistributionCount;

        private string m_PassAlarmCount;
        #endregion

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

        #region Property
        public bool IsServoOff
        {
            get { return this.m_IsServoOff; }
            set { this.m_IsServoOff = value; }
        }
        public bool IsServoAlarm
        {
            get { return this.m_IsServoAlarm; }
            set { this.m_IsServoAlarm = value; }
        }
        public bool IsLoadCellError
        {
            get { return this.m_IsLoadCellError; }
            set { this.m_IsLoadCellError = value; }
        }
        public bool IsEntrySensorError
        {
            get { return this.m_IsEntrySensorError; }
            set { this.m_IsEntrySensorError = value; }
        }
        public bool IsInverterError
        {
            get { return this.m_IsInverterError; }
            set { this.m_IsInverterError = value; }
        }
        public bool IsEntrySensor1Error
        {
            get { return this.m_IsEntrySensor1Error; }
            set { this.m_IsEntrySensor1Error = value; }
        }
        public bool IsDrainSensorError
        {
            get { return this.m_IsDrainSensorError; }
            set { this.m_IsDrainSensorError = value; }
        }
        public bool IsEntrySensor2Error
        {
            get { return this.m_IsEntrySensor2Error; }
            set { this.m_IsEntrySensor2Error = value; }
        }
        public bool IsServoTorqueError
        {
            get { return this.m_IsServoTorqueError; }
            set { this.m_IsServoTorqueError = value; }
        }
        public bool IsPressureSensingError
        {
            get { return this.m_IsPressureSensingError; }
            set { this.m_IsPressureSensingError = value; }
        }
        public bool IsMetalError
        {
            get { return this.m_IsMetalError; }
            set { this.m_IsMetalError = value; }
        } 

        public DateTime StartTime
        {
            get { return this.m_StartTime; }
            set { this.m_StartTime = value; }
        }
        public DateTime StopTime
        {
            get { return this.m_StopTime; }
            set { this.m_StopTime = value; }
        } 

        public int UnderCount
        {
            get { return this.m_UnderCount; }
            set { this.m_UnderCount = value; }
        }
        public double UnderSumWeight
        {
            get { return this.m_UnderSumWeight; }
            set { this.m_UnderSumWeight = 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 double UnderAverage
        {
            get
            {
                double ret = 0.0;

                if (this.UnderCount == 0 || this.UnderSumWeight == 0.0)
                    ret = 0.0;
                else
                    ret = this.UnderSumWeight / this.UnderCount;

                return ret;
            }
        }
        public string UnderSumWeightKG
        {
            get 
            {
                string temp = "", ret = "";

                temp = string.Format("{0:f0}", this.UnderSumWeight);
                ret = string.Format("{0}", int.Parse(temp) / 1000);

                return ret;
            }
        }

        public int PassCount
        {
            get { return this.m_PassCount; }
            set { this.m_PassCount = value; }
        }
        public double PassSumWeight
        {
            get { return this.m_PassSumWeight; }
            set { this.m_PassSumWeight = 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 double PassAverage
        {
            get 
            {
                double ret = 0.0;

                if (this.PassCount == 0 || this.PassSumWeight == 0.0)
                    ret = 0.0;
                else
                    ret = this.PassSumWeight / this.PassCount;

                return ret;
            }
        }
        public string PassSumWeightKG
        {
            get
            {
                string temp = "", ret = "";

                temp = string.Format("{0:f0}", this.PassSumWeight);
                ret = string.Format("{0}", int.Parse(temp) / 1000);

                return ret;
            }
        }

        public int OverCount
        {
            get { return this.m_OverCount; }
            set { this.m_OverCount = value; }
        }
        public double OverSumWeight
        {
            get { return this.m_OverSumWeight; }
            set { this.m_OverSumWeight = 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 double OverAverage
        {
            get 
            {
                double ret = 0.0;

                if (this.OverCount == 0 || this.OverSumWeight == 0.0)
                    ret = 0.0;
                else
                    ret = this.OverSumWeight / this.OverCount;

                return ret;
            }
        }
        public string OverSumWeightKG
        {
            get
            {
                string temp = "", ret = "";

                temp = string.Format("{0:f0}", this.OverSumWeight);
                ret = string.Format("{0}", int.Parse(temp) / 1000);

                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 TotalNGCount1
        {
            get { return this.UnderCount + this.OverCount; }
        }

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

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

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

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

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

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

        public Collection<int> CollectionNormalDistributionCount
        {
            get { return this.m_CollectionNormalDistributionCount; }
            set { this.m_CollectionNormalDistributionCount = value; }
        }

        public string PassAlarmCount
        {
            get { return this.m_PassAlarmCount; }
            set { this.m_PassAlarmCount = value; }
        }         
        #endregion

        #region Mehtod
        public void ClearCount()
        {
            this.UnderCount = 0;
            this.UnderSumWeight = 0.0;
            this.PassCount = 0;
            this.PassSumWeight = 0.0;
            this.OverCount = 0;
            this.OverSumWeight = 0.0;
            this.ExNGCount = 0;

            this.StartTime = new DateTime(1111, 11, 11, 11, 11, 11);
            this.StopTime = new DateTime(1111, 11, 11, 11, 11, 11);

            for (int i = 0; i < this.CollectionNormalDistributionCount.Count; i++)
                this.CollectionNormalDistributionCount[i] = 0;
        }

        private void Initialization()
        {
            this.IsServoOff = false;
            this.IsServoAlarm = false;
            this.IsLoadCellError = false;
            this.IsEntrySensorError = false;
            this.IsInverterError = false;
            this.IsEntrySensor1Error = false;
            this.IsDrainSensorError = false;
            this.IsEntrySensor2Error = false;
            this.IsServoTorqueError = false;
            this.IsPressureSensingError = false;
            this.IsMetalError = false;
            this.StartTime = new DateTime(1111, 11, 11, 11, 11, 11);
            this.StopTime = new DateTime(1111, 11, 11, 11, 11, 11);
            this.UnderCount = 0;
            this.UnderSumWeight = 0.0;
            this.PassCount = 0;
            this.PassSumWeight = 0.0;
            this.OverCount = 0;
            this.OverSumWeight = 0.0;
            this.ExNGCount = 0;
            this.Weight = 0.0;
            this.ADCValue = "12345";
            this.JudgmentStatus = DataStore.JudgmentStatus.Empty;
            this.Status = DataStore.WeightStatus.Empty;
            this.ProductionSpeed = 0;
            this.WeightString = "0";
            this.PassAlarmCount = "0";

            this.CollectionNormalDistributionCount = new Collection<int>();
            this.CollectionNormalDistributionCount.Clear();
            for (int i = 0; i < 10; i++)
                this.CollectionNormalDistributionCount.Add(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;
            }
        }

        public void WeightSum(DataStore.JudgmentStatus status)
        {
            if (status == DataStore.JudgmentStatus.Over)
                this.OverSumWeight += this.Weight;
            else if (status == DataStore.JudgmentStatus.Pass)
                this.PassSumWeight += this.Weight;
            else if (status == DataStore.JudgmentStatus.Under)
                this.UnderSumWeight += this.Weight;
        }

        public void SetNormalDistribution(Collection<int> collectionRange, string weight)
        {
            int value = 0;

            value = int.Parse(weight);

            for (int i = 0; i < this.CollectionNormalDistributionCount.Count; i++)
            {
                if (i == collectionRange.Count)
                {
                    this.CollectionNormalDistributionCount[i]++;
                    break;
                }

                if (collectionRange[i] < value)
                {
                    this.CollectionNormalDistributionCount[i]++;
                    break;
                }
            }
        }
        #endregion
    }
    #endregion
    #region StructCounter
    [StructLayout(LayoutKind.Sequential)]
    public struct StructCounterItem
    {
        public int OverCount;
        public int PassCount;
        public int UnderCount;
        public int ExNGCount;

        public int NormalDistribution1;
        public int NormalDistribution2;
        public int NormalDistribution3;
        public int NormalDistribution4;
        public int NormalDistribution5;
        public int NormalDistribution6;
        public int NormalDistribution7;
        public int NormalDistribution8;
        public int NormalDistribution9;
        public int NormalDistribution10;

        public double OverSumWeight;
        public double PassSumWeight;
        public double UnderSumWeight;

        public DateTime StartTime;
        public DateTime StopTime;

        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;
        public int DummyInt4;
        public int DummyInt5;
    }
    #endregion

    #region JudgmentSetItem
    public class JudgmentSetItem
    {
        #region Field
        private int m_Filter;
        private int m_DownDelayTime;
        private int m_JudgmentDelayTime;
        private int m_UpDelayTime;
        private int m_JudgmentCount;
        private int m_FeedSpeed;
        private double m_DynamicCorrection;

        private int m_Sorter1Mode;
        private int m_Sorter1DelayTime;
        private int m_Sorter1RunTime;
        private int m_Sorter2Mode;
        private int m_Sorter2DelayTime;
        private int m_Sorter2RunTime;
        #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 DownDelayTime
        {
            get { return this.m_DownDelayTime; }
            set { this.m_DownDelayTime = value; }
        }
        public int JudgmentDelayTime
        {
            get { return this.m_JudgmentDelayTime; }
            set { this.m_JudgmentDelayTime = value; }
        }
        public int UpDelayTime
        {
            get { return this.m_UpDelayTime; }
            set { this.m_UpDelayTime = 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 double DynamicCorrection
        {
            get { return this.m_DynamicCorrection; }
            set { this.m_DynamicCorrection = value; }
        }

        public int Sorter1Mode
        {
            get { return this.m_Sorter1Mode; }
            set { this.m_Sorter1Mode = value; }
        }
        public int Sorter1DelayTime
        {
            get { return this.m_Sorter1DelayTime; }
            set { this.m_Sorter1DelayTime = value; }
        }
        public int Sorter1RunTime
        {
            get { return this.m_Sorter1RunTime; }
            set { this.m_Sorter1RunTime = value; }
        }
        public int Sorter2Mode
        {
            get { return this.m_Sorter2Mode; }
            set { this.m_Sorter2Mode = 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; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.Filter = 8;
            this.DownDelayTime = 500;
            this.JudgmentDelayTime = 500;
            this.UpDelayTime = 500;
            this.JudgmentCount = 10;
            this.FeedSpeed = 60;
            this.DynamicCorrection = 1.000000;

            this.Sorter1Mode = 0;
            this.Sorter1DelayTime = 1;
            this.Sorter1RunTime = 1000;
            this.Sorter2Mode = 0;
            this.Sorter2DelayTime = 1;
            this.Sorter2RunTime = 1000;
        }
        #endregion
    }
    #endregion
    #region Struct JudgmentSetItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructJudgmentSetItem
    {
        public int Filter;
        public int DownDelayTime;
        public int JudgmentDelayTime;
        public int UpDelayTime;
        public int JudgmentCount;
        public int FeedSpeed;
        public double DynamicCorrection;

        public int Sorter1Mode;
        public int Sorter1DelayTime;
        public int Sorter1RunTime;
        public int Sorter2Mode;
        public int Sorter2DelayTime;
        public int Sorter2RunTime;

        public int DummyInt1;
        public int DummyInt2;
        public int DummyInt3;
        public int DummyInt4;
        public int DummyInt5;

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

    #region CalibrationItem
    public class CalibrationItem
    {
        #region Field
        private string m_BalanceWeight;
        private string m_MaxWeight;
        private string m_Digit;
        private string m_Constant;
        #endregion

        #region Constructor
        public CalibrationItem()
        {
            this.BalanceWeight = "5000";
            this.MaxWeight = "9999";
            this.Digit = "1";
            this.Constant = "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 Constant
        {
            get { return this.m_Constant; }
            set { this.m_Constant = value; }
        }
        #endregion
    }
    #endregion

    #region SystemParameter1
    public class SystemParameter1
    {
        #region Field
        private string m_Serial1Mode;
        private string m_Serial1BaudRate;
        private string m_BuzzerOnTime;
        private string m_RelayOnTime;
        private string m_Chattering;
        private string m_SorterDoubleEntry;
        private string m_SorterExternalNgInput;
        private string m_StopWeighing;
        private string m_ExternalOperation;
        private string m_InitialDrive;
        private string m_PressureSensing;
        private string m_StackSensing;
        private string m_SorterDetecting;
        private string m_OptionBoard;
        private string m_PassAlarmCount;
        private string m_DrainConveyorDelayTime;
        private string m_DrainConveyorRunTime;

        private string m_Dummy4;
        private string m_Dummy5;
        private string m_Dummy6;
        #endregion

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

        #region Property
        public string Serial1Mode
        {
            get { return this.m_Serial1Mode; }
            set { this.m_Serial1Mode = value; }
        }
        public string Serial1BaudRate
        {
            get { return this.m_Serial1BaudRate; }
            set { this.m_Serial1BaudRate = value; }
        } 
        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 SorterDoubleEntry
        {
            get { return this.m_SorterDoubleEntry; }
            set { this.m_SorterDoubleEntry = value; }
        }
        public string SorterExternalNgInput
        {
            get { return this.m_SorterExternalNgInput; }
            set { this.m_SorterExternalNgInput = value; }
        }
        public string StopWeighing
        {
            get { return this.m_StopWeighing; }
            set { this.m_StopWeighing = value; }
        }
        public string ExternalOperation
        {
            get { return this.m_ExternalOperation; }
            set { this.m_ExternalOperation = value; }
        }
        public string InitialDrive
        {
            get { return this.m_InitialDrive; }
            set { this.m_InitialDrive = value; }
        }
        public string PressureSensing
        {
            get { return this.m_PressureSensing; }
            set { this.m_PressureSensing = value; }
        }
        public string StackSensing
        {
            get { return this.m_StackSensing; }
            set { this.m_StackSensing = value; }
        }
        public string SorterDetecting
        {
            get { return this.m_SorterDetecting; }
            set { this.m_SorterDetecting = value; }
        }
        public string OptionBoard
        {
            get { return this.m_OptionBoard; }
            set { this.m_OptionBoard = value; }
        }
        public string PassAlarmCount
        {
            get { return this.m_PassAlarmCount; }
            set { this.m_PassAlarmCount = value; }
        }

        public string DrainConveyorDelayTime
        {
            get { return this.m_DrainConveyorDelayTime; }
            set { this.m_DrainConveyorDelayTime = value; }
        }
        public string DrainConveyorRunTime
        {
            get { return this.m_DrainConveyorRunTime; }
            set { this.m_DrainConveyorRunTime = value; }
        }

        public string Dummy4
        {
            get { return this.m_Dummy4; }
            set { this.m_Dummy4 = value; }
        }
        public string Dummy5
        {
            get { return this.m_Dummy5; }
            set { this.m_Dummy5 = value; }
        }
        public string Dummy6
        {
            get { return this.m_Dummy6; }
            set { this.m_Dummy6 = value; }
        } 
        #endregion

        #region Method
        private void Initialization()
        {
            this.Serial1Mode = "0";
            this.Serial1BaudRate = "0";
            this.BuzzerOnTime = "0";
            this.RelayOnTime = "0";
            this.Chattering = "0";
            this.SorterDoubleEntry = "0";
            this.SorterExternalNgInput = "0";
            this.StopWeighing = "0";
            this.ExternalOperation = "0";
            this.InitialDrive = "0";
            this.PressureSensing = "0";
            this.StackSensing = "0";
            this.SorterDetecting = "0";
            this.OptionBoard = "0";
            this.PassAlarmCount = "0";
            this.DrainConveyorDelayTime = "0";
            this.DrainConveyorRunTime = "0";

            this.Dummy4 = "0";
            this.Dummy5 = "0";
            this.Dummy6 = "0";
        }
        #endregion
    } 
    #endregion
    #region SystemParameter2
    public class SystemParameter2
    {
        #region Field
        private string m_OPT1SamplingCount;
        private string m_OPT1DelayCount;
        private string m_OPT1PulseWidth;
        private string m_OPT1IsWeightSetting;
        private string m_OPT1OverRange;
        private string m_OPT1UnderRange;
        private string m_OPT1Port;

        private string m_OPT2Port;
        private string m_OPT2DelayTime;
        private string m_OPT2RunTime;

        private string m_Dummy1;
        private string m_Dummy2;
        private string m_Dummy3;
        private string m_Dummy4; 
        private string m_Dummy5;
        private string m_Dummy6;
        private string m_Dummy7;
        #endregion

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

        #region Property
        public string OPT1SamplingCount
        {
            get { return this.m_OPT1SamplingCount; }
            set { this.m_OPT1SamplingCount = value; }
        }
        public string OPT1DelayCount
        {
            get { return this.m_OPT1DelayCount; }
            set { this.m_OPT1DelayCount = value; }
        }
        public string OPT1PulseWidth
        {
            get { return this.m_OPT1PulseWidth; }
            set { this.m_OPT1PulseWidth = value; }
        }
        public string OPT1IsWeightSetting
        {
            get { return this.m_OPT1IsWeightSetting; }
            set { this.m_OPT1IsWeightSetting = value; }
        }
        public string OPT1OverRange
        {
            get { return this.m_OPT1OverRange; }
            set { this.m_OPT1OverRange = value; }
        }
        public string OPT1UnderRange
        {
            get { return this.m_OPT1UnderRange; }
            set { this.m_OPT1UnderRange = value; }
        } 
        public string OPT1Port
        {
            get { return this.m_OPT1Port; }
            set { this.m_OPT1Port = value; }
        }

        public string OPT2Port
        {
            get { return this.m_OPT2Port; }
            set { this.m_OPT2Port = value; }
        }
        public string OPT2DelayTime
        {
            get { return this.m_OPT2DelayTime; }
            set { this.m_OPT2DelayTime = value; }
        }
        public string OPt2RunTime
        {
            get { return this.m_OPT2RunTime; }
            set { this.m_OPT2RunTime = value; }
        }

        public string Dummy1
        {
            get { return this.m_Dummy1; }
            set { this.m_Dummy1 = value; }
        }
        public string Dummy2
        {
            get { return this.m_Dummy2; }
            set { this.m_Dummy2 = value; }
        }
        public string Dummy3
        {
            get { return this.m_Dummy3; }
            set { this.m_Dummy3 = value; }
        }
        public string Dummy4
        {
            get { return this.m_Dummy4; }
            set { this.m_Dummy4 = value; }
        }
        public string Dummy5
        {
            get { return this.m_Dummy5; }
            set { this.m_Dummy5 = value; }
        }
        public string Dummy6
        {
            get { return this.m_Dummy6; }
            set { this.m_Dummy6 = value; }
        }
        public string Dummy7
        {
            get { return this.m_Dummy7; }
            set { this.m_Dummy7 = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.OPT1SamplingCount = "0";
            this.OPT1DelayCount = "0";
            this.OPT1PulseWidth = "0";
            this.OPT1IsWeightSetting = "0";
            this.OPT1OverRange = "0";
            this.OPT1UnderRange = "0";
            this.OPT1Port = "0";

            this.OPT2Port = "0";
            this.OPT2DelayTime = "0";
            this.OPt2RunTime = "0";

            this.Dummy1 = "0";
            this.Dummy2 = "0";
            this.Dummy3 = "0";
            this.Dummy4 = "0";
            this.Dummy5 = "0";
            this.Dummy6 = "0";
            this.Dummy7 = "0";
        }
        #endregion
    } 
    #endregion
    #region SystemParameter3
    public class SystemParameter3
    {
        #region Field
        private string m_ExternalOut1Mode;
        private string m_ExternalOut1DelayTime;
        private string m_ExternalOut1RunTime;

        private string m_ExternalOut2Mode;
        private string m_ExternalOut2DelayTime;
        private string m_ExternalOut2RunTime;

        private string m_ExternalOut3Mode;
        private string m_ExternalOut3DelayTime;
        private string m_ExternalOut3RunTime;

        private string m_ExternalOut4Mode;
        private string m_ExternalOut4DelayTime;
        private string m_ExternalOut4RunTime;

        private string m_ExternalOut9Mode;
        private string m_ExternalOut9DelayTime;
        private string m_ExternalOut9RunTime;

        private string m_ExternalOut10Mode;
        private string m_ExternalOut10DelayTime;
        private string m_ExternalOut10RunTime;

        private string m_Dummy1;
        private string m_Dummy2;
        #endregion

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

        #region Property
        public string ExternalOut1Mode
        {
            get { return this.m_ExternalOut1Mode; }
            set { this.m_ExternalOut1Mode = value; }
        }
        public string ExternalOut1DelayTime
        {
            get { return this.m_ExternalOut1DelayTime; }
            set { this.m_ExternalOut1DelayTime = value; }
        }
        public string ExternalOut1RunTime
        {
            get { return this.m_ExternalOut1RunTime; }
            set { this.m_ExternalOut1RunTime = value; }
        }

        public string ExternalOut2Mode
        {
            get { return this.m_ExternalOut2Mode; }
            set { this.m_ExternalOut2Mode = value; }
        }
        public string ExternalOut2DelayTime
        {
            get { return this.m_ExternalOut2DelayTime; }
            set { this.m_ExternalOut2DelayTime = value; }
        }
        public string ExternalOut2RunTime
        {
            get { return this.m_ExternalOut2RunTime; }
            set { this.m_ExternalOut2RunTime = value; }
        }

        public string ExternalOut3Mode
        {
            get { return this.m_ExternalOut3Mode; }
            set { this.m_ExternalOut3Mode = value; }
        }
        public string ExternalOut3DelayTime
        {
            get { return this.m_ExternalOut3DelayTime; }
            set { this.m_ExternalOut3DelayTime = value; }
        }
        public string ExternalOut3RunTime
        {
            get { return this.m_ExternalOut3RunTime; }
            set { this.m_ExternalOut3RunTime = value; }
        }

        public string ExternalOut4Mode
        {
            get { return this.m_ExternalOut4Mode; }
            set { this.m_ExternalOut4Mode = value; }
        }
        public string ExternalOut4DelayTime
        {
            get { return this.m_ExternalOut4DelayTime; }
            set { this.m_ExternalOut4DelayTime = value; }
        }
        public string ExternalOut4RunTime
        {
            get { return this.m_ExternalOut4RunTime; }
            set { this.m_ExternalOut4RunTime = value; }
        }

        public string ExternalOut9Mode
        {
            get { return this.m_ExternalOut9Mode; }
            set { this.m_ExternalOut9Mode = value; }
        }
        public string ExternalOut9DelayTime
        {
            get { return this.m_ExternalOut9DelayTime; }
            set { this.m_ExternalOut9DelayTime = value; }
        }
        public string ExternalOut9RunTime
        {
            get { return this.m_ExternalOut9RunTime; }
            set { this.m_ExternalOut9RunTime = value; }
        }

        public string ExternalOut10Mode
        {
            get { return this.m_ExternalOut10Mode; }
            set { this.m_ExternalOut10Mode = value; }
        }
        public string ExternalOut10DelayTime
        {
            get { return this.m_ExternalOut10DelayTime; }
            set { this.m_ExternalOut10DelayTime = value; }
        }
        public string ExternalOut10RunTime
        {
            get { return this.m_ExternalOut10RunTime; }
            set { this.m_ExternalOut10RunTime = value; }
        }

        public string Dummy1
        {
            get { return this.m_Dummy1; }
            set { this.m_Dummy1 = value; }
        }
        public string Dummy2
        {
            get { return this.m_Dummy2; }
            set { this.m_Dummy2 = value; }
        }
        #endregion

        #region Method
        private void Initialization()
        {
            this.ExternalOut1Mode = "0";
            this.ExternalOut1DelayTime = "0";
            this.ExternalOut1RunTime = "0";

            this.ExternalOut2Mode = "0";
            this.ExternalOut2DelayTime = "0";
            this.ExternalOut2RunTime = "0";

            this.ExternalOut3Mode = "0";
            this.ExternalOut3DelayTime = "0";
            this.ExternalOut3RunTime = "0";

            this.ExternalOut4Mode = "0";
            this.ExternalOut4DelayTime = "0";
            this.ExternalOut4RunTime = "0";

            this.ExternalOut9Mode = "0";
            this.ExternalOut9DelayTime = "0";
            this.ExternalOut9RunTime = "0";

            this.ExternalOut10Mode = "0";
            this.ExternalOut10DelayTime = "0";
            this.ExternalOut10RunTime = "0";

            this.Dummy1 = "0";
            this.Dummy2 = "0";
        }
        #endregion
    } 
    #endregion
    #region SystemParameter4
    public class SystemParameter4
    {
        #region Field
        private string m_AutoZero1Range;
        private string m_AutoZero1Time;
        private string m_AutoZero1Variate;
        private string m_AutoZero1Mode;

        private string m_AutoZero2Mode;
        private string m_AutoZero2Range;
        private string m_AutoZero2Time;
        private string m_AutoZero2Variate;

        private string m_Dummy1;
        private string m_Dummy2;
        private string m_Dummy3;
        private string m_Dummy4;
        private string m_Dummy5;
        private string m_Dummy6;
        #endregion

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

        #region Property
        public string AutoZero1Range
        {
            get { return this.m_AutoZero1Range; }
            set { this.m_AutoZero1Range = value; }
        }
        public string AutoZero1Time
        {
            get { return this.m_AutoZero1Time; }
            set { this.m_AutoZero1Time = value; }
        }
        public string AutoZero1Variate
        {
            get { return this.m_AutoZero1Variate; }
            set { this.m_AutoZero1Variate = value; }
        }
        public string AutoZero1Mode
        {
            get { return this.m_AutoZero1Mode; }
            set { this.m_AutoZero1Mode = value; }
        } 

        public string AutoZero2Mode
        {
            get { return this.m_AutoZero2Mode; }
            set { this.m_AutoZero2Mode = value; }
        }
        public string AutoZero2Range
        {
            get { return this.m_AutoZero2Range; }
            set { this.m_AutoZero2Range = value; }
        }
        public string AutoZero2Time
        {
            get { return this.m_AutoZero2Time; }
            set { this.m_AutoZero2Time = value; }
        }
        public string AutoZero2Variate
        {
            get { return this.m_AutoZero2Variate; }
            set { this.m_AutoZero2Variate = value; }
        }

        public string Dummy1
        {
            get { return this.m_Dummy1; }
            set { this.m_Dummy1 = value; }
        }
        public string Dummy2
        {
            get { return this.m_Dummy2; }
            set { this.m_Dummy2 = value; }
        }
        public string Dummy3
        {
            get { return this.m_Dummy3; }
            set { this.m_Dummy3 = value; }
        }
        public string Dummy4
        {
            get { return this.m_Dummy4; }
            set { this.m_Dummy4 = value; }
        }
        public string Dummy5
        {
            get { return this.m_Dummy5; }
            set { this.m_Dummy5 = value; }
        }
        public string Dummy6
        {
            get { return this.m_Dummy6; }
            set { this.m_Dummy6 = value; }
        }
        #endregion

        #region Method
        private void Initialization()
        {
            this.AutoZero1Range = "0";
            this.AutoZero1Time = "0";
            this.AutoZero1Variate = "0";
            this.AutoZero1Mode = "0";

            this.AutoZero2Mode = "0";
            this.AutoZero2Range = "0";
            this.AutoZero2Time = "0";
            this.AutoZero2Variate = "0";

            this.Dummy1 = "0";
            this.Dummy2 = "0";
            this.Dummy3 = "0";
            this.Dummy4 = "0";
            this.Dummy5 = "0";
            this.Dummy6 = "0";
        }
        #endregion
    } 
    #endregion
 
    #region SystemStatus
    public class SystemStatus
    {
        #region Field
        private DataStore.EquipmentStatus m_Equipment;
        private DataStore.DisplayStore m_CurrentDisplay;
        private DataStore.DisplayMode m_CurrentMode;
        private DataStore.WeightInputMode m_CurrentWeightInputMode;

        private User m_CurrentUser;
        #endregion

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

        #region Property
        public DataStore.EquipmentStatus Equipment
        {
            get { return this.m_Equipment; }
            set { this.m_Equipment = value; }
        }
        public DataStore.DisplayStore CurrentDisplay
        {
            get { return this.m_CurrentDisplay; }
            set { this.m_CurrentDisplay = value; }
        }
        public DataStore.DisplayMode CurrentMode
        {
            get { return this.m_CurrentMode; }
            set { this.m_CurrentMode = value; }
        }
        public DataStore.WeightInputMode CurrentWeightInputMode
        {
            get { return this.m_CurrentWeightInputMode; }
            set { this.m_CurrentWeightInputMode = value; }
        }
       
        public User CurrentUser
        {
            get { return this.m_CurrentUser; }
            set { this.m_CurrentUser = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.Equipment = DataStore.EquipmentStatus.Stop;
            this.CurrentDisplay = DataStore.DisplayStore.MainDisplay;
            this.CurrentMode = DataStore.DisplayMode.Normal;
            this.CurrentWeightInputMode = DataStore.WeightInputMode.Weight;
            this.CurrentUser = new User();
        }
        #endregion
    }
    #endregion

    #region User
    public class User
    {
        #region Field
        private string m_Level1Password;
        private string m_Level2Password;
        private string m_Level3Password;
        private string m_Level4Password;

        private DataStore.UserGroup m_Group;
        #endregion

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

        #region Property
        public string Level1Password
        {
            get { return this.m_Level1Password; }
            set { this.m_Level1Password = value; }
        }
        public string Level2Password
        {
            get { return this.m_Level2Password; }
            set { this.m_Level2Password = value; }
        }
        public string Level3Password
        {
            get { return this.m_Level3Password; }
            set { this.m_Level3Password = value; }
        }
        public string Level4Password
        {
            get { return this.m_Level4Password; }
            set { this.m_Level4Password = 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.Group = DataStore.UserGroup.LogOff;
        }
        #endregion
    }
    #endregion
}
