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

using INT63DC_6CH.In_UserManager;

namespace INT63DC_6CH
{
    public class DataStore
    {
        #region Enum
        public enum FeedbackStatus
        {
            None,
            Positive,
            Negative,
        };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        public enum E_DataType
        {
            None,
            History,
            Inspection,
            Others,
        };
        public enum E_TrackingOperation
        {
            None,
            PowerOn,
            BootingComplete,
            EquipmentStart,
            EquipmentStop,
            Login,
            Logout,
            Calibration,
            Zero,
            Clear,
            UserEditor,
            Bypass,
            Update,
            FunctionUpdate,
            DataBackup,
            GroupEditor,

            BP_PassOnce,
            BP_NgOnce,
            BP_PassON,
            BP_PassOFF,
            BP_NgON,
            BP_NgOFF,
            MainCut,
            ProductCopy,
            ProductPaste,
            ProductAllPaste,
            Initialization,
            TryEthernetStart,
            TryEthernetStop,
            EthernetConnect,
            EthernetDisconnect,

            MotorOrigin,
            MotorAlarmReset,
            MotorStep,
            MotorJogCW,
            MotorJogCCW,
            MotorEEPROM,
        };
        public enum TrackingParameter
        {
            ProductNumber,
            WeightOverRange,
            WeightPassRange,
            WeightUnderRange,
            WeightTareRange,
            
            WeightOverRangeLimit,
            WeightUnderRangeLimit,
            WeightLimit_Activate,

            ChangeTime,
            ChangeName,
            ChangeLOT,

            BP_Individual,
            BP_Direction,
            BP_Mode,

            JudgmentDelayTime,
            JudgmentCount,
            TurnDelayTime,

            Sorter1DelayTime,
            Sorter1RunTime,
            Sorter2DelayTime,
            Sorter2RunTime,

            DischargeStopperDelayTime,
            DischargeStopperRunTime,
            EntryGateDelayTime,
            EntryGateRunTime,

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

            EtcChattering,
            EtcBuzzerRunTime,
            EtcRelayRunTime,
            EtcEmptyWeight,

            MotorOriginOffset,
            MotorOriginSpeed,
            MotorSpeed,
            MotorPosition0,
            MotorPosition1,
            MotorPosition2,
            MotorAcceleration,
            MotorDeceleration,

            Level1Name,
            Level2Name,
            Level3Name,
            AutoLogout,
            NumberOfLoginFailure,

            DataStoragePeriod,
        };
        public enum TrackingAlarm
        {
            None,
            a1_PressureError,
            a2_LoadcellError,
            a3_EntrySensorError,
            a4_ServoTorqueAlarm,
            a5_ServoAlarm,
            a6_ServoOff,
        };

        public enum _30000_ModbusAddress
        {
            DecimalPoint = 0,
            Operation_High = 40,
            Operation_Low = 41,
            UnderRange_High_Float = 1010,
            UnderRange_Low_Float = 1011,
            PassRange_High_Float = 1012,
            PassRange_Low_Float = 1013,
            OverRange_High_Float = 1014,
            OverRange_Low_Float = 1015,
            TareRange_High_Float = 1016,
            TareRange_Low_Float = 1017,
            HighLimit_High_Float = 1018,
            HighLimit_Low_Float = 1019,
            DeadZoneHighLimit_High_Float = 1020,
            DeadZoneHighLimit_Low_Float = 1021,
            DeadZoneLowLimit_High_Float = 1022,
            DeadZoneLowLimit_Low_Float = 1023,
            LowLimit_High_Float = 1024,
            LowLimit_Low_Float = 1025,
            SampleCount_High = 1026,
            SampleCount_Low = 1027,
            IgnoreCount_High = 1028,
            IgnoreCount_Low = 1029,
            UnderRange_High_Int = 1030,
            UnderRange_Low_Int = 1031,
            PassRange_High_Int = 1032,
            PassRange_Low_Int = 1033,
            OverRange_High_Int = 1034,
            OverRange_Low_Int = 1035,
            TareRange_High_Int = 1036,
            TareRange_Low_Int = 1037,
            HighLimit_High_Int = 1038,
            HighLimit_Low_Int = 1039,
            DeadZoneHighLimit_High_Int = 1040,
            DeadZoneHighLimit_Low_Int = 1041,
            DeadZoneLowLimit_High_Int = 1042,
            DeadZoneLowLimit_Low_Int = 1043,
            LowLimit_High_Int = 1044,
            LowLimit_Low_Int = 1045,

            _1_Update = 1200,
            _1_Grade = 1201,
            _1_Weight_High_Float = 1202,
            _1_Weight_Low_Float = 1203,
            _1_UnderCount_High = 1204,
            _1_UnderCount_Low = 1205,
            _1_PassCount_High = 1206,
            _1_PassCount_Low = 1207,
            _1_OverCount_High = 1208,
            _1_OverCount_Low = 1209,
            _1_NGCount_High = 1210,
            _1_NgCount_Low = 1211,
            _1_ExNGCount_High = 1212,
            _1_ExNgCount_Low = 1213,
            _1_TotalCount_High = 1214,
            _1_TotalCount_Low = 1215,
            _1_FeedbackWeight_High_Float = 1216,
            _1_FeedbackWeight_Low_Float = 1217,
            _1_FeedbackWeight_High_Int = 1218,
            _1_FeedbackWeight_Low_Int = 1219,
            _1_Weight_High_Int = 1220,
            _1_Weight_Low_Int = 1221,
            _1_UpdateFeedbackData = 1222,

            _2_Update = 1250,
            _2_Grade = 1251,
            _2_Weight_High_Float = 1252,
            _2_Weight_Low_Float = 1253,
            _2_UnderCount_High = 1254,
            _2_UnderCount_Low = 1255,
            _2_PassCount_High = 1256,
            _2_PassCount_Low = 1257,
            _2_OverCount_High = 1258,
            _2_OverCount_Low = 1259,
            _2_NGCount_High = 1260,
            _2_NgCount_Low = 1261,
            _2_ExNGCount_High = 1262,
            _2_ExNgCount_Low = 1263,
            _2_TotalCount_High = 1264,
            _2_TotalCount_Low = 1265,
            _2_FeedbackWeight_High_Float = 1266,
            _2_FeedbackWeight_Low_Float = 1267,
            _2_FeedbackWeight_High_Int = 1268,
            _2_FeedbackWeight_Low_Int = 1269,
            _2_Weight_High_Int = 1270,
            _2_Weight_Low_Int = 1271,
            _2_UpdateFeedbackData = 1272,

