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 System.Threading;

using INT51DB.DialogForms;
using INT51DB.Forms;
using INT51DB_ImageDll;

namespace INT51DB.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 == DataStore.LanguageID.English)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
            {
            }
            else
            {
            }
        }
        private void DefaultSetting()
        {
            this.labelDisplayVer.Text = "5.1.0";
            this.labelSerialNo.Text = this.ParentForm.ParentForm.SystemConfig.SerialNumber;
        }

        public void UpdateMainBoardVersionDisplay(string version)
        {
            StringBuilder sb;

            sb = new StringBuilder(version);
            sb.Insert(sb.Length - 1, ".");
            sb.Insert(sb.Length - 3, ".");
            this.labelControlVer.Text = sb.ToString();
        }

        public void DisplayRefresh(DataStore.UserGroup group)
        {
            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.InforSystem;
            this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);
            Thread.Sleep(100);
            this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress.MainProgramVersion1, "");
        }
        #endregion

        #region Event Handler
        private void labelSerialNo_Click(object sender, EventArgs e)
        {
            if (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group == DataStore.UserGroup.Level4Developer)
            {
                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.SaveSystemConfigurationFile(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
    }
}
