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

using ITC81DB_0H.DialogForms;
using ITC81DB_0H.Forms;
using ITC81DB_0H_ImageDll;

namespace ITC81DB_0H.Controls
{
    public partial class ControlCenterBasicProduct : UserControl
    {
        #region Field
        private FormMenu m_ParentForm;

        private int SelectedProductNo;
        private ProductItem SelectedProductItem;
        #endregion

        #region Constructor
        public ControlCenterBasicProduct(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.SystemConfig1.Language == DataStore.LanguageID.English)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundProduct));

                this.buttonItemNo.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoDisable));
                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundProduct));

                this.buttonItemNo.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormProductNoDisable));
                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormProductNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnFormProductNoUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
            {
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundProduct));

                this.buttonItemNo.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoDisable));
                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoUp));
            }
            else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundProduct));

                this.buttonItemNo.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerProductNoDisable));
                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerProductNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerProductNoUp));
            }
            else
            {
                this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundProduct));

                this.buttonItemNo.DisableImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoDisable));
                this.buttonItemNo.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoDown));
                this.buttonItemNo.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engProductNoUp));
            }
        }
        private void DefaultSetting()
        {
            this.SelectedProductNo = 1;
            this.SelectedProductItem = new ProductItem();

            if (this.listBoxProductList.Items.Count == 0)
            {
                this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
                this.AddProductList();
                this.listBoxProductList.SelectedIndex = this.SelectedProductNo - 1;
                this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);
            }
        }

        private void AddProductList()
        {
            Collection<string> productNames = new Collection<string>();

            this.ParentForm.ParentForm.LoadProductName(ref productNames);

            this.listBoxProductList.Items.Clear();

            for (int i = 0; i < productNames.Count; i++)
                this.listBoxProductList.Items.Add(productNames[i]);

        }
        private void DisplayControls(ProductItem item)
        {
            int iValue = 0;
            string sValue = "";

            if (this.SelectedProductItem == null && item == null)
                return;

            sValue = item.Number.ToString();
            if (this.buttonItemNo.Text != sValue)
                this.buttonItemNo.Text = sValue;

            sValue = item.Name;
            if (this.textBoxProductName.Text != sValue)
                this.textBoxProductName.Text = sValue;

            sValue = item.LotNo;
            if (this.textBoxLotNo.Text != sValue)
                this.textBoxLotNo.Text = sValue;

            if (this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable == true)
            {
                #region 바코드 사용 시
                if (this.SelectedProductNo == 1 || this.SelectedProductNo == 2)
                {
                    this.buttonNameEdit.Enabled = false;
                    this.buttonLotEdit.Enabled = false;
                }
                else
                {
                    this.buttonNameEdit.Enabled = true;
                    this.buttonLotEdit.Enabled = true;
                }
                #endregion
            }

            sValue = Helper.StringToDecimalPlaces(item.OverRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelOverRange.Text != sValue)
                this.labelOverRange.Text = sValue;

            sValue = Helper.StringToDecimalPlaces(item.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelPassRange.Text != sValue)
                this.labelPassRange.Text = sValue;

            sValue = Helper.StringToDecimalPlaces(item.UnderRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelUnderRange.Text != sValue)
                this.labelUnderRange.Text = sValue;

            sValue = Helper.StringToDecimalPlaces(item.TareRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            if (this.labelTareRange.Text != sValue)
                this.labelTareRange.Text = sValue;

            iValue = int.Parse(item.OverRange) - int.Parse(item.PassRange);
            sValue = Helper.StringToDecimalPlaces(iValue.ToString(), this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);
            sValue = string.Format("+{0}", sValue);
            if (this.labelDeviationOver.Text != sValue)
                this.labelDeviationOver.Text = sValue;

            iValue = int.Parse(item.PassRange) - int.Parse(item.UnderRange);
            sValue = string.Format("-{0}", Helper.StringToDecimalPlaces(iValue.ToString(), this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces));
            if (this.labelDeviationUnder.Text != sValue)
                this.labelDeviationUnder.Text = sValue;
        }

        public void DisplayRefresh(SystemStatus status)
        {
            this.buttonItemNo.Visible = true;

            this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.BasicProduct;
            this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.Menu);
            this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);
            
            this.smartKeyboard.Hide();
            this.buttonNameEdit.Enabled = true;
            this.buttonLotEdit.Enabled = true;
            this.textBoxProductName.Enabled = true;
            this.textBoxLotNo.Enabled = true;
            this.listBoxProductList.Enabled = true;

            this.buttonItemNo.Text = this.ParentForm.ParentForm.SystemConfig1.ProductNumber.ToString();
            this.SelectedProductNo = this.ParentForm.ParentForm.SystemConfig1.ProductNumber;

            if (this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable == true)
            {
                #region 바코드 사용 시
                if (this.SelectedProductNo == 1 || this.SelectedProductNo == 2)
                {
                    this.buttonNameEdit.Enabled = false;
                    this.buttonLotEdit.Enabled = false;
                }
                else
                {
                    this.buttonNameEdit.Enabled = true;
                    this.buttonLotEdit.Enabled = true;
                } 
                #endregion
            }

            this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
            this.listBoxProductList.SelectedIndex = this.SelectedProductNo - 1;
            this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);

            this.ParentForm.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);

            this.DisplayControls(this.SelectedProductItem);
        }
        #endregion

        #region Event Handler
        private void buttonProductNo_Click(object sender, EventArgs e)
        {
            string message = "";
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.buttonItemNo.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);
            myKeyPad.Location = new Point(280, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > 1000)
                {
                    // 입력범위를 확인하세요
                    message = string.Format("1 ~ {0}", 1000);
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.buttonItemNo.Text = myKeyPad.StringValue;
                    this.SelectedProductNo = myKeyPad.IntValue;

                    this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
                    this.listBoxProductList.SelectedIndex = this.SelectedProductNo - 1;
                    this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);

                    this.ParentForm.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);
                    
                    this.DisplayControls(this.SelectedProductItem);
                }
            }
        }
        private void buttonNameEdit_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(9, 176);
            this.smartKeyboard.Size = new Size(684, 274);
            this.smartKeyboard.Hide();

            this.smartKeyboard.TargetInputObject = this.textBoxProductName;
            this.smartKeyboard.Show();

            this.textBoxProductName.Select(this.textBoxProductName.Text.Length, 0);

            this.buttonNameEdit.Enabled = false;
            this.buttonLotEdit.Enabled = false;
            this.textBoxLotNo.Enabled = false;
            this.listBoxProductList.Enabled = false;
        }
        private void buttonLotEdit_Click(object sender, EventArgs e)
        {
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Location = new Point(9, 176);
            this.smartKeyboard.Size = new Size(684, 274);
            this.smartKeyboard.Hide();

            this.smartKeyboard.TargetInputObject = this.textBoxLotNo;
            this.smartKeyboard.Show();

            this.textBoxLotNo.Select(this.textBoxLotNo.Text.Length, 0);

            this.buttonNameEdit.Enabled = false;
            this.buttonLotEdit.Enabled = false;
            this.textBoxProductName.Enabled = false;
            this.listBoxProductList.Enabled = false;
        }

        private void textBoxProductName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.SelectedProductItem.Name = this.textBoxProductName.Text;
                this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].Name = this.textBoxProductName.Text;

                this.listBoxProductList.SelectedIndexChanged -= new EventHandler(this.listBoxProductList_SelectedIndexChanged);
                this.listBoxProductList.Items.Insert(this.SelectedProductItem.Number - 1, this.textBoxProductName.Text);
                this.listBoxProductList.Items.RemoveAt(this.SelectedProductItem.Number);
                this.listBoxProductList.SelectedIndex = this.SelectedProductItem.Number - 1;
                this.listBoxProductList.SelectedIndexChanged += new EventHandler(this.listBoxProductList_SelectedIndexChanged);

                e.Handled = true;
                this.smartKeyboard.Hide();
                this.smartKeyboard.OnHanYoungKeyChange -= new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
                if (this.ParentForm.ParentForm.IsCurrentKeyKorean == true)
                {
                    this.smartKeyboard.HanYoungKeyToggle();
                    this.ParentForm.ParentForm.IsCurrentKeyKorean = false;
                }
                this.smartKeyboard.OnHanYoungKeyChange += new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);

                this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxLotNo.Enabled = true;
                this.listBoxProductList.Enabled = true;

                this.ParentForm.ParentForm.ClearAlarm(0);
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;
                this.smartKeyboard.Hide();
                this.smartKeyboard.OnHanYoungKeyChange -= new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
                if (this.ParentForm.ParentForm.IsCurrentKeyKorean == true)
                {
                    this.smartKeyboard.HanYoungKeyToggle();
                    this.ParentForm.ParentForm.IsCurrentKeyKorean = false;
                }
                this.smartKeyboard.OnHanYoungKeyChange += new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
                this.ParentForm.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);
                this.DisplayControls(this.SelectedProductItem);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxLotNo.Enabled = true;
                this.listBoxProductList.Enabled = true;
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }
        private void textBoxLotNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.SelectedProductItem.LotNo = this.textBoxLotNo.Text;
                this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].LotNo = this.textBoxLotNo.Text;
                if(this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable == true)
                    this.ParentForm.ParentForm.CurrentBarcode.SetLotNo(this.ParentForm.ParentForm.CollectionProductItem,
                    this.ParentForm.ParentForm.ProductCount);

                e.Handled = true;
                this.smartKeyboard.Hide();
                this.smartKeyboard.OnHanYoungKeyChange -= new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
                if (this.ParentForm.ParentForm.IsCurrentKeyKorean == true)
                {
                    this.smartKeyboard.HanYoungKeyToggle();
                    this.ParentForm.ParentForm.IsCurrentKeyKorean = false;
                }
                this.smartKeyboard.OnHanYoungKeyChange += new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);

                this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxProductName.Enabled = true;
                this.listBoxProductList.Enabled = true;

                this.ParentForm.ParentForm.ClearAlarm(0);
            }
            else if (e.KeyChar == 27)
            {
                e.Handled = true;
                this.smartKeyboard.Hide();
                this.smartKeyboard.OnHanYoungKeyChange -= new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
                if (this.ParentForm.ParentForm.IsCurrentKeyKorean == true)
                {
                    this.smartKeyboard.HanYoungKeyToggle();
                    this.ParentForm.ParentForm.IsCurrentKeyKorean = false;
                }
                this.smartKeyboard.OnHanYoungKeyChange += new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
                this.ParentForm.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);
                this.DisplayControls(this.SelectedProductItem);

                this.buttonNameEdit.Enabled = true;
                this.buttonLotEdit.Enabled = true;
                this.textBoxProductName.Enabled = true;
                this.listBoxProductList.Enabled = true;
            }
            else if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == '*' || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\')
            {
                e.Handled = true;
            }
        }

        private void labelOverRange_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelOverRange.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces, 
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < Helper.StringToWeight(this.SelectedProductItem.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ClearAlarm(0);

                    this.labelOverRange.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.OverRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].OverRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);
                    this.DisplayControls(this.SelectedProductItem);
                }
            }
        }
        private void labelPassRange_Click(object sender, EventArgs e)
        {
            int digit = 0, temp = 0, range = 0;
            string value = "", feedbackValue = "";
            int oldUnderRangeDeviation = this.SelectedProductItem.UnderRangeDeviation;
            int oldOverRangeDeviation = this.SelectedProductItem.OverRangeDeviation;

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPassRange.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces, 
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() != DialogResult.OK)
                return;

            this.ParentForm.ParentForm.ClearAlarm(0);

            this.SelectedProductItem.PassRange = myKeyPad.StringValue.Replace(".", "");
            this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].PassRange = myKeyPad.StringValue.Replace(".", "");

            #region UnderRange
            temp = this.SelectedProductItem.PassRangeInt + oldUnderRangeDeviation;
            if (temp < 0)
                value = "0";
            else
                value = temp.ToString();

            this.SelectedProductItem.UnderRange = value;
            this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].UnderRange = value;
            #endregion

            #region OverRange
            if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 0)
                range = 9999;
            else
                range = 99999;
            // V6.2.0
            //if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 2)
            //    range = 1000000;
            //else if (this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces == 1)
            //    range = 100000;
            //else
            //    range = 10000;
            temp = this.SelectedProductItem.PassRangeInt + oldOverRangeDeviation;
            if (temp >= range)
                value = myKeyPad.StringValue.Replace(".", "");
            else
                value = temp.ToString();

            this.SelectedProductItem.OverRange = value;
            this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].OverRange = value;
            #endregion

            this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);
            this.DisplayControls(this.SelectedProductItem);
        }
        private void labelUnderRange_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelUnderRange.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces, 
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue > Helper.StringToWeight(this.SelectedProductItem.PassRange.ToString(), this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ClearAlarm(0);

                    this.labelUnderRange.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.UnderRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].UnderRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);

                    this.DisplayControls(this.SelectedProductItem);
                }
            }
        }
        private void labelDeviationOver_Click(object sender, EventArgs e)
        {
            int digit = 0;
            string sValue = "";
            double dValue = 0.0;

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDeviationOver.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces,
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                dValue = Helper.StringToWeight(this.SelectedProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces)
                       + myKeyPad.doubleValue;
                sValue = Helper.DoubleToString(dValue, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);

                if (dValue < Helper.StringToWeight(this.SelectedProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces))
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ClearAlarm(0);

                    this.labelDeviationOver.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.OverRange = sValue.Replace(".", "");
                    this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].OverRange = sValue.Replace(".", "");
                    this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);

                    this.DisplayControls(this.SelectedProductItem);
                }
            }
        }
        private void labelDeviationUnder_Click(object sender, EventArgs e)
        {
            int digit = 0;
            string sValue = "";
            double dValue = 0.0;

            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDeviationUnder.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces,
                false, this.ParentForm.ParentForm.SystemConfig1.Language);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                dValue = Helper.StringToWeight(this.SelectedProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces)
                       - Math.Abs(myKeyPad.doubleValue);
                sValue = Helper.DoubleToString(dValue, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces);

                if (dValue > Helper.StringToWeight(this.SelectedProductItem.PassRange, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces) || dValue < 0)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ClearAlarm(0);

                    this.labelDeviationUnder.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.UnderRange = sValue.Replace(".", "");
                    this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].UnderRange = sValue.Replace(".", "");
                    this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);

                    this.DisplayControls(this.SelectedProductItem);
                }
            }
        }
        private void labelTareRange_Click(object sender, EventArgs e)
        {
            DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelTareRange.Text, 5, this.ParentForm.ParentForm.SystemConfig1.DecimalPlaces, 
                false, this.ParentForm.ParentForm.SystemConfig1.Language);
            myKeyPad.Location = new Point(100, 90);

            if (myKeyPad.ShowDialog() == DialogResult.OK)
            {
                if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 99999)
                {
                    // 입력범위를 확인하세요
                    DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
                    myMsg.ShowDialog();
                }
                else
                {
                    this.ParentForm.ParentForm.ClearAlarm(0);

                    this.labelTareRange.Text = myKeyPad.StringValue;
                    this.SelectedProductItem.TareRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.CollectionProductItem[this.SelectedProductNo - 1].TareRange = myKeyPad.StringValue.Replace(".", "");
                    this.ParentForm.ParentForm.SaveProductFile(this.SelectedProductItem, this.SelectedProductNo - 1);
                }
            }
        }
        private void listBoxProductList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listBoxProductList.SelectedItem == null)
                return;

            this.ParentForm.ParentForm.ClearAlarm(0);

            this.SelectedProductNo = this.listBoxProductList.SelectedIndex + 1;
            this.buttonItemNo.Text = this.SelectedProductNo.ToString();

            if (this.ParentForm.ParentForm.SystemConfig1.IsBarcodeEnable == true)
            {
                if (this.SelectedProductNo == 1 || this.SelectedProductNo == 2)
                {
                    this.buttonNameEdit.Enabled = false;
                    this.buttonLotEdit.Enabled = false;
                }
                else
                {
                    this.buttonNameEdit.Enabled = true;
                    this.buttonLotEdit.Enabled = true;
                }
            }

            this.ParentForm.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);

            this.DisplayControls(this.SelectedProductItem);
        }

        private void smartKeyboard_OnHanYoungKeyChange(object sender, EventArgs e)
        {
            if (this.ParentForm.ParentForm.IsCurrentKeyKorean == false)
                this.ParentForm.ParentForm.IsCurrentKeyKorean = true;
            else
                this.ParentForm.ParentForm.IsCurrentKeyKorean = false;
        }
        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            this.smartKeyboard.Hide();
            this.smartKeyboard.OnHanYoungKeyChange -= new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
            if (this.ParentForm.ParentForm.IsCurrentKeyKorean == true)
            {
                this.smartKeyboard.HanYoungKeyToggle();
                this.ParentForm.ParentForm.IsCurrentKeyKorean = false;
            }
            this.smartKeyboard.OnHanYoungKeyChange += new EventHandler(this.smartKeyboard_OnHanYoungKeyChange);
            this.ParentForm.ParentForm.LoadProductFile(ref this.SelectedProductItem, this.SelectedProductNo - 1);
            this.DisplayControls(this.SelectedProductItem);
            this.buttonNameEdit.Enabled = true;
            this.buttonLotEdit.Enabled = true;
            this.textBoxProductName.Enabled = true;
            this.textBoxLotNo.Enabled = true;
            this.listBoxProductList.Enabled = true;
        }
        #endregion
    }
}