            _3_Update = 1300,
            _3_Grade = 1301,
            _3_Weight_High_Float = 1302,
            _3_Weight_Low_Float = 1303,
            _3_UnderCount_High = 1304,
            _3_UnderCount_Low = 1305,
            _3_PassCount_High = 1306,
            _3_PassCount_Low = 1307,
            _3_OverCount_High = 1308,
            _3_OverCount_Low = 1309,
            _3_NGCount_High = 1310,
            _3_NgCount_Low = 1311,
            _3_ExNGCount_High = 1312,
            _3_ExNgCount_Low = 1313,
            _3_TotalCount_High = 1314,
            _3_TotalCount_Low = 1315,
            _3_FeedbackWeight_High_Float = 1316,
            _3_FeedbackWeight_Low_Float = 1317,
            _3_FeedbackWeight_High_Int = 1318,
            _3_FeedbackWeight_Low_Int = 1319,
            _3_Weight_High_Int = 1320,
            _3_Weight_Low_Int = 1321,
            _3_UpdateFeedbackData = 1322,

            _4_Update = 1350,
            _4_Grade = 1351,
            _4_Weight_High_Float = 1352,
            _4_Weight_Low_Float = 1353,
            _4_UnderCount_High = 1354,
            _4_UnderCount_Low = 1355,
            _4_PassCount_High = 1356,
            _4_PassCount_Low = 1357,
            _4_OverCount_High = 1358,
            _4_OverCount_Low = 1359,
            _4_NGCount_High = 1360,
            _4_NgCount_Low = 1361,
            _4_ExNGCount_High = 1362,
            _4_ExNgCount_Low = 1363,
            _4_TotalCount_High = 1364,
            _4_TotalCount_Low = 1365,
            _4_FeedbackWeight_High_Float = 1366,
            _4_FeedbackWeight_Low_Float = 1367,
            _4_FeedbackWeight_High_Int = 1368,
            _4_FeedbackWeight_Low_Int = 1369,
            _4_Weight_High_Int = 1370,
            _4_Weight_Low_Int = 1371,
            _4_UpdateFeedbackData = 1372,

            _5_Update = 1400,
            _5_Grade = 1401,
            _5_Weight_High_Float = 1402,
            _5_Weight_Low_Float = 1403,
            _5_UnderCount_High = 1404,
            _5_UnderCount_Low = 1405,
            _5_PassCount_High = 1406,
            _5_PassCount_Low = 1407,
            _5_OverCount_High = 1408,
            _5_OverCount_Low = 1409,
            _5_NGCount_High = 1410,
            _5_NgCount_Low = 1411,
            _5_ExNGCount_High = 1412,
            _5_ExNgCount_Low = 1413,
            _5_TotalCount_High = 1414,
            _5_TotalCount_Low = 1415,
            _5_FeedbackWeight_High_Float = 1416,
            _5_FeedbackWeight_Low_Float = 1417,
            _5_FeedbackWeight_High_Int = 1418,
            _5_FeedbackWeight_Low_Int = 1419,
            _5_Weight_High_Int = 1420,
            _5_Weight_Low_Int = 1421,
            _5_UpdateFeedbackData = 1422,

            _6_Update = 1450,
            _6_Grade = 1451,
            _6_Weight_High_Float = 1452,
            _6_Weight_Low_Float = 1453,
            _6_UnderCount_High = 1454,
            _6_UnderCount_Low = 1455,
            _6_PassCount_High = 1456,
            _6_PassCount_Low = 1457,
            _6_OverCount_High = 1458,
            _6_OverCount_Low = 1459,
            _6_NGCount_High = 1460,
            _6_NgCount_Low = 1461,
            _6_ExNGCount_High = 1462,
            _6_ExNgCount_Low = 1463,
            _6_TotalCount_High = 1464,
            _6_TotalCount_Low = 1465,
            _6_FeedbackWeight_High_Float = 1466,
            _6_FeedbackWeight_Low_Float = 1467,
            _6_FeedbackWeight_High_Int = 1468,
            _6_FeedbackWeight_Low_Int = 1469,
            _6_Weight_High_Int = 1470,
            _6_Weight_Low_Int = 1471,
            _6_UpdateFeedbackData = 1472,

            _7_Update = 1500,
            _7_Grade = 1501,
            _7_Weight_High_Float = 1502,
            _7_Weight_Low_Float = 1503,
            _7_UnderCount_High = 1504,
            _7_UnderCount_Low = 1505,
            _7_PassCount_High = 1506,
            _7_PassCount_Low = 1507,
            _7_OverCount_High = 1508,
            _7_OverCount_Low = 1509,
            _7_NGCount_High = 1510,
            _7_NgCount_Low = 1511,
            _7_ExNGCount_High = 1512,
            _7_ExNgCount_Low = 1513,
            _7_TotalCount_High = 1514,
            _7_TotalCount_Low = 1515,
            _7_FeedbackWeight_High_Float = 1516,
            _7_FeedbackWeight_Low_Float = 1517,
            _7_FeedbackWeight_High_Int = 1518,
            _7_FeedbackWeight_Low_Int = 1519,
            _7_Weight_High_Int = 1520,
            _7_Weight_Low_Int = 1521,
            _7_UpdateFeedbackData = 1522,

            _8_Update = 1550,
            _8_Grade = 1551,
            _8_Weight_High_Float = 1552,
            _8_Weight_Low_Float = 1553,
            _8_UnderCount_High = 1554,
            _8_UnderCount_Low = 1555,
            _8_PassCount_High = 1556,
            _8_PassCount_Low = 1557,
            _8_OverCount_High = 1558,
            _8_OverCount_Low = 1559,
            _8_NGCount_High = 1560,
            _8_NgCount_Low = 1561,
            _8_ExNGCount_High = 1562,
            _8_ExNgCount_Low = 1563,
            _8_TotalCount_High = 1564,
            _8_TotalCount_Low = 1565,
            _8_FeedbackWeight_High_Float = 1566,
            _8_FeedbackWeight_Low_Float = 1567,
            _8_FeedbackWeight_High_Int = 1568,
            _8_FeedbackWeight_Low_Int = 1569,
            _8_Weight_High_Int = 1570,
            _8_Weight_Low_Int = 1571,
            _8_UpdateFeedbackData = 1572,

