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

namespace INT_LKD_2.DataStore
{
    #region SystemConfiguration
    public class SystemConfiguration
    {
        #region Field
        private bool m_IS_LOGIN;

        private string m_MAINBOARD_VERSION_MASTER;
        private string m_MAINBOARD_VERSION_SLAVE;
        private int m_RECIPE_NUMBER;

        private Define.E_LanguageID m_LANGUAGE;

        private int m_CHART1_DRAW_STEP;
        private int m_CHART2_DRAW_STEP;

        private int m_LCD_DATA_PERIOD;
        private int m_CHATTERING;
        private int m_JUDGMENT_DELAY_MSEC;
        private int m_BUZZER_OP;

        private int m_SB_DIFF_FILTER;
        private int m_SB_DIFF_MODE;
        private int m_SB_DATA_MODE;
        private int m_SB_DATA_PERIOD;

        private int m_AUTOMATIC_LOGOUT;
        private int m_NUMBER_OF_LOGIN_FAILURE;

        private int m_EQUIPMENT_LANE;
        private int m_CHECK_LANE;

        private int m_ETHERNET_COMM_MODE;
        private int m_ETHERNET_OP_MODE;
        private int m_ETHERNET_LOCAL_PORT;
        private int m_ETHERNET_SERVER_PORT;
        private int m_MODBUS_TCP_SELECTFUNCTION;
        private int m_MODBUS_TCP_START_ADDRESS;

        private string m_SERIAL_NUMBER;
        
        private string m_LEVEL1_NAME;
        private string m_LEVEL2_NAME;
        private string m_LEVEL3_NAME;

        private string m_ETHERNET_SERVER_IP;
        #endregion

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

        #region Property
        public bool IS_LOGIN
        {
            get { return this.m_IS_LOGIN; }
            set { this.m_IS_LOGIN = value; }
        }

        public string MAINBOARD_VERSION_MASTER
        {
            get { return this.m_MAINBOARD_VERSION_MASTER; }
            set { this.m_MAINBOARD_VERSION_MASTER = value; }
        }
        public string MAINBOARD_VERSION_SLAVE
        {
            get { return this.m_MAINBOARD_VERSION_SLAVE; }
            set { this.m_MAINBOARD_VERSION_SLAVE = value; }
        }
        public int RECIPE_NUMBER
        {
            get { return this.m_RECIPE_NUMBER; }
            set { this.m_RECIPE_NUMBER = value; }
        }

        public Define.E_LanguageID LANGUAGE
        {
            get { return this.m_LANGUAGE; }
            set { this.m_LANGUAGE = value; }
        }

        public int CHART1_DRAW_STEP
        {
            get { return this.m_CHART1_DRAW_STEP; }
            set { this.m_CHART1_DRAW_STEP = value; }
        }
        public int CHART2_DRAW_STEP
        {
            get { return this.m_CHART2_DRAW_STEP; }
            set { this.m_CHART2_DRAW_STEP = value; }
        }

        public int LCD_DATA_PERIOD
        {
            get { return this.m_LCD_DATA_PERIOD; }
            set { this.m_LCD_DATA_PERIOD = value; }
        }
        public int CHATTERING
        {
            get { return this.m_CHATTERING; }
            set { this.m_CHATTERING = value; }
        }
        public int JUDGMENT_DELAY_MSEC
        {
            get { return this.m_JUDGMENT_DELAY_MSEC; }
            set { this.m_JUDGMENT_DELAY_MSEC = value; }
        }
        public int BUZZER_OP
        {
            get { return this.m_BUZZER_OP; }
            set { this.m_BUZZER_OP = value; }
        }

        public int SB_DIFF_FILTER
        {
            get { return this.m_SB_DIFF_FILTER; }
            set { this.m_SB_DIFF_FILTER = value; }
        }
        public int SB_DIFF_MODE
        {
            get { return this.m_SB_DIFF_MODE; }
            set { this.m_SB_DIFF_MODE = value; }
        }
        public int SB_DATA_MODE
        {
            get { return this.m_SB_DATA_MODE; }
            set { this.m_SB_DATA_MODE = value; }
        }
        public int SB_DATA_PERIOD
        {
            get { return this.m_SB_DATA_PERIOD; }
            set { this.m_SB_DATA_PERIOD = value; }
        }

        public string SERIAL_NUMBER
        {
            get { return this.m_SERIAL_NUMBER; }
            set { this.m_SERIAL_NUMBER = value; }
        }

        public int AUTOMATIC_LOGOUT
        {
            get { return this.m_AUTOMATIC_LOGOUT; }
            set { this.m_AUTOMATIC_LOGOUT = value; }
        }
        public int NUMBER_OF_LOGIN_FAILURE
        {
            get { return this.m_NUMBER_OF_LOGIN_FAILURE; }
            set { this.m_NUMBER_OF_LOGIN_FAILURE = value; }
        }

