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 INT_PT002.DataStore;
using INT_PT002.DialogForms;

namespace INT_PT002.Forms
{
    public partial class FormConfiguration : Form
    {
        #region Field
        private FormMain m_ParentForm;
        #endregion
        
        #region Constructor
        public FormConfiguration(FormMain parent)
        {
            InitializeComponent();

            this.ParentForm = parent;
        } 
        #endregion

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

        #region Method
        public void UpdateDisplayTime()
        {
            this.labelTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public void DisplayRefresh()
        {
            string value = "";

            //value = Helper.StringToDecimalPlaces(this.ParentForm.SystemConfig.OverRange, this.ParentForm.DecimalPlaces4);
            //if (this.labelOverRange.Text != value)
            //    this.labelOverRange.Text = value;

            //value = this.ParentForm.SystemConfig.VacuumStartTime.ToString();
            //if (this.labelVacuumStartTime.Text != value)
            //    this.labelVacuumStartTime.Text = value;

            //value = this.ParentForm.SystemConfig.VacuumHoldTime.ToString();
            //if (this.labelVacuumHoldTime.Text != value)
            //    this.labelVacuumHoldTime.Text = value;

            //value = this.ParentForm.SystemConfig.VacuumBreakTime.ToString();
            //if (this.labelVacuumBreakTime.Text != value)
            //    this.labelVacuumBreakTime.Text = value;

            value = this.ParentForm.SystemConfig.CHART1_DRAW_STEP.ToString();
            if (this.labelChart1DrawStep.Text != value)
                this.labelChart1DrawStep.Text = value;

            value = this.ParentForm.SystemConfig.CHART2_DRAW_STEP.ToString();
            if (this.labelChart2DrawStep.Text != value)
                this.labelChart2DrawStep.Text = value;
        }
        #endregion

        #region Event Handler
        private void buttonMainDisplay_Click(object sender, EventArgs e)
        {
            this.ParentForm.FormChange((int)Define.E_FormStore.FormMainDisplay);
        }

        //private void labelOverRange_Click(object sender, EventArgs e)
        //{
        //    DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.labelOverRange.Text, 6, 4, false);

        //    if (myKeypad.ShowDialog() == DialogResult.OK)
        //    {
        //        this.labelOverRange.Text = myKeypad.StringValue;
        //        this.ParentForm.SystemConfig.OverRange = myKeypad.StringValue.Replace(".", "");

        //        this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
        //        this.ParentForm.TransferDataStream6(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._2301_OverRange, this.ParentForm.SystemConfig.OverRange);
        //    }
        //}
        //private void labelVacuumStartTime_Click(object sender, EventArgs e)
        //{
        //    DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.labelVacuumStartTime.Text, 3, 0, false);

        //    if (myKeypad.ShowDialog() == DialogResult.OK)
        //    {
        //        this.labelVacuumStartTime.Text = myKeypad.StringValue;
        //        this.ParentForm.SystemConfig.VacuumStartTime = myKeypad.IntValue;

        //        this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
        //        this.ParentForm.TransferDataStream4(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5504_VacuumStartTime, myKeypad.StringValue);
        //    }
        //}
        //private void labelVacuumHoldTime_Click(object sender, EventArgs e)
        //{
        //    DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.labelVacuumHoldTime.Text, 3, 0, false);

        //    if (myKeypad.ShowDialog() == DialogResult.OK)
        //    {
        //        this.labelVacuumHoldTime.Text = myKeypad.StringValue;
        //        this.ParentForm.SystemConfig.VacuumHoldTime = myKeypad.IntValue;

        //        this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
        //        this.ParentForm.TransferDataStream4(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5505_VacuumHoldTime, myKeypad.StringValue);
        //    }
        //}
        //private void labelVacuumBreakTime_Click(object sender, EventArgs e)
        //{
        //    DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.labelVacuumBreakTime.Text, 3, 0, false);

        //    if (myKeypad.ShowDialog() == DialogResult.OK)
        //    {
        //        this.labelVacuumBreakTime.Text = myKeypad.StringValue;
        //        this.ParentForm.SystemConfig.VacuumBreakTime = myKeypad.IntValue;

        //        this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
        //        this.ParentForm.TransferDataStream4(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._5506_VacuumBreakTime, myKeypad.StringValue);
        //    }
        //}
        private void labelChart1DrawStep_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel11.Text, this.labelChart1DrawStep.Text, 2, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue == 0)
                    return;

                this.labelChart1DrawStep.Text = myKeypad.StringValue;
                this.ParentForm.SystemConfig.CHART1_DRAW_STEP = myKeypad.IntValue;

                this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
            }
        }
        private void labelChart2DrawStep_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeypad = new DialogFormNumKeyPad(this.smartLabel11.Text, this.labelChart2DrawStep.Text, 2, 0, false);

            if (myKeypad.ShowDialog() == DialogResult.OK)
            {
                if (myKeypad.IntValue == 0)
                    return;

                this.labelChart2DrawStep.Text = myKeypad.StringValue;
                this.ParentForm.SystemConfig.CHART2_DRAW_STEP = myKeypad.IntValue;

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

        private void buttonOrigin_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorOrigin, CommunicationID.SubBoardAll);
        }
        private void buttonAlarmReset_1W_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorAlarmReset, CommunicationID.SubBoard2);
        }
        private void buttonMove1_1W_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorStep, CommunicationID.SubBoard2);
        }
        private void buttonAlarmReset_4W_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorAlarmReset, CommunicationID.SubBoard1);
        }
        private void buttonMove1_4W_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorMove1, CommunicationID.SubBoard1);
        }
        private void buttonMove2_4W_Click(object sender, EventArgs e)
        {
            this.ParentForm.TransferData(CommunicationCommand.MotorMove2, CommunicationID.SubBoard1);
        }
        #endregion
    }
}