            _9_Update = 1600,
            _9_Grade = 1601,
            _9_Weight_High_Float = 1602,
            _9_Weight_Low_Float = 1603,
            _9_UnderCount_High = 1604,
            _9_UnderCount_Low = 1605,
            _9_PassCount_High = 1606,
            _9_PassCount_Low = 1607,
            _9_OverCount_High = 1608,
            _9_OverCount_Low = 1609,
            _9_NGCount_High = 1610,
            _9_NgCount_Low = 1611,
            _9_ExNGCount_High = 1612,
            _9_ExNgCount_Low = 1613,
            _9_TotalCount_High = 1614,
            _9_TotalCount_Low = 1615,
            _9_FeedbackWeight_High_Float = 1616,
            _9_FeedbackWeight_Low_Float = 1617,
            _9_FeedbackWeight_High_Int = 1618,
            _9_FeedbackWeight_Low_Int = 1619,
            _9_Weight_High_Int = 1620,
            _9_Weight_Low_Int = 1621,
            _9_UpdateFeedbackData = 1622,

            _10_Update = 1650,
            _10_Grade = 1651,
            _10_Weight_High_Float = 1652,
            _10_Weight_Low_Float = 1653,
            _10_UnderCount_High = 1654,
            _10_UnderCount_Low = 1655,
            _10_PassCount_High = 1656,
            _10_PassCount_Low = 1657,
            _10_OverCount_High = 1658,
            _10_OverCount_Low = 1659,
            _10_NGCount_High = 1660,
            _10_NgCount_Low = 1661,
            _10_ExNGCount_High = 1662,
            _10_ExNgCount_Low = 1663,
            _10_TotalCount_High = 1664,
            _10_TotalCount_Low = 1665,
            _10_FeedbackWeight_High_Float = 1666,
            _10_FeedbackWeight_Low_Float = 1667,
            _10_FeedbackWeight_High_Int = 1668,
            _10_FeedbackWeight_Low_Int = 1669,
            _10_Weight_High_Int = 1670,
            _10_Weight_Low_Int = 1671,
            _10_UpdateFeedbackData = 1672,

            _11_Update = 1700,
            _11_Grade = 1701,
            _11_Weight_High_Float = 1702,
            _11_Weight_Low_Float = 1703,
            _11_UnderCount_High = 1704,
            _11_UnderCount_Low = 1705,
            _11_PassCount_High = 1706,
            _11_PassCount_Low = 1707,
            _11_OverCount_High = 1708,
            _11_OverCount_Low = 1709,
            _11_NGCount_High = 1710,
            _11_NgCount_Low = 1711,
            _11_ExNGCount_High = 1712,
            _11_ExNgCount_Low = 1713,
            _11_TotalCount_High = 1714,
            _11_TotalCount_Low = 1715,
            _11_FeedbackWeight_High_Float = 1716,
            _11_FeedbackWeight_Low_Float = 1717,
            _11_FeedbackWeight_High_Int = 1718,
            _11_FeedbackWeight_Low_Int = 1719,
            _11_Weight_High_Int = 1720,
            _11_Weight_Low_Int = 1721,
            _11_UpdateFeedbackData = 1722,

            _12_Update = 1750,
            _12_Grade = 1751,
            _12_Weight_High_Float = 1752,
            _12_Weight_Low_Float = 1753,
            _12_UnderCount_High = 1754,
            _12_UnderCount_Low = 1755,
            _12_PassCount_High = 1756,
            _12_PassCount_Low = 1757,
            _12_OverCount_High = 1758,
            _12_OverCount_Low = 1759,
            _12_NGCount_High = 1760,
            _12_NgCount_Low = 1761,
            _12_ExNGCount_High = 1762,
            _12_ExNgCount_Low = 1763,
            _12_TotalCount_High = 1764,
            _12_TotalCount_Low = 1765,
            _12_FeedbackWeight_High_Float = 1766,
            _12_FeedbackWeight_Low_Float = 1767,
            _12_FeedbackWeight_High_Int = 1768,
            _12_FeedbackWeight_Low_Int = 1769,
            _12_Weight_High_Int = 1770,
            _12_Weight_Low_Int = 1771,
            _12_UpdateFeedbackData = 1772,
        };
        #endregion
    }

    #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 CalibrationInternalBalance = "Cca00";

        // 파라미터 쓰기
        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 Zero = "Cbz00";
        // 소거
        public static readonly string Clear = "Cbe00";
        // NG Signal
        public static readonly string NgSignal = "Cbn00";
        // Pass Signal
        public static readonly string PassSignal = "Cbm00";
        // 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 _1502_ProgramVersion = "1502";
        // 시스템설정 - 업데이트
        public static readonly string _1651_UpdateForMain = "1651";

