using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using ITC81DB_0H.Forms;

namespace ITC81DB_0H.Controls
{
    public partial class ControlUserGroupEditor : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        #endregion
        
        #region Constructor
        public ControlUserGroupEditor(FormMenu parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

            this.InitializeDesign();
            this.DefaultSetting();
        } 
        #endregion

        #region Property
        public FormMenu ParentForm
        {
            get { return this.m_ParentForm; }
            private set { this.m_ParentForm = value; }
        } 
        #endregion

        #region Method
        public void InitializeDesign()
        {
        }
        private void DefaultSetting()
        {
        }

        private void SaveUserGroupLevel1()
        {
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasic = this.checkBoxBasic.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicTime = this.checkBoxBasicTime.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicProduct = this.checkBoxBasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicDataBackup = this.checkBoxBasicDataBackup.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsBasicDataStatistics = this.checkBoxBasicDataStatistics.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiguration = this.checkBoxConfiguration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiCommunication = this.checkBoxConfiCommunication.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsConfiOption = this.checkBoxConfiOption.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystem = this.checkBoxSystem.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemCalibration = this.checkBoxSystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemJudgmentSetting = this.checkBoxSystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemSorterSetting = this.checkBoxSystemSorterSetting.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemAutoZero = this.checkBoxSystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemIOTest = this.checkBoxSystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsSystemExternalOutput = this.checkBoxSystemExternalOut.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipment = this.checkBoxEquipment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipUpdate = this.checkBoxEquipUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipInitialize = this.checkBoxEquipInitialize.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipFunctionSetting = this.checkBoxEquipFunctionSetting.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsEquipUser = this.checkBoxEquipUser.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsInformation = this.checkBoxInformation.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsInforSystem = this.checkBoxInforSystem.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsInforAS = this.checkBoxInforAS.Checked;

            this.ParentForm.ParentForm.SaveUserGroupFile_Level1(this.ParentForm.ParentForm.CurrentUserGroup.Level1);
        }
        private void SaveUserGroupLevel2()
        {
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasic = this.checkBoxBasic.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicTime = this.checkBoxBasicTime.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicProduct = this.checkBoxBasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicDataBackup = this.checkBoxBasicDataBackup.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsBasicDataStatistics = this.checkBoxBasicDataStatistics.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiguration = this.checkBoxConfiguration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiCommunication = this.checkBoxConfiCommunication.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsConfiOption = this.checkBoxConfiOption.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystem = this.checkBoxSystem.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemCalibration = this.checkBoxSystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemJudgmentSetting = this.checkBoxSystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemSorterSetting = this.checkBoxSystemSorterSetting.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemAutoZero = this.checkBoxSystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemIOTest = this.checkBoxSystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsSystemExternalOutput = this.checkBoxSystemExternalOut.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipment = this.checkBoxEquipment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipUpdate = this.checkBoxEquipUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipInitialize = this.checkBoxEquipInitialize.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipFunctionSetting = this.checkBoxEquipFunctionSetting.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsEquipUser = this.checkBoxEquipUser.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsInformation = this.checkBoxInformation.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsInforSystem = this.checkBoxInforSystem.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsInforAS = this.checkBoxInforAS.Checked;

            this.ParentForm.ParentForm.SaveUserGroupFile_Level2(this.ParentForm.ParentForm.CurrentUserGroup.Level2);
        }
        private void SaveUserGroupLevel3()
        {
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasic = this.checkBoxBasic.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicTime = this.checkBoxBasicTime.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicProduct = this.checkBoxBasicProduct.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicDataBackup = this.checkBoxBasicDataBackup.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsBasicDataStatistics = this.checkBoxBasicDataStatistics.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiguration = this.checkBoxConfiguration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiCommunication = this.checkBoxConfiCommunication.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsConfiOption = this.checkBoxConfiOption.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystem = this.checkBoxSystem.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemCalibration = this.checkBoxSystemCalibration.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemJudgmentSetting = this.checkBoxSystemJudgment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemSorterSetting = this.checkBoxSystemSorterSetting.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemAutoZero = this.checkBoxSystemAutoZero.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemIOTest = this.checkBoxSystemIOTest.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsSystemExternalOutput = this.checkBoxSystemExternalOut.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipment = this.checkBoxEquipment.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipUpdate = this.checkBoxEquipUpdate.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipInitialize = this.checkBoxEquipInitialize.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipFunctionSetting = this.checkBoxEquipFunctionSetting.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsEquipUser = this.checkBoxEquipUser.Checked;

            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsInformation = this.checkBoxInformation.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsInforSystem = this.checkBoxInforSystem.Checked;
            this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsInforAS = this.checkBoxInforAS.Checked;

            this.ParentForm.ParentForm.SaveUserGroupFile_Level3(this.ParentForm.ParentForm.CurrentUserGroup.Level3);
        }

