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 INT69DC_7C.Forms;
using INT69DC_7C.DialogForms;
using INT69DC_ImageDll;

namespace INT69DC_7C.Controls
{
    public partial class ControlChildformSystemSetting : UserControl
    {
        #region Field
        private FormSystemSetting m_ParentForm;
        #endregion

        #region Constructor
        public ControlChildformSystemSetting(FormSystemSetting parent)
        {
            InitializeComponent();

            this.ParentForm = parent;

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

        #region Property
        public FormSystemSetting 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.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
            {

            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
            {
                this.groupBoxJudgment.Text = "Setting Judgment2";
                this.labelStaticForcedZeroDelayTime.Text = "ForcedZeroDelayTime";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
                this.groupBoxJudgment.Text = "判断设置2";
                this.labelStaticForcedZeroDelayTime.Text = "零延迟时间";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
                this.groupBoxJudgment.Text = "Nastavení rozhodnutí2";
                this.labelStaticForcedZeroDelayTime.Font = new Font("새굴림", 9F, System.Drawing.FontStyle.Bold);
                this.labelStaticForcedZeroDelayTime.Text = "Vynucená doba nulového zpoždění";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
            {
                this.groupBoxJudgment.Text = "Tascheneinstellung2";
                this.labelStaticForcedZeroDelayTime.Font = new Font("새굴림", 9F, System.Drawing.FontStyle.Bold);
                this.labelStaticForcedZeroDelayTime.Text = "Erzwungene Null-Verzögerungszeit";
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
            {
                this.groupBoxJudgment.Text = "判定設定2";
                this.labelStaticForcedZeroDelayTime.Font = new Font("새굴림", 9F, System.Drawing.FontStyle.Bold);
                this.labelStaticForcedZeroDelayTime.Text = "強制ゼロ遅延時間";
            }
            else
            {

            }
        }
        private void DefaultSetting()
        {
        }

        public void DisplayRefresh(JudgmentSetItem item)
        {
            string sValue = "";

            if (item == null)
                return;

            sValue = item.ForcedZeroDelayTime.ToString();
            if (this.labelForcedZeroDelayTime.Text != sValue)
                this.labelForcedZeroDelayTime.Text = sValue;
        }
        #endregion

        #region Event Handler
        private void labelForcedZeroDelayTime_Click(object sender, EventArgs e)
        {
            string value = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelForcedZeroDelayTime.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 9999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.labelForcedZeroDelayTime.Text = myKeyPad.StringValue;
                    this.ParentForm.SelectedJudgmentSetItem.ForcedZeroDelayTime = myKeyPad.IntValue;

                    value = Helper.StringZeroFillDigits4(this.labelForcedZeroDelayTime.Text);
                    this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._4501_ForcedZeroDelayTime, value);

                    this.ParentForm.ParentForm.SaveJudgmentSetFile(this.ParentForm.SelectedJudgmentSetItem, this.ParentForm.SelectedProductNo - 1);
                }
            }
        } 
        #endregion
    }
}