        // 품목설정 - 품번
        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 _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";
        // 판정설정 - 선별기 모드 값
        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";
        // 판정설정 - 외부출력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 _9054_ParameterSystem = "9054";
        // 레시피 설정 모두 쓰기
        public static readonly string _9055_ParameterRecipe = "9055";
    }
    #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 UserPasswordType
    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
        // Extanal use
        private bool m_IsDataBackup;
        private bool m_IsEachNG;
        private bool m_IsLogin;
        private bool m_IsWeightViewForward;
        private bool m_IsDataStatistics;
        private bool m_IsPart11;
        private bool m_IsModbus;
        private bool m_IsFeedback;
        
        private int m_AutoLogoutTime;
        private int m_UsbID;
        private int m_ProductNumber;
        private int m_StoragePeriod;
        private int m_EquipmentColumns;
        private int m_Chattering;
        private int m_BuzzerRunTime;
        private int m_RelayRunTime;
        private int m_Sorter1Location;
        private int m_Sorter2Location;
        private int m_WeightLimitIgnoreCount;
        private int m_Serial3BaudRate;
        private int m_Serial3Mode;
        private int m_EthernetLocalPort;
        private int m_EthernetServerPort;
        private int m_EthernetMode;
        private int m_EthernetOperationMode;
        private int m_ModbusTcpAddress1;
        private int m_ModbusTcpAddress2;
        private int m_ModbusTcpStartAddress;
        private int m_NumberOfLoginFailures;
        private int m_FeedbackSampleCount;
        private int m_FeedbackIgnorePackages;

        private string m_Unit;
        private string m_EmptyWeight;
        private string m_SerialNumber;
        private string m_User_Level1_Name;
        private string m_User_Level2_Name;
        private string m_User_Level3_Name;
        private string m_EthernetServerAddress;
        private string m_MainBoardVersion;

        private DataStore.E_LanguageID m_Language;

        // Internal use
        private bool m_IsBypassMode;
        private bool m_IsBypassDirectionPass;
        private bool m_IsBypassOnce;
        private bool m_IsCutView;
        private bool m_IsWeightLimitEnable;

        private int m_DecimalPlaces;

        private DataStore.FormStore m_CurrentForm;
        private UserItem m_CurrentUser;
        #endregion

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

        #region Property
        // Extanal use
        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 IsLogin
        {
            get { return this.m_IsLogin; }
            set { this.m_IsLogin = value; }
        }
        public bool IsWeightViewForward
        {
            get { return this.m_IsWeightViewForward; }
            set { this.m_IsWeightViewForward = value; }
        }
        public bool IsDataStatistics
        {
            get { return this.m_IsDataStatistics; }
            set { this.m_IsDataStatistics = value; }
        }
        public bool IsPart11
        {
            get { return this.m_IsPart11; }
            set { this.m_IsPart11 = value; }
        }
        public bool IsModbus
        {
            get { return this.m_IsModbus; }
            set { this.m_IsModbus = value; }
        }
        public bool IsFeedback
        {
            get { return this.m_IsFeedback; }
            set { this.m_IsFeedback = value; }
        }

        public int UsbID
        {
            get { return this.m_UsbID; }
            set { this.m_UsbID = value; }
        }
        public int ProductNumber
        {
            get { return this.m_ProductNumber; }
            set { this.m_ProductNumber = value; }
        }
        public int StoragePeriod
        {
            get { return this.m_StoragePeriod; }
            set { this.m_StoragePeriod = value; }
        }
        public int EquipmentColumns
        {
            get { return this.m_EquipmentColumns; }
            set { this.m_EquipmentColumns = value; }
        }
        public int Chattering
        {
            get { return this.m_Chattering; }
            set { this.m_Chattering = value; }
        }
        public int BuzzerRunTime
        {
            get { return this.m_BuzzerRunTime; }
            set { this.m_BuzzerRunTime = value; }
        }
        public int RelayRunTime
        {
            get { return this.m_RelayRunTime; }
            set { this.m_RelayRunTime = 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 WeightLimitIgnoreCount
        {
            get { return this.m_WeightLimitIgnoreCount; }
            set { this.m_WeightLimitIgnoreCount = 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 EthernetLocalPort
        {
            get { return this.m_EthernetLocalPort; }
            set { this.m_EthernetLocalPort = value; }
        }
        public int EthernetServerPort
        {
            get { return this.m_EthernetServerPort; }
            set { this.m_EthernetServerPort = value; }
        }
        public int EthernetMode
        {
            get { return this.m_EthernetMode; }
            set { this.m_EthernetMode = value; }
        }
        public int EthernetOperationMode
        {
            get { return this.m_EthernetOperationMode; }
            set { this.m_EthernetOperationMode = value; }
        }
        public int 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 int AutoLogoutTime
        {
            get { return this.m_AutoLogoutTime; }
            set { this.m_AutoLogoutTime = value; }
        }
        public int NumberOfLoginFailures
        {
            get { return this.m_NumberOfLoginFailures; }
            set { this.m_NumberOfLoginFailures = value; }
        }
        public int FeedbackSampleCount
        {
            get { return this.m_FeedbackSampleCount; }
            set { this.m_FeedbackSampleCount = value; }
        }
        public int FeedbackIgnorePackages
        {
            get { return this.m_FeedbackIgnorePackages; }
            set { this.m_FeedbackIgnorePackages = value; }
        }

        public string Unit
        {
            get { return this.m_Unit; }
            set { this.m_Unit = value; }
        }
        public string EmptyWeight
        {
            get { return this.m_EmptyWeight; }
            set { this.m_EmptyWeight = value; }
        }
        public string SerialNumber
        {
            get { return this.m_SerialNumber; }
            set { this.m_SerialNumber = 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 string EthernetServerAddress
        {
            get { return this.m_EthernetServerAddress; }
            set { this.m_EthernetServerAddress = value; }
        }
        public string MainBoardVersion
        {
            get { return this.m_MainBoardVersion; }
            set { this.m_MainBoardVersion = value; }
        }

        public DataStore.E_LanguageID Language
        {
            get { return this.m_Language; }
            set { this.m_Language = value; }
        }

        // Intanal use
        public bool IsBypassMode
        {
            get { return this.m_IsBypassMode; }
            set { this.m_IsBypassMode = 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 IsCutView
        {
            get { return this.m_IsCutView; }
            set { this.m_IsCutView = value; }
        }
        public bool IsWeightLimitEnable
        {
            get { return this.m_IsWeightLimitEnable; }
            set { this.m_IsWeightLimitEnable = value; }
        }
        public bool IsEthernetEnable
        {
            get
            {
                if (this.EthernetOperationMode == 0)
                    return false;
                else
                    return true;
            }
        }

        public int DecimalPlaces
        {
            get { return this.m_DecimalPlaces; }
            set { this.m_DecimalPlaces = 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; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            // Extanal use
            this.IsDataBackup = false;
            this.IsEachNG = true;
            this.IsLogin = false;
            this.IsWeightViewForward = true;
            this.IsDataStatistics = false;
            this.IsPart11 = false;
            this.IsModbus = false;
            this.IsFeedback = false;

            this.UsbID = 1;
            this.ProductNumber = 1;
            this.StoragePeriod = 12;
            this.EquipmentColumns = 6;
            this.Chattering = 300;
            this.BuzzerRunTime = 500;
            this.RelayRunTime = 1000;
            this.Sorter1Location = 3;
            this.Sorter2Location = 5;
            this.WeightLimitIgnoreCount = 3;
            this.Serial3BaudRate = 0;
            this.Serial3Mode = 0;
            this.EthernetLocalPort = 5001;
            this.EthernetServerPort = 5002;
            this.EthernetMode = 0;
            this.EthernetOperationMode = 0;
            this.ModbusTcpAddress1 = 1000;
            this.ModbusTcpAddress2 = 1100;
            this.ModbusTcpStartAddress = 1010;
            this.AutoLogoutTime = 90;
            this.NumberOfLoginFailures = 5;
            this.FeedbackSampleCount = 10;
            this.FeedbackIgnorePackages = 5;

            this.Unit = "g";
            this.EmptyWeight = "0";
            this.SerialNumber = "26A0000";
            this.User_Level1_Name = "Level 1";
            this.User_Level2_Name = "Level 2";
            this.User_Level3_Name = "Level 3";
            this.EthernetServerAddress = "0.0.0.0";
            this.MainBoardVersion = "000";

            this.Language = DataStore.E_LanguageID.Korean;

            // Intanal use
            this.IsBypassMode = false;
            this.IsBypassDirectionPass = true;
            this.IsBypassOnce = true;
            this.IsCutView = false;
            this.IsWeightLimitEnable = true;

            this.DecimalPlaces = 2;

            this.CurrentForm = DataStore.FormStore.FormMainDisplay;
            this.CurrentUser = new UserItem();
            this.CurrentUser.Group = DataStore.UserGroup.NotLogin;
        }
        #endregion
    }
    #endregion
    #region Struct SystemConfiguration
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem
    {
        public bool IsDataBackup;
        public bool IsEachNG;
        public bool IsLogin;
        public bool IsWeightViewForward;
        public bool IsDataStatistics;
        public bool IsPart11;
        public bool IsModbus;
        public bool IsFeedback;
        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 int AutoLogoutTime;
        public int UsbID;
        public int ProductNumber;
        public int StoragePeriod;
        public int EquipmentColumns;
        public int Chattering;
        public int BuzzerRunTime;
        public int RelayRunTime;
        public int Sorter1Location;
        public int Sorter2Location;
        public int WeightLimitIgnoreCount;
        public int Serial3BaudRate;
        public int Serial3Mode;
        public int EthernetLocalPort;
        public int EthernetMode;
        public int EthernetOperationMode;
        public int EthernetServerPort;
        public int ModbusTcpAddress1;
        public int ModbusTcpAddress2;
        public int ModbusTcpStartAddress;
        public int NumberOfLoginFailures;
        public int FeedbackSampleCount;
        public int FeedbackIgnorePackages;
        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;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string Unit;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string EmptyWeight;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string SerialNumber;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string dummyString1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string dummyString2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string dummyString3;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string dummyString4;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
        public string dummyString5;
        [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 = 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 dummyString10;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string EthernetServerAddress;
   
        public DataStore.E_LanguageID Language;
    }
    #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 int m_ProductionSpeed;
        private string m_WeightString;
        private string m_Sign;
        private DataStore.WeightStatus m_Status;
        private DataStore.JudgmentStatus m_JudgmentStatus;

        private bool m_IsBypassMode;
        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; }
        }

        public int ProductionSpeed
        {
            get { return this.m_ProductionSpeed; }
            set { this.m_ProductionSpeed = value; }
        }
        /// <summary>
        /// 소수점 포함된 중량값
        /// </summary>
        private double Weight
        {
            get 
            {
                double ret = 0.0;

                ret = Helper.StringToWeight(this.WeightString, 2);

                return ret;
            }
        }
        /// <summary>
        /// 소수점 없는 중량값(INT) / 음수이면 0
        /// </summary>
        public int WeightInt
        {
            get
            {
                int ret = 0;

                if (this.Sign == "-")
                    ret = 0;
                else
                    ret = int.Parse(this.WeightString);

                return ret;
            }
        }
        /// <summary>
        /// 소수점 없는 중량값
        /// </summary>
        public string WeightString
        {
            get
            {
                string ret = "";

                if (this.Sign == "-")
                    ret = "-" + this.m_WeightString;
                else
                    ret = this.m_WeightString;

                return ret;
            }
            set { this.m_WeightString = value; }
            //get { return this.m_WeightString; }
            //set { this.m_WeightString = value; }
        }
        public string Sign
        {
            get { return this.m_Sign; }
            set { this.m_Sign = value; }
        }
        public DataStore.WeightStatus Status
        {
            get { return this.m_Status; }
            set { this.m_Status = value; }
        }
        public DataStore.JudgmentStatus JudgmentStatus
        {
            get { return this.m_JudgmentStatus; }
            set
            {
                this.m_JudgmentStatus = value;

                //this.ProductionSpeedCalculation();

                if (value == DataStore.JudgmentStatus.Under)
                {
                    if (this.UnderCount < 10000000)
                        this.UnderCount++;
                    else
                        this.UnderCount = 0;
                }
                else if (value == DataStore.JudgmentStatus.Pass || value == DataStore.JudgmentStatus.BP_Individual || value == DataStore.JudgmentStatus.BP_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 || value == DataStore.JudgmentStatus.BP_NG)
                {
                    if (this.ExNGCount < 10000000)
                        this.ExNGCount++;
                    else
                        this.ExNGCount = 0;
                }
            }
        }

        public bool IsBypassMode
        {
            get { return m_IsBypassMode; }
            set { m_IsBypassMode = 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.ProductionSpeed = 0;
            this.WeightString = "0";
            this.Sign = "";
            this.Status = DataStore.WeightStatus.WeightZero;
            this.JudgmentStatus = DataStore.JudgmentStatus.None;

            this.IsBypassMode = false;
            this.IsSamplingData = false;
            this.UpdateCount = 0;
        }
        #endregion
    }
    #endregion
    #region Struct Counter
    [StructLayout(LayoutKind.Sequential)]
    public struct StructCounter
    {
        public int OverCount1;
        public int PassCount1;
        public int UnderCount1;
        public int ExNGCount1;

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

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

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

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

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

        public int 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 JudgmentSetItem
    public class JudgmentSetItem
    {
        #region Field
        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_EntryGateDelayTime;
        private int m_EntryGateRunTime;
        private int m_DischargeStopperDelayTime;
        private int m_DischargeStopperRunTime;
        #endregion

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

        #region Property
        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 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; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.JudgmentDelayTime = 1000;
            this.JudgmentCount = 10;
            this.FeedSpeed = 2300;
            this.TurnDelayTime = 0;
            this.Sorter1DelayTime = 500;
            this.Sorter1RunTime = 1000;
            this.Sorter2DelayTime = 500;
            this.Sorter2RunTime = 1000;
            this.EntryGateDelayTime = 500;
            this.EntryGateRunTime = 1000;
            this.DischargeStopperDelayTime = 500;
            this.DischargeStopperRunTime = 1000;
        }
        #endregion
    }
    #endregion
    #region Struct JudgmentSetItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructJudgmentSetItem
    {
        public int JudgmentDelayTime;
        public int JudgmentCount;
        public int FeedSpeed;
        public int TurnDelayTime;
        public int Sorter1RunTime;
        public int Sorter1DelayTime;
        public int Sorter2RunTime;
        public int Sorter2DelayTime;
        public int EntryGateDelayTime;
        public int EntryGateRunTime;
        public int DischargeStopperDelayTime;
        public int DischargeStopperRunTime;

        [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 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_IsPinchPoint;

        private bool m_IsBuzzerStatus;
        #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 IsPinchPoint
        {
            get { return this.m_IsPinchPoint; }
            set { this.m_IsPinchPoint = 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.IsPinchPoint = 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')
            {
                this.IsPinchPoint = false;
                this.IsBuzzerStatus = false;
            }
            else
                this.IsPinchPoint = true;
            #endregion
            #region 알람 15-
            if (sValue4[1] == '0')
            { }
            else
            { }
            #endregion
            #region 알람 14-
            if (sValue4[2] == '0')
            { }
            else
            { }
            #endregion
            #region 알람 13-
            if (sValue4[3] == '0')
            { }
            else
            { }
            #endregion

            #region 알람 12-서보알람토크
            if (sValue3[0] == '0')
                this.IsServoAlarmTorque = false;
            else
                this.IsServoAlarmTorque = true;
            #endregion
            #region 알람 11-
            if (sValue3[1] == '0')
            { }
            else
            { }
            #endregion
            #region 알람 10-서보알람
            if (sValue3[2] == '0')
                this.IsServoAlarm = false;
            else
                this.IsServoAlarm = true;
            #endregion
            #region 알람 9-
            if (sValue3[3] == '0')
            { }
            else
            { }
            #endregion

            #region 알람 8-비상정지
            if (sValue2[0] == '0')
                this.IsEmergencyStop = false;
            else
                this.IsEmergencyStop = true;
            #endregion
            #region 알람 7-
            if (sValue2[1] == '0')
            { }
            else
            { }
            #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')
                this.IsPressureError = false;
            else
                this.IsPressureError = true;
            #endregion
            #region 알람 2-셀 에러
            if (sValue1[2] == '0')
                this.IsLoadcellError = false;
            else
                this.IsLoadcellError = true;
            #endregion
            #region 알람 1-입력센서 에러
            if (sValue1[3] == '0')
                this.IsEntrySensorError = false;
            else
                this.IsEntrySensorError = true;
            #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 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 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 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 Modbus
    public class _30000_ModbusData
    {
        #region Field
        private short m_DecimalPoint;
        private int m_OperationStatus;
        private double m_UnderValue;
        private double m_PassValue;
        private double m_OverValue;
        private double m_TareValue;
        private double m_HighLimit;
        private double m_DeadZoneHighLimit;
        private double m_DeadZoneLowLimit;
        private double m_LowLimit;
        private UInt32 m_SampleCount;
        private UInt32 m_IgnoreCount;

        private Collection<_30000_LaneModbusData> m_ModbusLaneData;
        #endregion

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

        #region Property
        public short DecimalPoint
        {
            get { return this.m_DecimalPoint; }
            set { this.m_DecimalPoint = value; }
        }
        public int OperationStatus
        {
            get { return this.m_OperationStatus; }
            set { this.m_OperationStatus = value; }
        }
        public double UnderValue
        {
            get { return this.m_UnderValue; }
            set { this.m_UnderValue = value; }
        }
        public double PassValue
        {
            get { return this.m_PassValue; }
            set { this.m_PassValue = value; }
        }
        public double OverValue
        {
            get { return this.m_OverValue; }
            set { this.m_OverValue = value; }
        }
        public double TareValue
        {
            get { return this.m_TareValue; }
            set { this.m_TareValue = value; }
        }
        public double HighLimit
        {
            get { return this.m_HighLimit; }
            set { this.m_HighLimit = value; }
        }
        public double DeadZoneHighLimit
        {
            get { return this.m_DeadZoneHighLimit; }
            set { this.m_DeadZoneHighLimit = value; }
        }
        public double DeadZoneLowLimit
        {
            get { return this.m_DeadZoneLowLimit; }
            set { this.m_DeadZoneLowLimit = value; }
        }
        public double LowLimit
        {
            get { return this.m_LowLimit; }
            set { this.m_LowLimit = value; }
        }
        public UInt32 SampleCount
        {
            get { return this.m_SampleCount; }
            set { this.m_SampleCount = value; }
        }
        public UInt32 IgnoreCount
        {
            get { return this.m_IgnoreCount; }
            set { this.m_IgnoreCount = value; }
        }

        public Collection<_30000_LaneModbusData> ModbusLaneData
        {
            get { return this.m_ModbusLaneData; }
            set { this.m_ModbusLaneData = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.DecimalPoint = 1;
            this.OperationStatus = 0;
            this.UnderValue = 100.0;
            this.PassValue = 200.0;
            this.OverValue = 300.0;
            this.TareValue = 0.0;
            this.HighLimit = 300.0;
            this.DeadZoneHighLimit = 0.0;
            this.DeadZoneLowLimit = 0.0;
            this.LowLimit = 100.0;
            this.SampleCount = 10;
            this.IgnoreCount = 5;

            this.ModbusLaneData = new Collection<_30000_LaneModbusData>();
            this.ModbusLaneData.Clear();

            for (int i = 0; i < 12; i++)
                this.ModbusLaneData.Add(new _30000_LaneModbusData());
        }
        #endregion
    }
    public class _30000_LaneModbusData
    {
        #region Field
        private ushort m_Update;
        private ushort m_Grade;
        private double m_WeightDouble;
        private UInt32 m_UnderCount;
        private UInt32 m_PassCount;
        private UInt32 m_OverCount;
        private UInt32 m_ExNGCount;
        private double m_FeedbackWeightDouble;
        private int m_FeedbackWeightInt;
        private int m_WeightInt;
        private ushort m_UpdateFeedbackData;
        #endregion

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

        #region Property
        public ushort Update
        {
            get { return this.m_Update; }
            set { this.m_Update = value; }
        }
        public ushort Grade
        {
            get { return this.m_Grade; }
            set { this.m_Grade = value; }
        }
        public double WeightDouble
        {
            get { return this.m_WeightDouble; }
            set { this.m_WeightDouble = value; }
        }
        public UInt32 UnderCount
        {
            get { return this.m_UnderCount; }
            set { this.m_UnderCount = value; }
        }
        public UInt32 PassCount
        {
            get { return this.m_PassCount; }
            set { this.m_PassCount = value; }
        }
        public UInt32 OverCount
        {
            get { return this.m_OverCount; }
            set { this.m_OverCount = value; }
        }
        public UInt32 ExNGCount
        {
            get { return this.m_ExNGCount; }
            set { this.m_ExNGCount = value; }
        }
        public UInt32 NGCount
        {
            get { return this.m_UnderCount + this.m_OverCount + this.m_ExNGCount; }
        }
        public UInt32 TotalCount
        {
            get { return this.m_UnderCount + this.m_PassCount + this.m_OverCount + this.m_ExNGCount; }
        }
        public double FeedbackWeightDouble
        {
            get { return this.m_FeedbackWeightDouble; }
            set { this.m_FeedbackWeightDouble = value; }
        }
        public int FeedbackWeightInt
        {
            get { return int.Parse((this.FeedbackWeightDouble.ToString()).Replace(".", "")); }
        }
        public int WeightInt
        {
            get { return int.Parse((this.WeightDouble.ToString()).Replace(".", "")); }
        }
        public ushort UpdateFeedbackData
        {
            get { return this.m_UpdateFeedbackData; }
            set { this.m_UpdateFeedbackData = value; }
        }

        public string HexStringUpdate
        {
            get
            {
                string hexString = this.Update.ToString("X8");
                return hexString;
            }
        }
        public string HexStringGrade
        {
            get
            {
                string hexString = this.Grade.ToString("X8");
                return hexString;
            }
        }
        public string HexStringWeightDouble
        {
            get
            {
                byte[] bytes = BitConverter.GetBytes((float)this.WeightDouble);
                Array.Reverse(bytes);
                string hexString = BitConverter.ToString(bytes);
                hexString = hexString.Replace("-", "");

                return hexString;
            }
        }
        public string HexStringUnderCount
        {
            get
            {
                string hexString = this.UnderCount.ToString("X8");
                return hexString;
            }
        }
        public string HexStringPassCount
        {
            get
            {
                string hexString = this.PassCount.ToString("X8");
                return hexString;
            }
        }
        public string HexStringOverCount
        {
            get
            {
                string hexString = this.OverCount.ToString("X8");
                return hexString;
            }
        }
        public string HexStringExNGCount
        {
            get
            {
                string hexString = this.ExNGCount.ToString("X8");
                return hexString;
            }
        }
        public string HexStringNGCount
        {
            get
            {
                string hexString = this.NGCount.ToString("X8");
                return hexString;
            }
        }
        public string HexStringTotalCount
        {
            get
            {
                string hexString = this.TotalCount.ToString("X8");
                return hexString;
            }
        }
        public string HexStringFeedbackWeightDouble
        {
            get
            {
                byte[] bytes = BitConverter.GetBytes((float)this.FeedbackWeightDouble);
                Array.Reverse(bytes);
                string hexString = BitConverter.ToString(bytes);
                hexString = hexString.Replace("-", "");

                return hexString;
            }
        }
        public string HexStringFeedbackWeigntInt
        {
            get
            {
                string hexString = this.FeedbackWeightInt.ToString("X8");
                return hexString;
            }
        }
        public string HexStringWeightInt
        {
            get
            {
                string hexString = this.WeightInt.ToString("X8");
                return hexString;
            }
        }
        public string HexStringUpdateFeedbackData
        {
            get
            {
                string hexString = this.UpdateFeedbackData.ToString("X8");
                return hexString;
            }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this.Update = 0;
            this.Grade = 0;
            this.WeightDouble = 0.0;
            this.UnderCount = 0;
            this.PassCount = 0;
            this.OverCount = 0;
            this.ExNGCount = 0;
            this.FeedbackWeightDouble = 0.0;
            this.UpdateFeedbackData = 0;
        }
        #endregion
    }

    public class _40000_ModbusAddress
    {
        public const int _01_Clear = 10;
        public const int _02_ClearResult = 11;
        public const int _03_Operation = 12;
        public const int _04_OperationResult = 13;
        public const int _05_ProductChange_High = 14;
        public const int _06_ProductChange_Low = 15;
        public const int _07_ProductChangeResult = 16;
        public const int _08_UnderRange_High = 17;
        public const int _09_UnderRange_Low = 18;
        public const int _10_UnderRangeResult = 19;
        public const int _11_PassRange_High = 20;
        public const int _12_PassRange_Low = 21;
        public const int _13_PassRangeResult = 22;
        public const int _14_OverRange_High = 23;
        public const int _15_OverRange_Low = 24;
        public const int _16_OverRangeResult = 25;
        public const int _17_TareWeight_High = 26;
        public const int _18_TareWeight_Low = 27;
        public const int _19_TareWeightResult = 28;
    }
    public class _40000_ModbusData
    {
        #region Field
        private int m_40011_Clear;
        private int m_40012_ClearResult;
        private int m_40013_Operation;
        private int m_40014_OperationResult;
        private int m_40015_ProductChange;
        private int m_40017_ProductChangeResult;
        private int m_40018_UnderRange;
        private int m_40020_UnderRangeResult;
        private int m_40021_PassRange;
        private int m_40023_PassRangeResult;
        private int m_40024_OverRange;
        private int m_40026_OverRangeResult;
        private int m_40027_TareWeight;
        private int m_40029_TareWeightResult;
        #endregion

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

        #region Property
        public int _40011_Clear
        {
            get { return this.m_40011_Clear; }
            set { this.m_40011_Clear = value; }
        }
        public int _40012_ClearResult
        {
            get { return this.m_40012_ClearResult; }
            set { this.m_40012_ClearResult = value; }
        }
        public int _40013_Operation
        {
            get { return this.m_40013_Operation; }
            set { this.m_40013_Operation = value; }
        }
        public int _40014_OperationResult
        {
            get { return this.m_40014_OperationResult; }
            set { this.m_40014_OperationResult = value; }
        }
        public int _40015_ProductChange
        {
            get { return this.m_40015_ProductChange; }
            set { this.m_40015_ProductChange = value; }
        }
        public int _40017_ProductChangeResult
        {
            get { return this.m_40017_ProductChangeResult; }
            set { this.m_40017_ProductChangeResult = value; }
        }
        public int _40018_UnderRange
        {
            get { return this.m_40018_UnderRange; }
            set { this.m_40018_UnderRange = value; }
        }
        public int _40020_UnderRangeResult
        {
            get { return this.m_40020_UnderRangeResult; }
            set { this.m_40020_UnderRangeResult = value; }
        }
        public int _40021_PassRange
        {
            get { return this.m_40021_PassRange; }
            set { this.m_40021_PassRange = value; }
        }
        public int _40023_PassRangeResult
        {
            get { return this.m_40023_PassRangeResult; }
            set { this.m_40023_PassRangeResult = value; }
        }
        public int _40024_OverRange
        {
            get { return this.m_40024_OverRange; }
            set { this.m_40024_OverRange = value; }
        }
        public int _40026_OverRangeResult
        {
            get { return this.m_40026_OverRangeResult; }
            set { this.m_40026_OverRangeResult = value; }
        }
        public int _40027_TareWeight
        {
            get { return this.m_40027_TareWeight; }
            set { this.m_40027_TareWeight = value; }
        }
        public int _40029_TareWeightResult
        {
            get { return this.m_40029_TareWeightResult; }
            set { this.m_40029_TareWeightResult = value; }
        }
        #endregion

        #region Method
        public void Initialization()
        {
            this._40011_Clear = 0;
            this._40012_ClearResult = 0;
            this._40013_Operation = 0;
            this._40014_OperationResult = 0;
            this._40015_ProductChange = 0;
            this._40017_ProductChangeResult = 0;
            this._40018_UnderRange = 0;
            this._40020_UnderRangeResult = 0;
            this._40021_PassRange = 0;
            this._40023_PassRangeResult = 0;
            this._40024_OverRange = 0;
            this._40026_OverRangeResult = 0;
            this._40027_TareWeight = 0;
            this._40029_TareWeightResult = 0;
        }
        #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 UpdateForMainBoard
    public class UpdateForMainBoard
    {
        #region Field
        private bool m_IsUpdateFinish;
        private bool m_IsAckResponse;
        private bool m_IsLastData;
        private byte[] m_ByteData;
        private byte[] m_SendData;
        private int m_Index;
        private int m_RetryCount;
        private int m_SendDataCount;
        private int m_ProgressBar1;
        private int m_ProgressBar2;
        private int m_ProgressBar3;
        private int m_ProgressBar4;
        private int m_ProgressBar5;
        private int m_ProgressBar6;
        private int m_ProgressBar7;
        private int m_ProgressBar8;
        #endregion

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

        #region Property
        public bool IsUpdateFinish
        {
            get { return this.m_IsUpdateFinish; }
            set { this.m_IsUpdateFinish = value; }
        }
        public bool IsAckResponse
        {
            get { return this.m_IsAckResponse; }
            set { this.m_IsAckResponse = value; }
        }
        public bool IsLastData
        {
            get { return this.m_IsLastData; }
            set { this.m_IsLastData = value; }
        }
        public byte[] ByteData
        {
            get { return this.m_ByteData; }
            set { this.m_ByteData = value; }
        }
        public byte[] SendData
        {
            get { return this.m_SendData; }
            set { this.m_SendData = value; }
        }
        public int Index
        {
            get { return this.m_Index; }
            set { this.m_Index = value; }
        }
        public int RetryCount
        {
            get { return this.m_RetryCount; }
            set { this.m_RetryCount = value; }
        }
        public int SendDataCount
        {
            get { return this.m_SendDataCount; }
            set
            {
                int iValue = 0;

                this.m_SendDataCount = value;

                iValue = value / 8;

                this.ProgressBar1 = iValue;
                this.ProgressBar2 = iValue * 2;
                this.ProgressBar3 = iValue * 3;
                this.ProgressBar4 = iValue * 4;
                this.ProgressBar5 = iValue * 5;
                this.ProgressBar6 = iValue * 6;
                this.ProgressBar7 = iValue * 7;
                this.ProgressBar8 = iValue * 8;
            }
        }

        public int ProgressBar1
        {
            get { return this.m_ProgressBar1; }
            private set { this.m_ProgressBar1 = value; }
        }
        public int ProgressBar2
        {
            get { return this.m_ProgressBar2; }
            private set { this.m_ProgressBar2 = value; }
        }
        public int ProgressBar3
        {
            get { return this.m_ProgressBar3; }
            private set { this.m_ProgressBar3 = value; }
        }
        public int ProgressBar4
        {
            get { return this.m_ProgressBar4; }
            private set { this.m_ProgressBar4 = value; }
        }
        public int ProgressBar5
        {
            get { return this.m_ProgressBar5; }
            private set { this.m_ProgressBar5 = value; }
        }
        public int ProgressBar6
        {
            get { return this.m_ProgressBar6; }
            private set { this.m_ProgressBar6 = value; }
        }
        public int ProgressBar7
        {
            get { return this.m_ProgressBar7; }
            private set { this.m_ProgressBar7 = value; }
        }
        public int ProgressBar8
        {
            get { return this.m_ProgressBar8; }
            private set { this.m_ProgressBar8 = value; }
        }
        #endregion

        #region Method
        public void Initialize()
        {
            this.IsUpdateFinish = false;
            this.IsAckResponse = false;
            this.IsLastData = false;
            this.ByteData = new byte[100];
            this.SendData = new byte[100];
            this.Index = 1;
            this.RetryCount = 0;
            this.SendDataCount = 0;
            this.ProgressBar1 = 0;
            this.ProgressBar2 = 0;
            this.ProgressBar3 = 0;
            this.ProgressBar4 = 0;
            this.ProgressBar5 = 0;
            this.ProgressBar6 = 0;
            this.ProgressBar7 = 0;
            this.ProgressBar8 = 0;
        }
        #endregion
    }
    #endregion

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

        private int m_IgnoreCount;

        private double m_FeedbackWeight;

        private DataStore.FeedbackStatus m_Status;

        private Collection<int> m_WeightList;

        private int m_UpdateFeedbackData;
        #endregion

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

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

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

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

                return sum;
            }
        }

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

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

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

        public int UpdateFeedbackData
        {
            get { return this.m_UpdateFeedbackData; }
            set { this.m_UpdateFeedbackData = value; }
        }

        #endregion

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

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

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

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

            this.UpdateFeedbackData = 0;
            this.FeedbackWeight = 0.0;
        }
        #endregion
    }
    #endregion
    #region FeedbackItem
    public class FeedbackConfiguration
    {
        #region Field
        private string m_HighLimit;
        private string m_LowLimit;
        private string m_DeadZone;
        #endregion

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

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

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

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

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

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