        private void UpdateUserDisplay(DataStore.UserGroup group)
        {
            if (group == DataStore.UserGroup.Level3Manager || group == DataStore.UserGroup.Level4Developer)
                this.radioButtonLevel3.Visible = true;
            else
                this.radioButtonLevel3.Visible = false;
        }
        private void UpdateUserGroupDisplay(UserGroupItem item)
        {
            // 기본
            this.checkBoxBasic.Checked = item.IsBasic;
            this.checkBoxBasicTime.Checked = item.IsBasicTime;
            this.checkBoxBasicProduct.Checked = item.IsBasicProduct;
            this.checkBoxBasicDataBackup.Checked = item.IsBasicDataBackup;
            this.checkBoxBasicDataStatistics.Checked = item.IsBasicDataStatistics;

            // 환경
            this.checkBoxConfiguration.Checked = item.IsConfiguration;
            this.checkBoxConfiCommunication.Checked = item.IsConfiCommunication;
            this.checkBoxConfiOption.Checked = item.IsConfiOption;

            // 시스템
            this.checkBoxSystem.Checked = item.IsSystem;
            this.checkBoxSystemCalibration.Checked = item.IsSystemCalibration;
            this.checkBoxSystemJudgment.Checked = item.IsSystemJudgmentSetting;
            this.checkBoxSystemSorterSetting.Checked = item.IsSystemSorterSetting;
            this.checkBoxSystemAutoZero.Checked = item.IsSystemAutoZero;
            this.checkBoxSystemIOTest.Checked = item.IsSystemIOTest;
            this.checkBoxSystemExternalOut.Checked = item.IsSystemExternalOutput;

            // 장비
            this.checkBoxEquipment.Checked = item.IsEquipment;
            this.checkBoxEquipUpdate.Checked = item.IsEquipUpdate;
            this.checkBoxEquipInitialize.Checked = item.IsEquipInitialize;
            this.checkBoxEquipFunctionSetting.Checked = item.IsEquipFunctionSetting;
            this.checkBoxEquipUser.Checked = item.IsEquipUser;

            // 정보
            this.checkBoxInformation.Checked = item.IsInformation;
            this.checkBoxInforSystem.Checked = item.IsInforSystem;
            this.checkBoxInforAS.Checked = item.IsInforAS;
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.radioButtonLevel1.Checked = true;
            this.radioButtonLevel2.Checked = false;
            this.radioButtonLevel3.Checked = false;

            this.UpdateUserGroupDisplay(this.ParentForm.ParentForm.CurrentUserGroup.Level1);
        }
        #endregion

        #region Event Handler
        private void radioButtonLevel1_Click(object sender, EventArgs e)
        {
            this.UpdateUserGroupDisplay(this.ParentForm.ParentForm.CurrentUserGroup.Level1);
        }
        private void radioButtonLevel2_Click(object sender, EventArgs e)
        {
            this.UpdateUserGroupDisplay(this.ParentForm.ParentForm.CurrentUserGroup.Level2);
        }
        private void radioButtonLevel3_Click(object sender, EventArgs e)
        {
            this.UpdateUserGroupDisplay(this.ParentForm.ParentForm.CurrentUserGroup.Level3);
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (this.radioButtonLevel1.Checked == true)
                this.SaveUserGroupLevel1();
            else if (this.radioButtonLevel2.Checked == true)
                this.SaveUserGroupLevel2();
            else if (this.radioButtonLevel3.Checked == true)
                this.SaveUserGroupLevel3();
        }

        private void buttonUserEditor_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }
        #endregion
    }
}