        public int ETHERNET_COMM_MODE
        {
            get { return this.m_ETHERNET_COMM_MODE; }
            set { this.m_ETHERNET_COMM_MODE = value; }
        }
        public int ETHERNET_OP_MODE
        {
            get { return this.m_ETHERNET_OP_MODE; }
            set { this.m_ETHERNET_OP_MODE = value; }
        }
        public int ETHERNET_LOCAL_PORT
        {
            get { return this.m_ETHERNET_LOCAL_PORT; }
            set { this.m_ETHERNET_LOCAL_PORT = value; }
        }
        public int ETHERNET_SERVER_PORT
        {
            get { return this.m_ETHERNET_SERVER_PORT; }
            set { this.m_ETHERNET_SERVER_PORT = value; }
        }
        public int MODBUS_TCP_SELECTFUNCTION
        {
            get { return this.m_MODBUS_TCP_SELECTFUNCTION; }
            set { this.m_MODBUS_TCP_SELECTFUNCTION = value; }
        }
        public int MODBUS_TCP_START_ADDRESS
        {
            get { return this.m_MODBUS_TCP_START_ADDRESS; }
            set { this.m_MODBUS_TCP_START_ADDRESS = value; }
        }

        public string LEVEL1_NAME
        {
            get { return this.m_LEVEL1_NAME; }
            set { this.m_LEVEL1_NAME = value; }
        }
        public string LEVEL2_NAME
        {
            get { return this.m_LEVEL2_NAME; }
            set { this.m_LEVEL2_NAME = value; }
        }
        public string LEVEL3_NAME
        {
            get { return this.m_LEVEL3_NAME; }
            set { this.m_LEVEL3_NAME = value; }
        }

        public string ETHERNET_SERVER_IP
        {
            get { return this.m_ETHERNET_SERVER_IP; }
            set { this.m_ETHERNET_SERVER_IP = value; }
        }

        public int EQUIPMENT_LANE
        {
            get { return this.m_EQUIPMENT_LANE; }
            set { this.m_EQUIPMENT_LANE = value; }
        }
        public int CHECK_LANE
        {
            get { return this.m_CHECK_LANE; }
            set { this.m_CHECK_LANE = value; }
        }
        #endregion

        #region Method
        public void Initialize()
        {
            this.IS_LOGIN = false;

            this.MAINBOARD_VERSION_MASTER = "000";
            this.MAINBOARD_VERSION_SLAVE = "000";
            this.RECIPE_NUMBER = 1;

            this.LANGUAGE = Define.E_LanguageID.English;

            this.CHART1_DRAW_STEP = 4;
            this.CHART2_DRAW_STEP = 2;

            this.LCD_DATA_PERIOD = 100;
            this.CHATTERING = 500;
            this.JUDGMENT_DELAY_MSEC = 2000;
            this.BUZZER_OP = 1000;

            this.SB_DIFF_FILTER = 15;
            this.SB_DATA_MODE = 2;
            this.SB_DATA_PERIOD = 100;
            this.SB_DIFF_MODE = 1;

            this.AUTOMATIC_LOGOUT = 10;
            this.NUMBER_OF_LOGIN_FAILURE = 5;

            this.ETHERNET_LOCAL_PORT = 0;
            this.ETHERNET_SERVER_PORT = 0;
            this.ETHERNET_COMM_MODE = 0;
            this.ETHERNET_OP_MODE = 0;
            this.MODBUS_TCP_SELECTFUNCTION = (int)Define.E_ModbusFunction._04_ReadInputRegister;
            this.MODBUS_TCP_START_ADDRESS = 10;

            this.EQUIPMENT_LANE = 12;
            this.CHECK_LANE = 1;

            this.SERIAL_NUMBER = "24D0000";

            this.LEVEL1_NAME = "Level 1";
            this.LEVEL2_NAME = "Level 2";
            this.LEVEL3_NAME = "Level 3";

            this.ETHERNET_SERVER_IP = "0.0.0.0";
        }

        public bool IsEthernetEnable
        {
            get
            {
                if (this.ETHERNET_OP_MODE != 0)
                    return true;
                else
                    return false;
            }
        }
        #endregion
    }
    #endregion
    #region Struct SystemConfiguration
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem
    {
        public bool DummyBool1;
        public bool DummyBool2;
        public bool DummyBool3;
        public bool DummyBool4;
        public bool DummyBool5;
        public bool DummyBool6;
        public bool DummyBool7;
        public bool DummyBool8;
        public bool DummyBool9;
        public bool DummyBool10;

        public int RECIPE_NUMBER;
        public Define.E_LanguageID LANGUAGE;

        public int CHART1_DRAW_STEP;
        public int CHART2_DRAW_STEP;

        public int LCD_DATA_PERIOD;
        public int CHATTERING;
        public int JUDGMENT_DELAY_MSEC;
        public int BUZZER_OP;

        public int SB_DIFF_FILTER;
        public int SB_DIFF_MODE;
        public int SB_DATA_MODE;
        public int SB_DATA_PERIOD;

        public int EQUIPMENT_LANE;
        public int CHECK_LANE;

        public int AUTOMATIC_LOGOUT;
        public int NUMBER_OF_LOGIN_FAILURE;

        public int ETHERNET_COMM_MODE;
        public int ETHERNET_OP_MODE;
        public int ETHERNET_LOCAL_PORT;
        public int ETHERNET_SERVER_PORT;
        public int MODBUS_TCP_SELECTFUNCTION;
        public int MODBUS_TCP_START_ADDRESS;

        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;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
        public string SERIAL_NUMBER;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string LEVEL1_NAME;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string LEVEL2_NAME;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string LEVEL3_NAME;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string ETHERNET_SERVER_IP;

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