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_2.DialogForms;
using ITC81DB_2.Forms;
using ITC81DB_2_ImageDll;

namespace ITC81DB_2.Controls
{
    public partial class ControlCenterInforSystem : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;
        #endregion

        #region Constructor
        public ControlCenterInforSystem(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()
        {
            Class1 images = new Class1();

            if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.English)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Chinese)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == Define.E_LanguageID.Spanish)
            {
            }
            else
            {
            }
        }
        private void DefaultSetting()
        {
            this.labelSerialNo.Text = this.ParentForm.ParentForm.SystemConfig.SerialNumber;
            this.labelDisplayVer.Text = "3.2.0";
        }

        public void UpdateMainBoardVersionDisplay(string version)
        {
            StringBuilder sb;

            if (version.Length < 4)
                return;

            sb = new StringBuilder(version);
            sb.Insert(sb.Length - 1, ".");
            sb.Insert(sb.Length - 3, ".");

            this.labelControlVer.Text = sb.ToString();
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.InforSystem;
            this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);

            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._1501_ProgramVersion, "");
        }
        #endregion

        #region Event Handler
        private void labelSerialNo_Click(object sender, EventArgs e)
        {
            DialogFormPasswordKeyPad password = new DialogFormPasswordKeyPad(this.ParentForm.ParentForm.SystemConfig.Language, this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUserPasswordType);
            DialogResult dialogResult = password.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {

                this.textBoxSerialNo.Visible = true;
                this.smartKeyboard1.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
                this.smartKeyboard1.Left = 15;
                this.smartKeyboard1.Top = 118;
                this.smartKeyboard1.Width = 680;
                this.smartKeyboard1.Height = 268;
                this.smartKeyboard1.Hide();

                this.smartKeyboard1.TargetInputObject = this.textBoxSerialNo;
                this.textBoxSerialNo.Text = this.labelSerialNo.Text;

                this.smartKeyboard1.Show();
            }
        }

        private void smartKeyboard1_OnXKeyClick(object sender, EventArgs e)
        {
            this.smartKeyboard1.Hide();
            this.textBoxSerialNo.Text = this.labelSerialNo.Text;

            this.textBoxSerialNo.Visible = false;
        }

        private void textBoxSerialNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                e.Handled = true;

                this.smartKeyboard1.Hide();

                this.textBoxSerialNo.Visible = false;

                this.labelSerialNo.Text = this.textBoxSerialNo.Text.Trim();

                this.ParentForm.ParentForm.SystemConfig.SerialNumber = this.labelSerialNo.Text;
                this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig);
            }
            else if (e.KeyChar == 27) // ESC 눌렀을 때
            {
                e.Handled = true;

                this.smartKeyboard1.Hide();
                this.textBoxSerialNo.Text = this.labelSerialNo.Text;

                this.textBoxSerialNo.Visible = false;
            }
        }
        #endregion
    }
}
