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

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

        private string m_MAINBOARD_VERSION;
        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 string m_SERIAL_NUMBER;

        private int m_AUTOMATIC_LOGOUT;

        private string m_LEVEL1_NAME;
        private string m_LEVEL2_NAME;
        private string m_LEVEL3_NAME;
        #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
        {
            get { return this.m_MAINBOARD_VERSION; }
            set { this.m_MAINBOARD_VERSION = 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 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; }
        }
        #endregion

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

            this.MAINBOARD_VERSION = "000";
            this.RECIPE_NUMBER = 1;

            this.LANGUAGE = Define.E_LanguageID.Korean;

            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.SERIAL_NUMBER = "23D0000";

            this.AUTOMATIC_LOGOUT = 10;

            this.LEVEL1_NAME = "Level 1";
            this.LEVEL2_NAME = "Level 2";
            this.LEVEL3_NAME = "Level 3";
        }
        #endregion
    }
    #endregion
    #region Struct SystemConfiguration
    [StructLayout(LayoutKind.Sequential)]
    public struct StructSystemConfigurationItem
    {
        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;

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

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

        private User m_DefaultUsers;
        private User m_DeveloperUser;
        #endregion

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

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

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

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

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

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

            this.DefaultUsers = new User();

            this.DeveloperUser = new User();
            this.DeveloperUser.ID = "Intech";
            this.DeveloperUser.Password = "20090810";
            this.DeveloperUser.Group = Define.E_UserStatus.Developer;
        }

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

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

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

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

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

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

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

            return user;
        }

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

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

            return ret;
        }
        #endregion
    }
    #endregion
    #region User
    public class User
    {
        #region Field
        private string m_ID;
        private string m_Password;
        private Define.E_UserStatus m_Group;
        #endregion

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

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

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

        public Define.E_UserStatus Group;

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

    #region UserGroup
    public class UserGroup
    {
        #region Field
        private UserGroupItem m_Level1;
        private UserGroupItem m_Level2;
        private UserGroupItem m_Level3;
        private UserGroupItem m_Default;
        #endregion

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

        #region Property
        public UserGroupItem Level1
        {
            get { return this.m_Level1; }
            set { this.m_Level1 = value; }
        }
        public UserGroupItem Level2
        {
            get { return this.m_Level2; }
            set { this.m_Level2 = value; }
        }
        public UserGroupItem Level3
        {
            get { return this.m_Level3; }
            set { this.m_Level3 = value; }
        }
        public UserGroupItem Default
        {
            get { return this.m_Default; }
            set { this.m_Default = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Level1 = new UserGroupItem();
            this.Level2 = new UserGroupItem();
            this.Level3 = new UserGroupItem();
            this.Default = new UserGroupItem();
        }

        public bool GetSet1AccessRight(Define.E_FormStore display)
        {
            bool ret = false;

            return ret;
        }
        public bool GetSet2AccessRight(Define.E_FormStore display)
        {
            bool ret = false;

            return ret;
        }
        public bool GetSet3AccessRight(Define.E_FormStore display)
        {
            bool ret = false;

            return ret;
        }
        #endregion
    }
    #endregion
    #region UserGroupItem
    public class UserGroupItem
    {
        #region Field
        private bool m_IsMainDisplayProductChange;
        private bool m_IsMainDisplayClear;
        private bool m_IsMainDisplaySubMenu;

        private bool m_IsMenuRecipe;
        private bool m_IsMenuUserSetting;
        private bool m_IsMenuUserGroupEditor;
        private bool m_IsMenuIOTest;
        private bool m_IsMenuHistoryLog;
        private bool m_IsMenuInspectionLog;
        private bool m_IsMenuAlarmLog;
        private bool m_IsMenuInformation;
        private bool m_IsMenuStatus;
        #endregion

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

        #region Property
        public bool IsMainDisplayProductChange
        {
            get { return this.m_IsMainDisplayProductChange; }
            set { this.m_IsMainDisplayProductChange = value; }
        }
        public bool IsMainDisplayClear
        {
            get { return this.m_IsMainDisplayClear; }
            set { this.m_IsMainDisplayClear = value; }
        }
        public bool IsMainDisplaySubMenu
        {
            get { return this.m_IsMainDisplaySubMenu; }
            set { this.m_IsMainDisplaySubMenu = value; }
        }

        public bool IsMenuRecipe
        {
            get { return this.m_IsMenuRecipe; }
            set { this.m_IsMenuRecipe = value; }
        }
        public bool IsMenuUserSetting
        {
            get { return this.m_IsMenuUserSetting; }
            set { this.m_IsMenuUserSetting = value; }
        }
        public bool IsMenuUserGroupEditor
        {
            get { return this.m_IsMenuUserGroupEditor; }
            set { this.m_IsMenuUserGroupEditor = value; }
        }
        public bool IsMenuIOTest
        {
            get { return this.m_IsMenuIOTest; }
            set { this.m_IsMenuIOTest = value; }
        }

        public bool IsMenuHistoryLog
        {
            get { return this.m_IsMenuHistoryLog; }
            set { this.m_IsMenuHistoryLog = value; }
        }
        public bool IsMenuInspectionLog
        {
            get { return this.m_IsMenuInspectionLog; }
            set { this.m_IsMenuInspectionLog = value; }
        }
        public bool IsMenuAlarmLog
        {
            get { return this.m_IsMenuAlarmLog; }
            set { this.m_IsMenuAlarmLog = value; }
        }
        public bool IsMenuInformation
        {
            get { return this.m_IsMenuInformation; }
            set { this.m_IsMenuInformation = value; }
        }
        public bool IsMenuStatus
        {
            get { return this.m_IsMenuStatus; }
            set { this.m_IsMenuStatus = value; }
        }

        public bool IsMainEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMainDisplayProductChange == true || this.IsMainDisplayClear == true
                    || this.IsMainDisplaySubMenu == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsRecipeEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuRecipe == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsUserEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuUserSetting == true || this.IsMenuUserGroupEditor == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsManualEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuIOTest == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsLogEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuHistoryLog == true || this.IsMenuInspectionLog == true || this.IsMenuAlarmLog == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsSystemEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuInformation == true || this.IsMenuStatus == true)
                    ret = true;

                return ret;
            }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsMainDisplayProductChange = false;
            this.IsMainDisplayClear = false;
            this.IsMainDisplaySubMenu = false;

            this.IsMenuRecipe = false;
            this.IsMenuUserSetting = false;
            this.IsMenuUserGroupEditor = false;
            this.IsMenuIOTest = false;
            this.IsMenuHistoryLog = false;
            this.IsMenuInspectionLog = false;
            this.IsMenuAlarmLog = false;
            this.IsMenuInformation = false;
            this.IsMenuStatus = false;
        }
        #endregion
    }
    #endregion
    #region StructUserGroupItem(총 메뉴 개수 30개)
    [StructLayout(LayoutKind.Sequential)]
    public struct StructUserGroupItem
    {
        public bool IsMainDisplayRecipeChange;
        public bool IsMainDisplayClear;
        public bool IsMainDispalySubMenu;

        public bool IsMenuRecipe;
        public bool IsMenuUserSetting;
        public bool IsMenuUserGroupEditor;
        public bool IsMenuIOTest;
        public bool IsMenuEquipmentLog;
        public bool IsMenuCheckLog;
        public bool IsMenuAlarmList;
        public bool IsMenuInformation;
        public bool IsMenuStatus;

        public bool Dummy1;
        public bool Dummy2;
        public bool Dummy3;
        public bool Dummy4;
        public bool Dummy5;
        public bool Dummy6;
        public bool Dummy7;
        public bool Dummy8;
        public bool Dummy9;
        public bool Dummy10;
        public bool Dummy11;
        public bool Dummy12;
        public bool Dummy13;
        public bool Dummy14;
        public bool Dummy15;
        public bool Dummy16;
        public bool Dummy17;
        public bool Dummy18;
    }
    #endregion

    #region UserItem
    public class UserItem
    {
        #region Field
        private bool m_IsUpdate;

        private string m_ID;
        private string m_Password;
        private string m_PreviousPassword1;
        private string m_PreviousPassword2;
        private string m_PreviousPassword3;

        private int m_ExpireAccount;
        private int m_ExpirePassword;

        private bool m_IsLockAccount;
        private bool m_IsLockPassword;

        private DateTime m_DateRegister;
        private DateTime m_DateLogin;
        private DateTime m_DateExpireRegister;
        private DateTime m_DateExpireLogin;

        private Define.E_UserStatus m_Status;

        private bool m_IsAdmin;

        private bool m_IsMainRecipeChange;
        private bool m_IsMainClear;
        private bool m_IsMainSubMenu;

        private bool m_IsMenuProduct;
        private bool m_IsMenuUserSetting;
        private bool m_IsMenuUserGroupEditor;
        private bool m_IsMenuIOTest;
        private bool m_IsMenuEquipmentLog;
        private bool m_IsMenuCheckLog;
        private bool m_IsMenuAlarmList;
        private bool m_IsMenuInformation;
        private bool m_IsMenuEquipmentTest;
        #endregion

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

        #region Property
        public bool IsUpdate
        {
            get { return this.m_IsUpdate; }
            set { this.m_IsUpdate = value; }
        }

        public string ID
        {
            get { return this.m_ID; }
            set { this.m_ID = value; }
        }
        public string Password
        {
            get { return this.m_Password; }
            set { this.m_Password = value; }
        }
        public string PreviousPassword1
        {
            get { return this.m_PreviousPassword1; }
            set { this.m_PreviousPassword1 = value; }
        }
        public string PreviousPassword2
        {
            get { return this.m_PreviousPassword2; }
            set { this.m_PreviousPassword2 = value; }
        }
        public string PreviousPassword3
        {
            get { return this.m_PreviousPassword3; }
            set { this.m_PreviousPassword3 = value; }
        }

        public int ExpireAccount
        {
            get { return this.m_ExpireAccount; }
            set { this.m_ExpireAccount = value; }
        }
        public int ExpirePassword
        {
            get { return this.m_ExpirePassword; }
            set { this.m_ExpirePassword = value; }
        }

        public bool IsLockAccount
        {
            get { return this.m_IsLockAccount; }
            set { this.m_IsLockAccount = value; }
        }
        public bool IsLockPassword
        {
            get { return this.m_IsLockPassword; }
            set { this.m_IsLockPassword = value; }
        }

        public DateTime DateRegister
        {
            get { return this.m_DateRegister; }
            set { this.m_DateRegister = value; }
        }
        public DateTime DateLogin
        {
            get { return this.m_DateLogin; }
            set { this.m_DateLogin = value; }
        }
        public DateTime DateExpireRegister
        {
            get { return this.m_DateExpireRegister; }
            set { this.m_DateExpireRegister = value; }
        }
        public DateTime DateExpireLogin
        {
            get { return this.m_DateExpireLogin; }
            set { this.m_DateExpireLogin = value; }
        }

        public Define.E_UserStatus Status
        {
            get { return this.m_Status; }
            set { this.m_Status = value; }
        }

        public bool IsAdmin
        {
            get { return this.m_IsAdmin; }
            set { this.m_IsAdmin = value; }
        }

        public bool IsMainRecipeChange
        {
            get { return this.m_IsMainRecipeChange; }
            set { this.m_IsMainRecipeChange = value; }
        }
        public bool IsMainClear
        {
            get { return this.m_IsMainClear; }
            set { this.m_IsMainClear = value; }
        }
        public bool IsMainSubMenu
        {
            get { return this.m_IsMainSubMenu; }
            set { this.m_IsMainSubMenu = value; }
        }

        public bool IsMenuProduct
        {
            get { return this.m_IsMenuProduct; }
            set { this.m_IsMenuProduct = value; }
        }
        public bool IsMenuUserSetting
        {
            get { return this.m_IsMenuUserSetting; }
            set { this.m_IsMenuUserSetting = value; }
        }
        public bool IsMenuUserGroupEditor
        {
            get { return this.m_IsMenuUserGroupEditor; }
            set { this.m_IsMenuUserGroupEditor = value; }
        }
        public bool IsMenuIOTest
        {
            get { return this.m_IsMenuIOTest; }
            set { this.m_IsMenuIOTest = value; }
        }
        public bool IsMenuEquipmentLog
        {
            get { return this.m_IsMenuEquipmentLog; }
            set { this.m_IsMenuEquipmentLog = value; }
        }
        public bool IsMenuCheckLog
        {
            get { return this.m_IsMenuCheckLog; }
            set { this.m_IsMenuCheckLog = value; }
        }
        public bool IsMenuAlarmList
        {
            get { return this.m_IsMenuAlarmList; }
            set { this.m_IsMenuAlarmList = value; }
        }
        public bool IsMenuInformation
        {
            get { return this.m_IsMenuInformation; }
            set { this.m_IsMenuInformation = value; }
        }
        public bool IsMenuEquipmentTest
        {
            get { return this.m_IsMenuEquipmentTest; }
            set { this.m_IsMenuEquipmentTest = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsUpdate = false;

            this.ID = "-";
            this.Password = "-";

            this.PreviousPassword1 = "-";
            this.PreviousPassword2 = "-";
            this.PreviousPassword3 = "-";

            this.ExpireAccount = 0;
            this.ExpirePassword = 0;

            this.DateRegister = DateTime.Now;
            this.DateLogin = DateTime.Now;
            this.DateExpireRegister = DateTime.Now;
            this.DateExpireLogin = DateTime.Now;

            this.Status = Define.E_UserStatus.None;

            this.IsAdmin = false;

            this.IsMainRecipeChange = false;
            this.IsMainClear = false;
            this.IsMainSubMenu = false;

            this.IsMenuProduct = false;
            this.IsMenuUserSetting = false;
            this.IsMenuUserGroupEditor = false;
            this.IsMenuIOTest = false;
            this.IsMenuEquipmentLog = false;
            this.IsMenuCheckLog = false;
            this.IsMenuAlarmList = false;
            this.IsMenuInformation = false;
            this.IsMenuEquipmentTest = false;
        }

        public void SetPassword(string pass)
        {
            this.PreviousPassword3 = this.PreviousPassword2;
            this.PreviousPassword2 = this.PreviousPassword1;
            this.PreviousPassword1 = pass;
            this.Password = pass;
        }
        public bool CheckID(string id)
        {
            bool ret = false;


            return ret;
        }
        public bool CheckPassword(string pass)
        {
            bool ret = false;

            return ret;
        }
        #endregion
    }
    #endregion
    #region StructUserItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructUserItem
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string ID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string Password;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string PreviousPassword1;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string PreviousPassword2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string PreviousPassword3;

        public int ExpireAccount;
        public int ExpirePassword;

        public DateTime DateRegister;
        public DateTime DateLogin;

        public bool IsAdmin;

        public bool IsMainProductChange;
        public bool IsMainWeightSetting;
        public bool IsMainClear;
        public bool IsMainSubMenu;

        public bool IsMenuProduct;
        public bool IsMenuUserSetting;
        public bool IsMenuUserGroupEditor;
        public bool IsMenuIOTest;
        public bool IsMenuEquipmentLog;
        public bool IsMenuCheckLog;
        public bool IsMenuAlarmList;
        public bool IsMenuInformation;
        public bool IsMenuStatus;
    }
    #endregion

    #region AlarmList
    public class AlarmList
    {
        #region Field
        private bool m_IsServo1Alarm;
        private bool m_IsServo2Alarm;
        private bool m_IsServo1TorqueAlarm;
        private bool m_IsServo2TorqueAlarm;
        private bool m_IsPressureError;
        private bool m_IsServoEmergencyStop;

        private Collection<bool> m_CollectionIsSensorBoardError;

        public event Define.EventHandlerAlarmStateChange EventAlarmStateChange;
        #endregion

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

        #region Property
        public bool IsServo1Alarm
        {
            get { return this.m_IsServo1Alarm; }
            set { this.m_IsServo1Alarm = value; }
        }
        public bool IsServo2Alarm
        {
            get { return this.m_IsServo2Alarm; }
            set { this.m_IsServo2Alarm = value; }
        }
        public bool IsServoTorque1AlarmTorque
        {
            get { return this.m_IsServo1TorqueAlarm; }
            set { this.m_IsServo1TorqueAlarm = value; }
        }
        public bool IsServoTorque2AlarmTorque
        {
            get { return this.m_IsServo2TorqueAlarm; }
            set { this.m_IsServo2TorqueAlarm = value; }
        }
        public bool IsPressureError
        {
            get { return this.m_IsPressureError; }
            set { this.m_IsPressureError = value; }
        }
        public bool IsServoEmergencyStop
        {
            get { return this.m_IsServoEmergencyStop; }
            set { this.m_IsServoEmergencyStop = value; }
        }

        public Collection<bool> CollectionIsSensorBoardError
        {
            get { return this.m_CollectionIsSensorBoardError; }
            set { this.m_CollectionIsSensorBoardError = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsServo1Alarm = false;
            this.IsServo2Alarm = false;
            this.IsServoTorque1AlarmTorque = false;
            this.IsServoTorque2AlarmTorque = false;
            this.IsPressureError = false;
            this.IsServoEmergencyStop = false;

            this.CollectionIsSensorBoardError = new Collection<bool>();
            for (int i = 0; i < 10; i++)
                this.CollectionIsSensorBoardError.Add(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');

            // 알람 16-센서보드10 에러
            if (sValue4[0] == '0')
            {
                if (this.CollectionIsSensorBoardError[9] != false)
                {
                    this.CollectionIsSensorBoardError[9] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a16_SensorBoard10Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[9] != true)
                {
                    this.CollectionIsSensorBoardError[9] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a16_SensorBoard10Error, "ON");
                }
            }
            // 알람 15-센서보드9 에러
            if (sValue4[1] == '0')
            {
                if (this.CollectionIsSensorBoardError[8] != false)
                {
                    this.CollectionIsSensorBoardError[8] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a15_SensorBoard9Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[8] != true)
                {
                    this.CollectionIsSensorBoardError[8] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a15_SensorBoard9Error, "ON");
                }
            }
            // 알람 14-센서보드8 에러
            if (sValue4[2] == '0')
            {
                if (this.CollectionIsSensorBoardError[7] != false)
                {
                    this.CollectionIsSensorBoardError[7] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a14_SensorBoard8Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[7] != true)
                {
                    this.CollectionIsSensorBoardError[7] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a14_SensorBoard8Error, "ON");
                }
            }
            // 알람 13-센서보드7 에러
            if (sValue4[3] == '0')
            {
                if (this.CollectionIsSensorBoardError[6] != false)
                {
                    this.CollectionIsSensorBoardError[6] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a13_SensorBoard7Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[6] != true)
                {
                    this.CollectionIsSensorBoardError[6] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a13_SensorBoard7Error, "ON");
                }
            }

            // 알람 12-센서보드6 에러
            if (sValue3[0] == '0')
            {
                if (this.CollectionIsSensorBoardError[5] != false)
                {
                    this.CollectionIsSensorBoardError[5] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a12_SensorBoard6Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[5] != true)
                {
                    this.CollectionIsSensorBoardError[5] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a12_SensorBoard6Error, "ON");
                }
            }
            // 알람 11-센서보드5 에러
            if (sValue3[1] == '0')
            {
                if (this.CollectionIsSensorBoardError[4] != false)
                {
                    this.CollectionIsSensorBoardError[4] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a11_SensorBoard5Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[4] != true)
                {
                    this.CollectionIsSensorBoardError[4] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a11_SensorBoard5Error, "ON");
                }
            }
            // 알람 10-센서보드4 에러
            if (sValue3[2] == '0')
            {
                if (this.CollectionIsSensorBoardError[3] != false)
                {
                    this.CollectionIsSensorBoardError[3] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a10_SensorBoard4Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[3] != true)
                {
                    this.CollectionIsSensorBoardError[3] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a10_SensorBoard4Error, "ON");
                }
            }
            // 알람 9-센서보드3 에러
            if (sValue3[3] == '0')
            {
                if (this.CollectionIsSensorBoardError[2] != false)
                {
                    this.CollectionIsSensorBoardError[2] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a9_SensorBoard3Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[2] != true)
                {
                    this.CollectionIsSensorBoardError[2] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a9_SensorBoard3Error, "ON");
                }
            }

            // 알람 8-센서보드2 에러
            if (sValue2[0] == '0')
            {
                if (this.CollectionIsSensorBoardError[1] != false)
                {
                    this.CollectionIsSensorBoardError[1] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a8_SensorBoard2Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[1] != true)
                {
                    this.CollectionIsSensorBoardError[1] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a8_SensorBoard2Error, "ON");
                }
            }
            // 알람 7-센서보드1 에러
            if (sValue2[1] == '0')
            {
                if (this.CollectionIsSensorBoardError[0] != false)
                {
                    this.CollectionIsSensorBoardError[0] = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a7_SensorBoard1Error, "OFF");
                }
            }
            else
            {
                if (this.CollectionIsSensorBoardError[0] != true)
                {
                    this.CollectionIsSensorBoardError[0] = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a7_SensorBoard1Error, "ON");
                }
            }
            // 알람 6-압력에러
            if (sValue2[2] == '0')
            {
                if (this.IsPressureError != false)
                {
                    this.IsPressureError = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a6_PressureError, "OFF");
                }            
            }
            else
            {
                if (this.IsPressureError != true)
                {
                    this.IsPressureError = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a6_PressureError, "ON");
                }
            }
            // 알람 5-서보2 토크
            if (sValue2[3] == '0')
            {
                if (this.IsServoTorque2AlarmTorque != false)
                {
                    this.IsServoTorque2AlarmTorque = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a5_Servo2TorqueAlarm, "OFF");
                }
            }
            else
            {
                if (this.IsServoTorque2AlarmTorque != true)
                {
                    this.IsServoTorque2AlarmTorque = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a5_Servo2TorqueAlarm, "ON");
                }
            }

            // 알람 4-서보1 토크
            if (sValue1[0] == '0')
            {
                if (this.IsServoTorque1AlarmTorque != false)
                {
                    this.IsServoTorque1AlarmTorque = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a4_Servo1TorqueAlarm, "OFF");
                }
            }
            else
            {
                if (this.IsServoTorque1AlarmTorque != true)
                {
                    this.IsServoTorque1AlarmTorque = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a4_Servo1TorqueAlarm, "ON");
                }
            }
            // 알람 3-서보2 알람
            if (sValue1[1] == '0')
            {
                if (this.IsServo2Alarm != false)
                {
                    this.IsServo2Alarm = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a3_Servo2Alarm, "OFF");
                }
            }
            else
            {
                if (this.IsServo2Alarm != true)
                {
                    this.IsServo2Alarm = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a3_Servo2Alarm, "ON");
                }
            }
            // 알람 2-서보1 알람
            if (sValue1[2] == '0')
            {
                if (this.IsServo1Alarm != false)
                {
                    this.IsServo1Alarm = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a2_Servo1Alarm, "OFF");
                }
            }
            else
            {
                if (this.IsServo1Alarm != true)
                {
                    this.IsServo1Alarm = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a2_Servo1Alarm, "ON");
                }
            }
            // 알람 1-서보OFF
            if (sValue1[3] == '0')
            {
                if (this.IsServoEmergencyStop != false)
                {
                    this.IsServoEmergencyStop = false;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a1_ServoEmergencyStop, "OFF");
                }
            }
            else
            {
                if (this.IsServoEmergencyStop != true)
                {
                    this.IsServoEmergencyStop = true;
                    this.EventAlarmStateChange(Define.E_Trackingalarm.a1_ServoEmergencyStop, "ON");
                }
            }
        }
        #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()
        {
            this.Initialize();
        }
        #endregion

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

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

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

        public List<DataBackupMonth> Months;
        #endregion

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

            this.Year = year;
        }
        #endregion

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

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

        public List<string> Days;
        #endregion

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

            this.Month = month;
        }
        #endregion

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

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

    #region 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
}
