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

using INT69DB_2A_ImageDll;
using INT69DB_2A.DialogForms;
using SmartX;
using INT69DB_2A.Part11_UserManager;

namespace INT69DB_2A.Forms
{
    public partial class FormOption : Form
    {
        #region Field
        private FormMain m_ParentForm;
        #endregion

        #region Constructor
        public FormOption(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

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

        #region Method
        private void InitializeDesign()
        {
            ImageDll images = new ImageDll();

            if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
                this.labelTitle.Text = "Option Setting";
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.labelTitle.Text = "选项设置";

                this.buttonPart11.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonPart11.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));
                this.buttonStatistics.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnEnable));
                this.buttonStatistics.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnDisable));
            }
            else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.labelTitle.Text = "オプション設定";

                this.labelDescription.Text = "※ Part11 ON : [ログイン], [デㅡタバックアップ], [デㅡタ統計] 活性化";
            }
            else
            {

            }
        }
        private void InitializeControl()
        {
        }

        private void UpdateParameter()
        {
            // Part11
            if (this.ParentForm.SystemConfig.IsPart11 == true)
                this.buttonPart11.ButtonDown();
            else
                this.buttonPart11.ButtonUp();

            // 데이터 통계 기능 사용 유무
            if (this.ParentForm.SystemConfig.IsOptDataStatistics == true)
                this.buttonStatistics.ButtonDown();
            else
                this.buttonStatistics.ButtonUp();

            this.buttonSave.Visible = false;
        }

        public void DisplayRefresh()
        {
            this.UpdateParameter();

            this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormOption;
        }
        #endregion

        #region Event Handler
        private void Control_Click(object sender, EventArgs e)
        {
            if (this.buttonSave.Visible == false)
                this.buttonSave.Visible = true;

            if (this.buttonPart11.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
                this.buttonStatistics.ButtonDown();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            // Part11
            if (this.buttonPart11.ButtonStatus == SmartX.SmartButton.BUTSTATUS.DOWN)
            {
                this.ParentForm.SystemConfig.IsPart11 = true;
                this.ParentForm.SystemConfig.IsDataBackup = true;
                this.ParentForm.SystemConfig.IsLogin = true;
            }
            else
            {
                this.ParentForm.SystemConfig.IsPart11 = false;
                this.ParentForm.SystemConfig.IsDataBackup = false;
                this.ParentForm.SystemConfig.IsLogin = false;

                // Delete user list
                UserManager.UserManager_UserAllDel();
            }

            // 데이터 통계 기능 사용 유무
            if (this.buttonStatistics.ButtonStatus == SmartButton.BUTSTATUS.DOWN)
                this.ParentForm.SystemConfig.IsOptDataStatistics = true;
            else
                this.ParentForm.SystemConfig.IsOptDataStatistics = false;

            this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);

            DialogFormMessage myMsg = new DialogFormMessage(18, this.ParentForm.SystemConfig.Language);
            myMsg.ShowDialog();

            this.smartGroupBox1.Enabled = false;
            this.buttonBack.Visible = false;
            this.buttonSave.Visible = false;
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.ParentForm.ChildFormMenu.DisplayRefresh();
            ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
        }
        #endregion
    }
}